Skip to content
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

expose transform for e.g. d3.scaleSequentialLog? #171

Closed
Fil opened this issue Apr 17, 2019 · 3 comments
Closed

expose transform for e.g. d3.scaleSequentialLog? #171

Fil opened this issue Apr 17, 2019 · 3 comments

Comments

@Fil
Copy link
Member

Fil commented Apr 17, 2019

Currently there is no simple way (or no way at all?) to discover the transform of a scaleSequential{Log,Symlog,Sqrt…} scale, which makes it difficult to generate an automatic legend.

scale.ticks() can be a proxy to this information, but it might be nice to be able to read the transform directly.

@mbostock
Copy link
Member

In general d3-scale does not support inspection of scale types, so I wouldn’t expect it would support inspection of scale transforms either (if we did support generic transforms, which we do not). The hope is that the scale implementation encapsulates the behavior, and then things like axes and legends don’t need type-specific (or transform-specific) logic, which would make the axis or legend incompatible with future types.

@Fil
Copy link
Member Author

Fil commented Apr 17, 2019

Concretely the question came from trying to adapt https://observablehq.com/@mbostock/color-ramp to a d3.scaleSequentialLog(); knowledge of the domain is not enough to “invert” the scale and generate the ~512 uniformly spaced points we would like to have.

Using ticks() is not an option in this case, since they can't give us 500 values on a log-scale domain of e.g. [1e-7, 1e7]. But maybe that's a different issue (related: #44 #100 & #162).

@mbostock
Copy link
Member

mbostock commented Apr 17, 2019

Typically, you’d just pass the scale’s interpolator to generate the ramp, not the scale itself. And interpolators are always linear in [0, 1].

@Fil Fil closed this as completed Apr 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants