Comments (8)
And, d3-interpolate now supports opacity interpolation as of release 0.5.2! For example:
var i = d3.interpolate("transparent", "red");
i(0.5); // "rgba(255, 0, 0, 0.5)"
from d3-color.
I couldn’t think of an elegant way to represent optional alpha without adding it to all color spaces, and then it didn’t seem very useful. (Also, you couldn’t name it a
as in RGBA, because then you’d have two a
channels for Lab color.)
It would be possible to strip out the alpha channel when parsing CSS rgba(…)
and hsla(…)
specifications, but I don’t see this as immediately useful so I haven’t been motivated to implement it. Perhaps you could elaborate on how would you use it?
from d3-color.
I have a function that calculates the perceived color displayed on screen when depicting a slightly transparent color on top of another color (ex. 50% black on top of white looks grey).
Kind of an edge case I know, but I'm rolling it out into a large color utility and love the way your new d3-color module validates colors (returns null
instead of just black for non-colors). Even if you just parsed out the appropriate RGB and HSL values and didn't touch the alpha channel, I could parse that out on my own.
from d3-color.
My buddy @alexandersimoes had a quirky idea: naming the variable after the actual greek alpha symbol: α
from d3-color.
Another option would be an object that represents a color and an opacity. So like, call it a “paint”:
function paint(string) {
return {
color: …,
opacity: …
};
}
So the returned paint.color
would be a color
instance (such as rgb
or hsl
) and paint.opacity
would be a number between 0 and 1 inclusive. If you pass it an rgb(…)
string rather than an rgba(…)
string then opacity would be 1.
from d3-color.
naming the variable after the actual greek alpha symbol
We used greek names for many private variables in D3. It arguably improved the readability of the (mathematical) code, but it came at the expense of confusing people unfamiliar with character encodings. At the time, it felt like a reasonable trade-off since character encodings are such a critical concept. But I’ve softened my stance on that, and I’m not planning on using non-ASCII characters for the new D3 modules.
Even then, I wouldn’t recommend using them for a public API, if only because they can be tedious to type. You can enable the Greek input source (γνῶθι σεαυτόν), but that shouldn’t be a requirement. And copy-paste to type is a pain.
Edit: I cheated and copy-pasted that.
from d3-color.
👍
from d3-color.
oh man, that's super sexy
from d3-color.
Related Issues (20)
- d3.rgb doesn't parse HSL hues with `deg` units HOT 1
- Changing color.s changes luminosity and color.l saturation.
- Security vulnerability fix for d3-color required in version 2.x HOT 7
- Security vulnerability fix for d3-color nice-to-have in version 1.x HOT 4
- Unexpected token 'export' while update from 2.x.x to 3.x.x HOT 2
- Why d3 uses illuminant D50 instead of D65? HOT 1
- d3.hsl doesnt seem to work with grey scale values HOT 2
- Alpha value of 0 breaks rgb HOT 1
- Add formatHex8() to include opacity HOT 7
- Brightening black in RGB HOT 3
- bug: hue is NaN when convert hsl HOT 2
- Unexpected conversion to HSL
- Incorrect conversion from HCL / LCH to hex or rgb HOT 2
- oklab / oklch? HOT 8
- More exports. HOT 9
- Doesn't work - color is not defined HOT 1
- Does the Common JS version of the module work? HOT 1
- Supporting CSS color level 4 HOT 3
- Avoid catastrophic backtracking when parsing HOT 11
- formatHex with alpha channel HOT 1
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-color.