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

feat(interaction): crosshair #96

Merged
merged 15 commits into from
Mar 22, 2019
Merged

Conversation

markov00
Copy link
Member

@markov00 markov00 commented Mar 8, 2019

close #80
close #58
close #88

Summary

This PR introduce the Crosshair interaction.
Screenshot 2019-03-18 at 19 23 07

We have removed every listeners to canvas elements. We are instead using a map for each value on the chart: this map maps x value and any relative Y values associated. We then just invert the x scale relative to the mouse point to get the right X key to use on that map. This increase the performance on highly/medium dense charts.

We added two new props to Settings:

  • tooltipType: that describe the type of tooltip/crosshair to use Crosshair,VerticalCursor,Follow, None
  • tooltipSnap: that define if we want to tooltip to snap to the grid/x axis values or not for line/area charts

NOTE
The inverted function on time scales, currently works correctly when using UTC dates. Further investigation needs to be done to make that works with any time zone. To test this check Interactions - brush selection tool on time charts story and remove the Z from the now constant time.

ToDo:

  • add crosshair style to theme
  • adjust crosshair tooltip position
  • fix tooltip style
    • fix tooltip position on rotated charts
    • highlight element/s
      • add increased radius point on line/area chart
      • add highlighted bar on barchart
      • add background on whole stack/cluster group
      • add highlight on tooltip for hovered elements
    • add colors beside each series
    • fix series labels with the right series name
    • hide hidden series from legend
  • invert crosshair on rotated charts
  • add crosshair props to spec
  • convert/ revert element on hover handlers
  • style a bit better the highlighted elements
  • check area/line legend on hover style

Checklist

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

  • 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

@markov00 markov00 added wip work in progress :interactions Interactions related issue labels Mar 8, 2019
This was referenced Mar 8, 2019
@markov00 markov00 force-pushed the feature/crosshair branch 2 times, most recently from a848e45 to d54a2cb Compare March 18, 2019 18:22
@codecov-io
Copy link

codecov-io commented Mar 18, 2019

Codecov Report

Merging #96 into master will increase coverage by 0.54%.
The diff coverage is 88.6%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #96      +/-   ##
==========================================
+ Coverage   89.63%   90.17%   +0.54%     
==========================================
  Files          28       31       +3     
  Lines        1167     1405     +238     
  Branches      119      150      +31     
==========================================
+ Hits         1046     1267     +221     
- Misses        111      125      +14     
- Partials       10       13       +3
Impacted Files Coverage Δ
src/lib/themes/light_theme.ts 100% <ø> (ø) ⬆️
src/lib/utils/dimensions.ts 76.92% <ø> (ø) ⬆️
src/lib/themes/dark_theme.ts 100% <ø> (ø) ⬆️
src/lib/series/specs.ts 100% <ø> (ø) ⬆️
src/lib/series/domains/y_domain.ts 100% <ø> (+1.58%) ⬆️
src/lib/series/legend.ts 100% <100%> (ø) ⬆️
src/lib/series/domains/x_domain.ts 100% <100%> (ø) ⬆️
src/lib/series/series.ts 92.96% <100%> (ø) ⬆️
src/lib/themes/theme.ts 100% <100%> (ø) ⬆️
src/lib/utils/scales/scales.ts 100% <100%> (ø) ⬆️
... and 19 more

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 43578e0...f75f77f. Read the comment docs.

Copy link
Contributor

@emmacunningham emmacunningham 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 on Firefox & looks good! Just left a few comments & questions here

src/components/crosshair.tsx Show resolved Hide resolved
src/components/crosshair.tsx Outdated Show resolved Hide resolved
src/components/crosshair.tsx Outdated Show resolved Hide resolved
strokeHitEnabled={false}
listening={false}
perfectDrawEnabled={true}
perfectDrawEnabled={false}
Copy link
Contributor

Choose a reason for hiding this comment

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

To maintain consistency of the props between the animated and non-animated versions, could create an object with the shared props and spread them? (Here and for other animated components)

Copy link
Member Author

Choose a reason for hiding this comment

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

will work on that on a different PR

src/components/tooltips.tsx Outdated Show resolved Hide resolved
src/lib/series/series_utils.ts Outdated Show resolved Hide resolved
src/state/chart_state.ts Outdated Show resolved Hide resolved
if (this.onElementOverListener) {
this.onElementOverListener(tooltip.value);

setCursorPosition = action((x: number, y: number) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps some of the computation in this function can be pulled into utils as pure functions which (hopefully) will make test writing a bit easier.

Copy link
Member Author

Choose a reason for hiding this comment

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

partially solved 7212d51

src/state/chart_state.ts Outdated Show resolved Hide resolved
src/state/crosshair_utils.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@emmacunningham emmacunningham left a comment

Choose a reason for hiding this comment

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

Code changes LGTM 👍 and tested locally on Firefox

fixed crosshair/tooltip positioning on rotated charts, moved computation to state, add testing for
set cursor function
Refactor based on review. Removed an unused function
for ordinal chart with line/area only, we have to take in consideration that the bandwidth of the
cursorBand is the same as the bandwidth of the scale, and we don't have to take in consideration
that the totalgroupcount is 0 (that compute only bar groups)
I've refactored the name because it's a bit more clear to read and understand than a generic
groupCount. In fact, that value counts the number of bars clusteres on each x value.
Refactored the mergeYdomains to avoid throwing that will never happens
@markov00 markov00 removed the wip work in progress label Mar 22, 2019
@markov00 markov00 merged commit 5ddd1a8 into elastic:master Mar 22, 2019
@markov00
Copy link
Member Author

🎉 This PR is included in version 3.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@markov00 markov00 added the released Issue released publicly label Mar 22, 2019
@markov00 markov00 added this to the 7.1 milestone Mar 26, 2019
@markov00 markov00 removed this from the 7.1 milestone Apr 1, 2019
@markov00 markov00 deleted the feature/crosshair branch April 16, 2019 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:interactions Interactions related issue released Issue released publicly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tooltip x value field Crosshair and vertical/horizontal cursors Tooltip with multiple values on hover
3 participants