Commits

Anonymous committed d096ea5

Autoscaling ticks on linear axis now works with number ticks set.
Added option to align ticks across axes (e.g. y2axis with yaxis), which is
possible now with improved scaling with number ticks.
Updated ui example to align ticks.

Comments (0)

Files changed (5)

       File: Axis Label Renderer  (no auto-title, jqplot.axisLabelRenderer.js)
       File: Theme Engine  (no auto-title, jqplot.themeEngine.js)
       File: fn  (jqplot.toImage.js)
-      File: jquery-1.4.2.js  (jquery-1.4.2.js)
-      File: jquery-1.4.3.js  (jquery-1.4.3.js)
-      File: jquery-1.6.1.js  (jquery-1.6.1.js)
-      File: jquery-1.6.4.js  (jquery-1.6.4.js)
+      File: jqplot.lineAxisRenderer.js  (jqplot.lineAxisRenderer.js)
       }  # Group: Core Renderers
 
    Group: Plugins  {
    Function Index: Functions
    Hook Index: Hooks
    File Index: Files
-   Variable Index: Variables
    }  # Group: Index
 
           lengend:{show:true},
           series:[{},{yaxis:'y2axis'}, {yaxis:'y3axis'}],
           cursor:{show:true, zoom:true},
-          axesDefaults:{useSeriesColor:true}
+          axesDefaults:{useSeriesColor:true, rendererOptions: { alignTicks: true}}
         });
 
         plot2 = $.jqplot('chart2', [l4], {

src/jqplot.linearAxisRenderer.js

         // Major ticks are ticks supplied by user or auto computed.
         // Minor ticks cannot be created by user.
         this.minorTicks = 0;
-        this.alignAxes = false;
+        this.alignTicks = false;
         this._autoFormatString = '';
         this._overrideFormatString = false;
+        this._scalefact = 1.0;
         $.extend(true, this, options);
         if (this.breakPoints) {
             if (!$.isArray(this.breakPoints)) {
                 this.breakPoints = null;
             }
         }
-        if (this.numberTicks < 2) {
+        if (this.numberTicks != null && this.numberTicks < 2) {
             this.numberTicks = 2;
         }
         this.resetDataBounds();
             else {
                 dim = this._plotDimensions.height;
             }
+
+            var _numberTicks = this.numberTicks;
+
+            // if aligning this axis, use number of ticks from previous axis.
+            // Do I need to reset somehow if alignTicks is changed and then graph is replotted??
+            if (this.alignTicks) {
+                if (this.name === 'x2axis' && plot.axes.xaxis.show) {
+                    _numberTicks = plot.axes.xaxis.numberTicks;
+                }
+                else if (this.name.charAt(0) === 'y' && this.name !== 'yaxis' && this.name !== 'yMidAxis' && plot.axes.yaxis.show) {
+                    _numberTicks = plot.axes.yaxis.numberTicks;
+                }
+            }
             
             // // if min, max and number of ticks specified, user can't specify interval.
             // if (!this.autoscale && this.min != null && this.max != null && this.numberTicks != null) {
 
                 var threshold = 30;
                 var tdim = Math.max(dim, threshold+1);
-                var scalefact =  (tdim-threshold)/300.0;
-                var ret = $.jqplot.LinearTickGenerator(min, max, scalefact, this.numberTicks); 
+                this._scalefact =  (tdim-threshold)/300.0;
+                var ret = $.jqplot.LinearTickGenerator(min, max, this._scalefact, _numberTicks); 
                 // calculate a padded max and min, points should be less than these
                 // so that they aren't too close to the edges of the plot.
                 // User can adjust how much padding is allowed with pad, padMin and PadMax options. 
                 if (min <tumin || max > tumax) {
                     tumin = min - range*(this.padMin - 1);
                     tumax = max + range*(this.padMax - 1);
-                    ret = $.jqplot.LinearTickGenerator(tumin, tumax, scalefact, this.numberTicks);
+                    ret = $.jqplot.LinearTickGenerator(tumin, tumax, this._scalefact, _numberTicks);
                 }
 
                 this.min = ret[0];

src/jqplot.linearTickGenerator.js

         var residual = minimum / magnitude;
         var interval;
         // "nicest" ranges are 1, 2, 5 or powers of these.
-        if (magnitude < 100) {
+        // for magnitudes below 1, only allow these. 
+        if (magnitude < 1) {
             if (residual > 5) {
                 interval = 10 * magnitude;
             }
                 interval = magnitude;
             }
         }
-        // for large ranges, allow intervals like 300, 400 or powers of these.
+        // for large ranges (whole integers), allow intervals like 3, 4 or powers of these.
         // this helps a lot with poor choices for number of ticks. 
         else {
             if (residual > 5) {
         else if (f<=16.0) {
             fact = 2;
         }
-        // else if (f<=20.0) {
-        //     fact = 3;
-        // }
         else {
             fact = 5;
         } 
         var r = [];
         var ss = bestLinearInterval(axis_max - axis_min, scalefact);
         
-        if (numberTicks === undefined) {
+        if (numberTicks == null) {
 
             // Figure out the axis min, max and number of ticks
             // the min and max will be some multiple of the tick interval,
         }
 
         else {
-            // console.log('number ticks: ', numberTicks);
-            // console.log('axis_min: %s, axis_max: %s', axis_min, axis_max);
             var tempr = [];
 
             // Figure out the axis min, max and number of ticks
             tempr[3] = bestFormatString(ss);            // format string
             tempr[4] = ss;                              // tick Interval
 
-            // console.log('tempr: ', tempr);
-
             // first, see if we happen to get the right number of ticks
             if (tempr[2] === numberTicks) {
                 r = tempr;
             else {
 
                 var newti = bestInterval(tempr[1] - tempr[0], numberTicks);
-                // console.log('new ti: ', newti);
 
                 r[0] = tempr[0];
                 r[2] = numberTicks;
             }
         }
 
-        // console.log('r is: ', r);
-
         return r;
     };
 

src/plugins/jqplot.cursor.js

                                 newmin = dp;
                                 newmax = start[ax];
                             }
+
+                            var curax = axes[ax];
+
+                            var _numberTicks = null;
+
+                            // if aligning this axis, use number of ticks from previous axis.
+                            // Do I need to reset somehow if alignTicks is changed and then graph is replotted??
+                            if (curax.alignTicks) {
+                                if (curax.name === 'x2axis' && plot.axes.xaxis.show) {
+                                    _numberTicks = plot.axes.xaxis.numberTicks;
+                                }
+                                else if (curax.name.charAt(0) === 'y' && curax.name !== 'yaxis' && curax.name !== 'yMidAxis' && plot.axes.yaxis.show) {
+                                    _numberTicks = plot.axes.yaxis.numberTicks;
+                                }
+                            }
                             
                             if (this.looseZoom && (axes[ax].renderer.constructor === $.jqplot.LinearAxisRenderer || axes[ax].renderer.constructor === $.jqplot.DateAxisRenderer)) {
-                                var ret = $.jqplot.LinearTickGenerator(newmin, newmax);
+                                var ret = $.jqplot.LinearTickGenerator(newmin, newmax, curax._scalefact, _numberTicks);
 
                                 // if new minimum is less than "true" minimum of axis display, adjust it
-                                if (ret[0] < axes[ax].min + axes[ax].tickInset * axes[ax].tickInterval) {
+                                if (axes[ax].tickInset && ret[0] < axes[ax].min + axes[ax].tickInset * axes[ax].tickInterval) {
                                     ret[0] += ret[4];
                                     ret[2] -= 1;
                                 }
 
                                 // if new maximum is greater than "true" max of axis display, adjust it
-                                if (ret[1] > axes[ax].max - axes[ax].tickInset * axes[ax].tickInterval) {
+                                if (axes[ax].tickInset && ret[1] > axes[ax].max - axes[ax].tickInset * axes[ax].tickInterval) {
                                     ret[1] -= ret[4];
                                     ret[2] -= 1;
                                 }