Skip to content

charton API


charton API / @chart-on/core / index / levelColor

Function: levelColor() ​

levelColor(value, theme): string | undefined

Defined in: packages/core/src/drawing/level-color.ts:37

Color of a drawing level with value value in theme: the shared rule behind every built-in level tool's default levels. It depends only on the value and the theme, so a ratio has the same color in every tool, and it changes lightness, not only hue, from level to level:

  • A whole multiple (0, 1, 2 …: the move's own ends and its repeats) is neutral, the theme's text.
  • Any other value takes its fraction f of a whole move and counts the golden steps from the move's end, log_φ(1/f). One step is the golden section (0.618, and 1.618 and 2.618 past the move): the key ratio of the Fibonacci tools, drawn in the pure accent (drawing). Fewer steps (0.786, 0.75) lie between the accent and the neutral; more steps (0.5, 0.382 … down to an eighth) fade from the accent towards the canvas (background). The fade runs along the square root of the steps beyond the key, so the key's close neighbours, such as 0.5, still differ clearly in lightness.
  • Each whole move past the first fades the level a further 18% of its way towards the canvas, so 1.618 and 2.618, or 2, 3 and 4, stay apart.

Negative values mirror positive ones. Returns undefined for a theme without level colors (levelNeutral unset, as forcedColorsTheme makes it), so the level takes the drawing's color.

Parameters ​

value ​

number

theme ​

ChartTheme

Returns ​

string | undefined