* lots of goodies.
[scdataviz] / graph.c
diff --git a/graph.c b/graph.c
index 891fc6f..cd2b056 100644 (file)
--- a/graph.c
+++ b/graph.c
@@ -185,6 +185,7 @@ struct graph_axis* autoset_axis(Graph* g, GString* title, double min, double max
   double range_mag;
   double start_mag;
   double stop_mag;
+  int i, j;
   if(g->points->len == 0) {
     return NULL;
   }
@@ -207,12 +208,19 @@ struct graph_axis* autoset_axis(Graph* g, GString* title, double min, double max
       stop_mag = 0;
     else
       stop_mag = copysign(pow(10, ceil(log10(max))), max);
-    if(stop_mag == start_mag) stop_mag *= 10;
+    for(i=1; i<9; i++) {
+      if(i*start_mag > min) break;
+    }
+    i--;
+    for(j=10; j>1; j--) {
+      if(j*(stop_mag/10) < max) break;
+    }
+    j++;
     axis->major=10;
     axis->minor=1;
     axis->subminor=4;
-    axis->major_start=start_mag;
-    axis->major_step=(stop_mag - start_mag)/(axis->major);
+    axis->major_start=i*start_mag;
+    axis->major_step=(j*(stop_mag/10) - axis->major_start)/(axis->major);
   }
   axis->title=g_string_new(title->str);
   #ifdef DEBUG_AUTOAXIS