Skip to content
ChartForgeX
Class

SvgColorVariables

ChartForgeX.Themes

Namespace
ChartForgeX.Themes
Assembly
ChartForgeX
Modifiers
sealed

Maps colours to CSS custom properties so SVG output can follow a host's design tokens: every paint value (fill, stroke, stop-color, flood-color, lighting-color, color, in attributes, style attributes, and <style> elements) whose colour is mapped is written as var(--name, #rrggbb), with the literal colour as the fallback, so the SVG looks the same where the property is not defined. A paint more transparent than its variable is written as color-mix(in srgb, var(--name, #rrggbb) N%, transparent). PNG output is not affected.

Inheritance

  • object
  • SvgColorVariables

Remarks

Set on a chart, grid, or topology (Chart.WithSvgColorVariables, ChartGrid.WithSvgColorVariables, TopologyRenderOptions.SvgColorVariables), the renderers write colours by role. A colour the renderer derives (the white sheen of a line, the highlight of a surface, the contrast stroke of a topology icon) stays literal even when it equals a token colour. A blend of token colours (bar gradients, heatmap and calendar ramp steps, neutral zero and empty days, topology tints) is written as color-mix(in srgb, …) of their properties, so it follows a theme switch. A colour written for a role (a series, a status, a ramp step, the surface behind marks) takes the variable of that role when several share its colour. Text on filled marks (heatmap and hexbin values, categorical cell text, Gantt lane labels) is written as the text colour or, on strong marks, the surface behind the marks, by role. Other paints match by colour value. on finished markup only matches by colour value (red, green, and blue; a paint is only matched when it is no more opaque than the variable): every paint of a mapped colour takes the variable, including derived colours that happen to equal it. When two variables share a colour, the one added first is used, and variables are not used for text fills. Do not apply variables to SVG rendered with variables: its derived colours are literal on purpose and would be mapped by value. Roles tell token kinds apart (a series colour from a ramp step of the same value), not tokens within a kind: when two surface tokens share a colour in one theme, the one added first names it.

Usage

Explore 66 API references to this type

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

Accepted by parameters 55

Constructors

public SvgColorVariables() #

Methods

public SvgColorVariables Add(string name, ChartColor color, SvgColorRole role = Any) #

Adds a variable. When a variable for the same colour was added before, that one keeps the colour for paints without a role and this one is only used by paints of its own role.

Parameters

name string required
The custom property name, for example --brand-series-1.
color ChartForgeX.Primitives.ChartColor required
The colour it stands for; its literal value is the fallback.
role ChartForgeX.Themes.SvgColorRole = Any optional
The role of the colour; SvgColorRole.Surface keeps text fills of this colour literal when they are matched by value.

Returns

SvgColorVariables The same instance.

Exceptions

  • ArgumentException – The name is not -- followed by letters, digits, -, or _.
  • ArgumentOutOfRangeException – The role is not defined.
public SvgColorVariables AddInk(string name, ChartColor fill, ChartColor ink, SvgColorRole fillRole) #

Adds the contrasting text property paired with a filled mark. The renderer selects this property by the fill, so black or white text follows that mark when the host switches themes, without changing unrelated text.

Parameters

name string required
The CSS custom property for the ink, for example --cfx-series-1-ink.
fill ChartForgeX.Primitives.ChartColor required
The opaque mark colour in this theme.
ink ChartForgeX.Primitives.ChartColor required
The contrasting text colour in this theme.
fillRole ChartForgeX.Themes.SvgColorRole required
The role of the filled mark. SvgColorRole.Ramp also overrides both theme-ramp families.

Returns

SvgColorVariables The same instance.

Exceptions

  • ArgumentException – The property name is invalid.
  • ArgumentOutOfRangeException – The role is not defined.
public SvgColorVariables AddThemeToken(VisualThemeColorToken token, string cssVariableName) #

Binds a canonical theme color to a CSS custom property while preserving the token's identity.

Parameters

token ChartForgeX.Themes.VisualThemeColorToken required
The canonical theme color to bind.
cssVariableName string required
The CSS custom property name, for example --app-surface.

Returns

SvgColorVariables The same instance. Adding the same token again replaces its previous binding.

Exceptions

  • ArgumentOutOfRangeException – The theme token is not defined.
  • ArgumentException – The CSS custom property name is invalid.
public string Apply(string svg) #

Writes mapped paint values in finished svg as custom properties, by colour value. Applying it twice changes nothing more. Renderers given these variables also write derived colours by role (see remarks).

Parameters

svg string required
SVG markup, for example from ToSvg().

Returns

string The markup with mapped paints replaced.
public SvgColorVariables Clone() #

Creates an independent copy.

public IReadOnlyList<SvgColorVariable> GetVariablesForSvg(string svg) #

Gets this theme's colour variables and the contrasting inks required by the supplied SVG.

Parameters

svg string required
An SVG exported with colour variables enabled.

Returns

IReadOnlyList<SvgColorVariable> The base variables followed by the referenced derived ink variables, evaluated in this theme.
public static string SharedRoleName(string tokenPath) #

Returns the shared design-role property CanopyX and HtmlForgeX pages define for a token path (see VisualDesignTokens.ToSvgColorVariables): ramps.* become --hfx-ramp-* and every other path --hfx-color-*, in kebab case. For example series.1 is --hfx-color-series-1, surface.card is --hfx-color-surface-card, surface.line is --hfx-color-surface-line, text.primary is --hfx-color-text-primary, text.secondary is --hfx-color-text-secondary, accent.base is --hfx-color-accent-base and ramps.sequential.1 is --hfx-ramp-sequential-1.

Parameters

tokenPath string required
A token path such as surface.cardAlt.

Returns

string The custom property name.

Exceptions

  • ArgumentException – The path is empty or holds characters other than ASCII letters, digits and dots.
public static SvgColorVariables SharedRoles(VisualTheme? theme = null, ThemeMode mode = Light) #

Creates colour variables named after the shared --hfx-* design roles (SvgColorVariables.SharedRoleName), with the theme's colours as fallbacks: a chart on a CanopyX or HtmlForgeX page takes the page's theme, and a page that defines none of the properties shows the theme unchanged. Series paints keep their palette slot, so two slots with equal colours still write --hfx-color-series-n of their own slot.

Parameters

theme ChartForgeX.Themes.VisualTheme? = null optional
The theme the chart is prepared with; null uses VisualTheme.Graphite.
mode ChartForgeX.ThemeMode = Light optional
The mode the chart is prepared in.

Returns

SvgColorVariables The colour variables, for Chart.WithSvgColorVariables, ChartGrid.WithSvgColorVariables or a VisualSvgOptions.

Properties

public IReadOnlyList<SvgColorVariable> Variables { get; } #

Gets the variables in the order they were added.

Fields

public const string SharedFontFamily #

The shared design-role property for the page's proportional font family.

Value: --hfx-font-sans