/* PSPP - a program for statistical analysis.
- Copyright (C) 2004 Free Software Foundation, Inc.
+ 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
#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>
+#include "xalloc.h"
/* Start a new vector called NAME */
void
-chart_vector_start (struct chart *ch, const char *name)
+chart_vector_start (cairo_t *cr, struct chart_geometry *geom, const char *name)
{
- if ( ! ch )
- return ;
+ const struct chart_colour *colour;
- pl_savestate_r (ch->lp);
+ cairo_save (cr);
- pl_colorname_r (ch->lp, data_colour [ch->n_datasets % N_CHART_COLOURS]);
+ 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);
- ch->n_datasets++;
- ch->dataset = xrealloc (ch->dataset, ch->n_datasets * sizeof (*ch->dataset));
+ geom->n_datasets++;
+ geom->dataset = xrealloc (geom->dataset,
+ geom->n_datasets * sizeof (*geom->dataset));
- ch->dataset[ch->n_datasets - 1] = strdup (name);
+ geom->dataset[geom->n_datasets - 1] = strdup (name);
}
/* 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 ;
-
- {
- const double x_pos =
- (x - ch->x_min) * ch->abscissa_scale + ch->data_left ;
+ 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 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);
}
void
-chart_vector_end (struct chart *ch)
+chart_vector_end (cairo_t *cr, struct chart_geometry *geom)
{
- pl_endpath_r (ch->lp);
- pl_colorname_r (ch->lp, "black");
- ch->in_path = false;
- pl_restorestate_r (ch->lp);
+ cairo_stroke (cr);
+ cairo_restore (cr);
+ geom->in_path = false;
}
/* Plot a data point */
void
-chart_vector (struct chart *ch, double x, double y)
+chart_vector (cairo_t *cr, struct chart_geometry *geom, double x, double y)
{
- if ( ! ch )
- return ;
-
- {
- 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 ;
-
- if ( ch->in_path)
- pl_fcont_r (ch->lp, x_pos, y_pos);
- else
- {
- pl_fmove_r (ch->lp, x_pos, y_pos);
- ch->in_path = true;
- }
- }
+ 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;
+ }
}
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 )
{
- x1 = ( limit1 - intercept ) / slope ;
- x2 = ( limit2 - intercept ) / slope ;
+ x1 = ( limit1 - intercept ) / slope;
+ x2 = ( limit2 - intercept ) / slope;
y1 = limit1;
y2 = limit2;
}
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);
}