Skip to content

Commit

Permalink
fix: handle chart click as mouseUp to prevent click while brushing (#269
Browse files Browse the repository at this point in the history
)
  • Loading branch information
emmacunningham authored Jul 24, 2019
1 parent f196560 commit 7881b8d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/components/react_canvas/reactive_chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ class Chart extends React.Component<ReactiveChartProps, ReactiveChartState> {
};
onStartBrusing = (event: { evt: MouseEvent }) => {
window.addEventListener('mouseup', this.onEndBrushing);
this.props.chartStore!.onBrushStart();
const { brushExtent } = this.props.chartStore!;
const point = getPoint(event.evt, brushExtent);
this.setState(() => ({
Expand All @@ -316,6 +315,9 @@ class Chart extends React.Component<ReactiveChartProps, ReactiveChartState> {
if (!this.state.brushing) {
return;
}
if (!this.props.chartStore!.isBrushing.get()) {
this.props.chartStore!.onBrushStart();
}
const { brushExtent } = this.props.chartStore!;
const point = getPoint(event.evt, brushExtent);
this.setState(() => ({
Expand Down Expand Up @@ -420,7 +422,10 @@ class Chart extends React.Component<ReactiveChartProps, ReactiveChartState> {
onMouseLeave={() => {
setCursorPosition(-1, -1);
}}
onClick={() => {
onMouseUp={() => {
if (this.props.chartStore!.isBrushing.get()) {
return;
}
this.props.chartStore!.handleChartClick();
}}
className={className}
Expand Down
6 changes: 5 additions & 1 deletion stories/interactions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,11 @@ storiesOf('Interactions', module)
const oneDay = 1000 * 60 * 60 * 24;
return (
<Chart className={'story-chart'}>
<Settings debug={boolean('debug', false)} onBrushEnd={action('onBrushEnd')} />
<Settings
debug={boolean('debug', false)}
onBrushEnd={action('onBrushEnd')}
onElementClick={action('onElementClick')}
/>
<Axis
id={getAxisId('bottom')}
position={Position.Bottom}
Expand Down

0 comments on commit 7881b8d

Please sign in to comment.