Skip to content

Add diagram editor with Mermaid import and image support#120

Merged
JE-Chen merged 4 commits intomainfrom
dev
Apr 15, 2026
Merged

Add diagram editor with Mermaid import and image support#120
JE-Chen merged 4 commits intomainfrom
dev

Conversation

@JE-Chen
Copy link
Copy Markdown
Member

@JE-Chen JE-Chen commented Apr 15, 2026

Summary

  • Add a full-featured WYSIWYG architecture diagram editor under Tools > Diagram Editor
  • Support Mermaid flowchart syntax import with automatic BFS-based layout
  • Support local file and URL image embedding on the canvas
  • Add CLAUDE.md project documentation

Features

Diagram Editor Core

  • Node shapes: Rectangle, Rounded Rect, Ellipse, Diamond
  • Connections: edge-to-edge cubic bezier with arrowhead, solid/dashed/dotted styles
  • Resize handles on all nodes and images (4-corner drag)
  • Undo/Redo via snapshot-based QUndoStack (Ctrl+Z / Ctrl+Y)
  • Grid background with snap toggle
  • Property panel for node (text, size, shape, colors, font), connection (label, style, color, width), and image (caption, source, size)
  • Align tools: left / right / top / bottom / center H/V / distribute H/V
  • Copy/Paste/Duplicate, right-click context menu
  • Keyboard shortcuts: Ctrl+Z/Y/C/V/D/S/A, Delete, Escape
  • Export: PNG (2x retina) and SVG
  • Save/Load: .diagram.json format
  • Tab + Dock support

Mermaid Import

  • Paste Mermaid graph TD/LR/RL/BT syntax and auto-generate diagram
  • Bracket-to-shape mapping: [] rect, () rounded, {} diamond, (()) ellipse
  • Arrow styles: --> solid, -.-> dashed, ==> thick
  • Label support: -->|label| and -- label -->
  • Chained edges: A --> B --> C
  • Auto BFS layered layout with text-adaptive node widths

Image Support

  • Local images: PNG, JPG, BMP, GIF, SVG, WebP via file dialog
  • URL images: paste any image URL, auto-downloaded
  • Images are movable, resizable, with optional caption
  • Image source paths saved in diagram JSON for reload

Performance

  • BSP tree index (depth 14) for O(log n) spatial queries
  • DeviceCoordinateCache on all shape bodies, connections, and images
  • MinimalViewportUpdate — only repaint dirty regions
  • CacheBackground — grid painted once, blitted on scroll

i18n

  • ~70 new keys in both English and Traditional Chinese

Files changed

  • New (pybreeze/pybreeze_ui/diagram_editor/): 8 files, ~3100 lines
  • Modified: tools_menu.py, extend_english.py, extend_traditional_chinese.py
  • New: CLAUDE.md

Test plan

  • All 49 existing unit tests pass
  • All module imports verified
  • Manual: create nodes (all 4 shapes), connect them, resize, undo/redo
  • Manual: import Mermaid code, verify layout
  • Manual: add local image and URL image
  • Manual: save diagram, close, reopen and verify
  • Manual: export PNG and SVG

JE-Chen added 2 commits April 16, 2026 00:50
- Diagram editor in Tools menu (tab + dock)
- Node shapes: rectangle, rounded rect, ellipse, diamond
- Connections: edge-to-edge bezier with arrowhead, solid/dashed/dotted styles
- Resize handles on nodes and images
- Undo/redo (snapshot-based QUndoStack)
- Grid background + snap toggle
- Property panel for node, connection, and image editing
- Align tools (left/right/top/bottom/center/distribute)
- Copy/paste/duplicate, right-click context menu
- Mermaid flowchart import with auto BFS layout
- Local and URL image support with caption
- Performance: BSP tree index, DeviceCoordinateCache, MinimalViewportUpdate
- Keyboard shortcuts (Ctrl+Z/Y/C/V/D/S/A, Delete, Escape)
- Full i18n (English + Traditional Chinese)
- Add CLAUDE.md project documentation
@codacy-production
Copy link
Copy Markdown

codacy-production bot commented Apr 15, 2026

Not up to standards ⛔

🔴 Issues 1 high · 2 medium

Alerts:
⚠ 3 issues (≤ 0 issues of at least minor severity)

Results:
3 new issues

Category Results
ErrorProne 1 high
Security 2 medium

View in Codacy

🟢 Metrics 545 complexity · 4 duplication

Metric Results
Complexity 545
Duplication 4

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

JE-Chen added 2 commits April 16, 2026 01:17
- Add diagram_net_utils.py with SSRF prevention:
  block file/ftp schemes, reject private/loopback/link-local IPs,
  enforce 20 MB download limit and connection timeout
- URL image download now routes through safe_download_image()
- Image reload from saved JSON validates file extension allowlist
- Add Security section to CLAUDE.md with full checklist
- Remove unused imports: QImage (items), QTransform, QGraphicsItem (scene)
- Remove unused signal: zoom_requested (scene)
- Add convention: delete all unused code immediately, no dead code allowed
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
4 Security Hotspots

See analysis details on SonarQube Cloud

@JE-Chen JE-Chen merged commit 16ee980 into main Apr 15, 2026
6 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant