From c5c8d145b14681aa110b0317b4044a84829e971d Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Tue, 27 Dec 2016 00:29:18 -0500 Subject: [PATCH] all tests pass --- auto_tests/tests/interaction_model.js | 45 +++++++++++++++-------------------- src/dygraph.js | 40 +++++++++++++++---------------- 2 files changed, 39 insertions(+), 46 deletions(-) diff --git a/auto_tests/tests/interaction_model.js b/auto_tests/tests/interaction_model.js index a846df5..2015e11 100644 --- a/auto_tests/tests/interaction_model.js +++ b/auto_tests/tests/interaction_model.js @@ -1,4 +1,4 @@ -/** +/** * @fileoverview Test cases for the interaction model. * * @author konigsberg@google.com (Robert Konigsbrg) @@ -344,7 +344,7 @@ it('testCorrectAxisValueRangeAfterUnzoom', function() { dateWindow: [1, 9], animatedZooms:false }); - + // Zoom x axis DygraphOps.dispatchMouseDown_Point(g, 100, 100); DygraphOps.dispatchMouseMove_Point(g, 130, 100); @@ -356,13 +356,13 @@ it('testCorrectAxisValueRangeAfterUnzoom', function() { 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); @@ -370,13 +370,10 @@ it('testCorrectAxisValueRangeAfterUnzoom', function() { 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()); }); /** @@ -468,8 +465,9 @@ it('testCorrectAxisPaddingAfterUnzoom', function() { 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); @@ -479,15 +477,11 @@ it('testCorrectAxisPaddingAfterUnzoom', function() { 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); @@ -495,11 +489,10 @@ it('testCorrectAxisPaddingAfterUnzoom', function() { 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()); }); }); diff --git a/src/dygraph.js b/src/dygraph.js index e865950..9997c54 100644 --- a/src/dygraph.js +++ b/src/dygraph.js @@ -529,6 +529,22 @@ Dygraph.prototype.xAxisExtremes = function() { }; /** + * 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. @@ -1354,18 +1370,7 @@ Dygraph.prototype.resetZoom = function() { 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, @@ -1375,7 +1380,7 @@ Dygraph.prototype.resetZoom = function() { if (axis.valueRange) delete axis.valueRange; } if (zoomCallback) { - zoomCallback(this, minDate, maxDate, this.yAxisRanges()); + zoomCallback.call(this, minDate, maxDate, this.yAxisRanges()); } }); }; @@ -2542,12 +2547,7 @@ Dygraph.prototype.computeYAxisRanges_ = function(extremes) { } 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]; @@ -2555,7 +2555,7 @@ Dygraph.prototype.computeYAxisRanges_ = function(extremes) { } 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) { -- 2.7.4