colorAssign
Assigns a color to a value using a predefined set of defaults.
Basic example
Section titled “Basic example”Turns any data value into a color using colorDefaults: null and undefined get the missing grey, true and false get the on green and off red, a valid CSS color is passed through unchanged, and any other value is fed to the ordinal scale, so the same string ("Apples") always gets the same color.
import {colorAssign} from "@d3plus/color";
colorAssign(null);
colorAssign(undefined);
colorAssign(true);
colorAssign(false);
colorAssign("#1c7ed6");
colorAssign("rebeccapurple");
colorAssign("Apples");
colorAssign("Bananas");
colorAssign("Apples");
Overrides
Section titled “Overrides”The second argument overrides any of the default slots for that call. Charts pass their colorDefaults config here, which is how a theme changes the missing, on, and off colors everywhere at once.
import {colorAssign} from "@d3plus/color";
colorAssign(true, {on: "#0ca678"});
colorAssign(false, {off: "#f03e3e"});
colorAssign(null, {missing: "#868e96"});
Parameters
import {colorAssign} from "@d3plus/color";