Function Signature
Parameters
This function takes no parameters.Returns
An object containing color values for different label visualization contexts
Description
ThebuildRandomLabelColor function generates a cohesive color scheme for label visualization by creating four related color variants based on a random hue. All colors share the same hue (0-360 degrees) but vary in saturation, lightness, and opacity to provide different visual weights for different UI contexts.
The function uses HSL (Hue, Saturation, Lightness) color space to ensure:
- Visual consistency: All four colors are harmonious since they share the same hue
- Accessibility: The solid color has sufficient contrast for text
- Flexibility: Different variants for backgrounds, overlays, and primary display
Example Usage
Color Properties
| Property | Saturation | Lightness | Opacity | Use Case |
|---|---|---|---|---|
solid | 70% | 40% | 100% | Primary label color, text, borders |
soft | 95% | 96% | 100% | Background fills, subtle highlights |
overlay | 85% | 45% | 14% | Light hover states, secondary backgrounds |
overlayStrong | 85% | 45% | 24% | Stronger hover states, active selections |
Implementation Details
The function generates a random hue value between 0 and 360 degrees usingMath.random(), then constructs four HSL color strings with predefined saturation, lightness, and opacity values optimized for label visualization in UI contexts.