+ this.datasets.push(set_xy);
+ this.setNames.push(setname);
+};
+
+DygraphLayout.prototype.getPlotArea = function() {
+ return this.computePlotArea_();
+};
+
+// Compute the box which the chart should be drawn in. This is the canvas's
+// box, less space needed for axis and chart labels.
+DygraphLayout.prototype.computePlotArea_ = function() {
+ var area = {
+ // TODO(danvk): per-axis setting.
+ x: 0,
+ y: 0
+ };
+ if (this.attr_('drawYAxis')) {
+ area.x = this.attr_('yAxisLabelWidth') + 2 * this.attr_('axisTickSize');
+ }
+
+ area.w = this.dygraph_.width_ - area.x - this.attr_('rightGap');
+ area.h = this.dygraph_.height_;
+ if (this.attr_('drawXAxis')) {
+ if (this.attr_('xAxisHeight')) {
+ area.h -= this.attr_('xAxisHeight');
+ } else {
+ area.h -= this.attr_('axisLabelFontSize') + 2 * this.attr_('axisTickSize');
+ }
+ }
+
+ // Shrink the drawing area to accomodate additional y-axes.
+ if (this.dygraph_.numAxes() == 2) {
+ // TODO(danvk): per-axis setting.
+ area.w -= (this.attr_('yAxisLabelWidth') + 2 * this.attr_('axisTickSize'));
+ } else if (this.dygraph_.numAxes() > 2) {
+ this.dygraph_.error("Only two y-axes are supported at this time. (Trying " +
+ "to use " + this.dygraph_.numAxes() + ")");
+ }
+
+ // Add space for chart labels: title, xlabel and ylabel.
+ if (this.attr_('title')) {
+ area.h -= this.attr_('titleHeight');
+ area.y += this.attr_('titleHeight');
+ }
+ if (this.attr_('xlabel')) {
+ area.h -= this.attr_('xLabelHeight');
+ }
+ if (this.attr_('ylabel')) {
+ // It would make sense to shift the chart here to make room for the y-axis
+ // label, but the default yAxisLabelWidth is large enough that this results
+ // in overly-padded charts. The y-axis label should fit fine. If it
+ // doesn't, the yAxisLabelWidth option can be increased.
+ }
+
+ if (this.attr_('y2label')) {
+ // 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')) {
+ area.h -= this.attr_('rangeSelectorHeight') + 4;
+ }
+
+ return area;