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

Adding a "length" function to scaleLinear (and maybe other continuous scales) #214

Open
rben01 opened this issue Jun 19, 2020 · 0 comments

Comments

@rben01
Copy link

rben01 commented Jun 19, 2020

When I have a d3.scaleLinear object, very frequently I'll want to convert the length of some object in domain coordinates into range coordinates. For instance, if an object has a length of x in domain coordinates, then I'd compute its length in range coordinates using scale(x)-scale(0), but this introduces a needless computation of scale(0). It would be nice to have a convenience function scale.length(x), where a scale whose equation is y = a*x+b computes scale.length(x) as simply a*x. This would be useful for shapes like rect and circle that are defined by their dimensions in range coordinates (width, height, r), but which you might want to specify using their dimensions in domain coordinates.

This could probably also be extended to other continuous scales. For instance, a log scale y = m*log(x) + b would treat x as a ratio of two points in the domain and have scale.length(x) == m*log(x).

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

1 participant