From c41b09b844232e4ec944773bc94156094e845974 Mon Sep 17 00:00:00 2001 From: David Schnur Date: Tue, 5 Mar 2013 21:09:20 -0500 Subject: [PATCH] Only save references to old Canvas methods once. Plugins are re-initialized with each re-plot (which may not be the right thing to do, but that's how it works for now). The previous approach of saving references to the original Canvas functions therefore broke, since the second time around we'd get a reference to our new function. Instead we hold those references as globals within the plugin, and only set them once. This whole idea of replacing prototype functions is, now that I step back and look at it, really awful. This needs to be changed ASAP to something less ridiculous. --- jquery.flot.canvas.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/jquery.flot.canvas.js b/jquery.flot.canvas.js index 45bd32b..3722646 100644 --- a/jquery.flot.canvas.js +++ b/jquery.flot.canvas.js @@ -33,16 +33,25 @@ browser, but needs to redraw with canvas text when exporting as an image. canvas: true }; + var render, getTextInfo, addText; + // Cache the prototype hasOwnProperty for faster access var hasOwnProperty = Object.prototype.hasOwnProperty; function init(plot, classes) { - var Canvas = classes.Canvas, + var Canvas = classes.Canvas; + + // We only want to replace the functions once; the second time around + // we would just get our new function back. This whole replacing of + // prototype functions is a disaster, and needs to be changed ASAP. + + if (render == null) { getTextInfo = Canvas.prototype.getTextInfo, addText = Canvas.prototype.addText, render = Canvas.prototype.render; + } // Finishes rendering the canvas, including overlaid text