diff --git a/spec/api.zoom-spec.js b/spec/api.zoom-spec.js index 203ae9150..a469d3bff 100644 --- a/spec/api.zoom-spec.js +++ b/spec/api.zoom-spec.js @@ -45,6 +45,23 @@ describe("API zoom", function() { expect(Math.round(domain[0])).to.be.equal(target[0]); expect(Math.round(domain[1])).to.be.equal(target[1]); }); + + it("should be zoomed and showing focus grid properly when target contained minus value", () => { + const target = [-2, 3]; // zoom in cotaining minus value + + chart.zoom(target); + + const zoomScale = chart.internal.zoomScale; + + // If target contained minus value should not be null + expect(zoomScale).to.not.be.null; + + const domain = chart.internal.zoomScale.domain(); + + // domain value must be above than target + expect(Math.round(domain[0])).to.be.above(target[0]); + expect(Math.round(domain[1])).to.be.above(target[1]); + }); }); describe("zoom line chart #2", () => { diff --git a/src/interactions/zoom.js b/src/interactions/zoom.js index c47ccf610..45df1f0db 100644 --- a/src/interactions/zoom.js +++ b/src/interactions/zoom.js @@ -103,14 +103,17 @@ extend(ChartInternal.prototype, { // .on("dblclick.zoom", null); if ($$.zoomScale) { - const range1 = $$.zoomScale.domain()[0]; - const range2 = $$.x.domain()[0]; - const delta = 0.015; - - // reset scale when zoom is out as initial - if (range1 <= range2 || (range1 - delta) <= range2) { - $$.zoomScale = null; + const zoomDomain = $$.zoomScale.domain(); + const xDomain = $$.x.domain(); + const delta = 0.015; // arbitrary value + + // check if the zoomed chart is fully shown, then reset scale when zoom is out as initial + if ( + (zoomDomain[0] <= xDomain[0] || (zoomDomain[0] - delta) <= xDomain[0]) && + (xDomain[1] <= zoomDomain[1] || xDomain[1] <= (zoomDomain[1] - delta)) + ) { $$.xAxis.scale($$.x); + $$.zoomScale = null; } }