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.
Description
This issue closes #75
Added
output
option togenerateContrastColors
andgenerateAdaptiveTheme
functions.The output option refers to the desired color format that is returned by the function. Currently (and now by default), the output format is
"HEX"
. However, now the following additional formats can be chosen by the user:'HEX'
(default)#RRGGBB
'RGB'
rgb(255, 255, 255)
'HSL'
hsl(360deg, 0%, 100%)
'HSV'
hsv(360deg, 0%, 100%)
'HSLuv'
hsluv(360, 0, 100)
'LAB'
lab(100%, 0, 0)
'LCH'
lch(100%, 0, 360deg)
'CAM02'
jab(100%, 0, 0)
'CAM02p'
jch(100%, 0, 360deg)
Output formats conform to the W3C CSS Color Module Level 4 spec for the supported options (rgb, hex, lab, lch, hsl).
The formatting is performed by the
fixColorValue(color, format, object)
function.color
is the input color, of any formatformat
is the desired output of the colorobject
is a boolean option to either return a string or object. The object format conforms to d3 module formatting for these colors (sans the opacity object), and the string format conforms to W3C spec as mentioned above.Within this function, another helper function filters through any
NaN
values that d3 returns for a color and replaces them with 0. While this may not be technically correct in the color science realm, the output and consumption of these colors using a0
value where aNaN
is defined is inconsequential. Primary example being the definition of grays in LCh space. While LCh would assignNaN
to the chroma and hue, a value of0
would produce the same color, as any value in place ofNaN
would produce the same output when clamped to RGB.Motivation
This enhancement will enable teams that want to manipulate colors beyond Leonardo, or leverage supported color specs more directly. This removes the barrier for users to create their own color transformations as well.
This PR includes thorough testing for the new
fixColorValue()
function.Additional tests to verify accuracy of output option are included in
generateContrastColors
andgenerateAdaptiveTheme
test suites.Screenshots
To-do list