Commits

Chris Leonello committed 74bf6bc

Fixed some lint from memory leak patch. Added scaling to axis tick computation to put less ticks in small plots and more ticks in large plots.

  • Participants
  • Parent commits f8e51b5

Comments (0)

Files changed (7)

src/jqplot.core.js

     // Memory Leaks patch : garbage collector
     $.gcInit = function() {
       var gc = $("<div id='gc_jqPlotSalsaGarbage' style='display:none;visibility:hidden;'></div>");
-      $("body").append(gc)
+      $("body").append(gc);
       $._gc = gc;
     };
 
                     $(this).find(".jqplot-seriesToggle").each( function() {
                         $(this).unbind();
                     });
-                    $.gcCollect(this)
+                    $.gcCollect(this);
                 });
                 
                 this.target.find(".jqplot-title").each( function() {
                     $(this).unbind();
-                    $.gcCollect(this)
+                    $.gcCollect(this);
                 });
                 
                 $.gcClear();

src/jqplot.lineRenderer.js

     // insert it before the eventCanvas, so eventCanvas will still capture events.
     function postPlotDraw() {
         // Memory Leaks patch    
-        if (this.plugins.lineRenderer 
-          && this.plugins.lineRenderer.highlightCanvas) {
+        if (this.plugins.lineRenderer && this.plugins.lineRenderer.highlightCanvas) {
           this.plugins.lineRenderer.highlightCanvas.resetCanvas();
           this.plugins.lineRenderer.highlightCanvas = null;
         }

src/jqplot.linearAxisRenderer.js

                     }
                 }
 
-                var ret = $.jqplot.LinearTickGenerator(min, max); 
+                // console.log(this.name);
+                var threshold = 30;
+                var tdim = Math.max(dim, threshold+1);
+                var scalefact =  (tdim-threshold)/300.0;
+                // scalefact = 1;
+                var ret = $.jqplot.LinearTickGenerator(min, max, scalefact); 
                 // 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);
+                    ret = $.jqplot.LinearTickGenerator(tumin, tumax, scalefact);
                 }
 
+
+                // if (ret[2] > max_number_ticks) {
+                //     ret[4] = Math.ceil(r[2]/max_number_ticks) * ret[4];
+                    
+                // }
+
                 this.min = ret[0];
                 this.max = ret[1];
                 this.numberTicks = ret[2];
                 this._autoFormatString = ret[3];
                 //this.tickInterval = Math.abs(this.max - this.min)/(this.numberTicks - 1);
                 this.tickInterval = ret[4];
+                // console.log('numberticks: %s, interval: %s', ret[2], ret[4]);
             }
 
             // User has specified some axis scale related option, can use auto algorithm

src/jqplot.linearTickGenerator.js

     }
 
     // This will return an interval of form 2 * 10^n, 5 * 10^n or 10 * 10^n
-    function bestLinearInterval(range) {
+    function bestLinearInterval(range, scalefact) {
         var expv = Math.floor(Math.log(range)/Math.LN10);
         var magnitude = Math.pow(10, expv);
+        // 0 < f < 10
         var f = range / magnitude;
+        // console.log('f: %s, scaled: %s ', f, f/scalefact);
+        // for large plots, scalefact will decrease f and increase number of ticks.
+        // for small plots, scalefact will increase f and decrease number of ticks.
+        f = f/scalefact;
 
+        // for large plots, smaller interval, more ticks.
+        if (f<=0.38) {return 0.1*magnitude;}
         if (f<=1.6) {return 0.2*magnitude;}
         if (f<=4.0) {return 0.5*magnitude;}
         if (f<=8.0) {return magnitude;}
-        return 2*magnitude; 
+        // for very small plots, larger interval, less ticks in number ticks
+        if (f<=16.0) {return 2*magnitude;}
+        return 5*magnitude; 
     }
 
     // Given the min and max for a dataset, return suitable endpoints
     // for the graphing, a good number for the number of ticks, and a
     // format string so that extraneous digits are not displayed.
     // returned is an array containing [min, max, nTicks, format]
-    $.jqplot.LinearTickGenerator = function(axis_min, axis_max) {
+    $.jqplot.LinearTickGenerator = function(axis_min, axis_max, scalefact) {
         // if endpoints are equal try to include zero otherwise include one
         if (axis_min == axis_max) {
         axis_max = (axis_max) ? 0 : 1;
         }
 
+        scalefact = scalefact || 1.0;
+
         // make sure range is positive
         if (axis_max < axis_min) {
         var a = axis_max;
         axis_min = a;
         }
 
-        var ss = bestLinearInterval(axis_max - axis_min);
+        var ss = bestLinearInterval(axis_max - axis_min, scalefact);
         var r = [];
 
         // Figure out the axis min, max and number of ticks
         // axis min is negative, 0 will be a tick.
         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);    // number of ticks
+        r[2] = Math.round((r[1]-r[0])/ss+1.0);    // number of ticks
         r[3] = bestFormatString(ss);            // format string
         r[4] = ss;                              // tick Interval
         return r;

src/plugins/jqplot.barRenderer.js

     // insert it before the eventCanvas, so eventCanvas will still capture events.
     function postPlotDraw() {
         // Memory Leaks patch    
-        if (this.plugins.barRenderer 
-            && this.plugins.barRenderer.highlightCanvas) {
+        if (this.plugins.barRenderer && this.plugins.barRenderer.highlightCanvas) {
 
             this.plugins.barRenderer.highlightCanvas.resetCanvas();
             this.plugins.barRenderer.highlightCanvas = null;

src/plugins/jqplot.canvasAxisLabelRenderer.js

           // Memory Leaks patch
           if (this._elem) {
               if ($.jqplot.use_excanvas) {
-                  elem = this._elem.get(0);
+                  var elem = this._elem.get(0);
                   window.G_vmlCanvasManager.uninitElement(elem);
                   elem = null;
               }

src/plugins/jqplot.canvasAxisTickRenderer.js

         }
         
         // Memory Leaks patch
-        if (this._elem) {
-            if ($.jqplot.use_excanvas) {
-                elem = this._elem.get(0);
-                window.G_vmlCanvasManager.uninitElement(elem);
-                elem = null;
-            }
-            
-            this._elem.emptyForce();
-            this._domelem = null;
-            this._elem = null;
+        if (this._elem) {
+            if ($.jqplot.use_excanvas) {
+                var elem = this._elem.get(0);
+                window.G_vmlCanvasManager.uninitElement(elem);
+                elem = null;
+            }
+            
+            this._elem.emptyForce();
+            this._domelem = null;
+            this._elem = null;
         }
 
         // create a canvas here, but can't draw on it untill it is appended