From 4203a66eba482027b3e92c56aff44ce69aa9dfb4 Mon Sep 17 00:00:00 2001 From: David Schnur Date: Sun, 24 Feb 2013 12:13:39 -0500 Subject: [PATCH] Add text to its actual layer before measuring it. The getTextInfo method previously added new text to the top-level container when measuring it. Now it adds the text to the text layer, just as it will be when rendered, so that parent-child CSS rules can resolve correctly. This also avoids having to safe a reference to the top-level container, since it wasn't used anywhere else. --- examples/basic-canvas.html | 39 ++++++++++++++++++++++++++++++++++++++ jquery.flot.canvas.js | 6 +++++- jquery.flot.js | 14 ++++++-------- 3 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 examples/basic-canvas.html diff --git a/examples/basic-canvas.html b/examples/basic-canvas.html new file mode 100644 index 0000000..d9610eb --- /dev/null +++ b/examples/basic-canvas.html @@ -0,0 +1,39 @@ + + + + + Flot Examples + + + + + + + +

Flot Examples

+ +
+ +

Simple example. You don't need to specify much to get an + attractive look. Put in a placeholder, make sure you set its + dimensions (otherwise the plot library will barf) and call the + plot function with the data. The axes are automatically + scaled.

+ + + + + diff --git a/jquery.flot.canvas.js b/jquery.flot.canvas.js index 3499d50..81e0b3e 100644 --- a/jquery.flot.canvas.js +++ b/jquery.flot.canvas.js @@ -201,7 +201,11 @@ browser, but needs to redraw with canvas text when exporting as an image. var element = $("
").html(text) .addClass(typeof font === "string" ? font : null) - .appendTo(this.container); + .css({ + position: "absolute", + top: -9999 + }) + .appendTo(this.getTextLayer()); font = { style: element.css("font-style"), diff --git a/jquery.flot.js b/jquery.flot.js index 6c0db7b..6823e3c 100644 --- a/jquery.flot.js +++ b/jquery.flot.js @@ -56,8 +56,6 @@ Licensed under the MIT license. function Canvas(cls, container) { - this.container = container; - var element = document.createElement("canvas"); element.className = cls; this.element = element; @@ -292,10 +290,12 @@ Licensed under the MIT license. if (info == null) { - var element = $("
").html(text).css({ - position: "absolute", - top: -9999 - }); + var element = $("
").html(text) + .css({ + position: "absolute", + top: -9999 + }) + .appendTo(this.getTextLayer()); if (typeof font === "object") { element.css({ @@ -306,8 +306,6 @@ Licensed under the MIT license. element.addClass(font); } - element.appendTo(this.container); - info = { active: false, rendered: false,