Skip to content

Commit

Permalink
refactor(axis): prevent transition not found error
Browse files Browse the repository at this point in the history
- Prevent transition selection to throw error
- Make state.redrawing to be set false after redraw calls

Ref #2140
  • Loading branch information
netil committed Jun 30, 2021
1 parent 16611a9 commit 8732d87
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Chart/api/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default {
data = $$.convertData(args);
}

if (!data || !isTabVisible()) {
if ($$.state.redrawing || !data || !isTabVisible()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ChartInternal/Axis/AxisRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default class AxisRenderer {
path.enter().append("path")
.attr("class", "domain")
// https://observablehq.com/@d3/d3-selection-2-0
.merge(helper.transitionise(path).selection())
.merge(path as d3Selection)
.attr("d", () => {
const outerTickSized = config.outerTickSize * sign;

Expand Down
13 changes: 11 additions & 2 deletions src/ChartInternal/Axis/AxisRendererHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,17 @@ export default class AxisRendererHelper {

transitionise(selection): d3Selection {
const {config} = this;
let transitionSelection = config.withoutTransition ?
selection.interrupt() : selection.transition();

if (config.transition) {
// prevent for 'transition not found' case
// https://github.com/naver/billboard.js/issues/2140
try {
transitionSelection = selection.transition(config.transition);
} catch (e) {}
}

return config.withoutTransition ?
selection.interrupt() : selection.transition(config.transition);
return transitionSelection;
}
}
4 changes: 2 additions & 2 deletions src/ChartInternal/internals/redraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ export default {
const redrawList = $$.getRedrawList(shape, flow, flowFn, isTransition);

// callback function after redraw ends
const afterRedraw = flow || config.onrendered ? () => {
const afterRedraw = () => {
flowFn && flowFn();

state.redrawing = false;
callFn(config.onrendered, $$.api);
} : null;
};

if (afterRedraw) {
// Only use transition when current tab is visible.
Expand Down
15 changes: 15 additions & 0 deletions test/interactions/zoom-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,21 @@ describe("ZOOM", function() {

expect(clickedData).to.not.be.undefined;
});

it("shouldn't throw error on '.flow() -> .zoom()' flow calls", done => {
// when flow
chart.flow({
columns: [
["data1", 37]
],
length: 0,
duration: 0,
done: function() {
expect(this.zoom([1,2])).to.not.throw;
done();
}
});
})
});

describe("zoom on regions", () => {
Expand Down

0 comments on commit 8732d87

Please sign in to comment.