Skip to content

ColorScale

ClassChartGuruChartGuru
[Serializable]
public class ColorScale

Represents 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, …])

public ColorScale.ColorScaleType Type { get; }

The type of color scale (Gradient or CategoryMapping).

Returns

ChartGuru.ColorScale.ColorScaleType — No return description is available.

public float DomainMin { get; }

The minimum domain value for gradient scales.

Returns

System.Single — No return description is available.

public float DomainMax { get; }

The maximum domain value for gradient scales.

Returns

System.Single — No return description is available.

public Gradient Gradient { get; }

The gradient used for gradient-based scales.

Returns

UnityEngine.Gradient — No return description is available.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.
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.
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.

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.

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.

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.

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.

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.

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.