Commits

Anonymous committed bc8d5d7

Added canvas manager support to more plugins.

  • Participants
  • Parent commits 4fc010d

Comments (0)

Files changed (9)

examples/dynamicplot.html

   // the plot as a base set.  Adjust the close value by a random amount,
 
   // a slight adjustment to current price
-  var val = Math.random()*10 * (Math.random() - 0.5);
+  var val = Math.random()*20 * (Math.random() - 0.1);
   var d = plot1.series[0].data;
   var dp = d[d.length-1];
   // get the current values.
 function runUpdate() {
 
   // Simulate 1000 iterations of streaming for testing purposes.
-  if (counter < 1000) {
+  if (counter < 10000) {
     var newdata = getNewDataPoint();
     // updatePlot method each time have an updated data point.
     updatePlot(newdata);

examples/zoom1.html

   <link rel="stylesheet" type="text/css" href="../src/jquery.jqplot.css" />
   <link rel="stylesheet" type="text/css" href="examples.css" />
   
-  <!--[if lt IE 9]><script language="javascript" type="text/javascript" src="../src/excanvas.min.js"></script><![endif]-->
+  <!--[if lt IE 9]><script language="javascript" type="text/javascript" src="../src/excanvas.js"></script><![endif]-->
   <!-- BEGIN: load jquery -->
-  <script language="javascript" type="text/javascript" src="../src/jquery-1.5.1.min.js"></script>
+  <script language="javascript" type="text/javascript" src="../src/jquery-1.5.1.js"></script>
 
   <!-- END: load jquery -->
   

examples/zoom2.html

   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 
   <title>Simple Test</title>
-  <!--[if lt IE 9]><script language="javascript" type="text/javascript" src="../src/excanvas.min.js"></script><![endif]-->
+  <!--[if lt IE 9]><script language="javascript" type="text/javascript" src="../src/excanvas.js"></script><![endif]-->
   
   <link rel="stylesheet" type="text/css" href="../src/jquery.jqplot.css" />
   <link rel="stylesheet" type="text/css" href="examples.css" />

src/jqplot.axisLabelRenderer.js

         $.extend(true, this, options);
     };
     
-    $.jqplot.AxisLabelRenderer.prototype.draw = function() {
+    $.jqplot.AxisLabelRenderer.prototype.draw = function(ctx, plot) {
         // Memory Leaks patch
         if (this._elem) {
             this._elem.emptyForce();

src/jqplot.core.js

 
         this.getCanvas = function() {
             var canvas;
-            var idx = $.inArray(true, this.free);
-    
-            if (idx > -1) {
-                canvas = this.canvases[idx];
-                this.free[idx] = false;
-                $(canvas).addClass('reused');
+            var makeNew = true;
+
+            for (var i=0, l=this.canvases.length; i<l; i++) {
+                if (this.free[i] === true) {
+                    makeNew = false;
+                    canvas = this.canvases[i];
+                    this.free[i] = false;
+                    $(canvas).addClass('reused');
+                    break;
+                }
             }   
 
-            else {
+            if (makeNew) {
                 canvas = document.createElement('canvas');
                 this.canvases.push(canvas);
                 this.free.push(false);
-                idx = this.canvases.length;
             }   
             
             return canvas;
         };
 
         this.freeAllCanvases = function() {
+            var canvas;
             for (var i = 0; i < this.canvases.length; i++) {
-                var canvas = this.canvases[i];
+                canvas = this.canvases[i];
                 canvas.getContext('2d').clearRect(0, 0, canvas.width, canvas.height);
                 $(canvas).removeClass().removeAttr('style');
                 this.free[i] = true;
             }   
+            canvas = null;
         };
 
         this.destroyAllCanvases = function() {
         
     };
     
-    Axis.prototype.draw = function(ctx) {
+    Axis.prototype.draw = function(ctx, plot) {
         // Memory Leaks patch
         if (this.__ticks) {
           this.__ticks = null;
         }
 
-        return this.renderer.draw.call(this, ctx);
+        return this.renderer.draw.call(this, ctx, plot);
         
     };
     
             klass = clss;
         }
         var elem;
-        // if this canvas already has a dom element, don't make a new one.
-        if (this._elem) {
-            elem = this._elem.get(0);
-            // Memory Leaks patch
-            if ($.jqplot.use_excanvas) {
-                window.G_vmlCanvasManager.uninitElement(elem);
-            }
+
+        // if (this._elem) {
+        //     // Memory Leaks patch
+        //     if ($.jqplot.use_excanvas) {
+        //         window.G_vmlCanvasManager.uninitElement(this._elem.get(0));
+        //     }
+        // }
+        // else {
+        //     // don't use the canvas manager with excanvas.
+        //     if ($.jqplot.use_excanvas) {
+        //         elem = document.createElement('canvas');
+        //     }
+        //     else {
+        //         elem = plot.canvasManager.getCanvas();
+        //     }
+
+        // }
+
+        // don't use the canvas manager with excanvas.
+        if ($.jqplot.use_excanvas) {
+            window.G_vmlCanvasManager.uninitElement(elem);
+            elem = document.createElement('canvas');
         }
         else {
-            elem = document.createElement('canvas');
-            // don't use the canvas manager with excanvas.
-            if ($.jqplot.use_excanvas) {
-                elem = document.createElement('canvas');
-            }
-            else {
-                elem = plot.canvasManager.getCanvas();
-            }
+            elem = plot.canvasManager.getCanvas();
+        }
 
-        }
         // if new plotDimensions supplied, use them.
         if (plotDimensions != null) {
             this._plotDimensions = plotDimensions;
                 
                 $.gcClear();
 
+                this.eventCanvas._elem.unbind();
+                this.target.unbind();
+
                 // Couple of posts on Stack Overflow indicate that empty() doesn't
                 // always cear up the dom and release memory.  Sometimes setting
                 // innerHTML property to null is needed.  Particularly on IE, may 
                 
                 var ax = this.axes;
                 for (var name in ax) {
-                    this.target.append(ax[name].draw(this.baseCanvas._ctx));
+                    this.target.append(ax[name].draw(this.baseCanvas._ctx, this));
                     ax[name].set();
                 }
                 if (ax.yaxis.show) {

src/jqplot.linearAxisRenderer.js

     };
     
     // called with scope of axis
-    $.jqplot.LinearAxisRenderer.prototype.draw = function(ctx) {
+    $.jqplot.LinearAxisRenderer.prototype.draw = function(ctx, plot) {
         if (this.show) {
             // populate the axis label and value properties.
             // createTicks is a method on the renderer, but
             this._label = new this.labelRenderer(this.labelOptions);
             var elem;
             if (this._label.show) {
-                elem = this._label.draw(ctx);
+                elem = this._label.draw(ctx, plot);
                 elem.appendTo(this._elem);
             }
     
             for (var i=0; i<t.length; i++) {
                 var tick = t[i];
                 if (tick.show && tick.showLabel && (!tick.isMinorTick || this.showMinorTicks)) {
-                    elem = tick.draw(ctx);
+                    elem = tick.draw(ctx, plot);
                     elem.appendTo(this._elem);
                 }
             }

src/plugins/jqplot.canvasAxisLabelRenderer.js

         return a;
     };
     
-    $.jqplot.CanvasAxisLabelRenderer.prototype.draw = function(ctx) {
+    $.jqplot.CanvasAxisLabelRenderer.prototype.draw = function(ctx, plot) {
           // Memory Leaks patch
           if (this._elem) {
               if ($.jqplot.use_excanvas) {
-                  var elem = this._elem.get(0);
-                  window.G_vmlCanvasManager.uninitElement(elem);
-                  elem = null;
+                  window.G_vmlCanvasManager.uninitElement(this._elem.get(0));
               }
             
               this._elem.emptyForce();
-              this._domelem = null;
               this._elem = null;
           }
 
         // create a canvas here, but can't draw on it untill it is appended
         // to dom for IE compatability.
-        var domelem = document.createElement('canvas');
+
+        var elem;
+
+        // don't use the canvas manager with excanvas.
+        if ($.jqplot.use_excanvas) {
+            window.G_vmlCanvasManager.uninitElement(elem);
+            elem = document.createElement('canvas');
+        }
+        else {
+            elem = plot.canvasManager.getCanvas();
+        }
+
         this._textRenderer.setText(this.label, ctx);
         var w = this.getWidth(ctx);
         var h = this.getHeight(ctx);
-        domelem.width = w;
-        domelem.height = h;
-        domelem.style.width = w;
-        domelem.style.height = h;
-        // domelem.style.textAlign = 'center';
-        domelem.style.position = 'absolute';
-        this._domelem = domelem;
-        this._elem = $(domelem);
+        elem.width = w;
+        elem.height = h;
+        elem.style.width = w;
+        elem.style.height = h;
+        // // domelem.style.textAlign = 'center';
+        // elem.style.position = 'absolute';
+        this._elem = $(elem);
+        this._elem.css({ position: 'absolute'});
         this._elem.addClass('jqplot-'+this.axis+'-label');
+
+        if ($.jqplot.use_excanvas) {
+            // useless ?? window.G_vmlCanvasManager.init_(document);
+            elem = window.G_vmlCanvasManager.initElement(elem);
+        }
         
-        domelem = null;
+        elem = null;
         return this._elem;
     };
     
     $.jqplot.CanvasAxisLabelRenderer.prototype.pack = function() {
         if ($.jqplot.use_excanvas) {
-            window.G_vmlCanvasManager.init_(document);
-            this._domelem = window.G_vmlCanvasManager.initElement(this._domelem);
+            //window.G_vmlCanvasManager.init_(document);
+            this._elem.get(0) = window.G_vmlCanvasManager.initElement(this._elem.get(0));
         }
         this._textRenderer.draw(this._elem.get(0).getContext("2d"), this.label);
     };

src/plugins/jqplot.canvasAxisTickRenderer.js

         return this;
     };
     
-    $.jqplot.CanvasAxisTickRenderer.prototype.draw = function(ctx) {
+    $.jqplot.CanvasAxisTickRenderer.prototype.draw = function(ctx, plot) {
         if (!this.label) {
             this.label = this.prefix + this.formatter(this.formatString, this.value);
         }
         // Memory Leaks patch
         if (this._elem) {
             if ($.jqplot.use_excanvas) {
-                var elem = this._elem.get(0);
-                window.G_vmlCanvasManager.uninitElement(elem);
-                elem = null;
+                window.G_vmlCanvasManager.uninitElement(this._elem.get(0));
             }
             
             this._elem.emptyForce();
-            this._domelem = null;
             this._elem = null;
         }
 
         // create a canvas here, but can't draw on it untill it is appended
         // to dom for IE compatability.
-        var domelem = document.createElement('canvas');
+
+        var elem;
+
+        // don't use the canvas manager with excanvas.
+        if ($.jqplot.use_excanvas) {
+            window.G_vmlCanvasManager.uninitElement(elem);
+            elem = document.createElement('canvas');
+        }
+        else {
+            elem = plot.canvasManager.getCanvas();
+        }
+
         this._textRenderer.setText(this.label, ctx);
         var w = this.getWidth(ctx);
         var h = this.getHeight(ctx);
-        domelem.width = w;
-        domelem.height = h;
-        domelem.style.width = w;
-        domelem.style.height = h;
-        domelem.style.textAlign = 'left';
-        domelem.style.position = 'absolute';
-        this._domelem = domelem;
-        this._elem = $(domelem);
+        elem.width = w;
+        elem.height = h;
+        elem.style.width = w;
+        elem.style.height = h;
+        elem.style.textAlign = 'left';
+        elem.style.position = 'absolute';
+        this._elem = $(elem);
         this._elem.css(this._styles);
         this._elem.addClass('jqplot-'+this.axis+'-tick');
+
+        if ($.jqplot.use_excanvas) {
+            // useless ?? window.G_vmlCanvasManager.init_(document);
+            elem = window.G_vmlCanvasManager.initElement(elem);
+        }
         
-        domelem = null;
+        elem = null;
         return this._elem;
     };
     
     $.jqplot.CanvasAxisTickRenderer.prototype.pack = function() {
         if ($.jqplot.use_excanvas) {
-            window.G_vmlCanvasManager.init_(document);
-            this._domelem = window.G_vmlCanvasManager.initElement(this._domelem);
+            //window.G_vmlCanvasManager.init_(document);
+            this._elem.get(0) = window.G_vmlCanvasManager.initElement(this._elem.get(0));
         }
         this._textRenderer.draw(this._elem.get(0).getContext("2d"), this.label);
     };

src/plugins/jqplot.cursor.js

         }
 
         
-        // if (c.zoom) {
-        c.zoomCanvas = new $.jqplot.GenericCanvas();
-        this.eventCanvas._elem.before(c.zoomCanvas.createElement(this._gridPadding, 'jqplot-zoom-canvas', this._plotDimensions, this));
-        c.zoomCanvas.setContext();
-        // }
+        if (c.zoom) {
+            c.zoomCanvas = new $.jqplot.GenericCanvas();
+            this.eventCanvas._elem.before(c.zoomCanvas.createElement(this._gridPadding, 'jqplot-zoom-canvas', this._plotDimensions, this));
+            c.zoomCanvas.setContext();
+        }
+        
         c._tooltipElem = $('<div class="jqplot-cursor-tooltip" style="position:absolute;display:none"></div>');
-        c.zoomCanvas._elem.before(c._tooltipElem);
+        
+        if (c.zoomCanvas) {
+            c.zoomCanvas._elem.before(c._tooltipElem);
+        }
+
+        else {
+            this.eventCanvas._elem.before(c._tooltipElem);
+        }
+
         if (c.showVerticalLine || c.showHorizontalLine) {
             c.cursorCanvas = new $.jqplot.GenericCanvas();
             this.eventCanvas._elem.before(c.cursorCanvas.createElement(this._gridPadding, 'jqplot-cursor-canvas', this._plotDimensions, this));
     
     function handleMouseMove(ev, gridpos, datapos, neighbor, plot) {
         var c = plot.plugins.cursor;
-        var ctx = c.zoomCanvas._ctx;
         if (c.show) {
             if (c.showTooltip) {
                 updateTooltip(gridpos, datapos, plot);
                 moveLine(gridpos, plot);
             }
         }
-        ctx = null;
     }
             
     function getEventPosition(ev) {