Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output format #78

Merged
merged 3 commits into from
Aug 12, 2020
Merged

Output format #78

merged 3 commits into from
Aug 12, 2020

Conversation

NateBaldwinDesign
Copy link
Collaborator

@NateBaldwinDesign NateBaldwinDesign commented Jul 17, 2020

Description

This issue closes #75

Added output option to generateContrastColors and generateAdaptiveTheme 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:

Output option Sample value
'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 format
  • format is the desired output of the color
  • object 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 a 0 value where a NaN is defined is inconsequential. Primary example being the definition of grays in LCh space. While LCh would assign NaN to the chroma and hue, a value of 0 would produce the same color, as any value in place of NaN 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 and generateAdaptiveTheme test suites.

Screenshots

To-do list

  • This pull request is ready to merge.

@NateBaldwinDesign NateBaldwinDesign requested a review from lazd July 17, 2020 21:03
@NateBaldwinDesign NateBaldwinDesign changed the base branch from master to main July 24, 2020 16:10
@NateBaldwinDesign NateBaldwinDesign merged commit 72094f8 into main Aug 12, 2020
@NateBaldwinDesign NateBaldwinDesign deleted the output-format branch August 12, 2020 17:07
thierryc pushed a commit to thierryc/leonardo that referenced this pull request Mar 29, 2024
* Added color format output functionality to contrast-colors package

* readme update

* readme update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Output color format options
1 participant