ColorScale
public class ColorScaleRepresents a color scale for mapping values to colors, supporting both:
- Gradient-based continuous color scales (for numerical data like heatmaps)
- Category-based discrete color scales (for categorical data)
Matches Swift Charts' ColorScale API:
- ColorScale.fromGradient(gradient, domain: [min, max])
- ColorScale.fromMapping([value: color, ...])
Methods
Section titled “Methods”
FromGradient(Gradient, float, float)
Section titled “FromGradient(Gradient, float, float)”public static ColorScale FromGradient(Gradient gradient, float domainMin = 0, float domainMax = 1)Creates a gradient-based color scale for continuous numerical data. Maps values in [domainMin, domainMax] to colors along the gradient.
Example: var scale = ColorScale.FromGradient(heatGradient, 0f, 100f); Color c = scale.ColorForValue(50f); // Gets middle color
Parameters
| Name | Type | Description |
|---|---|---|
gradient |
UnityEngine.Gradient | The gradient to sample colors from. |
domainMin |
System.Single | The minimum value of the data domain. |
domainMax |
System.Single | The maximum value of the data domain. |
Returns
ChartGuru.ColorScale
FromColormap(ChartColormap, float, float)
Section titled “FromColormap(ChartColormap, float, float)”public static ColorScale FromColormap(ChartColormap colormap, float domainMin = 0, float domainMax = 1)Creates a gradient-based color scale that maps values in [domainMin, domainMax] to a named scientific colormap, evaluated from its published table.
Parameters
| Name | Type |
|---|---|
colormap |
ChartGuru.ChartColormap |
domainMin |
System.Single |
domainMax |
System.Single |
Returns
ChartGuru.ColorScale
FromColors(Color, Color, float, float)
Section titled “FromColors(Color, Color, float, float)”public static ColorScale FromColors(Color from, Color to, float domainMin = 0, float domainMax = 1)Creates a gradient-based color scale from two colors. Convenience method for simple two-color gradients.
Parameters
| Name | Type | Description |
|---|---|---|
from |
UnityEngine.Color | The color at the minimum domain value. |
to |
UnityEngine.Color | The color at the maximum domain value. |
domainMin |
System.Single | The minimum value of the data domain. |
domainMax |
System.Single | The maximum value of the data domain. |
Returns
ChartGuru.ColorScale
FromColors(Color[], float, float)
Section titled “FromColors(Color[], float, float)”public static ColorScale FromColors(Color[] colors, float domainMin = 0, float domainMax = 1)Creates a gradient-based color scale from multiple colors evenly distributed.
Parameters
| Name | Type | Description |
|---|---|---|
colors |
UnityEngine.Color[] | Array of colors from min to max. |
domainMin |
System.Single | The minimum value of the data domain. |
domainMax |
System.Single | The maximum value of the data domain. |
Returns
ChartGuru.ColorScale
FromMapping(Dictionary<object, Color>)
Section titled “FromMapping(Dictionary<object, Color>)”public static ColorScale FromMapping(Dictionary<object, Color> mapping)Creates a category-based color scale for discrete categorical data. Each category is mapped to a specific color.
Example: var scale = ColorScale.FromMapping(new Dictionary<object, Color> { { "High", Color.red }, { "Medium", Color.yellow }, { "Low", Color.green } }); Color c = scale.ColorForCategory("High"); // Returns red
Parameters
| Name | Type | Description |
|---|---|---|
mapping |
System.Collections.Generic.Dictionary{System.Object,UnityEngine.Color} | Dictionary mapping category values to colors. |
Returns
ChartGuru.ColorScale
FromMapping(Dictionary<string, Color>)
Section titled “FromMapping(Dictionary<string, Color>)”public static ColorScale FromMapping(Dictionary<string, Color> mapping)Creates a category-based color scale using string keys. Convenience method for common string-based categories.
Parameters
| Name | Type |
|---|---|
mapping |
System.Collections.Generic.Dictionary{System.String,UnityEngine.Color} |
Returns
ChartGuru.ColorScale
FromMapping(Dictionary<int, Color>)
Section titled “FromMapping(Dictionary<int, Color>)”public static ColorScale FromMapping(Dictionary<int, Color> mapping)Creates a category-based color scale using integer keys. Useful for enum-like category indexing.
Parameters
| Name | Type |
|---|---|
mapping |
System.Collections.Generic.Dictionary{System.Int32,UnityEngine.Color} |
Returns
ChartGuru.ColorScale
FromPalette(Color[])
Section titled “FromPalette(Color[])”public static ColorScale FromPalette(Color[] defaultColors)Creates an auto-mapped category scale from an array of default colors. Categories are assigned colors in order as they are encountered.
Parameters
| Name | Type | Description |
|---|---|---|
defaultColors |
UnityEngine.Color[] | The palette of colors to cycle through for new categories. |
Returns
ChartGuru.ColorScale
FromArray(Color[])
Section titled “FromArray(Color[])”public static ColorScale FromArray(Color[] colors)Creates a category-based color scale from a plain array of colors.
Categories are assigned colors in order as they are discovered at render time.
Swift Charts equivalent: .ChartForegroundStyleScale(range: [.red, .blue, .green]).
Parameters
| Name | Type |
|---|---|
colors |
UnityEngine.Color[] |
Returns
ChartGuru.ColorScale
FromDomainRange(string[], Color[])
Section titled “FromDomainRange(string[], Color[])”public static ColorScale FromDomainRange(string[] domain, Color[] range)Creates a category-based color scale from explicit domain and range arrays.
Swift Charts equivalent: .ChartForegroundStyleScale(domain: [“A”,“B”,“C”], range: [.red, .blue, .green]).
Parameters
| Name | Type |
|---|---|
domain |
System.String[] |
range |
UnityEngine.Color[] |
Returns
ChartGuru.ColorScale
ColorForValue(float)
Section titled “ColorForValue(float)”public Color ColorForValue(float value)Gets the color for a numerical value using the gradient scale. Values outside the domain are clamped.
Parameters
| Name | Type | Description |
|---|---|---|
value |
System.Single | The numerical value to map to a color. |
Returns
UnityEngine.Color: The interpolated color from the gradient.
ColorForCategory(object)
Section titled “ColorForCategory(object)”public Color ColorForCategory(object category)Gets the color for a category value using the category mapping. Returns white if the category is not found.
Parameters
| Name | Type | Description |
|---|---|---|
category |
System.Object | The category value to look up. |
Returns
UnityEngine.Color: The mapped color for the category.
GetColor(object)
Section titled “GetColor(object)”public Color GetColor(object value)Gets the color for any value, automatically determining whether to use gradient-based or category-based lookup.
Parameters
| Name | Type | Description |
|---|---|---|
value |
System.Object | The Value (numerical or categorical) to map. |
Returns
UnityEngine.Color: The mapped color.
SetCategoryColor(object, Color)
Section titled “SetCategoryColor(object, Color)”public void SetCategoryColor(object category, Color color)Adds or updates a category mapping.
Parameters
| Name | Type | Description |
|---|---|---|
category |
System.Object | The category key. |
color |
UnityEngine.Color | The color to map to. |
SetDomain(float, float)
Section titled “SetDomain(float, float)”public void SetDomain(float min, float max)Updates the domain range for gradient scales.
Parameters
| Name | Type | Description |
|---|---|---|
min |
System.Single | New minimum value. |
max |
System.Single | New maximum value. |
HeatMap(float, float)
Section titled “HeatMap(float, float)”public static ColorScale HeatMap(float domainMin = 0, float domainMax = 1)Creates a heat map color scale (blue -> green -> yellow -> red).
Parameters
| Name | Type |
|---|---|
domainMin |
System.Single |
domainMax |
System.Single |
Returns
ChartGuru.ColorScale
Cool(float, float)
Section titled “Cool(float, float)”public static ColorScale Cool(float domainMin = 0, float domainMax = 1)Creates a cool color scale (cyan -> blue -> purple).
Parameters
| Name | Type |
|---|---|
domainMin |
System.Single |
domainMax |
System.Single |
Returns
ChartGuru.ColorScale
Warm(float, float)
Section titled “Warm(float, float)”public static ColorScale Warm(float domainMin = 0, float domainMax = 1)Creates a warm color scale (yellow -> orange -> red).
Parameters
| Name | Type |
|---|---|
domainMin |
System.Single |
domainMax |
System.Single |
Returns
ChartGuru.ColorScale
Diverging(float, float)
Section titled “Diverging(float, float)”public static ColorScale Diverging(float domainMin = -1, float domainMax = 1)Creates a diverging color scale (red -> white -> blue). Useful for data with a meaningful center point.
Parameters
| Name | Type |
|---|---|
domainMin |
System.Single |
domainMax |
System.Single |
Returns
ChartGuru.ColorScale
Grayscale(float, float)
Section titled “Grayscale(float, float)”public static ColorScale Grayscale(float domainMin = 0, float domainMax = 1)Creates a grayscale color scale.
Parameters
| Name | Type |
|---|---|
domainMin |
System.Single |
domainMax |
System.Single |
Returns
ChartGuru.ColorScale
Viridis(float, float)
Section titled “Viridis(float, float)”public static ColorScale Viridis(float domainMin = 0, float domainMax = 1)Creates a viridis color scale, the perceptually uniform dark blue to yellow map, from its published table.
Parameters
| Name | Type |
|---|---|
domainMin |
System.Single |
domainMax |
System.Single |
Returns
ChartGuru.ColorScale
Magma(float, float)
Section titled “Magma(float, float)”public static ColorScale Magma(float domainMin = 0, float domainMax = 1)Creates a magma color scale, the perceptually uniform black to pale yellow map, from its published table.
Parameters
| Name | Type |
|---|---|
domainMin |
System.Single |
domainMax |
System.Single |
Returns
ChartGuru.ColorScale
Plasma(float, float)
Section titled “Plasma(float, float)”public static ColorScale Plasma(float domainMin = 0, float domainMax = 1)Creates a plasma color scale, the perceptually uniform blue to yellow map, from its published table.
Parameters
| Name | Type |
|---|---|
domainMin |
System.Single |
domainMax |
System.Single |
Returns
ChartGuru.ColorScale
Inferno(float, float)
Section titled “Inferno(float, float)”public static ColorScale Inferno(float domainMin = 0, float domainMax = 1)Creates an inferno color scale, the perceptually uniform black to pale yellow map, from its published table.
Parameters
| Name | Type |
|---|---|
domainMin |
System.Single |
domainMax |
System.Single |
Returns
ChartGuru.ColorScale
Cividis(float, float)
Section titled “Cividis(float, float)”public static ColorScale Cividis(float domainMin = 0, float domainMax = 1)Creates a cividis color scale, the perceptually uniform blue to yellow map that reads nearly the same with color vision deficiencies, from its published table.
Parameters
| Name | Type |
|---|---|
domainMin |
System.Single |
domainMax |
System.Single |
Returns
ChartGuru.ColorScale
Turbo(float, float)
Section titled “Turbo(float, float)”public static ColorScale Turbo(float domainMin = 0, float domainMax = 1)Creates a turbo color scale from its published table. Turbo is a rainbow map: vivid, but not perceptually uniform, so prefer the other colormaps when values must be read from color.
Parameters
| Name | Type |
|---|---|
domainMin |
System.Single |
domainMax |
System.Single |
Returns
ChartGuru.ColorScale
Blue(float, float)
Section titled “Blue(float, float)”public static ColorScale Blue(float domainMin = 0, float domainMax = 1)Creates a blue sequential color scale matching Swift Charts' default heatmap appearance. Light blue for low values, saturated dark blue for high values.
Parameters
| Name | Type |
|---|---|
domainMin |
System.Single |
domainMax |
System.Single |
Returns
ChartGuru.ColorScale
Properties
Section titled “Properties”
public ColorScale.ColorScaleType Type { get; }The type of color scale (Gradient or CategoryMapping).
Returns
ChartGuru.ColorScale.ColorScaleType
DomainMin
Section titled “DomainMin”public float DomainMin { get; }The minimum domain value for gradient scales.
Returns
System.Single
DomainMax
Section titled “DomainMax”public float DomainMax { get; }The maximum domain value for gradient scales.
Returns
System.Single
Gradient
Section titled “Gradient”public Gradient Gradient { get; }The gradient used for gradient-based scales. A colormap scale evaluates its published table and keeps the
eight-key ChartColormaps.CreateGradient(ChartColormap) approximation here for code that needs a Unity gradient.
Returns
UnityEngine.Gradient
Colormap
Section titled “Colormap”public ChartColormap Colormap { get; }The named colormap a gradient scale evaluates, or ChartColormap.Custom when it samples ColorScale.Gradient.
Returns
ChartGuru.ChartColormap
Categories
Section titled “Categories”public IReadOnlyList<object> Categories { get; }Gets all category keys in the order they were added.
Returns
System.Collections.Generic.IReadOnlyList{System.Object}