Permalink
Browse files

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.
  • Loading branch information...
1 parent 53ce9ad commit c41b09b844232e4ec944773bc94156094e845974 @dnschnur dnschnur committed Mar 6, 2013
Showing with 10 additions and 1 deletion.
  1. +10 −1 jquery.flot.canvas.js
View
@@ -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

0 comments on commit c41b09b

Please sign in to comment.