|
1 | | -export class ColorRGBA { |
2 | | - constructor( |
3 | | - public r: number, |
4 | | - public g: number, |
5 | | - public b: number, |
6 | | - public a: number |
7 | | - ) { } |
8 | | -} |
| 1 | +// colors.ts |
| 2 | + |
| 3 | +// Base custom colors as an object for configuration |
| 4 | +export const customColors = { |
| 5 | + 'custom-1': '#EC6FAA', |
| 6 | + 'custom-2': '#CE6FAC', |
| 7 | + 'custom-3': '#B47EB7', |
| 8 | + 'custom-4': '#9D8DC4', |
| 9 | + 'custom-5': '#689AD2', |
| 10 | + 'custom-6': '#35A5CC', |
| 11 | + 'custom-7': '#30A8B4', |
| 12 | + 'custom-8': '#32ABA2', |
| 13 | + 'custom-9': '#2EAD8D', |
| 14 | + 'custom-10': '#31B068', |
| 15 | + 'custom-11': '#6CAB43', |
| 16 | + 'custom-12': '#94A135', |
| 17 | + 'custom-13': '#B19B31', |
| 18 | + 'custom-14': '#CC9136', |
| 19 | + 'custom-15': '#F2793B', |
| 20 | + 'custom-16': '#F2728B', |
| 21 | +}; |
9 | 22 |
|
10 | | -// Define custom colors as an array to guarantee order. |
11 | | -export const customColors = [ |
12 | | - '#EC6FAA', // Channel 1 |
13 | | - '#CE6FAC', // Channel 2 |
14 | | - '#B47EB7', // Channel 3 |
15 | | - '#9D8DC4', // Channel 4 |
16 | | - '#689AD2', // Channel 5 |
17 | | - '#35A5CC', // Channel 6 |
18 | | - '#30A8B4', // Channel 7 |
19 | | - '#32ABA2', // Channel 8 |
20 | | - '#2EAD8D', // Channel 9 |
21 | | - '#31B068', // Channel 10 |
22 | | - '#6CAB43', // Channel 11 |
23 | | - '#94A135', // Channel 12 |
24 | | - '#B19B31', // Channel 13 |
25 | | - '#CC9136', // Channel 14 |
26 | | - '#F2793B', // Channel 15 |
27 | | - '#F2728B', // Channel 16 |
28 | | -]; |
| 23 | +// Derive an array from the object to preserve order for indexing |
| 24 | +export const customColorsArray: string[] = Object.values(customColors); |
29 | 25 |
|
30 | | -// Color adjustment functions remain unchanged. |
| 26 | +// --- Color adjustment functions --- |
31 | 27 | function darkenColor(hex: string, amount: number): string { |
32 | 28 | validateInput(hex, amount); |
33 | | - return adjustColor(hex, -amount); |
| 29 | + return adjustColor(hex, -amount); // Negative for darkening |
34 | 30 | } |
35 | 31 |
|
36 | 32 | function lightenColor(hex: string, amount: number): string { |
37 | 33 | validateInput(hex, amount); |
38 | | - return adjustColor(hex, amount); |
| 34 | + return adjustColor(hex, amount); // Positive for lightening |
39 | 35 | } |
40 | 36 |
|
41 | 37 | function adjustColor(hex: string, amount: number): string { |
@@ -66,21 +62,34 @@ function validateInput(hex: string, amount: number): void { |
66 | 62 | } |
67 | 63 | } |
68 | 64 |
|
69 | | -// Create theme-specific color arrays using the array ordering. |
70 | | -export const lightThemeColors = customColors.map(hex => darkenColor(hex, 0.2)); |
71 | | -export const darkThemeColors = customColors.map(hex => lightenColor(hex, 0.1)); |
| 65 | +// Create theme-specific color arrays using the array ordering |
| 66 | +export const lightThemeColors = customColorsArray.map(hex => darkenColor(hex, 0.2)); |
| 67 | +export const darkThemeColors = customColorsArray.map(hex => lightenColor(hex, 0.1)); |
72 | 68 |
|
| 69 | +// Helper function to retrieve a color based on channel index and theme |
73 | 70 | export function getCustomColor(index: number, theme: 'light' | 'dark'): string { |
74 | 71 | const colors = theme === 'dark' ? darkThemeColors : lightThemeColors; |
75 | 72 | return colors[index % colors.length]; |
76 | 73 | } |
77 | 74 |
|
| 75 | +// ColorRGBA class definition for plotting |
| 76 | +export class ColorRGBA { |
| 77 | + constructor( |
| 78 | + public r: number, |
| 79 | + public g: number, |
| 80 | + public b: number, |
| 81 | + public a: number |
| 82 | + ) { } |
| 83 | +} |
| 84 | + |
| 85 | +// Plot line color function (ensure proper indexing) |
78 | 86 | export const getLineColor = (channelNumber: number, theme: 'light' | 'dark'): ColorRGBA => { |
79 | | - const index = channelNumber - 1; // Convert 1-indexed to 0-indexed. |
| 87 | + // Convert 1-indexed channel number to 0-indexed index |
| 88 | + const index = channelNumber - 1; |
80 | 89 | const hex = getCustomColor(index, theme); |
81 | 90 | const r = parseInt(hex.slice(1, 3), 16) / 255; |
82 | 91 | const g = parseInt(hex.slice(3, 5), 16) / 255; |
83 | 92 | const b = parseInt(hex.slice(5, 7), 16) / 255; |
84 | | - const alpha = theme === "dark" ? 1 : 0.8; |
| 93 | + const alpha = theme === 'dark' ? 1 : 0.8; |
85 | 94 | return new ColorRGBA(r, g, b, alpha); |
86 | 95 | }; |
0 commit comments