You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Historically, there has not been a ordinal.invert for a few reasons:
There’s no requirement that ordinal.range values are unique, so for a given range value y, there could be more than one domain value x that matches.
While ordinal.domain values are keyed by string (i.e., the domain values are internally coerced to strings such that any subsequent input value x will match the domain value with the same string-coerced value), ordinal.range values are not. So you’d need to decide whether range values should also be keyed by string, or whether you’d want to use SameValueZero, strict equality, etc.
Related to 2, at the time ordinal scales were first implemented, ECMAScript collections were not widely available, so unless you string-coerced range values, invert would require a linear scan of the range to find the matching value.
d3/d3-scale#60 implements ordinal.invert, choosing to string-coerce range values for indexing (which seems reasonable). That pull request stalled with a discussion of an alternative implementation, but at some point I hope to close it.
Like the .invert() method for continuous scales (pass a range value, receive a domain value), has the d3 team considered making an equivalent method for Ordinal scale? Several people are interested in this capability; some making work-arounds, such as: http://stackoverflow.com/questions/20758373/inversion-with-ordinal-scale/20766269?noredirect=1#comment68394750_20766269
Thank you,
Nick
The text was updated successfully, but these errors were encountered: