Skip to content

@graphty/graphty-element / catalog / toColorValue

Function: toColorValue() ​

toColorValue(value): ColorValue | null

Defined in: graphty-element/src/session/styles/channels.ts:169

Turn anything the element accepts as a colour into the form a repaint reads.

TOTAL, deliberately. It is called from the encoding path that runs once per element, which has no try/catch of its own: a colour it cannot read answers null, and the caller leaves the element unpainted. It never throws, so one unreadable value cannot cost every later element its style.

A hex colour is read here. Anything else -- a CSS name, rgb(...), hsl(...) -- goes through the element's one colour normaliser so that a channel accepts exactly what the rest of the element's styles accept, and no second colour dialect appears.

Parameters ​

value ​

string | Rgba | null | undefined

A hex colour, any CSS colour the element understands, or components already parsed. An a outside 0-1 is clamped, and components are rounded into 0-255.

Returns ​

ColorValue | null

The colour with its numbers and its hex string, or null when the value is not a colour at all.