Allow passing custom axis tick formatters to VisCanvas#1756
Merged
Conversation
loichuder
approved these changes
Feb 6, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fix #1701
VisCanvas' internal tick formatter is meant as a good default:.3~gto strongly limit the number of characters and prevent tick labels from overflowing.0.00000123(for which D3 doesn't respect the precision ingmode).Unfortunately, this is far from perfect.
Finding the perfect tick formatting algorithm is just not possible, so the idea with this PR is to allow consumers of
VisCanvasto implement one that works for their use case.I think this opens the door to a lot of use cases. For instance, in the new
VisCanvasstory that demonstrates the use offormatTick, I pass a formatter that usestoFixedfor decimal numbers, andtoStringfor integers.One could even imagine toggling between different tick formatters based on zoom level using a combination of
useCameraStateand an external store (sinceuseCameraStatecan only be used insideVisCanvas).