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. add snapToPoint for line chart and support for supplied xDomain #103

Merged
merged 3 commits into from
Feb 21, 2023

Conversation

cam-shaw
Copy link
Contributor

@cam-shaw cam-shaw commented Aug 18, 2022

Purpose
Currently, the cursor moves smoothly along the line which creates a nice user experience but it may not accurately represent the data underneath the cursor at the point in time along x-axis.

By adding this snapToPoint functionality, we are now able to ensure the cursor sticks to the nearest data point on the chart compared to where the cursor/touch-point is. This can be important in finance applications where you don't want to falsely represent a value at a particular point in time.

xDomain purpose
When showing a chart that has partial data for the day (but is still represented on the x-axis with the full scale), we need to ensure the linear scale is performing correctly.

Snap On

e.g.

 <LineChart.CursorCrosshair
  snapToPoint // This is the important prop
  color={'transparent'}
  minDurationMs={150}
  onEnded={onTouchEnd}
  onActivated={onTouchActivated}
/>
Snap.on.mov

Snap off - Default behaviour

Snap.off.-.Default.mov

@arancauchi
Copy link
Collaborator

Thanks for the PR :)

If you could perhaps create a short recording of this feature in action, that would be fantastic, we can use that in the README

@cam-shaw
Copy link
Contributor Author

cam-shaw commented Jan 19, 2023

@arancauchi Have added some recordings to the original comment above!
I have an update coming to this PR later today that greatly improves the code. We actively use this update in prod at the moment.

@cam-shaw cam-shaw changed the title feat. add snapToPoint prop on line chart to allow moving to each individual data point feat. add snapToPoint for line chart and support for supplied xDomain Jan 20, 2023
@cam-shaw
Copy link
Contributor Author

@arancauchi I have updated this PR with some of our latest code and a bit of a better description.

@arancauchi
Copy link
Collaborator

Thanks @cam-shaw i'll take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants