Skip to content

Commit

Permalink
fix(reactive_chart): fix order of instantiation of onBruchEnd callback (
Browse files Browse the repository at this point in the history
#376)

Wait for setState to finish before calling onBrushEnd, in the event the callback triggers a
rerender.

fixes #360
  • Loading branch information
nickofthyme authored Sep 16, 2019
1 parent f37f94e commit 527d68d
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/components/react_canvas/reactive_chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ class Chart extends React.Component<ReactiveChartProps, ReactiveChartState> {
},
};

componentWillUnmount() {
window.removeEventListener('mouseup', this.onEndBrushing);
}

renderBarSeries = (clippings: ContainerConfig): ReactiveChartElementIndex[] => {
const { geometries, canDataBeAnimated, chartTheme } = this.props.chartStore!;
if (!geometries) {
Expand Down Expand Up @@ -292,8 +296,6 @@ class Chart extends React.Component<ReactiveChartProps, ReactiveChartState> {
let y = 0;
let width = 0;
let height = 0;
// x = {chartDimensions.left + chartTransform.x};
// y = {chartDimensions.top + chartTransform.y};
if (chartRotation === 0 || chartRotation === 180) {
x = brushStart.x;
y = chartDimensions.top + chartTransform.y;
Expand All @@ -320,12 +322,17 @@ class Chart extends React.Component<ReactiveChartProps, ReactiveChartState> {
onEndBrushing = () => {
window.removeEventListener('mouseup', this.onEndBrushing);
const { brushStart, brushEnd } = this.state;
this.props.chartStore!.onBrushEnd(brushStart, brushEnd);
this.setState(() => ({
brushing: false,
brushStart: { x: 0, y: 0 },
brushEnd: { x: 0, y: 0 },
}));

this.setState(
() => ({
brushing: false,
brushStart: { x: 0, y: 0 },
brushEnd: { x: 0, y: 0 },
}),
() => {
this.props.chartStore!.onBrushEnd(brushStart, brushEnd);
},
);
};
onBrushing = (event: { evt: MouseEvent }) => {
if (!this.state.brushing) {
Expand Down

0 comments on commit 527d68d

Please sign in to comment.