From: Dan Vanderkam Date: Fri, 6 Jul 2012 01:20:25 +0000 (-0400) Subject: re-add layout plugin event; title display works X-Git-Tag: v1.0.0~257 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=6dca682fe3a060c9ae73cdc8f669531edd7d3b9b;p=dygraphs.git re-add layout plugin event; title display works --- diff --git a/dygraph-canvas.js b/dygraph-canvas.js index f1e3c8c..56c26b8 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -239,7 +239,7 @@ DygraphCanvasRenderer.prototype.render = function() { // Do the ordinary rendering, as before this._renderLineChart(); this._renderAxis(); - this._renderChartLabels(); + // this._renderChartLabels(); this._renderAnnotations(); }; diff --git a/dygraph-dev.js b/dygraph-dev.js index e1d8830..e659221 100644 --- a/dygraph-dev.js +++ b/dygraph-dev.js @@ -29,6 +29,7 @@ "dygraph-tickers.js", "plugins/base.js", "plugins/legend.js", + "plugins/chart-labels.js", "plugins/install.js", "dygraph-options-reference.js" // Shouldn't be included in generate-combined.sh ]; diff --git a/dygraph-layout.js b/dygraph-layout.js index ac1eca0..81274ed 100644 --- a/dygraph-layout.js +++ b/dygraph-layout.js @@ -69,6 +69,38 @@ DygraphLayout.prototype.computePlotArea_ = function() { area.w = this.dygraph_.width_ - area.x - this.attr_('rightGap'); area.h = this.dygraph_.height_; + + // Let plugins reserve space. + var e = { + chart_div: this.dygraph_.graphDiv, + reserveSpaceLeft: function(px) { + var r = { + x: area.x, + y: area.y, + w: px, + h: area.h + }; + area.x += px; + area.w -= px; + return r; + }, + reserveSpaceTop: function(px) { + var r = { + x: area.x, + y: area.y, + w: area.w, + h: px + }; + area.y += px; + area.h -= px; + return r; + }, + chartRect: function() { + return {x:area.x, y:area.y, w:area.w, h:area.h}; + } + }; + this.dygraph_.cascadeEvents_('layout', e); + if (this.attr_('drawXAxis')) { if (this.attr_('xAxisHeight')) { area.h -= this.attr_('xAxisHeight'); @@ -86,6 +118,7 @@ DygraphLayout.prototype.computePlotArea_ = function() { "to use " + this.dygraph_.numAxes() + ")"); } +/* // Add space for chart labels: title, xlabel and ylabel. if (this.attr_('title')) { area.h -= this.attr_('titleHeight'); @@ -105,6 +138,7 @@ DygraphLayout.prototype.computePlotArea_ = function() { // same logic applies here as for ylabel. // TODO(danvk): make yAxisLabelWidth a per-axis property } +*/ // Add space for range selector, if needed. if (this.attr_('showRangeSelector')) { diff --git a/generate-combined.sh b/generate-combined.sh index 6443343..ab3a53d 100755 --- a/generate-combined.sh +++ b/generate-combined.sh @@ -18,6 +18,7 @@ rgbcolor/rgbcolor.js \ strftime/strftime-min.js \ plugins/base.js \ plugins/legend.js \ +plugins/chart-labels \ plugins/install.js \ | perl -ne 'print unless m,REMOVE_FOR_COMBINED,..m,/REMOVE_FOR_COMBINED,' \ > /tmp/dygraph.js diff --git a/plugins/chart-labels.js b/plugins/chart-labels.js index 0b6e4c2..3dad191 100644 --- a/plugins/chart-labels.js +++ b/plugins/chart-labels.js @@ -35,7 +35,7 @@ var createDivInRect = function(r) { return div; }; -chart_labels.layout = function(e) { +chart_labels.prototype.layout = function(e) { var g = e.dygraph; var div = e.chart_div; if (g.getOption('title')) {