Skip to content

Commit

Permalink
[flot] returned canvas reuse
Browse files Browse the repository at this point in the history
This gives us _massive_ improvement in memory use. Before that Chrome
could easily grab as much as 400M for heap, with this patch it seems
to stay way below 100M.

This basically reverts 6fe0258 back.
Which applied flot patch from here:
http://code.google.com/p/flot/issues/detail?id=269

Change-Id: Icf9bd8d828c1c36e4fdd0886bca44407148ef2b7
Reviewed-on: http://review.membase.org/3319
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Reviewed-by: Steve Yen <steve.yen@gmail.com>
  • Loading branch information
Aliaksey Kandratsenka authored and steveyen committed Oct 18, 2010
1 parent 34d6f1e commit 1b4199c
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions deps/menelaus/priv/js/jquery.flot.js
Expand Up @@ -540,10 +540,26 @@
c = window.G_vmlCanvasManager.initElement(c);
return c;
}

canvasWidth = placeholder.width();
canvasHeight = placeholder.height();
placeholder.html(""); // clear placeholder
var checkCanvas = placeholder.children('canvas');
if (checkCanvas.length &&
(checkCanvas.get(0).width == canvasWidth) &&
(checkCanvas.get(0).height == canvasHeight)){
canvas = checkCanvas.get(0);
ctx = canvas.getContext('2d');
overlay = checkCanvas.get(1);
octx = overlay.getContext('2d');

//do whatever manual clearing is necessary here
ctx.clearRect(0,0,canvasWidth,canvasHeight);
octx.clearRect(0,0,canvasWidth,canvasHeight);
unbindEvents();
} else {
placeholder.get(0).innerHTML = ''; //this helps with leaky memory possibly
//placeholder.html(""); // clear placeholder

if (placeholder.css("position") == 'static')
placeholder.css("position", "relative"); // for positioning labels and overlay

Expand All @@ -552,7 +568,7 @@

if ($.browser.msie) // excanvas hack
window.G_vmlCanvasManager.init_(document); // make sure everything is setup

// the canvas
canvas = $(makeCanvas(canvasWidth, canvasHeight)).appendTo(placeholder).get(0);
ctx = canvas.getContext("2d");
Expand All @@ -561,6 +577,7 @@
overlay = $(makeCanvas(canvasWidth, canvasHeight)).css({ position: 'absolute', left: 0, top: 0 }).appendTo(placeholder).get(0);
octx = overlay.getContext("2d");
octx.stroke();
}
}

function bindEvents() {
Expand All @@ -578,6 +595,13 @@
executeHooks(hooks.bindEvents, [eventHolder]);
}

function unbindEvents() {
// we include the canvas in the event holder too, because IE 7
// sometimes has trouble with the stacking order
eventHolder = $([overlay, canvas]);
eventHolder.unbind();
}

function setupGrid() {
function setTransformationHelpers(axis, o) {
function identity(x) { return x; }
Expand Down

0 comments on commit 1b4199c

Please sign in to comment.