Skip to content

Commit 91473ea

Browse files
committed
Enhance iframe styling and prevent scrollbars in interactive HTML plot
1 parent 7070a03 commit 91473ea

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

.github/workflows/data-availability-plot.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989
'<iframe class="data-availability-plot" ',
9090
'src="data-availability/data_availability.html" ',
9191
'title="Dates for which origin-destination data is available" ',
92-
'loading="lazy" style="width:100%;height:520px;border:0;"></iframe>'
92+
'loading="lazy" scrolling="no" style="width:100%;aspect-ratio:10/6.2;border:0;overflow:hidden;"></iframe>'
9393
)
9494
patched <- sub(pattern, iframe, html, perl = TRUE)
9595
if (!identical(patched, html)) {

tools/generate_data_availability_plot.R

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,5 +414,31 @@ if (requireNamespace("ggiraph", quietly = TRUE) && requireNamespace("htmlwidgets
414414
# Save to standalone interactive HTML
415415
html_output_path <- file.path(output_dir, "data_availability.html")
416416
htmlwidgets::saveWidget(x, html_output_path, selfcontained = TRUE)
417+
418+
# Prevent scrollbars in iframes by forcing absolute responsive sizing on html, body, and svg
419+
if (file.exists(html_output_path)) {
420+
html_content <- readLines(html_output_path, warn = FALSE)
421+
422+
# Inject CSS styles in head
423+
css_styles <- paste0(
424+
"<head>\n<style>\n",
425+
" html, body {\n",
426+
" margin: 0 !important;\n",
427+
" padding: 0 !important;\n",
428+
" width: 100% !important;\n",
429+
" height: 100% !important;\n",
430+
" overflow: hidden !important;\n",
431+
" }\n",
432+
" svg {\n",
433+
" width: 100% !important;\n",
434+
" height: 100% !important;\n",
435+
" }\n",
436+
"</style>"
437+
)
438+
439+
html_content <- gsub("<head>", css_styles, html_content, fixed = TRUE)
440+
writeLines(html_content, html_output_path, useBytes = TRUE)
441+
}
442+
417443
cat("Interactive plot saved to:", html_output_path, "\n")
418444
}

0 commit comments

Comments
 (0)