LIST: Remove WEIGHT subcommand.
[pspp-builds.git] / src / output / charts / cartesian.c
index ffa6e3c5323c5002d90b7c6868e67a88ef94c936..eabcf516e8e1cdc7b84a148646c3aef38de956bc 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <output/charts/cartesian.h>
 
+#include <cairo/cairo.h>
 #include <math.h>
 #include <assert.h>
 
 #include <output/charts/plot-chart.h>
 #include <libpspp/compiler.h>
 
-struct dataset
+#include "xalloc.h"
+
+/* Start a new vector called NAME */
+void
+chart_vector_start (cairo_t *cr, struct chart_geometry *geom, const char *name)
 {
-  int n_data;
-  const char *label;
-};
+  const struct chart_colour *colour;
 
+  cairo_save (cr);
 
-#define DATASETS 2
+  colour = &data_colour[geom->n_datasets % N_CHART_COLOURS];
+  cairo_set_source_rgb (cr,
+                        colour->red / 255.0,
+                        colour->green / 255.0,
+                        colour->blue / 255.0);
 
-static const struct dataset dataset[DATASETS] =
-  {
-    { 13, "male"},
-    { 11, "female"},
-  };
+  geom->n_datasets++;
+  geom->dataset = xrealloc (geom->dataset,
+                            geom->n_datasets * sizeof (*geom->dataset));
 
+  geom->dataset[geom->n_datasets - 1] = strdup (name);
+}
 
 /* Plot a data point */
 void
-chart_datum (plPlotter *lp, const struct chart_geometry *geom,
+chart_datum (cairo_t *cr, const struct chart_geometry *geom,
              int dataset UNUSED, double x, double y)
 {
   double x_pos = (x - geom->x_min) * geom->abscissa_scale + geom->data_left;
   double y_pos = (y - geom->y_min) * geom->ordinate_scale + geom->data_bottom;
 
-  pl_savestate_r (lp);
-  pl_fmarker_r (lp, x_pos, y_pos, 6, 15);
-  pl_restorestate_r (lp);
+  chart_draw_marker (cr, x_pos, y_pos, MARKER_SQUARE, 15);
+}
+
+void
+chart_vector_end (cairo_t *cr, struct chart_geometry *geom)
+{
+  cairo_stroke (cr);
+  cairo_restore (cr);
+  geom->in_path = false;
 }
 
+/* Plot a data point */
+void
+chart_vector (cairo_t *cr, struct chart_geometry *geom, double x, double y)
+{
+  const double x_pos =
+    (x - geom->x_min) * geom->abscissa_scale + geom->data_left ;
+
+  const double y_pos =
+    (y - geom->y_min) * geom->ordinate_scale + geom->data_bottom ;
+
+  if (geom->in_path)
+    cairo_line_to (cr, x_pos, y_pos);
+  else
+    {
+      cairo_move_to (cr, x_pos, y_pos);
+      geom->in_path = true;
+    }
+}
+
+
+
 /* Draw a line with slope SLOPE and intercept INTERCEPT.
    between the points limit1 and limit2.
    If lim_dim is CHART_DIM_Y then the limit{1,2} are on the
    y axis otherwise the x axis
 */
 void
-chart_line(plPlotter *lp, const struct chart_geometry *geom,
+chart_line(cairo_t *cr, const struct chart_geometry *geom,
            double slope, double intercept,
           double limit1, double limit2, enum CHART_DIM lim_dim)
 {
@@ -89,7 +124,7 @@ chart_line(plPlotter *lp, const struct chart_geometry *geom,
   x1 = (x1 - geom->x_min) * geom->abscissa_scale + geom->data_left;
   x2 = (x2 - geom->x_min) * geom->abscissa_scale + geom->data_left;
 
-  pl_savestate_r (lp);
-  pl_fline_r (lp, x1, y1, x2, y2);
-  pl_restorestate_r (lp);
+  cairo_move_to (cr, x1, y1);
+  cairo_line_to (cr, x2, y2);
+  cairo_stroke (cr);
 }