Commits

Anonymous committed 45fe7a9

adding auto tick format string when not using looze zooming.

Comments (0)

Files changed (2)

src/jqplot.linearAxisRenderer.js

             var rmin, rmax;
             var temp;
 
+            if (this.tickOptions == null || !this.tickOptions.formatString) {
+                this._overrideFormatString = true;
+            }
+
             // Doing complete autoscaling
             if (this.min == null && this.max == null && this.numberTicks == null && this.tickInterval == null && !this.autoscale) {
                 // check to see if we can override tick format string with autocalculated one
-                if (this.tickOptions == null || !this.tickOptions.formatString) {
-                    this._overrideFormatString = true;
-                }
 
 
                 // Check if user must have tick at 0 or 100 and ensure they are in range.
                 // Use the default algorithm which pads each axis to make the chart
                 // centered nicely on the grid.
                 else {
+
                     rmin = (this.min != null) ? this.min : min - range*(this.padMin - 1);
                     rmax = (this.max != null) ? this.max : max + range*(this.padMax - 1);
                     range = rmax - rmin;
                         rmin = rmax - this.tickInterval*(this.numberTicks - 1);
                     }
 
+                    this._autoFormatString = $.jqplot.bestFormatString(this.tickInterval);
+
                     this.min = rmin;
                     this.max = rmax;
                 }

src/jqplot.linearTickGenerator.js

     // A good format string depends on the interval. If the interval is greater 
     // than 1 then there is no need to show any decimal digits. If it is < 1.0, then
     // use the magnitude of the interval to determine the number of digits to show.
-    function bestFormatString (interval)
+    $.jqplot.bestFormatString = function (interval)
     {
+        var fstr;
         interval = Math.abs(interval);
-        if (interval > 1) {return '%d';}
+        if (interval > 1) {
+            fstr = '%d';
+        }
 
-        var expv = -Math.floor(Math.log(interval)/Math.LN10);
-        return '%.' + expv + 'f'; 
+        else {
+            var expv = -Math.floor(Math.log(interval)/Math.LN10);
+            fstr = '%.' + expv + 'f';
+        }
+        
+        return fstr; 
     }
 
     // This will return an interval of form 2 * 10^n, 5 * 10^n or 10 * 10^n
         r[0] = Math.floor(axis_min / ss) * ss;  // min
         r[1] = Math.ceil(axis_max / ss) * ss;   // max
         r[2] = Math.round((r[1]-r[0])/ss+1.0);    // number of ticks
-        r[3] = bestFormatString(ss);            // format string
+        r[3] = $.jqplot.bestFormatString(ss);            // format string
         r[4] = ss;                              // tick Interval
+        console.log(r);
         return r;
     };