feat: Switch color processing library#7536
Conversation
|
I created a couple of PRs (#78 and #81) in a dependency used by color that will add some new features for parsing color strings that would bring it closer to parity with TinyColor. The maintainer recently merged one of these and will (hopefully) be merging the other soon. Once he publishes a new release, I'll be able to use it in plotly.js. |
fc905c7 to
6e83d8a
Compare
|
@camdecoster Looks good overall, but lightened/darkened colors seem much less distinct after this change, is there any way to adjust that? Maybe increase the degree of lightening/darkening?
(codepen) |
| }; | ||
|
|
||
| color.rgb = function(cstr) { return color.tinyRGB(tinycolor(cstr)); }; | ||
| const rgb = (cstr) => { |
There was a problem hiding this comment.
Can you add a comment explaining that this is for returning a string which doesn't contain alpha? (Or whatever is the purpose of this function, I'm assuming it's that because of the comment in the old file.)
There was a problem hiding this comment.
More generally if you could add a few docstrings for the most-commonly-used functions in that file it would be a big improvement
There was a problem hiding this comment.
I'll add descriptions for all the functions in here.
| "- hex (e.g. '#d3d3d3', '#d3d3d3aa')", | ||
| "- rgb (e.g. 'rgb(255, 0, 0)', 'rgb(255 0 0)')", | ||
| "- rgba (e.g. 'rgba(255, 0, 0, 0.5)', 'rgba(255 0 0 / 0.5)')", | ||
| "- hsl (e.g. 'hsl(0, 100%, 50%)')", | ||
| "- hsla (e.g. 'hsla(0, 100%, 50%, 0.5)')", | ||
| "- hwb (e.g. 'hwb(0, 0%, 0%)')", |
There was a problem hiding this comment.
Weirdly, I can't find this info in the docs anywhere, although I could be missing it. We should make sure the supported color formats are documented with the next release.
There was a problem hiding this comment.
I agree. I'm prepping a migration guide for v4 that should include some of this info, but a follow up should be to update the docs for v4.
|
|
||
| for(i = 0; i < colorList.length; i++) { | ||
| colors.push(tinycolor(colorList[i]).lighten(20).toHexString()); | ||
| colors.push(Color.color(colorList[i]).lighten(0.2).hex()); |
There was a problem hiding this comment.
Re: my comment about lightened/darkened colors being too similar, I assume you could just increase this value here to fix.
There was a problem hiding this comment.
I reworked the lighten/darken code to better match what tinycolor did.
emilykl
left a comment
There was a problem hiding this comment.
My only concern is the lighten/darken changes, everything else looks good
|
@camdecoster Nice, with your edits, the lightened/darkened colors look identical to
|




Description
Switch color processing library from TinyColor to color.
Related to #7523.
Changes
rgb()/rgba()strings with decimal 0–1 fractions are no longer supported. The utility functionColor.clean()has been removed.Testing
npm run test-jasmineand verify that all tests passnpm run test-imageand verify that all image-baseline diffs match the regenerated baselines in this PRnpm run schemaproduces no diff againsttest/plot-schema.jsonScreenshots
Color.contrast,Color.brighten, andColor.addOpacityproduce slightly different RGB output. Here are some example plots that can be used to see the difference betweentinycolorandcolorwhen pasted into Plotly devtools:Auto-contrast text on a heatmap
Auto inside-text color on default colorway
Pie with extended colorway (lighten/darken)
Notes