Skip to content

Don't consider negative domain as valid in log/sqrt scale#1772

Merged
axelboc merged 2 commits intomainfrom
neg-domain
Mar 19, 2025
Merged

Don't consider negative domain as valid in log/sqrt scale#1772
axelboc merged 2 commits intomainfrom
neg-domain

Conversation

@axelboc
Copy link
Contributor

@axelboc axelboc commented Mar 18, 2025

Fix #1761

getValidDomainForScale used 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 negative dataDomain throughout, and this didn't work well with the DomainWidget: the extendDomain function 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 getValidDomainForScale to 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).

I'm not super happy that there's no visual feedback to indicate that the chosen data domain differs from the real data domain, but this is a problem for another day...

Screencast.from.2025-03-18.15-39-20.webm

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);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Member

Choose a reason for hiding this comment

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

🎣

@axelboc
Copy link
Contributor Author

axelboc commented Mar 18, 2025

/approve

Copy link
Member

@loichuder loichuder left a comment

Choose a reason for hiding this comment

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

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);
}
Copy link
Member

Choose a reason for hiding this comment

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

🎣

@axelboc axelboc merged commit ec0fc40 into main Mar 19, 2025
8 checks passed
@axelboc axelboc deleted the neg-domain branch March 19, 2025 09:06
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.

The user can't revert to linear scale after setting the scale to "Log" or "Square root" on an unsupported dataset

2 participants