Skip to content

colorValidate

Validates a chart color palette against the computable accessibility checks.

Runs the categorical accessibility checks against the first eight swatches of the built-in colorDefaults.scale, reporting each check’s pass/warn/fail state and whether the palette clears every hard requirement.

import {colorValidate, colorDefaults} from "@d3plus/color";

colorValidate(colorDefaults.scale.range().slice(0, 8));

Pass {ordinal: true} to validate an ordered single-hue ramp instead: it checks monotone lightness, visible step gaps, a light end that still clears the surface, and a single hue — the categorical checks would fail a correct ramp by design.

import {colorValidate, colorRamp, colorDefaults} from "@d3plus/color";

colorValidate(colorRamp(colorDefaults.sequential, 5, {ordinal: true}), {
  ordinal: true,
});

Parameters

import {colorValidate} from "@d3plus/color";
paletterequiredArray.<string>

An array of CSS color strings, in slot order.

optionsColorValidateOptionsDefault {}

Mode, surface, pair scope, and ordinal toggle.