From e7de87352483c0700851662c0951f1dc26b09b27 Mon Sep 17 00:00:00 2001 From: David Schnur Date: Sun, 24 Feb 2013 11:54:58 -0500 Subject: [PATCH] Factor out text layer creation to its own method. This sets the stage for allowing the use of multiple layers. --- jquery.flot.js | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/jquery.flot.js b/jquery.flot.js index f73cd05..6c0db7b 100644 --- a/jquery.flot.js +++ b/jquery.flot.js @@ -171,7 +171,7 @@ Licensed under the MIT license. var cache = this._textCache, cacheHasText = false, - info, key; + key; // Check whether the cache actually has any entries. @@ -188,23 +188,13 @@ Licensed under the MIT license. // Create the HTML text layer, if it doesn't already exist. - if (!this.text) { - this.text = $("
") - .addClass("flot-text") - .css({ - position: "absolute", - top: 0, - left: 0, - bottom: 0, - right: 0 - }) - .insertAfter(this.element); - } + var layer = this.getTextLayer(), + info; // Add all the elements to the text layer, then add it to the DOM at // the end, so we only trigger a single redraw. - this.text.hide(); + layer.hide(); for (key in cache) { if (hasOwnProperty.call(cache, key)) { @@ -213,7 +203,7 @@ Licensed under the MIT license. if (info.active) { if (!info.rendered) { - this.text.append(info.element); + layer.append(info.element); info.rendered = true; } } else { @@ -225,7 +215,31 @@ Licensed under the MIT license. } } - this.text.show(); + layer.show(); + }; + + // Creates (if necessary) and returns the text overlay container. + // + // @return {object} The jQuery-wrapped text-layer div. + + Canvas.prototype.getTextLayer = function() { + + // Create the text layer if it doesn't exist + + if (!this.text) { + this.text = $("
") + .addClass("flot-text") + .css({ + position: "absolute", + top: 0, + left: 0, + bottom: 0, + right: 0 + }) + .insertAfter(this.element); + } + + return this.text; }; // Creates (if necessary) and returns a text info object.