Skip to content

Commit 84f7cf6

Browse files
committed
fix: improve html diagram layout and sizing
1 parent b767d4a commit 84f7cf6

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

code-explainer/scripts/generate_html.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ def _diagram_cards(diagram_manifest: Dict[str, Any]) -> str:
135135
<div class="diagram-head">
136136
<h3>{_escape(title)}</h3>
137137
<div class="diagram-actions">
138-
<button class="btn-open" data-title="{_escape(title)}" data-src="{_escape(png_src)}" data-fallback="{_escape(svg_src)}" type="button">Open Full Screen</button>
138+
<button class="btn-open" data-title="{_escape(title)}" data-src="{_escape(svg_src)}" data-fallback="{_escape(png_src)}" type="button">Open Full Screen</button>
139139
<a href="{_escape(svg_src)}" target="_blank" rel="noopener">SVG</a>
140140
<a href="{_escape(png_src)}" target="_blank" rel="noopener">PNG</a>
141141
</div>
142142
</div>
143143
<div class="diagram-frame">
144-
<img class="diagram-preview" src="{_escape(png_src)}" data-fallback="{_escape(svg_src)}" alt="{_escape(title)} diagram" loading="lazy" />
144+
<img class="diagram-preview" src="{_escape(svg_src)}" data-fallback="{_escape(png_src)}" alt="{_escape(title)} diagram" loading="lazy" />
145145
</div>
146146
</article>
147147
"""
@@ -403,7 +403,7 @@ def generate_html(
403403
}}
404404
.diagram-grid {{
405405
display: grid;
406-
grid-template-columns: 1fr;
406+
grid-template-columns: repeat(2, minmax(0,1fr));
407407
gap: 14px;
408408
}}
409409
.diagram-card {{
@@ -449,18 +449,18 @@ def generate_html(
449449
border: 1px solid var(--line);
450450
border-radius: 10px;
451451
background: #ffffff;
452-
min-height: 300px;
452+
height: 340px;
453453
display: flex;
454454
align-items: center;
455455
justify-content: center;
456456
overflow: auto;
457457
padding: 8px;
458458
}}
459459
.diagram-preview {{
460-
width: min(100%, 980px);
461460
max-width: 100%;
461+
max-height: 100%;
462+
width: auto;
462463
height: auto;
463-
max-height: 420px;
464464
display: block;
465465
cursor: zoom-in;
466466
}}
@@ -514,8 +514,9 @@ def generate_html(
514514
@media (max-width: 1080px) {{
515515
.layout {{ grid-template-columns: 1fr; }}
516516
.toc {{ position: static; }}
517+
.diagram-grid {{ grid-template-columns: 1fr; }}
517518
.grid2 {{ grid-template-columns: 1fr; }}
518-
.diagram-preview {{ width: min(100%, 760px); max-height: 360px; }}
519+
.diagram-frame {{ height: 300px; }}
519520
.lightbox-img {{ min-width: 640px; }}
520521
}}
521522
</style>

code-explainer/scripts/render_diagrams.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,19 @@ def render_diagrams(diagrams_dir: Path, output_dir: Path, theme: str = "neutral"
4949
config_payload = {
5050
"themeVariables": {
5151
"fontFamily": "IBM Plex Sans, Segoe UI, Arial",
52-
"fontSize": "20px",
52+
"fontSize": "16px",
5353
"lineColor": "#334155",
5454
"primaryTextColor": "#111827",
5555
"primaryBorderColor": "#334155",
5656
"primaryColor": "#f8fafc",
5757
},
58-
"flowchart": {"nodeSpacing": 70, "rankSpacing": 100, "curve": "basis"},
58+
"flowchart": {"nodeSpacing": 55, "rankSpacing": 75, "curve": "basis"},
5959
"sequence": {
60-
"diagramMarginX": 60,
61-
"diagramMarginY": 30,
62-
"actorMargin": 90,
63-
"width": 220,
64-
"height": 90,
60+
"diagramMarginX": 40,
61+
"diagramMarginY": 24,
62+
"actorMargin": 70,
63+
"width": 180,
64+
"height": 76,
6565
},
6666
}
6767
Path(config_path).write_text(json.dumps(config_payload), encoding="utf-8")
@@ -73,8 +73,8 @@ def render_diagrams(diagrams_dir: Path, output_dir: Path, theme: str = "neutral"
7373
entry = {"diagram": mmd_path.name, "svg": svg_path.name, "png": png_path.name, "renderer": "", "ok": True, "errors": []}
7474
if mmdc:
7575
# White background + larger default typography/layout for cleaner onboarding visuals.
76-
svg_cmd = [mmdc, "-i", str(mmd_path), "-o", str(svg_path), "-t", theme, "-b", "white", "-s", "2", "-C", config_path]
77-
png_cmd = [mmdc, "-i", str(mmd_path), "-o", str(png_path), "-t", theme, "-b", "white", "-w", "3200", "-H", "2200", "-s", "2", "-C", config_path]
76+
svg_cmd = [mmdc, "-i", str(mmd_path), "-o", str(svg_path), "-t", theme, "-b", "white", "-s", "1.4", "-C", config_path]
77+
png_cmd = [mmdc, "-i", str(mmd_path), "-o", str(png_path), "-t", theme, "-b", "white", "-w", "2200", "-H", "1500", "-s", "1.4", "-C", config_path]
7878
code_svg, _out_svg, err_svg = common.run_cmd(svg_cmd, timeout=90)
7979
code_png, _out_png, err_png = common.run_cmd(png_cmd, timeout=90)
8080
entry["renderer"] = "mmdc"

0 commit comments

Comments
 (0)