* Well, the groundwork has been laid, but now I can't see my data anymore.
[scdataviz] / graphwidget.c
index 95b9722..f4a7d70 100644 (file)
@@ -79,6 +79,11 @@ static void draw_lines(gpointer data, gpointer user_data) {
   cairo_curve_to(cxt->cr, p1_x, p1_y, p2_x, p2_y, p3_x, p3_y);
 }
 
+static void draw_axis(gpointer data, gpointer user_data) {
+  struct graph_axis *xs = data;
+  struct drawing_context *cxt = user_data;
+}
+
 static void draw(GtkWidget *graph, cairo_t *cr) {
   struct drawing_context cxt;
   GraphWidget *gw = GRAPH_WIDGET(graph);
@@ -90,15 +95,27 @@ static void draw(GtkWidget *graph, cairo_t *cr) {
   double y0=graph->allocation.y;
   double height=graph->allocation.height;
   double width=graph->allocation.width;
+  double minx = gw->graph->minx;
+  double maxx = gw->graph->maxx;
+  double miny = gw->graph->miny;
+  double maxy = gw->graph->maxy;
+  if(gw->graph->xaxis != NULL) {
+    minx = gw->graph->xaxis->major_start;
+    maxx = gw->graph->xaxis->major_start + gw->graph->xaxis->major_step*gw->graph->xaxis->major;
+  }
+  if(gw->graph->yaxis != NULL) {
+    miny = gw->graph->yaxis->major_start;
+    maxy = gw->graph->yaxis->major_start + gw->graph->yaxis->major_step*gw->graph->yaxis->major;
+  }
   cxt.widget = graph;
   cxt.cr = cr;
   cxt.radius = 0.01;
-  cxt.xscaling = (gw->graph->points->len == 1)? 1 : (1/(gw->graph->maxx - gw->graph->minx));
-  cxt.yscaling = (gw->graph->points->len == 1)? 1 : (1/(gw->graph->maxy - gw->graph->miny));
-  cxt.xoffset = (gw->graph->points->len == 1)? (-gw->graph->minx/2) : (-gw->graph->minx);
-  cxt.yoffset = (gw->graph->points->len == 1)? (-gw->graph->miny/2) : (-gw->graph->miny);
+  cxt.xscaling = (gw->graph->points->len == 1)? 1 : (1/(maxx - minx));
+  cxt.yscaling = (gw->graph->points->len == 1)? 1 : (1/(maxy - miny));
+  cxt.xoffset = (gw->graph->points->len == 1)? (-minx/2) : (-minx);
+  cxt.yoffset = (gw->graph->points->len == 1)? (-miny/2) : (-miny);
   #ifdef DEBUG
-  fprintf(stderr, "minx=%g, maxx=%g, miny=%g, maxy=%g, xscaling=%g, yscaling=%g, xoffset=%g, yoffset=%g\n", gw->graph->minx, gw->graph->maxx, gw->graph->miny, gw->graph->maxy, cxt.xscaling, cxt.yscaling, cxt.xoffset, cxt.yoffset);
+  fprintf(stderr, "minx=%g, maxx=%g, miny=%g, maxy=%g, xscaling=%g, yscaling=%g, xoffset=%g, yoffset=%g\n", minx, maxx, miny, maxy, cxt.xscaling, cxt.yscaling, cxt.xoffset, cxt.yoffset);
   fprintf(stderr, "x0=%g, y0=%g, width=%g, height=%g\n", x0, y0, height, width);
   fprintf(stderr, "translate=(%g, %g)\n", x0 + ((width>height)?(width-height)/2.0:0), y0+((width > height)?height:width) + ((height>width)?(height-width)/2.0:0));
 #endif