SvgColorVariables
ChartForgeX.Themes
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.
Returned or exposed by 11
- Property ChartGrid.SvgColorVariables
- Property ChartOptions.SvgColorVariables
- Property VisualSvgOptions.ColorVariables
- Method SvgColorVariables.Add
- Method SvgColorVariables.AddInk
- Method SvgColorVariables.AddThemeToken
- Method SvgColorVariables.Clone
- Method SvgColorVariables.SharedRoles
- Method VisualDesignTokens.ToSvgColorVariables
- Property TopologyRenderOptions.SvgColorVariables
- Property VisualBlockOptions.SvgColorVariables
Accepted by parameters 55
- Extension method Chart.SvgColorVariables
- Method ChartFluent.SvgColorVariables
- Extension method ChartGrid.SvgColorVariables
- Method ChartGridFluent.SvgColorVariables
- Extension method ChartOptions.SvgColorVariables
- Method ChartOptionsFluent.SvgColorVariables
- Constructor VisualSvgOptions.VisualSvgOptions
- Extension method TopologyRenderOptions.SvgColorVariables
- Method TopologyRenderOptionsFluent.SvgColorVariables
- Extension method ActivityTimelineBlock.SvgColorVariables
- Method ActivityTimelineBlockFluent.SvgColorVariables
- Extension method BlockLayoutBlock.SvgColorVariables
- Method BlockLayoutBlockFluent.SvgColorVariables
- Extension method ChartList.SvgColorVariables
- Method ChartListFluent.SvgColorVariables
- Extension method ChartTable.SvgColorVariables
- Method ChartTableFluent.SvgColorVariables
- Extension method DateStripBlock.SvgColorVariables
- Method DateStripBlockFluent.SvgColorVariables
- Extension method EntityStripBlock.SvgColorVariables
- Method EntityStripBlockFluent.SvgColorVariables
- Extension method FishboneDiagramBlock.SvgColorVariables
- Method FishboneDiagramBlockFluent.SvgColorVariables
- Extension method GitGraphBlock.SvgColorVariables
- Method GitGraphBlockFluent.SvgColorVariables
- Extension method HeatmapInsightCard.SvgColorVariables
- Method HeatmapInsightCardFluent.SvgColorVariables
- Extension method JourneyDiagramBlock.SvgColorVariables
- Method JourneyDiagramBlockFluent.SvgColorVariables
- Extension method MetricCard.SvgColorVariables
- Method MetricCardFluent.SvgColorVariables
- Extension method PacketLayoutBlock.SvgColorVariables
- Method PacketLayoutBlockFluent.SvgColorVariables
- Extension method RadialMetricCard.SvgColorVariables
- Method RadialMetricCardFluent.SvgColorVariables
- Extension method RailroadDiagramBlock.SvgColorVariables
- Method RailroadDiagramBlockFluent.SvgColorVariables
- Extension method ScheduleTimelineBlock.SvgColorVariables
- Method ScheduleTimelineBlockFluent.SvgColorVariables
- Extension method SectionHeaderBlock.SvgColorVariables
- Method SectionHeaderBlockFluent.SvgColorVariables
- Extension method SegmentedMetricBlock.SvgColorVariables
- Method SegmentedMetricBlockFluent.SvgColorVariables
- Extension method TimelineDiagramBlock.SvgColorVariables
- Method TimelineDiagramBlockFluent.SvgColorVariables
- Extension method TreeViewBlock.SvgColorVariables
- Method TreeViewBlockFluent.SvgColorVariables
- Extension method VennDiagramBlock.SvgColorVariables
- Method VennDiagramBlockFluent.SvgColorVariables
- Extension method VisualBlockOptions.SvgColorVariables
- Method VisualBlockOptionsFluent.SvgColorVariables
- Extension method WardleyMapBlock.SvgColorVariables
- Method WardleyMapBlockFluent.SvgColorVariables
- Extension method WorkloadListBlock.SvgColorVariables
- Method WorkloadListBlockFluent.SvgColorVariables
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
- The custom property name, for example --brand-series-1.
- color ChartForgeX.Primitives.ChartColor
- The colour it stands for; its literal value is the fallback.
- role ChartForgeX.Themes.SvgColorRole = Any
- The role of the colour; SvgColorRole.Surface keeps text fills of this colour literal when they are matched by value.
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
- The CSS custom property for the ink, for example --cfx-series-1-ink.
- fill ChartForgeX.Primitives.ChartColor
- The opaque mark colour in this theme.
- ink ChartForgeX.Primitives.ChartColor
- The contrasting text colour in this theme.
- fillRole ChartForgeX.Themes.SvgColorRole
- The role of the filled mark. SvgColorRole.Ramp also overrides both theme-ramp families.
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
- The canonical theme color to bind.
- cssVariableName string
- 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
- SVG markup, for example from ToSvg().
Returns
string The markup with mapped paints replaced.public IReadOnlyList<SvgColorVariable> GetVariablesForSvg(string svg) #Gets this theme's colour variables and the contrasting inks required by the supplied SVG.
Parameters
- svg string
- An SVG exported with colour variables enabled.
Returns
IReadOnlyList<SvgColorVariable> The base variables followed by the referenced derived ink variables, evaluated in this theme.Inherited Methods
Properties
public IReadOnlyList<SvgColorVariable> Variables { get; } #Gets the variables in the order they were added.