* graphwidget.c: fixed a bug where we'd divide by 0 if min and max x and y were the...
[scdataviz] / graphwidget.c
index 4ecc55a..beba3c9 100644 (file)
@@ -26,7 +26,7 @@
 **  at http://gnomejournal.org/article/34/writing-a-widget-using-cairo-and-gtk28
 
 ** Started on  Thu Jul 17 10:51:32 2008 Johnny Q. Hacker
 **  at http://gnomejournal.org/article/34/writing-a-widget-using-cairo-and-gtk28
 
 ** Started on  Thu Jul 17 10:51:32 2008 Johnny Q. Hacker
-** Last update Sun May 12 01:17:25 2002 Speed Blue
+** Last update Thu Oct  8 17:13:50 2009 Johnny Q. Hacker
 */
 
 #include <graphwidget.h>
 */
 
 #include <graphwidget.h>
@@ -178,8 +178,8 @@ static void draw(GtkWidget *graph, cairo_t *cr) {
   double xoffset = (gw->graph->points->len == 1)? (-minx/2) : (-minx);
   double yoffset = (gw->graph->points->len == 1)? (-miny/2) : (-miny);
   /*Finish up our context information.*/
   double xoffset = (gw->graph->points->len == 1)? (-minx/2) : (-minx);
   double yoffset = (gw->graph->points->len == 1)? (-miny/2) : (-miny);
   /*Finish up our context information.*/
-  cxt.xscaling = (gw->graph->points->len == 1)? cxt.xmax : (cxt.xmax/(maxx - minx));
-  cxt.yscaling = (gw->graph->points->len == 1)? cxt.ymax : (cxt.ymax/(maxy - miny));
+  cxt.xscaling = (gw->graph->points->len == 1)? cxt.xmax : (cxt.xmax/(((maxx - minx)==0)?1:(maxx-minx)));
+  cxt.yscaling = (gw->graph->points->len == 1)? cxt.ymax : (cxt.ymax/(((maxy - miny)==0)?1:(maxy-miny)));
   cxt.xoffset = (gw->graph->points->len == 1)? (-minx/2) : (-minx);
   cxt.yoffset = (gw->graph->points->len == 1)? (-miny/2) : (-miny);
   cairo_matrix_translate(&(cxt.data_xlat), xoffset, yoffset);
   cxt.xoffset = (gw->graph->points->len == 1)? (-minx/2) : (-minx);
   cxt.yoffset = (gw->graph->points->len == 1)? (-miny/2) : (-miny);
   cairo_matrix_translate(&(cxt.data_xlat), xoffset, yoffset);
@@ -188,7 +188,7 @@ static void draw(GtkWidget *graph, cairo_t *cr) {
   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));
   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
+  #endif
   double offset_height =  ((width>=height)?height*INSET_PERCENT:0);;
   double offset_width = ((height>=width)?width*INSET_PERCENT:0); 
   double inset_height = height - offset_height;
   double offset_height =  ((width>=height)?height*INSET_PERCENT:0);;
   double offset_width = ((height>=width)?width*INSET_PERCENT:0); 
   double inset_height = height - offset_height;