add colors to each subject

This commit is contained in:
Kenneth SOARES
2025-09-09 14:50:48 +02:00
parent 306b71dad5
commit bd3a392850
2 changed files with 26 additions and 9 deletions

View File

@@ -87,6 +87,17 @@ document.addEventListener("alpine:init", () => {
width: 0,
},
colors: {} as Record<string, string>,
colorPalette: [
"#f87171",
"#60a5fa",
"#34d399",
"#fbbf24",
"#a78bfa",
"#f472b6",
"#38bdf8",
],
generate() {
try {
this.courses = parseSlots(this.content);
@@ -96,16 +107,28 @@ document.addEventListener("alpine:init", () => {
);
return;
}
// color each UE
let colorIndex = 0;
for (const slot of this.courses) {
if (!this.colors[slot.ueCode]) {
this.colors[slot.ueCode] =
this.colorPalette[colorIndex % this.colorPalette.length];
colorIndex++;
}
}
this.displayedWeekdays = WEEKDAYS.filter((day) =>
this.courses.some((slot: TimetableSlot) => slot.weekday === day),
);
this.startSlot = this.courses.reduce(
(acc: number, curr: TimetableSlot) => Math.min(acc, curr.startSlot),
24 * 4,
25 * 4,
);
this.endSlot = this.courses.reduce(
(acc: number, curr: TimetableSlot) => Math.max(acc, curr.endSlot),
0,
1,
);
this.table.height = SLOT_HEIGHT * (this.endSlot - this.startSlot);
this.table.width = SLOT_WIDTH * this.displayedWeekdays.length;
@@ -117,6 +140,7 @@ document.addEventListener("alpine:init", () => {
width: `${SLOT_WIDTH}px`,
top: `${(slot.startSlot - this.startSlot) * SLOT_HEIGHT}px`,
left: `${this.displayedWeekdays.indexOf(slot.weekday) * SLOT_WIDTH}px`,
backgroundColor: this.colors[slot.ueCode],
};
},