Allow passing custom axis tick formatters to VisCanvas
#1756
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~g
to strongly limit the number of characters and prevent tick labels from overflowing.0.00000123
(for which D3 doesn't respect the precision ing
mode).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
VisCanvas
to 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
VisCanvas
story that demonstrates the use offormatTick
, I pass a formatter that usestoFixed
for decimal numbers, andtoString
for integers.One could even imagine toggling between different tick formatters based on zoom level using a combination of
useCameraState
and an external store (sinceuseCameraState
can only be used insideVisCanvas
).