Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle chart click as mouseUp to prevent click while brushing #269

Merged
merged 1 commit into from Jul 24, 2019

Conversation

emmacunningham
Copy link
Contributor

@emmacunningham emmacunningham commented Jul 23, 2019

Summary

This PR implements a fix for the issue of the onElementClick handler being called onBrushEnd.

(In the Discover histogram, onElementClick and onBrushEnd 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 the onElementClick handler to take precendence as it will be called after the onBrushEnd handler is called, resulting in a brush event being overridden by a click on a bar.)

Before: (note how onElementClick is registered after onBrushEnd)
interactions_broken

After: (no onElementClick after onBrushEnd)
interactions_fixed

The source of this issue was that in the previous implementation, the onElementClick callback was called onClick; when both onBrushEnd and onElementClick are defined for a chart, then, the onClick event would be captured on mouse up, including on mouse up after the user has been brushing.

Preventing this required changing the onClick to onMouseUp and within the onMouseUp handler, checking if the chartStore's isBrushing property is true; when true, we return so that the event can be handled as the end of a brush event, and when false, we call the onElementClick callback. The reason for changing from onClick to onMouseUp is because we need to be able to check the isBrushing property; with onClick, the brush end handler has already set isBrushing to false (as this happens onMouseUp) and with onMouseDown, the brush start handler has not yet set isBrushing to true.

The other change is that we set isBrushing to true not right after onBrushStart but rather onBrushing. This was necessary because if we set isBrushing to true immediately onBrushStart (which is handled onMouseDown of the brush layer), then isBrushing would always be true after clicking–even when not brushing and just clicking. So we set isBrushing to true only onBrushing, that is, only onMouseMove followed by onMouseDown.

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

- [] Any consumer-facing exports were added to src/index.ts (and stories only import from ../src except for test data & storybook)

  • This was checked for cross-browser compatibility, including a check against IE11
  • Proper documentation or storybook story was added for features that require explanation or tutorials
  • Unit tests were updated or added to match the most common scenarios
  • Each commit follows the convention

@emmacunningham emmacunningham added :interactions Interactions related issue bug Something isn't working labels Jul 23, 2019
@codecov-io
Copy link

codecov-io commented Jul 23, 2019

Codecov Report

Merging #269 into master will increase coverage by 0.13%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #269      +/-   ##
==========================================
+ Coverage   98.12%   98.26%   +0.13%     
==========================================
  Files          37       37              
  Lines        2670     2939     +269     
  Branches      612      718     +106     
==========================================
+ Hits         2620     2888     +268     
- Misses         45       46       +1     
  Partials        5        5
Impacted Files Coverage Δ
src/lib/series/legend.ts 100% <0%> (ø) ⬆️
src/state/chart_state.ts 98% <0%> (+0.53%) ⬆️
src/state/utils.ts 97.65% <0%> (+0.97%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f196560...abaecf2. Read the comment docs.

Copy link
Collaborator

@nickofthyme nickofthyme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, LGTM 👍

@emmacunningham
Copy link
Contributor Author

jenkins test this please

@emmacunningham emmacunningham merged commit 7881b8d into elastic:master Jul 24, 2019
markov00 pushed a commit that referenced this pull request Jul 24, 2019
## [8.1.1](v8.1.0...v8.1.1) (2019-07-24)

### Bug Fixes

* handle chart click as mouseUp to prevent click while brushing ([#269](#269)) ([7881b8d](7881b8d))
@markov00
Copy link
Member

🎉 This PR is included in version 8.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@markov00 markov00 added the released Issue released publicly label Jul 24, 2019
AMoo-Miki pushed a commit to AMoo-Miki/OpenSearch-Dashboards that referenced this pull request Feb 10, 2022
## [8.1.1](elastic/elastic-charts@v8.1.0...v8.1.1) (2019-07-24)

### Bug Fixes

* handle chart click as mouseUp to prevent click while brushing ([opensearch-project#269](elastic/elastic-charts#269)) ([c3e979b](elastic/elastic-charts@c3e979b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working :interactions Interactions related issue released Issue released publicly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants