ChartColorUtils
public static class ChartColorUtilsUtility methods for color calculations in charts.
Methods
Section titled “Methods”
ForGL(Color)
Section titled “ForGL(Color)”public static Color ForGL(Color c)Converts a gamma-space color to the correct color for GL/vertex rendering. In Unity’s Linear color space, colors authored as gamma values must be converted to linear before being passed to GL.Color() or vertex buffers, because GL does not perform the conversion automatically (unlike texture sampling). Without this, gamma-authored colors are double-gamma-encoded by the sRGB framebuffer and appear washed out / too bright in Linear mode. In Gamma color space the color is returned unchanged.
Parameters
| Name | Type | Description |
|---|---|---|
c |
UnityEngine.Color |
Returns
UnityEngine.Color — No return description is available.
GetRelativeLuminance(Color)
Section titled “GetRelativeLuminance(Color)”public static float GetRelativeLuminance(Color color)Returns the relative luminance of a color (0 = black, 1 = white). Uses the sRGB formula per WCAG 2.1.
Parameters
| Name | Type | Description |
|---|---|---|
color |
UnityEngine.Color |
Returns
System.Single — No return description is available.
GetContrastRatio(Color, Color)
Section titled “GetContrastRatio(Color, Color)”public static float GetContrastRatio(Color foreground, Color background)Computes the contrast ratio between two Colors (L1 + 0.05) / (L2 + 0.05) where L1 is the lighter luminance and L2 is the darker.
Parameters
| Name | Type | Description |
|---|---|---|
foreground |
UnityEngine.Color | |
background |
UnityEngine.Color |
Returns
System.Single — No return description is available.
GetContrastingTextColor(Color)
Section titled “GetContrastingTextColor(Color)”public static Color GetContrastingTextColor(Color backgroundColor)Returns white or black text color for maximum contrast on the given background. Uses WCAG 2.1 contrast guidelines (4.5:1 minimum for normal text).
Parameters
| Name | Type | Description |
|---|---|---|
backgroundColor |
UnityEngine.Color | The background color behind the text. |
Returns
UnityEngine.Color — Color.white or Color.black, whichever provides better contrast.
GetContrastingTextColor(Color, float)
Section titled “GetContrastingTextColor(Color, float)”public static Color GetContrastingTextColor(Color backgroundColor, float minContrastRatio)Returns a contrasting text color that meets the specified minimum contrast ratio. Falls back to white or black based on which meets the threshold; if neither does, returns the one with better contrast.
Parameters
| Name | Type | Description |
|---|---|---|
backgroundColor |
UnityEngine.Color | The background color behind the text. |
minContrastRatio |
System.Single | Minimum contrast ratio (default: 4.5 for WCAG AA normal text). |
Returns
UnityEngine.Color — Color.white or Color.black for best readability.
Fields
Section titled “Fields”
WcagNormalTextContrastMinimum
Section titled “WcagNormalTextContrastMinimum”public const float WcagNormalTextContrastMinimum = 4.5WCAG 2.1 minimum contrast ratio for normal text (Level AA).
Returns
System.Single — No return description is available.
WcagLargeTextContrastMinimum
Section titled “WcagLargeTextContrastMinimum”public const float WcagLargeTextContrastMinimum = 3WCAG 2.1 minimum contrast ratio for large text (Level AA).
Returns
System.Single — No return description is available.