From: trelane@digitasaru.net Date: Fri, 9 Oct 2009 00:15:04 +0000 (-0500) Subject: * graphwidget.c: fixed a bug where we'd divide by 0 if min and max x and y were the... X-Git-Url: http://git.maemo.org/git/?p=scdataviz;a=commitdiff_plain;h=b5cfdf4d4f01bf9f8def7d69fd58e254886ed2d5 * graphwidget.c: fixed a bug where we'd divide by 0 if min and max x and y were the same. NOTE that this section of code is getting very, very, very kludgey. * graphwidget.h: not much of a change. * scdataviz.c: pointed to the new matdb.txt link. * matdb.txt: new link to the materials database. --- diff --git a/graphwidget.c b/graphwidget.c index 4ecc55a..beba3c9 100644 --- a/graphwidget.c +++ b/graphwidget.c @@ -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 -** Last update Sun May 12 01:17:25 2002 Speed Blue +** Last update Thu Oct 8 17:13:50 2009 Johnny Q. Hacker */ #include @@ -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.*/ - 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); @@ -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)); -#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; diff --git a/graphwidget.h b/graphwidget.h index 3b57af9..cb2e390 100644 --- a/graphwidget.h +++ b/graphwidget.h @@ -23,7 +23,7 @@ along with this program. If not, see . ** Started on Thu Jul 17 10:51:32 2008 Johnny Q. Hacker -** Last update Thu Jul 17 10:51:32 2008 Johnny Q. Hacker +** Last update Thu Oct 8 14:28:34 2009 Johnny Q. Hacker */ #ifndef GRAPHWIDGET_H_ diff --git a/matdb.txt b/matdb.txt new file mode 120000 index 0000000..e69de29 diff --git a/scdataviz.c b/scdataviz.c index 692f79d..812cd26 100644 --- a/scdataviz.c +++ b/scdataviz.c @@ -24,7 +24,7 @@ along with this program. If not, see . ** Started on Thu Jul 17 11:03:27 2008 Johnny Q. Hacker -** Last update Sun May 12 01:17:25 2002 Speed Blue +** Last update Thu Oct 8 19:13:57 2009 Johnny Q. Hacker */ #include @@ -141,7 +141,7 @@ int main(int argc, char *argv[]) { GtkWidget *window; GtkWidget *graph; - GString *file = g_string_new("../matdb"); + GString *file = g_string_new("matdb.txt"); int err=0; struct matdb *mdb = read_matdb_dotcode(file, &err); //fprintf(stderr, "read_matdb_dotcode(%s, %d)=%x", file->str, err,