Skip to content

Commit

Permalink
fix(zoom): Fix unzoom after appending regions
Browse files Browse the repository at this point in the history
When grids/regions APIs called, do not update legend,
where makes x's scale update.

Fix #2531
  • Loading branch information
netil authored Feb 4, 2022
1 parent 0ae640a commit de64c4e
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/ChartInternal/internals/redraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
};
67 changes: 67 additions & 0 deletions test/api/zoom-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});
});

0 comments on commit de64c4e

Please sign in to comment.