From de64c4e2618df844ce5a4b3c25a5ad357683d49d Mon Sep 17 00:00:00 2001 From: Jae Sung Park Date: Fri, 4 Feb 2022 16:02:53 +0900 Subject: [PATCH] fix(zoom): Fix unzoom after appending regions When grids/regions APIs called, do not update legend, where makes x's scale update. Fix #2531 --- src/ChartInternal/internals/redraw.ts | 5 +- test/api/zoom-spec.ts | 67 +++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/src/ChartInternal/internals/redraw.ts b/src/ChartInternal/internals/redraw.ts index 5f9ff1b25..0927dd326 100644 --- a/src/ChartInternal/internals/redraw.ts +++ b/src/ChartInternal/internals/redraw.ts @@ -246,10 +246,11 @@ export default { redrawWithoutRescale() { this.redraw({ withY: false, - withLegend: true, + withDimension: false, + withLegend: false, withSubchart: false, withEventRect: false, - withTransitionForAxis: false + withTransitionForAxis: false, }); } }; diff --git a/test/api/zoom-spec.ts b/test/api/zoom-spec.ts index 3a8d1d73d..14d82236a 100644 --- a/test/api/zoom-spec.ts +++ b/test/api/zoom-spec.ts @@ -561,4 +561,71 @@ describe("API zoom", function() { chkZoomEvents(); }); }); + + describe("zoom for timeseries axis type", () => { + before(() => { + chart = util.generate({ + data: { + columns: [ + ["sample", 30, 200, 100, 400, 150, 250, 150, 200, 170, 240, 350, 150, 100, 400, 150, 250, 150, 200, 170, 240, 100, 150, 250, 150, 200, 170, 240, 30, 200, 100, 400, 150, 250, 150, 200, 170, 240, 350, 150, 100, 400, 350, 220, 250, 300, 270, 140, 150, 90, 150, 50, 120, 70, 40] + ], + type: "line" + }, + legend: { + show: true + }, + zoom: { + enabled: true, + type: "drag", + }, + transition: { + duration: 0 + } + }); + }); + + it("unzoom after adding xgrid dynamically.", () => { + const {internal: $$} = chart; + + // zoom + chart.zoom([30, 40]); + + const {$el: {eventRect}, scale: {x, zoom}} = $$; + const xDomain = x.domain().reduce((prev, curr) => prev + curr); + const zoomDomain = zoom.domain().reduce((prev, curr) => prev + curr); + + // when + chart.xgrids([{value: 33, text: "123"}]); + + expect(zoomDomain).to.be.above(xDomain); + + // unzoom + chart.unzoom(); + + expect($$.scale.x.domain()).to.be.deep.equal(x.domain()); + expect($$.scale.zoom).to.be.null; + }); + + it("unzoom after adding regions dynamically.", () => { + const {internal: $$} = chart; + + // zoom + chart.zoom([30, 40]); + + const {$el: {eventRect}, scale: {x, zoom}} = $$; + const xDomain = x.domain().reduce((prev, curr) => prev + curr); + const zoomDomain = zoom.domain().reduce((prev, curr) => prev + curr); + + // when + chart.regions([{axis: "x", start: 30, end: 35}]); + + expect(zoomDomain).to.be.above(xDomain); + + // unzoom + chart.unzoom(); + + expect($$.scale.x.domain()).to.be.deep.equal(x.domain()); + expect($$.scale.zoom).to.be.null; + }); + }); });