Anonymous avatar Anonymous committed 2076212

Fixed the core to work with flotzai. Some changes previously in the core
were moved to the jqplot.core.changes.js.

Comments (0)

Files changed (4)

src/jqplot.core.changes.js

+(function($) {
+    
+    // canvas manager to reuse canvases on the plot.
+    // Should help solve problem of canvases not being freed and
+    // problem of waiting forever for firefox to decide to free memory.
+    $.jqplot.CanvasManager = function() {
+        // canvases are managed globally so that they can be reused
+        // across plots after they have been freed
+        if (typeof $.jqplot.CanvasManager.canvases == 'undefined') {
+            $.jqplot.CanvasManager.canvases = [];
+            $.jqplot.CanvasManager.free = [];
+        }
+        
+        var myCanvases = [];
+        
+        this.getCanvas = function() {
+            var canvas;
+            var makeNew = true;
+            
+            if (!$.jqplot.use_excanvas) {
+                for (var i = 0, l = $.jqplot.CanvasManager.canvases.length; i < l; i++) {
+                    if ($.jqplot.CanvasManager.free[i] === true) {
+                        makeNew = false;
+                        canvas = $.jqplot.CanvasManager.canvases[i];
+                        // $(canvas).removeClass('jqplot-canvasManager-free').addClass('jqplot-canvasManager-inuse');
+                        $.jqplot.CanvasManager.free[i] = false;
+                        myCanvases.push(i);
+                        break;
+                    }
+                }
+            }
+
+            if (makeNew) {
+                canvas = document.createElement('canvas');
+                myCanvases.push($.jqplot.CanvasManager.canvases.length);
+                $.jqplot.CanvasManager.canvases.push(canvas);
+                $.jqplot.CanvasManager.free.push(false);
+            }   
+            
+            return canvas;
+        };
+        
+        // this method has to be used after settings the dimesions
+        // on the element returned by getCanvas()
+        this.initCanvas = function(canvas) {
+            if ($.jqplot.use_excanvas) {
+                return window.G_vmlCanvasManager.initElement(canvas);
+            }
+            return canvas;
+        };
+
+        this.freeAllCanvases = function(dontFreeEventCanvas) {
+            if(dontFreeEventCanvas){
+                var ec_idx = -1;
+                for (var i = 0, l=myCanvases.length; i < l; i++) {
+                    if($($.jqplot.CanvasManager.canvases[myCanvases[i]]).attr('class')!="jqplot-event-canvas"){
+                        this.freeCanvas(myCanvases[i]);
+                    }
+                    else{
+                        ec_idx = myCanvases[i];
+                    }
+                }
+                myCanvases = ec_idx >= 0 ? [ec_idx] : [];
+            }
+            else{
+                for (var i = 0, l=myCanvases.length; i < l; i++) {
+                    this.freeCanvas(myCanvases[i]);
+                }
+                myCanvases = [];
+            }
+        };
+
+        this.freeCanvas = function(idx) {
+            if ($.jqplot.use_excanvas && window.G_vmlCanvasManager.uninitElement !== undefined) {
+                // excanvas can't be reused, but properly unset
+                window.G_vmlCanvasManager.uninitElement($.jqplot.CanvasManager.canvases[idx]);
+                $.jqplot.CanvasManager.canvases[idx] = null;
+            } 
+            else {
+                var canvas = $.jqplot.CanvasManager.canvases[idx];
+                canvas.getContext('2d').clearRect(0, 0, canvas.width, canvas.height);
+                $(canvas).unbind().removeAttr('class').removeAttr('style');
+                // Style attributes seemed to be still hanging around.  wierd.  Some ticks
+                // still retained a left: 0px attribute after reusing a canvas.
+                $(canvas).css({left: '', top: '', position: ''});
+                // setting size to 0 may save memory of unused canvases?
+                canvas.width = 0;
+                canvas.height = 0;
+                $.jqplot.CanvasManager.free[idx] = true;
+            }
+        };
+        
+    };
+    
+    
+   // Finds the point with the x coordinate closest to the given x.
+   $.jqplot.closest = function(x, serie) {
+        function binSearchPoint(array, x, f_, fail_) {
+            var begin = 0,
+                end = array.length,
+                middle,
+                point,
+                f = f_ || function(value) {return value;},
+                fail = fail_ || function(middle) {return -1;};
+
+            while (begin <= end) {
+                middle = Math.ceil((end - begin) / 2 + begin);
+                point = array[middle] ? array[middle][0] : null;
+
+                // Damn, we've hit a null point. Move middle around
+                // until we found a valid point.
+                if (point === null) {
+                    while (middle > begin && point === null) {
+                        middle -= 1;
+                        point = array[middle] ? array[middle][0] : null;
+                    };
+
+                    // If we can't find a point after begin that is not null,
+                    // move forward. Otherwise, there won't be progress.
+                    if (point === null) {
+                        middle = Math.floor((end - begin) / 2 + begin);
+
+                        while (middle < end && point === null) {
+                            middle += 1;
+                            point = array[middle] ? array[middle][0] : null;
+                        }
+                    }
+
+                    if (point === null) {
+                        break;
+                    }
+                }
+
+                if (x < f(point)) {
+                    end = middle - 1;
+                } else if (x > f(point)) {
+                    begin = middle + 1;
+                } else {
+                    return middle;
+                }
+            }
+
+            return fail(middle);
+        }
+        function minBy(array, f) {
+            var min = array[0];
+            for (var i = 1; i < array.length; i++) {
+                if (f(array[i]) < f(min)) {
+                    min = array[i];
+                }
+            }
+
+            return min;
+        }
+        function closestNeighbour(neighbours) {
+            var distance = function(fst, snd) {
+                return Math.abs(fst - snd);
+            };
+
+            return minBy(neighbours, function (elt) {
+                return elt >= 0 && elt < serie.length
+                    ? distance(x, serie[elt][0]) : Number.POSITIVE_INFINITY;
+            });
+        }
+
+        var idx = binSearchPoint(serie, x,
+                                 null,
+                                 function(middle) {
+                                     return closestNeighbour([middle - 1, middle, middle + 1]);
+                                 });
+        return idx;
+    };
+    
+})(jQuery);
+

src/jqplot.core.js

  * 
  */
 
-/* Plugin for jQuery for working with colors.
- * 
- * Version 1.1.
- * 
- * Inspiration from jQuery color animation plugin by John Resig.
- *
- * Released under the MIT license by Ole Laursen, October 2009.
- *
- * Examples:
- *
- *   $.color.parse("#fff").scale('rgb', 0.25).add('a', -0.5).toString()
- *   var c = $.color.extract($("#mydiv"), 'background-color');
- *   console.log(c.r, c.g, c.b, c.a);
- *   $.color.make(100, 50, 25, 0.4).toString() // returns "rgba(100,50,25,0.4)"
- *
- * Note that .scale() and .add() return the same modified object
- * instead of making a new one.
- *
- * V. 1.1: Fix error handling so e.g. parsing an empty string does
- * produce a color rather than just crashing.
- */ 
-(function(B){B.color={};B.color.make=function(F,E,C,D){var G={};G.r=F||0;G.g=E||0;G.b=C||0;G.a=D!=null?D:1;G.add=function(J,I){for(var H=0;H<J.length;++H){G[J.charAt(H)]+=I}return G.normalize()};G.scale=function(J,I){for(var H=0;H<J.length;++H){G[J.charAt(H)]*=I}return G.normalize()};G.toString=function(){if(G.a>=1){return"rgb("+[G.r,G.g,G.b].join(",")+")"}else{return"rgba("+[G.r,G.g,G.b,G.a].join(",")+")"}};G.normalize=function(){function H(J,K,I){return K<J?J:(K>I?I:K)}G.r=H(0,parseInt(G.r),255);G.g=H(0,parseInt(G.g),255);G.b=H(0,parseInt(G.b),255);G.a=H(0,G.a,1);return G};G.clone=function(){return B.color.make(G.r,G.b,G.g,G.a)};return G.normalize()};B.color.extract=function(D,C){var E;do{E=D.css(C).toLowerCase();if(E!=""&&E!="transparent"){break}D=D.parent()}while(!B.nodeName(D.get(0),"body"));if(E=="rgba(0, 0, 0, 0)"){E="transparent"}return B.color.parse(E)};B.color.parse=function(F){var E,C=B.color.make;if(E=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(F)){return C(parseInt(E[1],10),parseInt(E[2],10),parseInt(E[3],10))}if(E=/rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(F)){return C(parseInt(E[1],10),parseInt(E[2],10),parseInt(E[3],10),parseFloat(E[4]))}if(E=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(F)){return C(parseFloat(E[1])*2.55,parseFloat(E[2])*2.55,parseFloat(E[3])*2.55)}if(E=/rgba\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(F)){return C(parseFloat(E[1])*2.55,parseFloat(E[2])*2.55,parseFloat(E[3])*2.55,parseFloat(E[4]))}if(E=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(F)){return C(parseInt(E[1],16),parseInt(E[2],16),parseInt(E[3],16))}if(E=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(F)){return C(parseInt(E[1]+E[1],16),parseInt(E[2]+E[2],16),parseInt(E[3]+E[3],16))}var D=B.trim(F).toLowerCase();if(D=="transparent"){return C(255,255,255,0)}else{E=A[D]||[0,0,0];return C(E[0],E[1],E[2])}};var A={aqua:[0,255,255],azure:[240,255,255],beige:[245,245,220],black:[0,0,0],blue:[0,0,255],brown:[165,42,42],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgrey:[169,169,169],darkgreen:[0,100,0],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkviolet:[148,0,211],fuchsia:[255,0,255],gold:[255,215,0],green:[0,128,0],indigo:[75,0,130],khaki:[240,230,140],lightblue:[173,216,230],lightcyan:[224,255,255],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightyellow:[255,255,224],lime:[0,255,0],magenta:[255,0,255],maroon:[128,0,0],navy:[0,0,128],olive:[128,128,0],orange:[255,165,0],pink:[255,192,203],purple:[128,0,128],violet:[128,0,128],red:[255,0,0],silver:[192,192,192],white:[255,255,255],yellow:[255,255,0]}})(jQuery);
-
 (function($) {
     // make sure undefined is undefined
     var undefined;
             return canvas;
         };
 
-        this.freeAllCanvases = function(dontFreeEventCanvas) {
-            if(dontFreeEventCanvas){
-                var ec_idx = -1;
+        this.freeAllCanvases = function() {
             for (var i = 0, l=myCanvases.length; i < l; i++) {
-                    if($($.jqplot.CanvasManager.canvases[myCanvases[i]]).attr('class')!="jqplot-event-canvas"){
                 this.freeCanvas(myCanvases[i]);
             }
-                    else{
-                        ec_idx = myCanvases[i];
-                    }
-                }
-                myCanvases = ec_idx >= 0 ? [ec_idx] : [];
-            }
-            else{
-                for (var i = 0, l=myCanvases.length; i < l; i++) {
-                    this.freeCanvas(myCanvases[i]);
-                }
             myCanvases = [];
-            }
         };
 
         this.freeCanvas = function(idx) {
-            if ($.jqplot.use_excanvas) {
+            if ($.jqplot.use_excanvas && window.G_vmlCanvasManager.uninitElement !== undefined) {
                 // excanvas can't be reused, but properly unset
                 window.G_vmlCanvasManager.uninitElement($.jqplot.CanvasManager.canvases[idx]);
                 $.jqplot.CanvasManager.canvases[idx] = null;
     };
     
     Axis.prototype.resetScale = function(opts) {
-        if (this.append && this.append === true) {
-            $.extend(true, this, {min: null, max: null}, opts);
-        } else {
         $.extend(true, this, {min: null, max: null, numberTicks: null, tickInterval: null, _ticks: [], ticks: []}, opts);
-        }
         this.resetDataBounds();
     };
     
                 maxyidx = 2;
             }
             
-            for (var j=0; j<d.length; j++) { 
+            for (var j=0, l=d.length; j<l; j++) { 
                 if (this.name == 'xaxis' || this.name == 'x2axis') {
                     if ((d[j][0] != null && d[j][0] < db.min) || db.min == null) {
                         db.min = d[j][0];
         }
         
         for (j=0; j<$.jqplot.postDrawSeriesHooks.length; j++) {
-            $.jqplot.postDrawSeriesHooks[j].call(this, sctx, options);
+            $.jqplot.postDrawSeriesHooks[j].call(this, sctx, options, plot);
         }
         
         sctx = opts = plot = j = data = gridData = null;
                 if (axis.borderWidth == null) {
                     axis.borderWidth =this.grid.borderWidth;
                 }
-                if (axis.borderColor == null) {
-                    if (n != 'xaxis' && n != 'x2axis' && axis.useSeriesColor === true && axis.show) {
-                        axis.borderColor = axis._series[0].color;
-                    }
-                    else {
-                        axis.borderColor = this.grid.borderColor;
-                    }
-                }
             }
             
             if (typeof this.options.title == 'string') {
                 this.target.unbind();
                 this.target.find("[class!=jqplot-event-canvas]").remove();
             }
-            
             this.reInitialize();
             if (resetAxes) {
                 this.resetAxesScale(resetAxes, opts.axes);
                 var must_do_event_canvas_binding = false;
                 if(!this.eventCanvas._elem || this.eventCanvas._elem.attr('class') != 'jqplot-event-canvas'){
                     this._gridPadding.left = 50;
-                this.target.append(this.eventCanvas.createElement(this._gridPadding, 'jqplot-event-canvas', null, this));
-                this.eventCanvas.setContext();
-                this.eventCanvas._ctx.fillStyle = 'rgba(0,0,0,0)';
-                this.eventCanvas._ctx.fillRect(0,0,this.eventCanvas._ctx.canvas.width, this.eventCanvas._ctx.canvas.height);
+                    this.target.append(this.eventCanvas.createElement(this._gridPadding, 'jqplot-event-canvas', null, this));
+                    this.eventCanvas.setContext();
+                    this.eventCanvas._ctx.fillStyle = 'rgba(0,0,0,0)';
+                    this.eventCanvas._ctx.fillRect(0,0,this.eventCanvas._ctx.canvas.width, this.eventCanvas._ctx.canvas.height);
                     this.eventCanvas._elem.css('z-index', 20);
                     must_do_event_canvas_binding = true;
                 }
                         // make sure there are references back into plot objects.
                         this.eventCanvas._elem.bind($.jqplot.eventListenerHooks[i][0], {plot:this}, $.jqplot.eventListenerHooks[i][1]);
                     }
-            
+
                     // register event listeners on the overlay canvas
                     for (var i=0, l=this.eventListenerHooks.hooks.length; i<l; i++) {
                         // in the handler, this will refer to the eventCanvas dom element.
         yellow: 'rgb(255, 255, 0)',
         yellowgreen: 'rgb(154, 205, 50)'
     };
+
     
-         // Finds the point with the x coordinate closest to the given x.
-   $.jqplot.closest = function(x, serie) {
-        function binSearchPoint(array, x, f_, fail_) {
-            var begin = 0,
-                end = array.length,
-                middle,
-                point,
-                f = f_ || function(value) {return value;},
-                fail = fail_ || function(middle) {return -1;};
-
-            while (begin <= end) {
-                middle = Math.ceil((end - begin) / 2 + begin);
-                point = array[middle] ? array[middle][0] : null;
-
-                // Damn, we've hit a null point. Move middle around
-                // until we found a valid point.
-                if (point === null) {
-                    while (middle > begin && point === null) {
-                        middle -= 1;
-                        point = array[middle] ? array[middle][0] : null;
-                    };
-
-                    // If we can't find a point after begin that is not null,
-                    // move forward. Otherwise, there won't be progress.
-                    if (point === null) {
-                        middle = Math.floor((end - begin) / 2 + begin);
-
-                        while (middle < end && point === null) {
-                            middle += 1;
-                            point = array[middle] ? array[middle][0] : null;
-                        }
-                    }
-
-                    if (point === null) {
-                        break;
-                    }
-                }
-
-                if (x < f(point)) {
-                    end = middle - 1;
-                } else if (x > f(point)) {
-                    begin = middle + 1;
-                } else {
-                    return middle;
-                }
-            }
-
-            return fail(middle);
-        }
-        function minBy(array, f) {
-            var min = array[0];
-            for (var i = 1; i < array.length; i++) {
-                if (f(array[i]) < f(min)) {
-                    min = array[i];
-                }
-            }
-
-            return min;
-        }
-        function closestNeighbour(neighbours) {
-            var distance = function(fst, snd) {
-                return Math.abs(fst - snd);
-            };
-
-            return minBy(neighbours, function (elt) {
-                return elt >= 0 && elt < serie.length
-                    ? distance(x, serie[elt][0]) : Number.POSITIVE_INFINITY;
-            });
-        }
-
-        var idx = binSearchPoint(serie, x,
-                                 null,
-                                 function(middle) {
-                                     return closestNeighbour([middle - 1, middle, middle + 1]);
-                                 });
-        return idx;
-    };
-
-
 })(jQuery);

src/jquery.jqplot.js

         }
     };
 
-    var files = ['jqplot.core.js', 'jqplot.linearTickGenerator.js', 'jqplot.linearAxisRenderer.js', 'jqplot.axisTickRenderer.js', 'jqplot.axisLabelRenderer.js', 'jqplot.tableLegendRenderer.js', 'jqplot.lineRenderer.js', 'jqplot.markerRenderer.js', 'jqplot.divTitleRenderer.js', 'jqplot.canvasGridRenderer.js', 'jqplot.linePattern.js', 'jqplot.shadowRenderer.js', 'jqplot.shapeRenderer.js', 'jqplot.sprintf.js', 'jsdate.js', 'jqplot.themeEngine.js', 'jqplot.toImage.js', 'jqplot.effects.core.js', 'jqplot.effects.blind.js'];
+    var files = ['jqplot.core.js', 'jqplot.core.changes.js', 'jqplot.linearTickGenerator.js', 'jqplot.linearAxisRenderer.js', 'jqplot.axisTickRenderer.js', 'jqplot.axisLabelRenderer.js', 'jqplot.tableLegendRenderer.js', 'jqplot.lineRenderer.js', 'jqplot.markerRenderer.js', 'jqplot.divTitleRenderer.js', 'jqplot.canvasGridRenderer.js', 'jqplot.linePattern.js', 'jqplot.shadowRenderer.js', 'jqplot.shapeRenderer.js', 'jqplot.sprintf.js', 'jsdate.js', 'jqplot.themeEngine.js', 'jqplot.toImage.js', 'jqplot.effects.core.js', 'jqplot.effects.blind.js'];
     var rn = getRootNode().root;
     for (var i=0; i<files.length; i++) {
         var pp = rn+files[i];

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;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.