Skip to content

Commit 527d68d

Browse files
authored
fix(reactive_chart): fix order of instantiation of onBruchEnd callback (#376)
Wait for setState to finish before calling onBrushEnd, in the event the callback triggers a rerender. fixes #360
1 parent f37f94e commit 527d68d

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/components/react_canvas/reactive_chart.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ class Chart extends React.Component<ReactiveChartProps, ReactiveChartState> {
7676
},
7777
};
7878

79+
componentWillUnmount() {
80+
window.removeEventListener('mouseup', this.onEndBrushing);
81+
}
82+
7983
renderBarSeries = (clippings: ContainerConfig): ReactiveChartElementIndex[] => {
8084
const { geometries, canDataBeAnimated, chartTheme } = this.props.chartStore!;
8185
if (!geometries) {
@@ -292,8 +296,6 @@ class Chart extends React.Component<ReactiveChartProps, ReactiveChartState> {
292296
let y = 0;
293297
let width = 0;
294298
let height = 0;
295-
// x = {chartDimensions.left + chartTransform.x};
296-
// y = {chartDimensions.top + chartTransform.y};
297299
if (chartRotation === 0 || chartRotation === 180) {
298300
x = brushStart.x;
299301
y = chartDimensions.top + chartTransform.y;
@@ -320,12 +322,17 @@ class Chart extends React.Component<ReactiveChartProps, ReactiveChartState> {
320322
onEndBrushing = () => {
321323
window.removeEventListener('mouseup', this.onEndBrushing);
322324
const { brushStart, brushEnd } = this.state;
323-
this.props.chartStore!.onBrushEnd(brushStart, brushEnd);
324-
this.setState(() => ({
325-
brushing: false,
326-
brushStart: { x: 0, y: 0 },
327-
brushEnd: { x: 0, y: 0 },
328-
}));
325+
326+
this.setState(
327+
() => ({
328+
brushing: false,
329+
brushStart: { x: 0, y: 0 },
330+
brushEnd: { x: 0, y: 0 },
331+
}),
332+
() => {
333+
this.props.chartStore!.onBrushEnd(brushStart, brushEnd);
334+
},
335+
);
329336
};
330337
onBrushing = (event: { evt: MouseEvent }) => {
331338
if (!this.state.brushing) {

0 commit comments

Comments
 (0)