Skip to content

Commit b1915b0

Browse files
authored
Merge pull request #176 from MBARIMike/main
More fixed layout - take 2.
2 parents 687d956 + 9332c1f commit b1915b0

1 file changed

Lines changed: 23 additions & 12 deletions

File tree

‎src/data/lrauv_deployment_plots.py‎

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -404,10 +404,17 @@ def _update_index_html(
404404

405405
known_hrefs: set[str] = set()
406406
group_names: dict[str, str] = {} # dlist_dir → deployment name
407-
if not clobber and index_path.exists():
407+
if index_path.exists():
408408
content = index_path.read_text()
409-
known_hrefs = set(re.findall(r'href="([^"#][^"]*\.html)"', content))
409+
all_hrefs = set(re.findall(r'href="([^"#][^"]*\.html)"', content))
410410
group_names = dict(re.findall(r'<h2 id="([^"]+)">([^<]+)</h2>', content))
411+
# clobber=True drops only this deployment's existing entries so they are rebuilt;
412+
# other deployments' entries are always preserved.
413+
known_hrefs = (
414+
{h for h in all_hrefs if not h.startswith(f"{dlist_dir}/")}
415+
if clobber
416+
else all_hrefs
417+
)
411418

412419
group_names[dlist_dir] = deployment_name or group_names.get(dlist_dir, dlist_dir)
413420

@@ -421,22 +428,28 @@ def _update_index_html(
421428
grouped.setdefault(group, []).append(href)
422429

423430
max_cols = max((len(hrefs) for hrefs in grouped.values()), default=1)
431+
col_width = f"{100 // max_cols}%"
424432
body = ""
425433
for group in sorted(grouped):
426434
label = group_names.get(group, group)
427435
body += f'<h2 id="{group}">{label}</h2>\n'
428436
body += '<table width="100%">\n<tr>\n'
429-
sorted_hrefs = sorted(
430-
grouped[group],
431-
key=lambda h: next(
432-
(i for i, k in enumerate(self._PLOT_COLUMN_ORDER) if k in h),
437+
# Map each known href to its column index so gaps produce blank cells.
438+
col_map: dict[int, str] = {}
439+
for href in grouped[group]:
440+
col = next(
441+
(i for i, k in enumerate(self._PLOT_COLUMN_ORDER) if k in href),
433442
len(self._PLOT_COLUMN_ORDER),
434-
),
435-
)
436-
for href in sorted_hrefs:
443+
)
444+
col_map[col] = href
445+
for col in range(max_cols):
446+
href = col_map.get(col)
447+
if href is None:
448+
body += f' <td width="{col_width}"></td>\n'
449+
continue
437450
png_href = href[:-5] + ".png"
438451
png_path = year_dir / png_href
439-
body += ' <td valign="top">\n'
452+
body += f' <td valign="top" width="{col_width}">\n'
440453
if png_path.exists():
441454
body += (
442455
f' <a href="{href}">'
@@ -446,8 +459,6 @@ def _update_index_html(
446459
else:
447460
body += f' <a href="{href}">{Path(href).name}</a>\n'
448461
body += " </td>\n"
449-
for _ in range(max_cols - len(sorted_hrefs)):
450-
body += " <td></td>\n"
451462
body += "</tr>\n</table>\n"
452463

453464
year_label = year_dir.name

0 commit comments

Comments
 (0)