} acre_data_point_2d_t;
struct _acre_data {
+ /* The name of this data set. */
char *name;
+ /* Minimum and mximum extents of data. */
acre_data_point_2d_t min;
acre_data_point_2d_t max;
+ /* The data itself. */
acre_data_point_2d_t *points;
unsigned int points_size;
unsigned int num_points;
+
+ /* The names of data points (if any).
+ *
+ * This array is indexed with the same index as the 'points' array
+ * to provide names for points. It is legal for this array to be
+ * NULL or smaller than 'points', (in which case, the
+ * corresponding points simply have no names).
+ */
+ char **names;
+ unsigned int names_size;
+ unsigned int num_names;
};
typedef struct _acre_axis {
acre->font = NULL;
acre->colors = NULL;
acre->num_colors = 0;
+ acre->colors_size = 0;
acre->width = 0;
acre->height = 0;
{
PangoLayout *layout;
+ if (text == NULL)
+ text = "";
+
layout = pango_cairo_create_layout (acre->cr);
pango_layout_set_font_description (layout, acre->font);
pango_layout_set_text (layout, text, -1);
title_layout = _create_layout (acre, acre->title);
pango_layout_set_font_description (title_layout, title_font);
+ pango_font_description_free (title_font);
x_axis_layout = _create_layout (acre, acre->x_axis.label);
y_axis_layout = _create_layout (acre, acre->y_axis.label);
void
acre_data_destroy (acre_data_t *data)
{
+ unsigned i;
+
+ for (i = 0; i < data->num_names; i++) {
+ if (data->names[i])
+ free (data->names[i]);
+ }
+ free (data->names);
+
+ free (data->name);
+
free (data->points);
free (data);
data->num_points++;
}
+
+/* Add a datapoint with a name to the given dataset. */
+void
+acre_data_add_point_2d_named (acre_data_t *data, double x, double y, const char *name)
+{
+ unsigned i;
+
+ acre_data_add_point_2d (data, x, y);
+
+ if (data->names_size < data->points_size) {
+ data->names_size = data->points_size;
+ data->names = xrealloc_ab (data->names,
+ data->names_size,
+ sizeof (char *));
+ }
+
+ /* Initialize any newly-created holes in the array to NULL. */
+ for (i = data->num_names; i < data->num_points - 1; i++)
+ data->names[i] = NULL;
+
+ data->num_names = data->num_points;
+
+ data->names[data->num_names - 1] = xstrdup (name);
+}