Skip to content

Commit dfcb129

Browse files
committed
changed resizeAndPosition functions to use parentElement rect when correcting position to be more clear as to why the correct is necessary, renamed Time-Labels to timetable-time-labels to follow naming convention of other elements, changed headers id from Day-Header to Day-header to follow naming convention of other elements, added background colour and z positioning to timetable-headers div to fix an issue where background could be seen through gaps between headers and added resizing logic for this component within resizeAndPositionTimetableHeaders, changed the zIndex of various components to display correctly
1 parent b5c43ed commit dfcb129

4 files changed

Lines changed: 62 additions & 55 deletions

File tree

client/src/components/timetable.tsx

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import TimetableTask, {
1414

1515
/*
1616
NOTES:
17-
- Should rename timetable-content to timetable-content to be more descriptive.
1817
- Should use element.parentElement for position adjusting for more clarity.
1918
*/
2019

@@ -25,18 +24,18 @@ the timetable where timetable tasks are to be rendered.
2524
Visible area is the area:
2625
- Within timetable-content's bounding client rect
2726
- Right of timetable-separator (right of time labels)
28-
- Below time-header(s))
27+
- Below Time-header(s))
2928
3029
Returns nothing if any of the required elements are not found (that is, elements
31-
with id: time-header, timetable-content, timetable-separator, and
30+
with id: Time-header, timetable-content, timetable-separator, and
3231
timetable-content).
3332
*/
3433
export function getVisibleTimetableRect() {
35-
const time_header = document.getElementById("Time-Header");
34+
const time_header = document.getElementById("Time-header");
3635
if (time_header == null) return;
3736
const time_header_rect = time_header.getBoundingClientRect();
3837

39-
const time_labels = document.getElementById("Time-Labels");
38+
const time_labels = document.getElementById("timetable-time-labels");
4039
if (time_labels == null) return;
4140
const time_labels_rect = time_labels.getBoundingClientRect();
4241

@@ -130,28 +129,38 @@ function resizeAndPositionTimetableHeaders() {
130129
if (timetable_headers == null) return;
131130
const headers = timetable_headers.children;
132131

133-
const content = document.getElementById("timetable-content");
134-
if (content == null) return;
135-
const content_rect = content.getBoundingClientRect();
132+
const time_header = document.getElementById("Time-header");
133+
if (time_header == null) return;
134+
135+
const content_rect = document
136+
.getElementById("timetable-content")
137+
?.getBoundingClientRect();
138+
if (content_rect == undefined) return;
139+
140+
timetable_headers.style.width = content_rect.width + "px";
141+
timetable_headers.style.height =
142+
time_header.getBoundingClientRect().height + "px";
136143

137144
for (let i = 0; i < headers.length; i++) {
138145
const header_id = headers[i].id;
139146
const header = document.getElementById(header_id);
140-
if (header == null) return;
147+
if (header == null) continue;
141148

142149
const col_id = header.id.slice(0, -"-Header".length);
143150
const col = document.getElementById(col_id);
144-
if (col == null) return;
151+
if (col == null) continue;
145152
const col_rect = col.getBoundingClientRect();
146153

154+
const parent_rect = header.parentElement?.getBoundingClientRect();
155+
if (parent_rect == undefined) continue;
156+
147157
header.style.top = "0px";
148-
header.style.left = col_rect.left - content_rect.left + "px";
158+
header.style.left = col_rect.left - parent_rect.left + "px";
149159
header.style.width = col_rect.width + "px";
150160
}
151161

152-
const time_header = document.getElementById("Time-Header");
153-
if (time_header == null) return;
154162
time_header.style.left = "0px";
163+
time_header.style.top = "0px";
155164
time_header.style.zIndex = "1000";
156165
}
157166

@@ -160,18 +169,17 @@ Sync the TimeLabels column top position with the underlying Time column and set
160169
the left position to 0px.
161170
*/
162171
function resizeAndPositionTimetableTimeLabels() {
163-
const time_labels = document.getElementById("Time-Labels");
172+
const time_labels = document.getElementById("timetable-time-labels");
164173
if (time_labels == null) return;
165174

166175
const time_col = document.getElementById("Time");
167176
if (time_col == null) return;
168177
const time_col_rect = time_col.getBoundingClientRect();
169178

170-
const timetable_content = document.getElementById("timetable-content");
171-
if (timetable_content == null) return;
172-
const content_rect = timetable_content.getBoundingClientRect();
179+
const parent_rect = time_labels.parentElement?.getBoundingClientRect();
180+
if (parent_rect == undefined) return;
173181

174-
time_labels.style.top = time_col_rect.top - content_rect.top + "px";
182+
time_labels.style.top = time_col_rect.top - parent_rect.top + "px";
175183
time_labels.style.left = "0px";
176184

177185
time_labels.style.width = time_col_rect.width + "px";
@@ -188,21 +196,19 @@ function resizeAndPositionTimetableSeparator() {
188196
const separator = document.getElementById("timetable-separator");
189197
if (separator == null) return;
190198

191-
const time_col = document.getElementById("Time-Labels");
199+
const time_col = document.getElementById("timetable-time-labels");
192200
if (time_col == null) return;
193201
const col_rect = time_col.getBoundingClientRect();
194202

195-
const time_header = document.getElementById("Time-Header");
203+
const time_header = document.getElementById("Time-header");
196204
if (time_header == null) return;
197205
const header_rect = time_header.getBoundingClientRect();
198206

199-
const content_rect = document
200-
.getElementById("timetable-content")
201-
?.getBoundingClientRect();
202-
if (content_rect == undefined) return;
207+
const parent_rect = separator.parentElement?.getBoundingClientRect();
208+
if (parent_rect == undefined) return;
203209

204-
separator.style.top = header_rect.top - content_rect.top + "px";
205-
separator.style.left = col_rect.right - content_rect.left + "px";
210+
separator.style.top = header_rect.top - parent_rect.top + "px";
211+
separator.style.left = col_rect.right - parent_rect.left + "px";
206212
separator.style.height = col_rect.height + "px";
207213
}
208214

@@ -215,16 +221,14 @@ function resizeAndPositionTimetableTaskArea() {
215221
const task_container = document.getElementById("timetable-tasks");
216222
if (task_container == null) return;
217223

218-
const content_rect = document
219-
.getElementById("timetable-content")
220-
?.getBoundingClientRect();
221-
if (content_rect == undefined) return;
224+
const parent_rect = task_container.parentElement?.getBoundingClientRect();
225+
if (parent_rect == undefined) return;
222226

223227
const visible = getVisibleTimetableRect();
224228
if (visible == undefined) return;
225229

226-
task_container.style.top = visible.top - content_rect.top + "px";
227-
task_container.style.left = visible.left - content_rect.left + "px";
230+
task_container.style.top = visible.top - parent_rect.top + "px";
231+
task_container.style.left = visible.left - parent_rect.left + "px";
228232
task_container.style.width = visible.width + "px";
229233
task_container.style.height = visible.height + "px";
230234
}
@@ -296,7 +300,7 @@ export function scrollToCurrentDay(align?: string) {
296300
const timetable = document.getElementById("timetable-background");
297301
if (timetable == null) return;
298302

299-
const time_header = document.getElementById("Time-Header");
303+
const time_header = document.getElementById("Time-header");
300304
if (time_header == null) return;
301305
const time_header_width = time_header.getBoundingClientRect().width;
302306
const row_width = time_header_width; // easier to read later
@@ -390,7 +394,10 @@ function Timetable({ timetable_tasks_props }: TimetableProps) {
390394
id="timetable-foreground"
391395
className="pointer-events-none absolute overflow-hidden"
392396
>
393-
<div id="timetable-headers">
397+
<div
398+
id="timetable-headers"
399+
className="absolute left-0 top-0 z-[200] bg-slate-900"
400+
>
394401
{[
395402
"Time",
396403
"Monday",
@@ -407,7 +414,7 @@ function Timetable({ timetable_tasks_props }: TimetableProps) {
407414
<TimetableTimeLabelsColumn />
408415
<div
409416
id="timetable-separator"
410-
className="absolute z-[100] w-[4px] bg-slate-900"
417+
className="absolute z-[250] w-[4px] bg-slate-900"
411418
></div>
412419
<div
413420
id="timetable-tasks"

client/src/components/timetable_column.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ have text "HH:MM" for time time they represent. Already has sticky set.
7272
export function TimetableTimeLabelsColumn() {
7373
return (
7474
<div
75-
id="Time-Labels"
75+
id="timetable-time-labels"
7676
className="timetable-column absolute flex flex-col bg-slate-500"
7777
>
7878
<TimetableSlot
79-
time="time-header"
79+
time="time-background-header"
8080
label="Time"
8181
header={true}
8282
time_label={true}

client/src/components/timetable_slot.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ export default TimetableSlot;
7070
export function TimetableHeader({ label }: TimetableSlotProps) {
7171
return (
7272
<div
73-
id={label + "-Header"}
74-
className="timetable-header absolute z-[100] flex min-h-16 min-w-32 items-center justify-center border-b-2 border-b-slate-900 bg-slate-800"
73+
id={label + "-header"}
74+
className="timetable-header absolute z-[200] flex min-h-16 min-w-32 items-center justify-center border-b-2 border-b-slate-900 bg-slate-800"
7575
>
7676
<p className="text-xl font-semibold text-slate-400">{label}</p>
7777
</div>

client/src/components/timetable_task.tsx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,27 +55,24 @@ export function resizeAndPositionTimetableTask(task: HTMLElement) {
5555
if (task_data == null) return;
5656
const { day, hour, duration_hours, start_offset_hours } = task_data;
5757

58-
const visible = getVisibleTimetableRect();
59-
if (visible == null) return;
60-
61-
const col = document.getElementById(day);
62-
if (col == null) return;
63-
const col_rect = col.getBoundingClientRect();
58+
const col_rect = document.getElementById(day)?.getBoundingClientRect();
59+
if (col_rect == undefined) return;
6460

65-
const row = document.getElementById(hour);
66-
if (row == null) return;
67-
const row_rect = row.getBoundingClientRect();
61+
const row_rect = document.getElementById(hour)?.getBoundingClientRect();
62+
if (row_rect == undefined) return;
6863

6964
const one_hour_height = row_rect.height;
7065
const duration_height = one_hour_height * duration_hours;
7166

7267
const hours = Number(hour.substring(0, 2));
73-
7468
const time_top = getTimeTopPosition(hours, start_offset_hours * 60);
7569
if (time_top == undefined) return;
7670

77-
task.style.left = col_rect.left - visible.left + "px";
78-
task.style.top = time_top - visible.top + "px";
71+
const parent_rect = task.parentElement?.getBoundingClientRect();
72+
if (parent_rect == undefined) return;
73+
74+
task.style.left = col_rect.left - parent_rect.left + "px";
75+
task.style.top = time_top - parent_rect.top + "px";
7976
task.style.width = row_rect.width + "px";
8077
task.style.height = duration_height + "px";
8178
}
@@ -128,8 +125,11 @@ function resizeAndPositionTimetableTaskTooltip(tooltip: HTMLElement) {
128125
top = visible.bottom - tooltip_rect.height;
129126
}
130127

131-
tooltip.style.left = left - visible.left + "px";
132-
tooltip.style.top = top - visible.top + "px";
128+
const parent_rect = tooltip.parentElement?.getBoundingClientRect();
129+
if (parent_rect == undefined) return;
130+
131+
tooltip.style.left = left - parent_rect.left + "px";
132+
tooltip.style.top = top - parent_rect.top + "px";
133133
tooltip.style.width = width + "px";
134134
tooltip.style.height = height + "px";
135135
}
@@ -319,7 +319,7 @@ function TimetableTask({
319319
</div>
320320
<div
321321
id={id + "-tooltip"}
322-
className="timetable-task-tooltip pointer-events-auto absolute z-[100] max-w-64 rounded-lg bg-slate-800 p-3"
322+
className="timetable-task-tooltip pointer-events-auto absolute z-[150] max-w-64 rounded-lg bg-slate-800 p-3"
323323
style={{ display: "none" }}
324324
onMouseOver={mouseOverHandler}
325325
onMouseOut={mouseOutHandler}
@@ -328,7 +328,7 @@ function TimetableTask({
328328
{tooltip_props.map((props) => (
329329
<div
330330
key={id + "-tooltip-" + props.name}
331-
className="z-[75] h-fit w-full rounded-lg bg-slate-400 p-3 text-slate-100"
331+
className="h-fit w-full rounded-lg bg-slate-400 p-3 text-slate-100"
332332
>
333333
<TimetableTaskContent {...props} time_display="both" />
334334
</div>

0 commit comments

Comments
 (0)