Commits

chudaol committed 057e938

ported differences from ex-jqplotzai

  • Participants
  • Parent commits 6ed271c

Comments (0)

Files changed (5)

File examples/dynamicplot.html

   <script language="javascript" type="text/javascript" src="../src/plugins/jqplot.dateAxisRenderer.js"></script>
   <script language="javascript" type="text/javascript" src="../src/plugins/jqplot.categoryAxisRenderer.js"></script>
   <script language="javascript" type="text/javascript" src="../src/plugins/jqplot.canvasOverlay.js"></script>
+  <script language="javascript" type="text/javascript" src="../src/plugins/jqplot.cursor.js"></script>
+  <script language="javascript" type="text/javascript" src="../src/plugins/jqplot.zoom.js"></script>
   
   <!-- END: load jqplot -->
 <script language="javascript" type="text/javascript">
 // These will be reused when calling $.jqplot()
 ///////
 var plotOptions = {
+    zoom : {
+    interactive : true
+},
+cursor:{show:true, zoom:true}, 
   gridPadding: {top: 1},
   grid: {shadow:false, borderWidth:1.0},
   seriesDefaults: {

File examples/zoomProxy.html

   <!-- BEGIN: load jqplot -->
   <script language="javascript" type="text/javascript" src="../src/jquery.jqplot.js"></script>
   <script language="javascript" type="text/javascript" src="../src/plugins/jqplot.cursor.js"></script>
+  <script language="javascript" type="text/javascript" src="../src/plugins/jqplot.zoom.js"></script>
 	
 	<style type="text/css">
 	  .jqplot-cursor-legend {

File src/jqplot.lineRenderer.js

     // in the gridData array.
     // Called with scope of a series.
     $.jqplot.LineRenderer.prototype.setGridData = function(plot) {
+        
+        // Finds the index of the first point following points[idx] that is
+        // different than points[idx]
+        function nextDiff(idx, points) {
+            var i;
+            for (i = idx; i < points.length - 1 && points[i][1] === points[idx][1]; i ++);
+            return i;
+        }          
+        
         // recalculate the grid data
         var xp = this._xaxis.series_u2p;
         var yp = this._yaxis.series_u2p;
         this.renderer._lowBandSmoothedData = [];
         var bands = this.renderer.bands;
         var hasNull = false;
-        for (var i=0, l=this.data.length; i < l; i++) {
+        
+        var start = Math.max($.jqplot.closest(this._xaxis.min, data), 2),
+            end = nextDiff($.jqplot.closest(this._xaxis.max, data), data),
+            step = Math.max(1, (end - start) / this._plotDimensions.width);
+        
+        for (var i=0, ri = 0; ri <= end; i += step, ri = Math.round(i)) {
             // if not a line series or if no nulls in data, push the converted point onto the array.
-            if (data[i][0] != null && data[i][1] != null) {
-                this.gridData.push([xp.call(this._xaxis, data[i][0]), yp.call(this._yaxis, data[i][1])]);
+            if (data[ri][0] != null && data[ri][1] != null) {
+                this.gridData.push([xp.call(this._xaxis, data[ri][0]), yp.call(this._yaxis, data[ri][1])]);
             }
             // else if there is a null, preserve it.
-            else if (data[i][0] == null) {
+            else if (data[ri][0] == null) {
                 hasNull = true;
-                this.gridData.push([null, yp.call(this._yaxis, data[i][1])]);
+                this.gridData.push([null, yp.call(this._yaxis, data[ri][1])]);
             }
-            else if (data[i][1] == null) {
+            else if (data[ri][1] == null) {
                 hasNull = true;
-                this.gridData.push([xp.call(this._xaxis, data[i][0]), null]);
+                this.gridData.push([xp.call(this._xaxis, data[ri][0]), null]);
             }
             // if not a line series or if no nulls in data, push the converted point onto the array.
-            if (pdata[i] != null && pdata[i][0] != null && pdata[i][1] != null) {
-                this._prevGridData.push([xp.call(this._xaxis, pdata[i][0]), yp.call(this._yaxis, pdata[i][1])]);
+            if (pdata[ri] != null && pdata[ri][0] != null && pdata[ri][1] != null) {
+                this._prevGridData.push([xp.call(this._xaxis, pdata[ri][0]), yp.call(this._yaxis, pdata[ri][1])]);
             }
             // else if there is a null, preserve it.
-            else if (pdata[i] != null && pdata[i][0] == null) {
-                this._prevGridData.push([null, yp.call(this._yaxis, pdata[i][1])]);
+            else if (pdata[ri] != null && pdata[ri][0] == null) {
+                this._prevGridData.push([null, yp.call(this._yaxis, pdata[ri][1])]);
             }  
-            else if (pdata[i] != null && pdata[i][0] != null && pdata[i][1] == null) {
-                this._prevGridData.push([xp.call(this._xaxis, pdata[i][0]), null]);
+            else if (pdata[ri] != null && pdata[ri][0] != null && pdata[ri][1] == null) {
+                this._prevGridData.push([xp.call(this._xaxis, pdata[ri][0]), null]);
             }
         }
 
     // grid data associated with that series.
     // Called with scope of a series.
     $.jqplot.LineRenderer.prototype.makeGridData = function(data, plot) {
+        // Finds the index of the first point following points[idx] that is
+        // different than points[idx]
+        function nextDiff(idx, points) {
+            var i;
+            for (i = idx; i < points.length - 1 && points[i][1] === points[idx][1]; i ++);
+            return i;
+        }          
         // recalculate the grid data
         var xp = this._xaxis.series_u2p;
         var yp = this._yaxis.series_u2p;
         this.renderer._lowBandSmoothedData = [];
         var bands = this.renderer.bands;
         var hasNull = false;
-        for (var i=0; i<data.length; i++) {
+        
+        var start = Math.max($.jqplot.closest(this._xaxis.min, data), 2),
+            end = nextDiff($.jqplot.closest(this._xaxis.max, data), data),
+            step = Math.max(1, (end - start) / this._plotDimensions.width);        
+        
+        for (var i=0, ri = 0; ri <= end; i += step, ri = Math.round(i)) {
             // if not a line series or if no nulls in data, push the converted point onto the array.
-            if (data[i][0] != null && data[i][1] != null) {
-                gd.push([xp.call(this._xaxis, data[i][0]), yp.call(this._yaxis, data[i][1])]);
+            if (data[ri][0] != null && data[ri][1] != null) {
+                gd.push([xp.call(this._xaxis, data[ri][0]), yp.call(this._yaxis, data[ri][1])]);
             }
             // else if there is a null, preserve it.
-            else if (data[i][0] == null) {
+            else if (data[ri][0] == null) {
                 hasNull = true;
-                gd.push([null, yp.call(this._yaxis, data[i][1])]);
+                gd.push([null, yp.call(this._yaxis, data[ri][1])]);
             }
-            else if (data[i][1] == null) {
+            else if (data[ri][1] == null) {
                 hasNull = true;
-                gd.push([xp.call(this._xaxis, data[i][0]), null]);
+                gd.push([xp.call(this._xaxis, data[ri][0]), null]);
             }
         }
 

File src/jqplot.linearAxisRenderer.js

     // called with scope of axis
     $.jqplot.LinearAxisRenderer.prototype.createTicks = function(plot) {
         // we're are operating on an axis here
+//        if (this._ticks.length && this._ticks.length > 0) {
+//            this._ticks.length = 0;
+//        }
         var ticks = this._ticks;
         var userTicks = this.ticks;
         var name = this.name;

File src/plugins/jqplot.dateAxisRenderer.js

     
     $.jqplot.DateAxisRenderer.prototype.createTicks = function(plot) {
         // we're are operating on an axis here
+//        if (this._ticks.length > 0) {
+//            this._ticks.length = 0;
+//        }
         var ticks = this._ticks;
         var userTicks = this.ticks;
         var name = this.name;