fix: hex colors to allow alpha channel #1274
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Color logic now correctly handles alpha channel values for 8-bit hex values as was/is possible with
rgba
,hsla
formats.Details
The
getColor
method now leverageschroma.js
for robust color validation and parsing to feed tod3-color
utils.Below is a list of possible edge cases to supply as
inputs
togetColor
and the respective returnoutputs
undefined
{"r":255,"g":0,"b":0,"opacity":1}
""
{"r":255,"g":0,"b":0,"opacity":1}
"bad"
{"r":187,"g":170,"b":221,"opacity":1}
"#00000000"
{"r":0,"g":0,"b":0,"opacity":0}
"#000000"
{"r":0,"g":0,"b":0,"opacity":1}
"#6092c000"
{"r":96,"g":146,"b":192,"opacity":0}
"#6092c06b"
{"r":96,"g":146,"b":192,"opacity":0.42}
"blue"
{"r":0,"g":0,"b":255,"opacity":1}
"hsl(20, 100%, 40%)"
{"r":204,"g":68,"b":0,"opacity":1}
"hsla(20, 100%, 40%, 0.5)"
{"r":204,"g":68,"b":0,"opacity":0.5}
"hsla(20, 100%, 40%, 0)"
{"r":204,"g":68,"b":0,"opacity":0}
"rgb(0,128,128)"
{"r":0,"g":128,"b":128,"opacity":1}
"rgba(0,128,128,0.5)"
{"r":0,"g":128,"b":128,"opacity":0.5}
"rgba(0,128,128,0)"
{"r":0,"g":128,"b":128,"opacity":0}
Issues
fix #1263
Checklist
packages/charts/src/index.ts
(and stories only import from../src
except for test data & storybook)