qualpal 2.3.0
|
The main API of qualpal is a builder-style interface that allows you to configure the color palette generation process step by step.
The only required setting is the input color space, which defines the set of colors that can be selected from. There are currently three different ways to specify the input color space:
"Vermeer:PearlEarring"
.To specify the input color space using HSL, you can define ranges for hue, saturation, and lightness. For example, to create a color palette with colors sampled from the HSL color space, you can use the following code:
In this case, qualpal will generate a number of color points (by default 1000) in the specified HSL color space using a Halton pseudo-random sequence.
To generate the actual colors, you can then call the generate
method with the desired number of colors:
To specify the input color space using RGB, you can provide a list of RGB colors. For example:
And finally, to use a predefined color palette, you can use the setInputPalette
method:
A key feature of qualpal is its ability to generate color palettes that are accessible to users with color vision deficiencies (CVD). In order to do this, qualpal projects the RGB colors into the specific color vision deficiency space and then uses these colors to generate the palette. At the moment, qualpal supports CVD simulation for deuteranomaly, protanomaly, and tritanomaly. You can specify the severity of the CVD using a value between 0 and 1, where 0 means no CVD and 1 means full CVD. For example, to generate a color palette that is accessible to users with deuteranomaly, you can use the following code:
The simulation of color vision deficiency is based on the model by Machado et al. (2009), and is numerically stable and fast.
When generating color palettes for visualizations, it is often important to consider the background color against which the colors will be displayed. This matters especially for scatter plots or other visualizations where the canvas color is dominant. qualpal allows you to specify a background color to ensure that the selected colors are distinct from it. You can set the background color using the setBackgroundColor
method:
By default, the background color is not considered, so if you want to ensure that the selected colors are distinct from the background color, you need to explicitly set it. This also makes it easy to use qualpal for generating color palettes with a dark background, for instance:
You can extend an existing palette by keeping some colors fixed and adding more distinct colors from a candidate set. For example:
ext_pal
now contains the fixed colors plus two more distinct colors from input.