Don't consider negative domain as valid in log/sqrt scale#1772
Merged
Conversation
axelboc
commented
Mar 18, 2025
Comment on lines
+20
to
+27
| // On resize, move camera to the latest saved viewport center coordinates | ||
| if (viewportCenter.current) { | ||
| // On resize, move camera to the latest saved viewport center coordinates | ||
| moveCameraTo(dataToWorld(viewportCenter.current)); | ||
| const newPos = dataToWorld(viewportCenter.current); | ||
|
|
||
| // Ignore previous center if no longer valid with current scale | ||
| if (Number.isFinite(newPos.x) && Number.isFinite(newPos.y)) { | ||
| moveCameraTo(newPos); | ||
| } |
Contributor
Author
There was a problem hiding this comment.
Subtle bug fix here: when switching from linear to log when visualising a dataset with a negative domain in the Line vis, the viewport center saved (in data coordinates) while in linear scale cannot be converted back to world coordinates in log scale (because ordinateScale(<negativeValue>) returns NaN).
This breaks the visualization, because ViewportCenterer moves the camera position to a NaN y coordinate:
Screencast.from.2025-03-18.16-11-20.webm
Contributor
Author
|
/approve |
loichuder
approved these changes
Mar 19, 2025
Member
loichuder
left a comment
There was a problem hiding this comment.
Makes sense. Even Matplotlib does not support negative values in log plots: https://matplotlib.org/stable/gallery/scales/log_demo.html
Comment on lines
+20
to
+27
| // On resize, move camera to the latest saved viewport center coordinates | ||
| if (viewportCenter.current) { | ||
| // On resize, move camera to the latest saved viewport center coordinates | ||
| moveCameraTo(dataToWorld(viewportCenter.current)); | ||
| const newPos = dataToWorld(viewportCenter.current); | ||
|
|
||
| // Ignore previous center if no longer valid with current scale | ||
| if (Number.isFinite(newPos.x) && Number.isFinite(newPos.y)) { | ||
| moveCameraTo(newPos); | ||
| } |
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 #1761
getValidDomainForScaleused to consider negative domains like[-20, -10]as valid. (If I recall, we made this choice initially because the Line vis and D3 could technically handle it.) However, this meant that we ended up with a negativedataDomainthroughout, and this didn't work well with theDomainWidget: theextendDomainfunction used to throw, which triggered the error boundary and unmounted the toolbar.I could not find a straightforward way to handle negative domains in the domain widget, so I decided to change
getValidDomainForScaleto not consider negative domains as valid at all. This means we typically fall back to the default domain[0.1, 1], which is handled cleanly and doesn't throw any error (thus allowing to change the scale back to linear or whatever).Screencast.from.2025-03-18.15-39-20.webm