Skip to content

Commit

Permalink
fix: address iframe dynamic resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
dakshpokar committed Oct 16, 2024
1 parent 3d7b1ea commit e3f28dd
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions maidr/core/maidr.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,20 +191,35 @@ def _inject_plot(plot: HTML, maidr: str) -> Tag:

unique_id = "iframe_" + Maidr._unique_id()

resizing_script = f"""
function resizeIframe() {{
var iframe = document.getElementById('{unique_id}');
iframe.style.height = iframe.contentWindow.document.body.scrollHeight + 50 + 'px';
}}
var iframe = document.getElementById('{unique_id}');
iframe.onload = function() {{
resizeIframe();
iframe.contentWindow.addEventListener('resize', resizeIframe);
}};
"""

# Embed the rendering into an iFrame for proper working of JS library.
base_html = tags.iframe(
id=unique_id,
srcdoc=str(base_html.get_html_string()),
width="100%",
height="100%",
scrolling="auto",
style="background-color: #fff",
style="background-color: #fff; position: relative; border: none",
frameBorder=0,
onload="""
this.style.height = this.contentWindow.document.body.scrollHeight +
100 + 'px';
"""
+ Environment.initialize_llm_secrets(unique_id),
+ Environment.initialize_llm_secrets(unique_id)
+ " "
+ resizing_script,
)

return base_html

0 comments on commit e3f28dd

Please sign in to comment.