First stab on adding support for deltas and contrast from other color#96
First stab on adding support for deltas and contrast from other color#96DmitrySharabin wants to merge 27 commits intomainfrom
Conversation
✅ Deploy Preview for color-elements ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Show deltas within the scale.
|
Could you add some docs so I can review the API too? |
Sure |
Done! |
LeaVerou
left a comment
There was a problem hiding this comment.
- We don’t want to hardcode a specific deltaE algorithm, we should allow customizing it (it's unclear which one is being hardcoded here). I think this should be fine as part of coords.
coords="L: oklch.l, C: oklch.c, H: oklch.h, ΔΕ: deltaE2000". It should be easy to disambiguate the two. Perhaps we should even renamecoordstodatato not be confusing? - Don't use
deltas()yet, since this is not part of any released Color.js version. I just mentioned it so you could look at the implementation. Though after seeing the hue charts, not sure its approach would be the right one for hue - We don't want to have to style two parts for (visually) the same thing.
- Not sure we want a separate boolean attribute. We can use
vswithout a value to opt-in, and with a value to specify a specific color.
Use `vs` without a value to opt-in deltas (from the previous color) and with a value to specify a specific color.
* Rename: `coords` → `data` * Allow specifying `ΔΕ` algorithm (uses parameterized syntax under the hood) * Combine coords and `ΔΕ` in one part—data * Fix styles accordingly * Update docs
We can't use `deltas()` yet. It's not in any released version of Color.js.
|
Thank you for your feedback. I addressed all the issues you mentioned. Here is the summary of the changes:
|
src/color-scale/color-scale.js
Outdated
There was a problem hiding this comment.
Why would you check this and not this.vs !== undefined or something?
src/color-scale/color-scale.js
Outdated
There was a problem hiding this comment.
Ah I see why you're doing the #hasVs thing. That’s not the right way; it means that if someone sets it via the property you get a different behavior. You want two properties: one for the raw value, and one for the parsed value, which is either true (previous color), false (no vs), or a Color instance.
And yes, this is another case of rawProp.
There was a problem hiding this comment.
Yes, I'm doing this precisely because I can't see another way to distinguish different cases: color, no color, no vs.
There was a problem hiding this comment.
Another option would be to use a custom parse function. Up to you.
There was a problem hiding this comment.
I wonder if it may be useful to provide a way to do vs with the previous or next color. In that case we could have vs="previous" and vs="next" which may be more explanatory than a bare vs with no value.
There was a problem hiding this comment.
Another option would be to use a custom parse function.
Yeah, I was going to try this later. Glad it makes sense. :)
There was a problem hiding this comment.
I wonder if it may be useful to provide a way to do vs with the previous or next color. In that case we could have
vs="previous"andvs="next"which may be more explanatory than a barevswith no value.
I like it
LeaVerou
left a comment
There was a problem hiding this comment.
In addition to the other comments, the info is useful to get programmatically as well. Don't just calculate them inline, set a getter prop with them!
(same applies to info actually, so you probably want a data structure that supports both. Let's discuss the data structure before you implement)
|
Some ideas: Option 1: Two separate data structurescolorInfo: {"oklch.l": 0.5, deltaE2000: undefined, contrastAPCA: undefined},
vsInfo: {"oklch.l": 0.2, deltaE2000: 10, contrastAPCA: 25},Option 2: One data structure, one entry per keyOption 2.1: Object when 2 values, value otherwisecolorInfo: {
"oklch.l": {value: 0.5, delta: 0.2},
deltaE2000: 10,
contrastAPCA: 25
},Option 2.2: Object alwayscolorInfo: {
"oklch.l": {value: 0.5, delta: 0.2},
deltaE2000: {value: 10, delta: 10}, // or {value: undefined, delta: 10}?
contrastAPCA: {value: 25, delta: 25}, // or {value: undefined, delta: 25}?
},What do you think are the pros and cons of each approach? Do you see any other options? |
Pros
Cons
Pros
Cons
Pros
Cons
I would also add the colorInfo: {
"oklch.l": {value: 0.5, delta: 0.2, isAngle: false},
},Another option would be to provide the unit itself. colorInfo: {
"oklch.l": {value: 0.5, delta: 0.2, unit: "%"},
},However, in that case, we should probably either adjust colorInfo: {
"oklch.l": {value: 0.5, rawDelta: 0.2, delta: 20, unit: "%"},
},If we go with option 2.2, should we also add these properties ( |
- Remove `#hasVs` - Use custom `parse()` - Add support for `previous` and `next` keywords
You are right; there is no cycle. My brain simply refuses to work properly today. 🤦♂️ Thank you for checking it.
I looked at your example code and noticed that the deltaE and contrast info is stored in
Agreed!
After re-reading this one more time, I'm also leaning toward Option 1. It seems like it will also make the code more readable than we might get with other options. |

I chose
vsas the attribute name for the other color. We can easily change it if needed.For now, it looks like this: