fix: handle chart click as mouseUp to prevent click while brushing #269
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements a fix for the issue of the
onElementClick
handler being calledonBrushEnd
.(In the Discover histogram,
onElementClick
andonBrushEnd
are defined for the chart because a bar can be clickable to set the timefilter and the brush tool can also be used to set the timefilter. This bug causes theonElementClick
handler to take precendence as it will be called after theonBrushEnd
handler is called, resulting in a brush event being overridden by a click on a bar.)Before: (note how
onElementClick
is registered afteronBrushEnd
)After: (no
onElementClick
afteronBrushEnd
)The source of this issue was that in the previous implementation, the
onElementClick
callback was calledonClick
; when bothonBrushEnd
andonElementClick
are defined for a chart, then, theonClick
event would be captured on mouse up, including on mouse up after the user has been brushing.Preventing this required changing the
onClick
toonMouseUp
and within theonMouseUp
handler, checking if the chartStore'sisBrushing
property is true; when true, wereturn
so that the event can be handled as the end of a brush event, and when false, we call theonElementClick
callback. The reason for changing fromonClick
toonMouseUp
is because we need to be able to check theisBrushing
property; withonClick
, the brush end handler has already setisBrushing
to false (as this happensonMouseUp
) and withonMouseDown
, the brush start handler has not yet setisBrushing
to true.The other change is that we set
isBrushing
to true not right afteronBrushStart
but ratheronBrushing
. This was necessary because if we setisBrushing
to true immediatelyonBrushStart
(which is handledonMouseDown
of the brush layer), thenisBrushing
would always betrue
after clicking–even when not brushing and just clicking. So we setisBrushing
to true onlyonBrushing
, that is, onlyonMouseMove
followed byonMouseDown
.Checklist
Use
strikethroughsto remove checklist items you don't feel are applicable to this PR.- [] Any consumer-facing exports were added tosrc/index.ts
(and stories only import from../src
except for test data & storybook)