ColorGenerator Class — react Architecture
Architecture documentation for the ColorGenerator class in colors.js from the react codebase.
Entity Profile
Dependency Diagram
graph TD 8dce7fa7_d4a5_40fd_6aca_a2ba5fa2692a["ColorGenerator"] e8b75ea1_4270_75d6_defb_16c2f1811aef["colors.js"] 8dce7fa7_d4a5_40fd_6aca_a2ba5fa2692a -->|defined in| e8b75ea1_4270_75d6_defb_16c2f1811aef
Relationship Graph
Source Code
packages/react-devtools-timeline/src/content-views/utils/colors.js lines 70–113
export class ColorGenerator {
_hueSpace: ColorSpace;
_satSpace: ColorSpace;
_lightnessSpace: ColorSpace;
_alphaSpace: ColorSpace;
_colors: Map<string, HslaColor>;
constructor(
hueSpace?: ColorSpace,
satSpace?: ColorSpace,
lightnessSpace?: ColorSpace,
alphaSpace?: ColorSpace,
) {
this._hueSpace = hueSpace || {min: 0, max: 360};
this._satSpace = satSpace || 67;
this._lightnessSpace = lightnessSpace || 80;
this._alphaSpace = alphaSpace || 1;
this._colors = new Map();
}
setColorForID(id: string, color: HslaColor) {
this._colors.set(id, color);
}
colorForID(id: string): HslaColor {
const cachedColor = this._colors.get(id);
if (cachedColor) {
return cachedColor;
}
const color = this._generateColorForID(id);
this._colors.set(id, color);
return color;
}
_generateColorForID(id: string): HslaColor {
const hash = hashCode(id);
return {
h: indexToValueInSpace(hash, this._hueSpace),
s: indexToValueInSpace(hash >> 8, this._satSpace),
l: indexToValueInSpace(hash >> 16, this._lightnessSpace),
a: indexToValueInSpace(hash >> 24, this._alphaSpace),
};
}
}
Domain
Source
Frequently Asked Questions
What is the ColorGenerator class?
ColorGenerator is a class in the react codebase, defined in packages/react-devtools-timeline/src/content-views/utils/colors.js.
Where is ColorGenerator defined?
ColorGenerator is defined in packages/react-devtools-timeline/src/content-views/utils/colors.js at line 70.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free