Skip to content

symmetric diverging scales by domain extension #563

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

Merged
merged 1 commit into from
Sep 27, 2021

Conversation

mbostock
Copy link
Member

Rather than truncating the interpolator, this extends the domain so that it is symmetric around the pivot. While the effect is the same internally, this has two improvements.

First, it fixes #562 by returning a domain that is already symmetric, and hence applying the (default) symmetric transform again is idempotent and has no effect.

Second, it makes it easier to produce a good color legend for symmetric diverging scales. With the previous approach, you’d see something like this:

Screen Shot 2021-09-26 at 8 08 24 PM

While strictly accurate, it’s a bit visually unsettling and difficult to interpret. The lower half of the legend is given equal visual space to the upper half, but covers a smaller range of values ([-0.78, 0] vs. [0, 1.35]). Under the new approach in this PR, you’d instead get:

Screen Shot 2021-09-26 at 8 10 05 PM

The extended domain includes values that are not present in the chart, but the resulting interpolator no longer needs transformation, and the legend is much easier to interpret.

In retrospect, I now realize why you had symmetric = false when exposing diverging scales. 😅 But while returning symmetric = false would also fix #562, I think it’s likely to be confusing if people inspect the exposed diverging scale, and wonder why is says it’s asymmetric when you asked it to be symmetric. The approach here avoids that confusion, and makes it easier to produce a good color legend.

@mbostock mbostock requested a review from Fil September 27, 2021 03:13
@Fil
Copy link
Contributor

Fil commented Sep 27, 2021

A third possibility for the legend would be to show it with the data domain, but on a uniform x:

Capture d’écran 2021-09-27 à 11 32 29

But this would mean changing Legend rather than Plot?

@mbostock
Copy link
Member Author

That would require exporting the symmetric flag, and then we’d need to display the legend as a sequential rather than diverging scale, which feels confusing.

Alternatively, we would need to expose the numeric range representing the slice of the interpolator (e.g., [0.25, 1]), and then somehow incorporate that into the diverging scale to produce a legend. That would require changes to d3-scale that I don’t want to tackle now.

@mbostock
Copy link
Member Author

Also, the way the truncated interpolator worked previously, the pivot is still always exactly in the middle of the interpolator (t = 0.5) so we would need to make other changes… like probably at that point it would make the most sense to map a diverging scale to a linear (sequential) scale, and then you wouldn’t be able to inspect the pivot.

@Fil
Copy link
Contributor

Fil commented Sep 27, 2021

ok — we can get back to this idea later

@mbostock
Copy link
Member Author

I think mapping diverging scales to linear (sequential) scales is probably a nice simplification for the future.

@mbostock mbostock merged commit 0dc6658 into main Sep 27, 2021
@mbostock mbostock deleted the mbostock/symmetric-diverging-domain branch September 27, 2021 15:56
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 symmetric transform gets applied twice when reusing diverging scales
2 participants