this.fractions_ = attrs.fractions || false;
this.dateWindow_ = attrs.dateWindow || null;
- this.wilsonInterval_ = attrs.wilsonInterval || true;
this.is_initial_draw_ = true;
this.annotations_ = [];
* @return { Integer } The number of columns.
*/
Dygraph.prototype.numColumns = function() {
- return this.rawData_[0].length;
+ return this.rawData_[0] ? this.rawData_[0].length : this.attr_("labels").length;
};
/**
};
/**
+ * Returns the full range of the x-axis, as determined by the most extreme
+ * values in the data set. Not affected by zooming, visibility, etc.
+ * TODO(danvk): merge w/ xAxisExtremes
+ * @return { Array<Number> } A [low, high] pair
+ * @private
+ */
+Dygraph.prototype.fullXRange_ = function() {
+ if (this.numRows() > 0) {
+ return [this.rawData_[0][0], this.rawData_[this.numRows() - 1][0]];
+ } else {
+ return [0, 1];
+ }
+}
+
+/**
* Returns the value in the given row and column. If the row and column exceed
* the bounds on the data, returns null. Also returns null if the value is
* missing.
this.rangeSelector_.addToGraph(this.graphDiv, this.layout_);
}
- // Create the grapher
- this.layout_ = new DygraphLayout(this);
-
- if (this.rangeSelector_) {
- // This needs to happen after the graph canvases are added to the div and the layout object is created.
- this.rangeSelector_.addToGraph(this.graphDiv, this.layout_);
- }
-
var dygraph = this;
Dygraph.addEvent(this.mouseEventElement_, 'mousemove', function(e) {
dygraph.mouseMove_(e);
if (this.dateWindow_) {
range = [this.dateWindow_[0], this.dateWindow_[1]];
} else {
- range = [this.rawData_[0][0], this.rawData_[this.rawData_.length - 1][0]];
+ range = this.fullXRange_();
}
var xAxisOptionsView = this.optionsViewForAxis_('x');
// Convert the raw data (a 2D array) into the internal format and compute
// rolling averages.
this.rolledSeries_ = [null]; // x-axis is the first series and it's special
- for (var i = 1; i < this.rawData_[0].length; i++) {
+ for (var i = 1; i < this.numColumns(); i++) {
var connectSeparatedPoints = this.attr_('connectSeparatedPoints', i);
var logScale = this.attr_('logscale', i);
var series = this.extractSeries_(this.rawData_, i, logScale, connectSeparatedPoints);
if (bars) {
for (var j=0; j<series.length; j++) {
- val = [series[j][0], series[j][1][0], series[j][1][1], series[j][1][2]];
- series[j] = val;
+ series[j] = [series[j][0],
+ series[j][1][0],
+ series[j][1][1],
+ series[j][1][2]];
}
} else if (this.attr_("stackedGraph")) {
var l = series.length;
}
}
- // Now we remove series from seriesToAxisMap_ which are not visible. We do
- // this last so that hiding the first series doesn't destroy the axis
- // properties of the primary axis.
- var seriesToAxisFiltered = {};
- var vis = this.visibility();
- for (var i = 1; i < labels.length; i++) {
- var s = labels[i];
- if (vis[i - 1]) seriesToAxisFiltered[s] = this.seriesToAxisMap_[s];
- }
- this.seriesToAxisMap_ = seriesToAxisFiltered;
-
if (valueWindows != undefined) {
// Restore valueWindow settings.
for (var index = 0; index < valueWindows.length; index++) {
var minY = Infinity; // extremes[series[0]][0];
var maxY = -Infinity; // extremes[series[0]][1];
var extremeMinY, extremeMaxY;
+
for (var j = 0; j < series.length; j++) {
+ // this skips invisible series
+ if (!extremes.hasOwnProperty(series[j])) continue;
+
// Only use valid extremes to stop null data series' from corrupting the scale.
extremeMinY = extremes[series[j]][0];
if (extremeMinY != null) {
}
if (axis.includeZero && minY > 0) minY = 0;
- // Ensure we have a valid scale, otherwise defualt to zero for safety.
+ // Ensure we have a valid scale, otherwise default to [0, 1] for safety.
if (minY == Infinity) minY = 0;
- if (maxY == -Infinity) maxY = 0;
+ if (maxY == -Infinity) maxY = 1;
// Add some padding and round up to an integer to be human-friendly.
var span = maxY - minY;
var date = originalData[i][0];
var value = den ? num / den : 0.0;
if (this.attr_("errorBars")) {
- if (this.wilsonInterval_) {
+ if (this.attr_("wilsonInterval")) {
// For more details on this confidence interval, see:
// http://en.wikipedia.org/wiki/Binomial_confidence_interval
if (den) {
if (!this.attr_("visibility")) {
this.attrs_["visibility"] = [];
}
- while (this.attr_("visibility").length < this.rawData_[0].length - 1) {
+ while (this.attr_("visibility").length < this.numColumns() - 1) {
this.attr_("visibility").push(true);
}
return this.attr_("visibility");