From: Dan Vanderkam Date: Fri, 6 Jul 2012 01:35:15 +0000 (-0400) Subject: reasonable behavior for title X-Git-Tag: v1.0.0~255 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=1748a51c025b83c37fcf4c15ec0303de8aaf1a42;p=dygraphs.git reasonable behavior for title --- diff --git a/dygraph.js b/dygraph.js index 99fdf3b..38c1d05 100644 --- a/dygraph.js +++ b/dygraph.js @@ -2103,7 +2103,7 @@ Dygraph.prototype.predraw_ = function() { // Create a new plotter. if (this.plotter_) { - this.cascadeEvents_('clear'); + this.cascadeEvents_('clearChart'); this.plotter_.clear(); } this.plotter_ = new DygraphCanvasRenderer(this, @@ -2333,7 +2333,7 @@ Dygraph.prototype.drawGraph_ = function() { * @private */ Dygraph.prototype.renderGraph_ = function(is_initial_draw) { - this.cascadeEvents_('clear'); + this.cascadeEvents_('clearChart'); this.plotter_.clear(); this.plotter_.render(); diff --git a/plugins/chart-labels.js b/plugins/chart-labels.js index 3dad191..aa56337 100644 --- a/plugins/chart-labels.js +++ b/plugins/chart-labels.js @@ -20,7 +20,9 @@ chart_labels.prototype.toString = function() { chart_labels.prototype.activate = function(g) { return { - layout: this.layout + layout: this.layout, + // clearChart: this.clearChart, + drawChart: this.drawChart }; }; @@ -35,7 +37,27 @@ var createDivInRect = function(r) { return div; }; +// Detach and null out any existing nodes. +chart_labels.prototype.detachLabels_ = function() { + var els = [ this.title_div_, + this.xlabel_div_, + this.ylabel_div_, + this.y2label_div_ ]; + for (var i = 0; i < els.length; i++) { + var el = els[i]; + if (!el) continue; + if (el.parentNode) el.parentNode.removeChild(el); + } + + this.title_div_ = null; + this.xlabel_div_ = null; + this.ylabel_div_ = null; + this.y2label_div_ = null; +}; + chart_labels.prototype.layout = function(e) { + this.detachLabels_(); + var g = e.dygraph; var div = e.chart_div; if (g.getOption('title')) { @@ -64,11 +86,18 @@ chart_labels.prototype.layout = function(e) { */ }; +chart_labels.prototype.drawChart = function(e) { + var g = e.dygraph; + if (this.title_div_) { + this.title_div_.innerHTML = g.getOption('title'); + } +}; + +chart_labels.prototype.clearChart = function() { +}; + chart_labels.prototype.destroy = function() { - this.title_div_ = null; - this.xlabel_div_ = null; - this.ylabel_div_ = null; - this.y2label_div_ = null; + detachLabels(); };