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

Add invert to interpolated scales. #191

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

jheer
Copy link
Contributor

@jheer jheer commented Sep 14, 2019

This PR adds an invert method (and corresponding docs & test cases) to scaleSequential... and scaleDiverging.... Rather than invert the interpolator itself (which might not be bijective), these methods expect an interpolation fraction as input and return the corresponding domain value. (Thus they only "truly" invert the scale when using the default interpolated range [0, 1].)

The motivating use case for this PR is to perform interactive filtering in response to brushes over a color gradient legend. It is relatively simple to convert pixel brush coordinates into fractional domain values, which can then be inverted. While similar functionality could be achieved by creating an additional continuous scale with a numeric pixel range, these new methods enable direct usage of the existing scale, providing a more efficient and convenient mechanism within systems such as Vega / Vega-Lite.

I realize the name "invert" might be controversial here, but I kept it for parity with other scale types (and because inversion of arbitrary interpolators is not possible). If this PR is of interest, I'd be happy to consider an alternative method name. If this PR is not of interest, it would be great to know so we can make alternate arrangements. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants