-/**
+/**
* @fileoverview Test cases for the interaction model.
*
* @author konigsberg@google.com (Robert Konigsbrg)
dateWindow: [1, 9],
animatedZooms:false
});
-
+
// Zoom x axis
DygraphOps.dispatchMouseDown_Point(g, 100, 100);
DygraphOps.dispatchMouseMove_Point(g, 130, 100);
DygraphOps.dispatchMouseUp_Point(g, 100, 130);
var currentYAxisRange = g.yAxisRange();
var currentXAxisRange = g.xAxisRange();
-
+
//check that the range for the axis has changed
assert.notEqual(1, currentXAxisRange[0]);
assert.notEqual(10, currentXAxisRange[1]);
assert.notEqual(1, currentYAxisRange[0]);
assert.notEqual(50, currentYAxisRange[1]);
-
+
// unzoom by doubleclick. This is really the order in which a browser
// generates events, and we depend on it.
DygraphOps.dispatchMouseDown_Point(g, 10, 10);
DygraphOps.dispatchMouseDown_Point(g, 10, 10);
DygraphOps.dispatchMouseUp_Point(g, 10, 10);
DygraphOps.dispatchDoubleClick(g, null);
-
- // check if range for y-axis was reset to original value
- // TODO check if range for x-axis is correct.
- // Currently not possible because dateRange is set to null and extremes are returned
- var newYAxisRange = g.yAxisRange();
- assert.equal(1, newYAxisRange[0]);
- assert.equal(50, newYAxisRange[1]);
+
+ // check if the range for both axis was reset to show the full data.
+ assert.deepEqual(g.yAxisExtremes()[0], g.yAxisRange());
+ assert.deepEqual(g.xAxisExtremes(), g.xAxisRange());
});
/**
animatedZooms:false
});
- var extremes = g.xAxisExtremes();
-
+ var xExtremes = g.xAxisExtremes();
+ var [ yExtremes ] = g.yAxisExtremes();
+
// Zoom x axis
DygraphOps.dispatchMouseDown_Point(g, 100, 100);
DygraphOps.dispatchMouseMove_Point(g, 130, 100);
DygraphOps.dispatchMouseDown_Point(g, 100, 100);
DygraphOps.dispatchMouseMove_Point(g, 100, 130);
DygraphOps.dispatchMouseUp_Point(g, 100, 130);
- var currentYAxisRange = g.yAxisRange();
- var currentXAxisRange = g.xAxisRange();
-
+
//check that the range for the axis has changed
- assert.notEqual(1, currentXAxisRange[0]);
- assert.notEqual(10, currentXAxisRange[1]);
- assert.notEqual(1, currentYAxisRange[0]);
- assert.notEqual(50, currentYAxisRange[1]);
-
+ assert.notDeepEqual([1, 10], g.xAxisRange());
+ assert.notDeepEqual([1, 50], g.yAxisRange());
+
// unzoom by doubleclick. This is really the order in which a browser
// generates events, and we depend on it.
DygraphOps.dispatchMouseDown_Point(g, 10, 10);
DygraphOps.dispatchMouseDown_Point(g, 10, 10);
DygraphOps.dispatchMouseUp_Point(g, 10, 10);
DygraphOps.dispatchDoubleClick(g, null);
-
- // check if range for x-axis was reset to original value
- var newXAxisRange = g.xAxisRange();
- assert.equal(extremes[0], newXAxisRange[0]);
- assert.equal(extremes[1], newXAxisRange[1]);
+
+ // check if range for x-axis was reset to original value.
+ assert.deepEqual(xExtremes, g.xAxisRange());
+ assert.deepEqual(yExtremes, g.yAxisRange());
});
});
};
/**
+ * Returns the lower- and upper-bound y-axis values for each axis. These are
+ * the ranges you'll get if you double-click to zoom out or call resetZoom().
+ * The return value is an array of [low, high] tuples, one for each y-axis.
+ */
+Dygraph.prototype.yAxisExtremes = function() {
+ // TODO(danvk): this is pretty inefficient
+ const packed = this.gatherDatasets_(this.rolledSeries_, null);
+ const { extremes } = packed;
+ const saveAxes = this.axes_;
+ this.computeYAxisRanges_(extremes);
+ const newAxes = this.axes_;
+ this.axes_ = saveAxes;
+ return newAxes.map(axis => axis.extremeRange);
+}
+
+/**
* Returns the currently-visible y-range for an axis. This can be affected by
* zooming, panning or a call to updateOptions. Axis indices are zero-based. If
* called with no arguments, returns the range of the first axis.
if (dirtyY) {
oldValueRanges = this.yAxisRanges();
- // TODO(danvk): this is pretty inefficient
- var packed = this.gatherDatasets_(this.rolledSeries_, null);
- var extremes = packed.extremes;
-
- // this has the side-effect of modifying this.axes_.
- // this doesn't make much sense in this context, but it's convenient (we
- // need this.axes_[*].extremeValues) and not harmful since we'll be
- // calling drawGraph_ shortly, which clobbers these values.
- this.computeYAxisRanges_(extremes);
-
- newValueRanges = this.axes_.map(
- axis => axis.valueRange ? axis.valueRange : axis.extremeRange);
+ newValueRanges = this.yAxisExtremes();
}
this.doAnimatedZoom(oldWindow, newWindow, oldValueRanges, newValueRanges,
if (axis.valueRange) delete axis.valueRange;
}
if (zoomCallback) {
- zoomCallback(this, minDate, maxDate, this.yAxisRanges());
+ zoomCallback.call(this, minDate, maxDate, this.yAxisRanges());
}
});
};
}
axis.extremeRange = [minAxisY, maxAxisY];
}
- if (axis.valueWindow) {
- // This is only set if the user has zoomed on the y-axis. It is never set
- // by a user. It takes precedence over axis.valueRange because, if you set
- // valueRange, you'd still expect to be able to pan.
- axis.computedValueRange = [axis.valueWindow[0], axis.valueWindow[1]];
- } else if (axis.valueRange) {
+ if (axis.valueRange) {
// This is a user-set value range for this axis.
var y0 = isNullUndefinedOrNaN(axis.valueRange[0]) ? axis.extremeRange[0] : axis.valueRange[0];
var y1 = isNullUndefinedOrNaN(axis.valueRange[1]) ? axis.extremeRange[1] : axis.valueRange[1];
} else {
axis.computedValueRange = axis.extremeRange;
}
- if (!axis.valueWindow && !ypadCompat) {
+ if (!ypadCompat) {
// When using yRangePad, adjust the upper/lower bounds to add
// padding unless the user has zoomed/panned the Y axis range.
if (logscale) {