Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds an
invert
method (and corresponding docs & test cases) toscaleSequential...
andscaleDiverging...
. 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!