Skip to content

Commit dea795d

Browse files
author
Ritika Mishra
committed
update logic to handle buttons colors and plot colors
1 parent c93a7a8 commit dea795d

File tree

2 files changed

+45
-36
lines changed

2 files changed

+45
-36
lines changed

src/components/Colors.ts

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,37 @@
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+
};
922

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);
2925

30-
// Color adjustment functions remain unchanged.
26+
// --- Color adjustment functions ---
3127
function darkenColor(hex: string, amount: number): string {
3228
validateInput(hex, amount);
33-
return adjustColor(hex, -amount);
29+
return adjustColor(hex, -amount); // Negative for darkening
3430
}
3531

3632
function lightenColor(hex: string, amount: number): string {
3733
validateInput(hex, amount);
38-
return adjustColor(hex, amount);
34+
return adjustColor(hex, amount); // Positive for lightening
3935
}
4036

4137
function adjustColor(hex: string, amount: number): string {
@@ -66,21 +62,34 @@ function validateInput(hex: string, amount: number): void {
6662
}
6763
}
6864

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));
7268

69+
// Helper function to retrieve a color based on channel index and theme
7370
export function getCustomColor(index: number, theme: 'light' | 'dark'): string {
7471
const colors = theme === 'dark' ? darkThemeColors : lightThemeColors;
7572
return colors[index % colors.length];
7673
}
7774

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)
7886
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;
8089
const hex = getCustomColor(index, theme);
8190
const r = parseInt(hex.slice(1, 3), 16) / 255;
8291
const g = parseInt(hex.slice(3, 5), 16) / 255;
8392
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;
8594
return new ColorRGBA(r, g, b, alpha);
8695
};

src/components/Connection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Input } from "./ui/input";
55
import { EXGFilter, Notch } from './filters';
66
import { useTheme } from "next-themes";
77
import { useRouter } from "next/navigation"; // Import useRouter
8-
import { getCustomColor } from './Colors';
8+
import { getCustomColor, lightThemeColors } from './Colors';
99

1010
import {
1111
Cable,

0 commit comments

Comments
 (0)