Commit 2c2d714
committed
fix(mermaid): add compact spacing mode for PDF export
Problem:
Flowchart spacing improvements (commit 9592f89) work beautifully for chat
display but break PDF export. Complex diagrams render too large and don't
fit within the 550px PDF page width. The complex.txt diagram doesn't render
at all when printing.
Root Cause:
PDF export uses MermaidImageRenderer with fixed 550px width, but new flowchart
layout expects 1200px for optimal spacing. The calculateDynamic() function
was optimized for wide contexts (chat windows 1000-1500px) with generous
spacing (12%, 10%, 8%, 6%) and minimum node width of 120px.
Solution:
Added context detection in SpacingConfiguration.calculateDynamic():
- Narrow context (< 700px width) → PDF export, use COMPACT mode
- Wide context (≥ 700px width) → Chat display, use BEAUTIFUL mode
Compact Mode Changes (for targetWidth < 700):
- Reduced spacing percentages: 8%, 6%, 5%, 4% (vs 12%, 10%, 8%, 6%)
- Smaller minimum node width: 80px (vs 120px)
- Shorter node height: 50px (vs 70px)
- Tighter vertical spacing: 40-50px (vs 60-70px)
This allows complex diagrams to fit within PDF page width while maintaining
readability. Chat display keeps the beautiful, spacious layout.
Changes:
- MermaidGraphAnalyzer.swift: Enhanced calculateDynamic() with narrow context detection
Testing:
✅ Build: PASS
✅ Logic: Narrow width (550px) triggers compact mode automatically
✅ Logic: Wide width (1200px) uses beautiful mode as before
Impact:
PDF exports and prints now work for complex flowcharts that previously
overflowed the page. Chat display remains beautiful and spacious.
No API changes - the fix is internal to the spacing calculator.1 parent e024aa4 commit 2c2d714
1 file changed
Lines changed: 51 additions & 22 deletions
Lines changed: 51 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
162 | 165 | | |
163 | 166 | | |
164 | 167 | | |
165 | 168 | | |
166 | 169 | | |
167 | 170 | | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
180 | 189 | | |
181 | | - | |
182 | | - | |
183 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
184 | 211 | | |
185 | 212 | | |
186 | | - | |
187 | | - | |
| 213 | + | |
| 214 | + | |
188 | 215 | | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
194 | 223 | | |
195 | 224 | | |
196 | 225 | | |
| |||
0 commit comments