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
It’d be great if you could define the equivalent to ordinal.unknown for a threshold scale. Currently if you call a threshold scale with a NaN value, it returns undefined:
(Note that color(null) is treated equivalently to color(0), since +null === 0. That’s a separate issue, though.)
Returning undefined seems like reasonable default behavior, but it sometimes leads to surprising consequences that would be nice to avoid. For example, if you set context.strokeStyle to undefined, nothing happens! You continue to get whatever stroke style was set previously, thus silently displaying invalid data as whatever happened to come before it.
A similar argument can be made for continuous scales like d3.scaleLinear, d3.scaleSequential, etc. Currently the behavior depends on the interpolator: a NaN t is passed to the interpolator, which can then decide what to do. In the common case of d3.interpolateRgb, d3.rgb treats NaN channel values as zero, so you end up with opaque black for any NaN input. It’d be nice to have a scale.unknown here, too, whose value would be returned instead of invoking the interpolator.
mbostock
changed the title
threshold.unknown
Generalizing scale.unknown for missing data.
Mar 14, 2017
It’d be great if you could define the equivalent to ordinal.unknown for a threshold scale. Currently if you call a threshold scale with a NaN value, it returns undefined:
(Note that
color(null)
is treated equivalently tocolor(0)
, since+null === 0
. That’s a separate issue, though.)Returning undefined seems like reasonable default behavior, but it sometimes leads to surprising consequences that would be nice to avoid. For example, if you set context.strokeStyle to undefined, nothing happens! You continue to get whatever stroke style was set previously, thus silently displaying invalid data as whatever happened to come before it.
Safer would be something like this:
The text was updated successfully, but these errors were encountered: