Factor out text layer creation to its own method.

This sets the stage for allowing the use of multiple layers.
pull/1/head
David Schnur 13 years ago
parent a036aa962a
commit e7de873524

@ -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 = $("<div></div>")
.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 = $("<div></div>")
.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.

Loading…
Cancel
Save