/**
* Creates a new DygraphLayout object.
- * @param {Object} options Options for PlotKit.Layout
* @return {Object} The DygraphLayout object
*/
-DygraphLayout = function(dygraph, options) {
+DygraphLayout = function(dygraph) {
this.dygraph_ = dygraph;
- this.options = {}; // TODO(danvk): remove, use attr_ instead.
- Dygraph.update(this.options, options ? options : {});
this.datasets = new Array();
this.annotations = new Array();
+ this.yAxes_ = null;
+
+ // TODO(danvk): it's odd that xTicks_ and yTicks_ are inputs, but xticks and
+ // yticks are outputs. Clean this up.
+ this.xTicks_ = null;
+ this.yTicks_ = null;
};
DygraphLayout.prototype.attr_ = function(name) {
}
};
+DygraphLayout.prototype.setXTicks = function(xTicks) {
+ this.xTicks_ = xTicks;
+};
+
+// TODO(danvk): add this to the Dygraph object's API or move it into Layout.
+DygraphLayout.prototype.setYAxes = function (yAxes) {
+ this.yAxes_ = yAxes;
+};
+
+DygraphLayout.prototype.setDateWindow = function(dateWindow) {
+ this.dateWindow_ = dateWindow;
+};
+
DygraphLayout.prototype.evaluate = function() {
this._evaluateLimits();
this._evaluateLineCharts();
DygraphLayout.prototype._evaluateLimits = function() {
this.minxval = this.maxxval = null;
- if (this.options.dateWindow) {
- this.minxval = this.options.dateWindow[0];
- this.maxxval = this.options.dateWindow[1];
+ if (this.dateWindow_) {
+ this.minxval = this.dateWindow_[0];
+ this.maxxval = this.dateWindow_[1];
} else {
for (var name in this.datasets) {
if (!this.datasets.hasOwnProperty(name)) continue;
this.xrange = this.maxxval - this.minxval;
this.xscale = (this.xrange != 0 ? 1/this.xrange : 1.0);
- for (var i = 0; i < this.options.yAxes.length; i++) {
- var axis = this.options.yAxes[i];
+ for (var i = 0; i < this.yAxes_.length; i++) {
+ var axis = this.yAxes_[i];
axis.minyval = axis.computedValueRange[0];
axis.maxyval = axis.computedValueRange[1];
axis.yrange = axis.maxyval - axis.minyval;
if (!this.datasets.hasOwnProperty(setName)) continue;
var dataset = this.datasets[setName];
- var axis = this.options.yAxes[this.options.seriesToAxisMap[setName]];
+ var axis = this.dygraph_.axisPropertiesForSeries(setName);
for (var j = 0; j < dataset.length; j++) {
var item = dataset[j];
DygraphLayout.prototype._evaluateLineTicks = function() {
this.xticks = new Array();
- for (var i = 0; i < this.options.xTicks.length; i++) {
- var tick = this.options.xTicks[i];
+ for (var i = 0; i < this.xTicks_.length; i++) {
+ var tick = this.xTicks_[i];
var label = tick.label;
var pos = this.xscale * (tick.v - this.minxval);
if ((pos >= 0.0) && (pos <= 1.0)) {
}
this.yticks = new Array();
- for (var i = 0; i < this.options.yAxes.length; i++ ) {
- var axis = this.options.yAxes[i];
+ for (var i = 0; i < this.yAxes_.length; i++ ) {
+ var axis = this.yAxes_[i];
for (var j = 0; j < axis.ticks.length; j++) {
var tick = axis.ticks[j];
var label = tick.label;
*/
DygraphLayout.prototype.evaluateWithError = function() {
this.evaluate();
- if (!this.options.errorBars) return;
+ if (!(this.attr_('errorBars') || this.attr_('customBars'))) return;
// Copy over the error terms
var i = 0; // index in this.points
};
/**
- * Change the values of various layout options
- * @param {Object} new_options an associative array of new properties
- */
-DygraphLayout.prototype.updateOptions = function(new_options) {
- Dygraph.update(this.options, new_options ? new_options : {});
-};
-
-/**
* Return a copy of the point at the indicated index, with its yval unstacked.
* @param int index of point in layout_.points
*/
var colorCount = this.options.colorScheme.length;
var colorScheme = this.options.colorScheme;
var fillAlpha = this.options.fillAlpha;
- var errorBars = this.layout.options.errorBars;
+ var errorBars = this.attr_("errorBars");
var fillGraph = this.attr_("fillGraph");
- var stackedGraph = this.layout.options.stackedGraph;
- var stepPlot = this.layout.options.stepPlot;
+ var stackedGraph = this.attr_("stackedGraph");
+ var stepPlot = this.attr_("stepPlot");
var setNames = [];
for (var name in this.layout.datasets) {
for (var i = 0; i < setCount; i++) {
var setName = setNames[i];
- var axis = this.layout.options.yAxes[
- this.layout.options.seriesToAxisMap[setName]];
+ var axis = this.dygraph_.axisPropertiesForSeries(setName);
var color = this.colors[setName];
// setup graphics context
for (var i = setCount - 1; i >= 0; i--) {
var setName = setNames[i];
var color = this.colors[setName];
- var axis = this.layout.options.yAxes[
- this.layout.options.seriesToAxisMap[setName]];
+ var axis = this.dygraph_.axisPropertiesForSeries(setName);
var axisY = 1.0 + axis.minyval * axis.yscale;
if (axisY < 0.0) axisY = 0.0;
else if (axisY > 1.0) axisY = 1.0;