@@ -14,7 +14,6 @@ import TimetableTask, {
1414
1515/*
1616NOTES:
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.
2524Visible 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
3029Returns 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
3231timetable-content).
3332*/
3433export 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
160169the left position to 0px.
161170*/
162171function 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"
0 commit comments