output: Use Cairo and Pango to draw charts, instead of libplot.
[pspp-builds.git] / src / output / charts / cartesian.c
index e4f8e69bdb7c51ba5fac6a4816177b5d1bae6a53..74840c30c5254e949d610a839d54047a0b46a093 100644 (file)
@@ -1,34 +1,33 @@
-/* PSPP - computes sample statistics.
-   Copyright (C) 2004 Free Software Foundation, Inc.
-   Written by John Darrington <john@darrington.wattle.id.au>
+/* PSPP - a program for statistical analysis.
+   Copyright (C) 2004, 2009 Free Software Foundation, Inc.
 
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
 
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301, USA. */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 
+#include <config.h>
+
+#include <output/charts/cartesian.h>
+
+#include <cairo/cairo.h>
 #include <math.h>
 #include <assert.h>
 
 #include <output/chart.h>
-
+#include <output/chart-provider.h>
 #include <output/charts/plot-chart.h>
-#include <output/charts/cartesian.h>
 #include <libpspp/compiler.h>
 
-
-
 struct dataset
 {
   int n_data;
@@ -38,7 +37,7 @@ struct dataset
 
 #define DATASETS 2
 
-static const struct dataset dataset[DATASETS] = 
+static const struct dataset dataset[DATASETS] =
   {
     { 13, "male"},
     { 11, "female"},
@@ -47,46 +46,32 @@ static const struct dataset dataset[DATASETS] =
 
 /* Plot a data point */
 void
-chart_datum(struct chart *ch, int dataset UNUSED, double x, double y)
+chart_datum (cairo_t *cr, const struct chart_geometry *geom,
+             int dataset UNUSED, double x, double y)
 {
-  if ( ! ch ) 
-    return ;
+  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;
 
-  {
-    const double x_pos = 
-      (x - ch->x_min) * ch->abscissa_scale + ch->data_left ; 
-
-    const double y_pos = 
-      (y - ch->y_min) * ch->ordinate_scale + ch->data_bottom ;
-
-    pl_savestate_r(ch->lp);    
-  
-    pl_fmarker_r(ch->lp, x_pos, y_pos, 6, 15);
-
-    pl_restorestate_r(ch->lp);    
-  }
+  chart_draw_marker (cr, x_pos, y_pos, MARKER_SQUARE, 15);
 }
 
 /* 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 
+   If lim_dim is CHART_DIM_Y then the limit{1,2} are on the
    y axis otherwise the x axis
 */
 void
-chart_line(struct chart *ch, double slope, double intercept, 
+chart_line(cairo_t *cr, const struct chart_geometry *geom,
+           double slope, double intercept,
           double limit1, double limit2, enum CHART_DIM lim_dim)
 {
   double x1, y1;
-  double x2, y2 ;
-
-  if ( ! ch ) 
-    return ;
+  double x2, y2;
 
-
-  if ( lim_dim == CHART_DIM_Y ) 
+  if ( lim_dim == CHART_DIM_Y )
     {
-      x1 = ( limit1 - intercept ) / slope ;
-      x2 = ( limit2 - intercept ) / slope ;
+      x1 = ( limit1 - intercept ) / slope;
+      x2 = ( limit2 - intercept ) / slope;
       y1 = limit1;
       y2 = limit2;
     }
@@ -98,15 +83,12 @@ chart_line(struct chart *ch, double slope, double intercept,
       y2 = slope * x2 + intercept;
     }
 
-  y1 = (y1 - ch->y_min) * ch->ordinate_scale + ch->data_bottom ;
-  y2 = (y2 - ch->y_min) * ch->ordinate_scale + ch->data_bottom ;
-  x1 = (x1 - ch->x_min) * ch->abscissa_scale + ch->data_left ;
-  x2 = (x2 - ch->x_min) * ch->abscissa_scale + ch->data_left ;
-
-  pl_savestate_r(ch->lp);    
-
-  pl_fline_r(ch->lp, x1, y1, x2, y2);
+  y1 = (y1 - geom->y_min) * geom->ordinate_scale + geom->data_bottom;
+  y2 = (y2 - geom->y_min) * geom->ordinate_scale + geom->data_bottom;
+  x1 = (x1 - geom->x_min) * geom->abscissa_scale + geom->data_left;
+  x2 = (x2 - geom->x_min) * geom->abscissa_scale + geom->data_left;
 
-  pl_restorestate_r(ch->lp);    
-  
+  cairo_move_to (cr, x1, y1);
+  cairo_line_to (cr, x2, y2);
+  cairo_stroke (cr);
 }