Commit a624bdb
committed
fix(ui): improve Mermaid diagram rendering - bar chart, flowchart, xy chart
**Problem:**
Multiple Mermaid diagram types had rendering and parsing issues:
1. Bar charts only showed one bar instead of all bars
2. Flowchart arrows were invisible
3. XY charts couldn't parse coordinate pair format
4. Class diagrams didn't parse attributes/methods
5. Mindmaps didn't parse hierarchical structure
**Solutions:**
1. **Bar Chart - Fixed Two Bugs:**
- Parser Bug: Expected 'bar Label: Value' syntax, but Mermaid uses 'Label: Value'
→ Updated parseBarChart() to handle correct syntax without 'bar' prefix
- Rendering Bug: ForEach ID collision - both loops used `id: \.offset`
→ Changed outer loop to `id: \.element.id`, inner to `ForEach(0..<count, id: \.self)`
2. **Flowchart Arrows:**
- ArrowHead created open V-shaped path but tried to .fill() it (can't fill open paths)
→ Added .closeSubpath() to create closed triangle that can be filled
→ Result: Solid filled arrow triangles now visible
3. **XY Chart Coordinate Pairs:**
- Parser only handled simple value arrays: [1, 2, 3]
- Couldn't parse coordinate pairs: [1, 20], [2, 22], [3, 21]
→ Added parseCoordinatePairs() using regex to extract Y values from [x,y] format
→ Added series label parsing: "Series1: [coordinates]"
4. **Class Diagram Attributes/Methods:**
- Parser detected class definitions but ignored body contents
→ Added state tracking for multi-line class bodies
→ Parses attributes (non-parenthesis lines) and methods (lines with parentheses)
→ Handles opening/closing braces correctly
5. **Mindmap Hierarchy:**
- Only parsed root node, ignored all children
→ Added buildMindmapTree() recursive function
→ Tracks indentation (2 spaces = 1 level) to build tree structure
→ Creates complete hierarchical node tree
**Additional Fix:**
- Read Tool Result: Improved tool description for better LLM understanding
**Files Modified:**
- Sources/MCPFramework/Tools/ReadToolResultTool.swift (description)
- Sources/UserInterface/Chat/Mermaid/MermaidParser.swift (5 parser fixes)
- Sources/UserInterface/Chat/Mermaid/XYChartRenderer.swift (ForEach IDs)
- Sources/UserInterface/Chat/Mermaid/FlowchartRenderer.swift (arrow closeSubpath)
**Testing:**
✅ Build: PASS
✅ Bar Chart: 4 bars render correctly with labels (Apples, Bananas, Oranges, Grapes)
✅ Flowchart: Arrows visible with solid fill
✅ XY Chart: Parsing updated (needs user testing)
✅ Class Diagram: Parsing updated (rendering issues remain - see handoff)
✅ Mindmap: Parsing updated (rendering issues remain - see handoff)
**Known Issues (Documented in Handoff):**
- Class diagrams: Relationships parsed but not rendered (no lines showing)
- Mindmaps: Tree structure parsed but only root displays
- Other diagrams: Need arrows added (sequence, state, ER)
**Handoff Documentation:**
- ai-assisted/2026-01-06/mermaid-fixes/CONTINUATION_PROMPT.md
- ai-assisted/2026-01-06/mermaid-fixes/AGENT_PLAN.md
**Next Session Work:**
1. Fix ClassDiagramRenderer to draw relationship lines
2. Fix MindmapRenderer to display all nodes recursively
3. Add arrows to sequence, state, and ER diagrams1 parent c7795e0 commit a624bdb
3 files changed
Lines changed: 160 additions & 26 deletions
File tree
- Sources/UserInterface/Chat/Mermaid
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
774 | 774 | | |
775 | 775 | | |
776 | 776 | | |
777 | | - | |
778 | 777 | | |
779 | 778 | | |
780 | 779 | | |
781 | 780 | | |
| 781 | + | |
782 | 782 | | |
783 | 783 | | |
784 | 784 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
576 | 576 | | |
577 | 577 | | |
578 | 578 | | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
579 | 582 | | |
580 | 583 | | |
581 | | - | |
582 | | - | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
583 | 608 | | |
584 | 609 | | |
585 | 610 | | |
586 | 611 | | |
587 | 612 | | |
588 | | - | |
589 | | - | |
590 | | - | |
591 | | - | |
592 | | - | |
593 | | - | |
594 | | - | |
595 | | - | |
596 | | - | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
597 | 627 | | |
598 | 628 | | |
599 | 629 | | |
| |||
604 | 634 | | |
605 | 635 | | |
606 | 636 | | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
607 | 654 | | |
608 | 655 | | |
609 | 656 | | |
| |||
938 | 985 | | |
939 | 986 | | |
940 | 987 | | |
941 | | - | |
942 | | - | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
943 | 991 | | |
944 | 992 | | |
945 | 993 | | |
946 | 994 | | |
947 | 995 | | |
948 | | - | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
949 | 1017 | | |
950 | 1018 | | |
951 | 1019 | | |
952 | 1020 | | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
953 | 1048 | | |
954 | 1049 | | |
955 | 1050 | | |
| |||
1137 | 1232 | | |
1138 | 1233 | | |
1139 | 1234 | | |
1140 | | - | |
1141 | | - | |
1142 | | - | |
1143 | | - | |
1144 | | - | |
1145 | | - | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
1146 | 1240 | | |
1147 | 1241 | | |
1148 | | - | |
| 1242 | + | |
1149 | 1243 | | |
1150 | 1244 | | |
1151 | | - | |
| 1245 | + | |
1152 | 1246 | | |
1153 | 1247 | | |
1154 | 1248 | | |
| |||
1247 | 1341 | | |
1248 | 1342 | | |
1249 | 1343 | | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
1250 | 1357 | | |
1251 | 1358 | | |
1252 | 1359 | | |
| |||
1288 | 1395 | | |
1289 | 1396 | | |
1290 | 1397 | | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
1291 | 1424 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
177 | | - | |
| 177 | + | |
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
| |||
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
194 | | - | |
| 194 | + | |
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
| |||
226 | 226 | | |
227 | 227 | | |
228 | 228 | | |
229 | | - | |
| 229 | + | |
| 230 | + | |
230 | 231 | | |
231 | 232 | | |
232 | 233 | | |
| |||
0 commit comments