Re: Graphing - axis tick autospacing



On Mon, Oct 06, 2003 at 11:14:14AM +0200, Emmanuel PACAUD wrote:
@@ -341,6 +349,20 @@
 
      minima = axis->min_val;
      maxima = axis->max_val;
+     
+     data = gog_dataset_get_dim (GOG_DATASET (axis), AXIS_ELEM_MIN);
+     if ((data != NULL) && IS_GO_DATA_SCALAR (data)) {
+             tmp = go_data_scalar_get_value (GO_DATA_SCALAR (data));
+             if (finite (tmp)) 
+                     minima = tmp;
+     }
+     data = gog_dataset_get_dim (GOG_DATASET (axis),AXIS_ELEM_MAX);
+     if ((data != NULL) && IS_GO_DATA_SCALAR (data)) {
+             tmp = go_data_scalar_get_value (GO_DATA_SCALAR (data));
+             if (finite (tmp)) 
+                     maxima = tmp;
+     }
This bit is ugly.  Just tweak axis_get_entry if you need a flag to
know if something is found.

-             step  = pow (10, gnumeric_fake_trunc (log10 (range)));
-             if (range/step < 1.5)
-                     step /= 5.;     /* .2 .4 .6 */
-             else if (range/step < 3)
-                     step /= 2.;     /* 0 5 10 */
-             else if (range/step > 8)
-                     step *= 2.;     /* 2 4 6 */
+             
+             step = range / MAXIMUM_TICKS;
+             multiplier = step / pow (10, floor ( log10 (step)));
+
+             if (multiplier <= 2.0) {
+                     multiplier = 2.0;
+                     minor_tick_number=10;
+             }
+             else if (multiplier <= 5.0) {
+                     multiplier = 5.0;
+                     minor_tick_number=5;
+             }
+             else {
+                     multiplier = 10.0;
+                     minor_tick_number=10;
+             }
 
+             step = multiplier * pow (10, floor ( log10 (step)));
This is the meat of things.  Its a mixed bag.  I like the behavior
in the -1..1 region, but its not as useful for 1..20.


-             /* pull to zero if its nearby (do not pull both directions to 0) */
-             if (axis->auto_bound [AXIS_ELEM_MIN] > 0 &&
-                 (axis->auto_bound [AXIS_ELEM_MIN] - 10. * step) < 0)
-                     axis->auto_bound [AXIS_ELEM_MIN] = 0;
-             else if (axis->auto_bound [AXIS_ELEM_MAX] < 0 &&
-                 (axis->auto_bound [AXIS_ELEM_MAX] + 10. * step) < 0)
-                     axis->auto_bound [AXIS_ELEM_MAX] = 0;
+             axis->auto_bound [AXIS_ELEM_MINOR_TICK] = step / (double)minor_tick_number;

It is important to note that this is yet another area where we need
to take MS Excel into account.  The argument that the user can set
the bound manually misses the mark for imported xls files.  If we
choose significantly different scaling the resulting graph will look
'off'.  Its trivial, but a bit ugly to make the pull to zero
optional.  However, it seems like a nice heuristic to me.  I find it
helpful to visualize content relative to zero if it is conceptually
near by.

-             return 1 + fabs (maxima - minima) / major_tick;
+             return floor (fabs (maxima - minima) / major_tick + 1.5);
Why do we want to round here ?



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]