Comments (2)
Okay, it’s slightly more complicated. In some color spaces, valid colors have NaN channel values. For example, hsl("black") is a valid color but does not have a defined hue or saturation, so the h
and s
channels are NaN; for hsl("gray"), s
is 0 and h
is NaN. In other color spaces, such as RGB, valid colors always have numeric channel values; only an invalid color has NaN channel values.
In color spaces that expect NaN channel values, you want bidirectional inheritance for interpolation. For example, when interpolating from black to red or red to black in HSL color space, you should use a constant hue of 0°.
On the other hand, in RGB space, if the start color is red and the end color is rgb(NaN, NaN, NaN), it doesn’t make sense to treat the end color as red. If you were to just set the end color directly, it would be treated as black, not red. So the end color should be treated as black.
The point is, in some color spaces colors are uniquely defined; in others, there are multiple representations. Only in the latter case is it valid to substitute an invalid end color channel value using the corresponding channel from the start color; however, in all color spaces it is valid to substitute an invalid start channel value with the corresponding end channel value.
from d3-interpolate.
It’s actually slightly more complicated now that we have opacity: when an RGB color is transparent, it is rgb(NaN, NaN, NaN, 0). So, this is a valid color, and if it’s the end value for interpolation, those end channel values should be substituted with the start channel values.
So… I think it might be best to always use bidirectional substitution.
from d3-interpolate.
Related Issues (20)
- Images in readme not loading due to Content Security Policy
- Simple zoom-in with interpolateZoom gives negative duration
- Interpolated data spike value problem HOT 1
- d3-color vulnerable to ReDoS HOT 1
- d3-color dependency update due to ReDoS HOT 1
- d3-color version issue HOT 2
- [bug] require() of ES modules is not supported HOT 1
- NaN RGB values if passing zero to interpolateRgb
- Meteor app crashes HOT 1
- d3-color version issue
- interpolateBalanced? HOT 3
- d3.piecewise(values)?
- Non-uniform d3.interpolateRgbBasis HOT 2
- array.js sometimes reports errors HOT 1
- Catmull-Rom interpolator? HOT 1
- Interpolate with t=Infinity returns NaN instead of Infinity HOT 6
- d3.interpolateHcl(a,b)(1) doesn't return 'b' HOT 3
- 3.0.1 doesn't work with Jest HOT 10
- Require Cycle with object.js and value.js HOT 1
- Require cycle: `value.js` -> `object.js` -> `value.js` HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from d3-interpolate.