ColorScale
[Serializable]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, …])
Properties
Section titled “Properties”
public ColorScale.ColorScaleType Type { get; }The type of color scale (Gradient or CategoryMapping).
Returns
ChartGuru.ColorScale.ColorScaleType — No return description is available.
DomainMin
Section titled “DomainMin”public float DomainMin { get; }The minimum domain value for gradient scales.
Returns
System.Single — No return description is available.
DomainMax
Section titled “DomainMax”public float DomainMax { get; }The maximum domain value for gradient scales.
Returns
System.Single — No return description is available.
Gradient
Section titled “Gradient”public Gradient Gradient { get; }The gradient used for gradient-based scales.
Returns
UnityEngine.Gradient — No return description is available.
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} — No return description is available.
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 — No return description is available.
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 — No return description is available.
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 — No return description is available.
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 — No return description is available.
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 | Description |
|---|---|---|
mapping |
System.Collections.Generic.Dictionary{System.String,UnityEngine.Color} |
Returns
ChartGuru.ColorScale — No return description is available.
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 | Description |
|---|---|---|
mapping |
System.Collections.Generic.Dictionary{System.Int32,UnityEngine.Color} |
Returns
ChartGuru.ColorScale — No return description is available.
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 — No return description is available.
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 | Description |
|---|---|---|
colors |
UnityEngine.Color[] |
Returns
ChartGuru.ColorScale — No return description is available.
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 | Description |
|---|---|---|
domain |
System.String[] | |
range |
UnityEngine.Color[] |
Returns
ChartGuru.ColorScale — No return description is available.
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 | Description |
|---|---|---|
domainMin |
System.Single | |
domainMax |
System.Single |
Returns
ChartGuru.ColorScale — No return description is available.
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 | Description |
|---|---|---|
domainMin |
System.Single | |
domainMax |
System.Single |
Returns
ChartGuru.ColorScale — No return description is available.
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 | Description |
|---|---|---|
domainMin |
System.Single | |
domainMax |
System.Single |
Returns
ChartGuru.ColorScale — No return description is available.
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 | Description |
|---|---|---|
domainMin |
System.Single | |
domainMax |
System.Single |
Returns
ChartGuru.ColorScale — No return description is available.
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 | Description |
|---|---|---|
domainMin |
System.Single | |
domainMax |
System.Single |
Returns
ChartGuru.ColorScale — No return description is available.
Viridis(float, float)
Section titled “Viridis(float, float)”public static ColorScale Viridis(float domainMin = 0, float domainMax = 1)Creates a viridis-like perceptually uniform color scale.
Parameters
| Name | Type | Description |
|---|---|---|
domainMin |
System.Single | |
domainMax |
System.Single |
Returns
ChartGuru.ColorScale — No return description is available.
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 | Description |
|---|---|---|
domainMin |
System.Single | |
domainMax |
System.Single |
Returns
ChartGuru.ColorScale — No return description is available.