* graphwidget.c: fixed a bug where we'd divide by 0 if min and max x and y were the...
authortrelane@digitasaru.net <trelane@digitasaru.net>
Fri, 9 Oct 2009 00:15:04 +0000 (19:15 -0500)
committertrelane@digitasaru.net <trelane@digitasaru.net>
Fri, 9 Oct 2009 00:15:04 +0000 (19:15 -0500)
* graphwidget.h: not much of a change.
* scdataviz.c: pointed to the new matdb.txt link.
* matdb.txt: new link to the materials database.

graphwidget.c
graphwidget.h
matdb.txt [new symlink]
scdataviz.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
-** 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>
@@ -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;
index 3b57af9..cb2e390 100644 (file)
@@ -23,7 +23,7 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 ** 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 (symlink)
index 0000000..e69de29
index 692f79d..812cd26 100644 (file)
@@ -24,7 +24,7 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 ** 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 <gtk/gtk.h>
@@ -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,