mirror of
https://github.com/ae-utbm/sith.git
synced 2025-09-13 03:25:49 +00:00
add colors to each subject
This commit is contained in:
@@ -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],
|
||||
};
|
||||
},
|
||||
|
||||
|
Reference in New Issue
Block a user