* graphwidget.c: fixed a bug where we'd divide by 0 if min and max x and y were the...
[scdataviz] / scdataviz.c
index 4c0851d..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>
@@ -54,13 +54,13 @@ static void put_mat_in_graph(gpointer key, gpointer value, gpointer user_data) {
   if(!strcasecmp(mat->name->str, "vacuum")) return;
   if(!strcasecmp(mat->name->str, "pvb")) return;
   double *x, *y;
-  #ifdef DEBUG
+  #ifdef DEBUG_ASSIGNMENT
   fprintf(stderr, "put_mat_in_graph(%s) (x->%s, y->%s): ", (char*)key, propmap->xprop->str, propmap->yprop->str);
   #endif
   lookup_xy(mat->properties, propmap->xprop, propmap->yprop, &x, &y);
   if((x != NULL) && (y != NULL)) {
     graph_add_point(propmap->graph, *x, *y, mat->name);
-  #ifdef DEBUG
+  #ifdef DEBUG_ASSIGNMENT
     fprintf(stderr, "added (x->%s=%g, y->%s=%g)\n", propmap->xprop->str, *x, propmap->yprop->str, *y);
   }else{
     fprintf(stderr, "no such properties (x->%s, y->%s)\n", propmap->xprop->str, propmap->yprop->str);
@@ -81,7 +81,7 @@ static void inner_link_materials(gpointer key, gpointer value, gpointer user_dat
   double *p0_x, *p0_y, *p1_x, *p1_y, *p3_x, *p3_y;
   lookup_xy(propmap->mat->properties, propmap->xprop, propmap->yprop, &p0_x, &p0_y);
   lookup_xy(mat->properties, propmap->xprop, propmap->yprop, &p3_x, &p3_y);
-#ifdef DEBUG
+#ifdef DEBUG_ASSIGNMENT
   fprintf(stderr, "%s:%s x=%s y=%s p0(%g,%g) p3(%g,%g)\n", propmap->mat->name->str, mat->name->str, propmap->xprop->str, propmap->yprop->str, (p0_x)?*p0_x:0, (p0_y)?*p0_y:0, (p3_x)?*p3_x:0, (p3_y)?*p3_y:0);
 #endif
   if((p0_x != NULL) && (p0_y != NULL) && (p3_x != NULL) && (p3_y != NULL)) {
@@ -115,11 +115,11 @@ static void inner_link_materials(gpointer key, gpointer value, gpointer user_dat
       #ifdef DEBUG_SHOW_ONLY_BOWED
       free(l);
       return;
-      #endif;
+      #endif
       graph_bezier_linear_to_cubic(l->p0_x, l->p3_x, &(l->p1_x), &(l->p2_x));
       graph_bezier_linear_to_cubic(l->p0_y, l->p3_y, &(l->p1_y), &(l->p2_y));
     }
-    #ifdef DEBUG
+    #ifdef DEBUG_ASSIGNMENT
     fprintf(stderr, "%s:%s p0(%g,%g) p1(%g,%g) p2(%g,%g), p3(%g,%g)\n", propmap->mat->name->str, mat->name->str, l->p0_x, l->p0_y, l->p1_x, l->p1_y, l->p2_x, l->p2_y, l->p3_x, l->p3_y);
     #endif
     graph_add_graph_line(propmap->graph, l);
@@ -141,12 +141,12 @@ 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,
     //(int)mdb);
-    fprintf(stderr, "err=%d\n", err);
+    //fprintf(stderr, "err=%d\n", err);
     //print_matdb(mdb);
     
     gtk_init (&argc, &argv);
@@ -162,7 +162,8 @@ int main(int   argc, char *argv[])
     g_hash_table_foreach(mdb->materials, &put_mat_in_graph, &propmap);
     //graph_add_linear_connectors(propmap.graph);
     g_hash_table_foreach(mdb->materials, &link_materials, &propmap);
-
+    graph_autoset_xaxis(propmap.graph, propmap.xprop);
+    graph_autoset_yaxis(propmap.graph, propmap.yprop);
 
     //Connect signals
     g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);