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

Linear scale 'invert' method doesn't work #9

Closed
yay opened this issue Nov 29, 2018 · 1 comment
Closed

Linear scale 'invert' method doesn't work #9

yay opened this issue Nov 29, 2018 · 1 comment

Comments

@yay
Copy link
Contributor

yay commented Nov 29, 2018

fun main(args: Array<String>) {
    val scale = scaleLinear<Double>().domain(-100.0, 100.0).range(0.0, 100.0)
    println(scale(0.0))
    println(scale.invert(50.0)) // is this really supposed to throw?
}
@hudsonb
Copy link
Owner

hudsonb commented Nov 29, 2018

Ideally no, it wouldn't throw an IllegalStateException in this common case and I'll fix it so that it doesn't.

It's more complicated than it sounds. A DeinterpolatorFactory wasn't provided to the scale so it really doesn't have any idea how to invert R. However, for this exact reason I made scaleLinear reified R so that I can inspect R and provide default implementations of ReinterpolatorFactory and DeinterpolatorFactory in common cases. It looks like I did that for ReinterpolatorFactory but not DeinterpolatorFactory.

D3 handles this by providing a default deinterpolator factory which works on numbers, and ONLY on numbers. D3 doesn't allow you to invert if your range is non-numeric. In Kubed you can invert on a range of any type, but you've got to tell it how by providing a deinterpolator and comparator.

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

No branches or pull requests

2 participants