XML Graphic Generator (drawio Format)
Core Workflow
User Description → Parse Requirements → Design Graphics → Generate drawio XML → Validate Output → Save File
Detailed process as follows:
- Receive User Description
- Users may describe the required graph type (flowchart, card, chart, etc.), layout (horizontal, vertical, grid, etc.), content (text, emoji), and style (minimalist, professional, cute, etc.).
- Parse user input and extract key information to guide subsequent graphic design and generation.
- Parse User Requirements
- Determine the graph type, structure, elements, layout, and color scheme needed. If unclear, ask the user for confirmation.
- Evaluate the number of elements, group them reasonably, and avoid overloading a single graphic with too much content.
- Design Graphic Layout and Elements Based on Analysis Results
- Define the overall structure and hierarchical relationships of the graph
- Design the style of each element (color, shape, size, etc.)
- Determine the connection method between elements (lines, arrows, etc.)
- Generate drawio XML Code
- Build graphics using drawio's mxGraph XML format
- Embed CSS styles into SVG
- Apply filters and shadow effects according to the selected style
- Validate the Generated Graph to Ensure It Meets User Requirements and Expected Visual Effects
- Background Mode Confirmation:
- Confirm the background mode selected by the user (light/dark)
- Use light background by default if not specified
- Use light-colored text and borders in dark mode
- Basic Structure Validation (Avoid element overlap and layout distortion):
- Check if the graph structure and elements are correct
- Ensure all node coordinates are calculated accurately with no overlap
- Verify that connection line start/end points precisely point to node edges
- Check that the spacing between text and graphic borders is ≥8px to avoid text overflow
- Layout Specification Validation (Avoid excessive blank space and overcrowding):
- Canvas size should be compact and reasonable, with utilization rate ideally 60%-80%
- Node spacing should be reasonable, neither too large nor too small
- Branch paths should be clear with no path crossings
- Polyline turning points should not overlap with nodes
- Display Integrity Assurance (Avoid incomplete display):
- Calculate canvas size:
Canvas Height = Title Height + Total Content Height + Node Spacing × (Number of Nodes - 1) + Legend Area Height (if any) + Margins
- Ensure all nodes, text, connections, and arrows are within the canvas range
- Reserve ≥30-40px margins on all sides to avoid content cropping
- Arrow and Connection Validation (Avoid arrow chaos):
- Ensure consistent arrow styles
- Verify accurate arrow pointing with no offset or misalignment
- Check that polyline path node order is correct with no crossing chaos
- Verify that dashed lines are only used for asynchronous processes, and error branches use solid lines
- Robustness Design Check:
- Avoid nested coordinates; use explicit numerical values for all coordinates
- Ensure accurate center coordinates for diamond decision nodes, with branches starting from the bottom center
- Verify that convergence points are directly below branch nodes to avoid path crossings
- Legends should be placed at the bottom of the graphic, avoiding overlap with the main process, with a dedicated legend area reserved
- Style and Color Validation:
- Ensure colors and styles comply with the selected style
- Verify the correctness and compatibility of drawio XML code
- Check if the graph layout and element connections are reasonable, lines are clear and accurate, graphics are legible, colors meet expectations, and typesetting is neat
- Check if arrows in the graph are clear, connections are normal, and sizes are appropriate
- Check if the image can be displayed completely without elements being cropped
- Complex Flowchart Validation:
- Use different colors to distinguish branch processes (red for error branches, gray/blue for main lines)
- Use diamond shapes for conditional decision nodes
- Use dashed connections for asynchronous processes (only for asynchronous scenarios)
- Clearly mark convergence points
- Use dashed boxes to indicate optional areas
- Output the Final drawio XML File for User Use and Modification
- Save the drawio XML to the specified path, with the filename ending in
- Provide the drawio XML code string for users to copy and use
Core Principle: The generated drawio graphics should be concise and aesthetically pleasing, comply with modern design specifications, and maintain consistent style with svg-generator.
Visual Style Specifications
Background Mode
Important: Must confirm the background mode required by the user when generating graphics; use light background by default if not specified
1. Light Background Mode (Default)
Applicable to: Light-themed documents, PPTs, web pages, etc.
Reference Examples: Light flowchart, light architecture diagram
| Purpose | Color Code |
|---|
| Background Color | |
| Card Background | |
| Title Text | |
| Body Text | or |
| Border Color | |
| Arrow Color | or |
2. Dark Background Mode
Applicable to: Dark-themed documents, presentations, code editor themes, etc.
Reference Examples: Dark flowchart, dark timeline
| Purpose | Color Code |
|---|
| Background Color | |
| Card Background | |
| Title Text | |
| Body Text | or |
| Border Color | |
| Arrow Color | or |
Dark Mode Color Quick Reference:
| Purpose | Color Code |
|---|
| Primary Color (Blue) | |
| Success (Green) | |
| Warning (Orange) | |
| Error (Red) | |
| Purple | |
| Cyan | |
| Yellow | |
| Cyan 2 | |
Special Handling for Dark Background:
- Use light-colored text to ensure contrast
- Appropriately thicken node borders (2-3px) to enhance visibility
- Recommended to use rounded-corner cards to improve visual hierarchy
Color Scheme
| Purpose | Color Code |
|---|
| Primary Color (Blue) | |
| Secondary Color (Green) | |
| Accent Color (Orange) | |
| Warning Color (Red) | |
| Background Color | |
| Text Color | or |
| Border Color | |
| Arrow Color | or (Gray/Blue) |
Graphic Specifications
| Item | Light Mode Default Value | Dark Mode Default Value |
|---|
| Canvas Size | 800×600 | 800×600 |
| Radius of Corners | 8px (Cards) | 8px (Cards) |
| Shadow | Soft Shadow | No Shadow or Light Shadow |
| Border Width | 2px | 2-3px |
| Font | PingFang SC, Microsoft YaHei, sans-serif | PingFang SC, Microsoft YaHei, sans-serif |
| Line Thickness | 2px | 2px |
Layout Specifications (Important)
1. Shape Splicing Specification (Avoid不协调圆弧)
Problem Description: When one shape contains another shape (such as a card with a title bar), setting rounded corners separately will lead to inconsistent borders.
Correct Approach - Use Single-Layer Structure:
xml
<!-- Recommended: Use a single rounded rectangle, distinguish title by different color or position -->
<mxCell id="node1" value="Node Name" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#3498db;strokeWidth=2;fontColor=#333333;fontSize=14;fontStyle=1;shadow=1;" vertex="1" parent="1">
<mxGeometry x="100" y="100" width="140" height="60" as="geometry" />
</mxCell>
Simplified Design Principle:
- Avoid using double-layer shape overlay (a rounded rectangle + a rectangular title bar)
- If you need to distinguish the title area, use color filling instead of overlaying shapes
- Distinguish title text by using bold or different colors, do not create a separate title block
- Directly use in drawio to bold text, or use different to distinguish titles
2. Line Layout Specification (Avoid Chaos and Overlap)
Node Spacing Rules:
- Horizontal node spacing: ≥ 40px
- Vertical node spacing: ≥ 30px
- Branch node spacing: Vertical distance before branch point ≥ 50px
Connection Line Specifications:
- Distance between connection line endpoints and node borders: ≥ 5px
- Polyline turning points: Use integer coordinates
- Avoid three or more paths passing through the same coordinate point
- Prioritize straight lines, followed by polylines, and use curves cautiously
- Use
edgeStyle=orthogonalEdgeStyle
to ensure polyline orthogonality
Branch Path Rules:
- Deflection angle for double branches: 30-45°
- Reasonable branch expansion angle to avoid crossings
- Convergence points are located directly below all branch nodes
Anti-Overlap Check:
- Connection lines do not pass through other nodes
- Spacing between text and graphic borders ≥ 8px
- Maintain ≥ 30px spacing between legend and main process
drawio XML Format Specifications
Basic Structure
xml
<mxfile host="app.diagrams.net">
<diagram name="Page-1">
<mxGraphModel dx="1200" dy="800" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="800" pageHeight="600" math="0" shadow="1">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<!-- Graphic Elements -->
</root>
</mxGraphModel>
</diagram>
</mxfile>
Common Element Formats
1. Light Mode Rounded Rectangle Card
xml
<mxCell id="node1" value="Node Name" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#3498db;strokeWidth=2;fontColor=#333333;fontSize=14;fontStyle=1;shadow=1;" vertex="1" parent="1">
<mxGeometry x="100" y="100" width="140" height="60" as="geometry" />
</mxCell>
2. Dark Mode Rounded Rectangle Card
xml
<mxCell id="node1" value="Node Name" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#16213e;strokeColor=#3498db;strokeWidth=2;fontColor=#aaaaaa;fontSize=14;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="100" y="100" width="140" height="60" as="geometry" />
</mxCell>
3. Diamond Decision Node
xml
<mxCell id="node2" value="Decision?" style="rhombus;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#e67e22;strokeWidth=2;fontColor=#333333;fontSize=12;" vertex="1" parent="1">
<mxGeometry x="200" y="200" width="80" height="80" as="geometry" />
</mxCell>
4. Circular Node
xml
<mxCell id="node3" value="Start" style="ellipse;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#3498db;strokeWidth=2;fontColor=#333333;fontSize=12;" vertex="1" parent="1">
<mxGeometry x="100" y="100" width="60" height="60" as="geometry" />
</mxCell>
5. Arrow Connection Line
xml
<mxCell id="edge1" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeColor=#999999;strokeWidth=2;endArrow=classic;endFill=1;" edge="1" parent="1" source="node1" target="node2">
<mxGeometry relative="1" as="geometry" />
</mxCell>
6. Dashed Connection (Asynchronous/Optional Process)
xml
<mxCell id="edge2" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeColor=#9b59b6;strokeWidth=2;dashed=1;endArrow=classic;endFill=1;" edge="1" parent="1" source="node2" target="node3">
<mxGeometry relative="1" as="geometry" />
</mxCell>
7. Red Arrow (Error Branch)
xml
<mxCell id="edge3" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeColor=#e74c3c;strokeWidth=2;endArrow=classic;endFill=1;" edge="1" parent="1" source="node2" target="node4">
<mxGeometry relative="1" as="geometry" />
</mxCell>
8. Dashed Box (Optional Area)
xml
<mxCell id="optional" value="Optional Process" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8f9fa;strokeColor=#999999;strokeWidth=1;dashed=1;fontColor=#999999;fontSize=10;" vertex="1" parent="1">
<mxGeometry x="50" y="200" width="200" height="120" as="geometry" />
</mxCell>
9. Convergence Point
xml
<mxCell id="join" value="" style="ellipse;whiteSpace=wrap;html=1;fillColor=#666666;strokeColor=#666666;strokeWidth=0;" vertex="1" parent="1">
<mxGeometry x="300" y="400" width="12" height="12" as="geometry" />
</mxCell>
Style Attribute Description
| Attribute | Description | Common Values |
|---|
| rounded | Rounded Corners | 0=none, 1=enabled |
| whiteSpace | Text Wrapping | wrap |
| html | HTML Rendering | 1 |
| fillColor | Fill Color | #ffffff, #16213e, etc. |
| strokeColor | Border Color | #3498db, #e74c3c, etc. |
| strokeWidth | Border Width | 2 |
| fontColor | Text Color | #333333, #aaaaaa, etc. |
| fontSize | Font Size | 12, 14, 16, etc. |
| fontStyle | Font Style | 0=normal, 1=bold |
| dashed | Dashed Line | 0=solid, 1=dashed |
| shadow | Shadow | 0=none, 1=enabled |
| edgeStyle | Connection Line Style | orthogonalEdgeStyle=orthogonal, elbowEdgeStyle=elbow |
Layered Architecture Diagram Container
xml
<!-- Container Background -->
<mxCell id="layer1" value="" style="rounded=1;whiteSpace=wrap=1;html=1;fillColor=#E3F2FD;strokeColor=#3498db;strokeWidth=1;" vertex="1" parent="1">
<mxGeometry x="100" y="80" width="900" height="80" as="geometry" />
</mxCell>
<!-- Layer Label -->
<mxCell id="label1" value="① Access Layer" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;whiteSpace=wrap=1;rounded=0;fontColor=#3498db;fontSize=14;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="110" y="85" width="100" height="20" as="geometry" />
</mxCell>
Execution Steps
Step 1: Parse User Requirements
Users may provide:
- Graph Type: Flowchart, card, chart, icon, relationship diagram, architecture diagram
- Layout Description: Horizontal, vertical, grid, circular
- Content: Text, emoji, color preferences
- Style: Minimalist, professional, cute
- Background Mode: Light/Dark (Important: Must be confirmed; light background by default if not specified)
Background Mode Confirmation
Critical Step: Must confirm the required background mode with the user before generation
- Ask the user: "Do you need a light or dark background for the graph?"
- If not specified by the user, default to light background
- Application Scenario Reference:
- Light Background: Documents, PPTs, web page displays
- Dark Background: Code screenshots, IDE matching graphs, dark-themed design drafts
Step 2: Select Template or Create New
Common Templates:
- Horizontal Flowchart - Steps arranged from left to right
- Vertical Flowchart - Steps arranged from top to bottom
- Loop Flowchart - Closed loop with connected start and end
- Card Grid - Multiple cards arranged side by side
- Comparison Chart - Left-right comparison layout
- Timeline - Vertical or horizontal timeline
- Pie/Bar Chart - Data visualization
- Architecture Diagram - System, deployment, application architecture diagrams, which should be displayed in layers
- Table Comparison - Data table visualization
Step 3: Generate drawio XML Code
Generate complete drawio files based on requirements:
Light Background Template
xml
<mxfile host="app.diagrams.net">
<diagram name="Page-1">
<mxGraphModel dx="1200" dy="800" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="800" pageHeight="600" math="0" shadow="1">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<!-- Background -->
<mxCell id="bg" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f8f9fa;strokeColor=#e0e0e0;" vertex="1" parent="1">
<mxGeometry x="0" y="0" width="800" height="600" as="geometry" />
</mxCell>
<!-- Title -->
<mxCell id="title" value="Graphic Title" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap=1;rounded=0;fontSize=20;fontStyle=1;fontColor=#333333;" vertex="1" parent="1">
<mxGeometry x="300" y="20" width="200" height="30" as="geometry" />
</mxCell>
<!-- Graphic Content -->
...
</root>
</mxGraphModel>
</diagram>
</mxfile>
Dark Background Template
xml
<mxfile host="app.diagrams.net">
<diagram name="Page-1">
<mxGraphModel dx="1200" dy="800" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="800" pageHeight="600" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<!-- Dark Background -->
<mxCell id="bg" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#1a1a2e;strokeColor=#333333;" vertex="1" parent="1">
<mxGeometry x="0" y="0" width="800" height="600" as="geometry" />
</mxCell>
<!-- Title -->
<mxCell id="title" value="Graphic Title" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap=1;rounded=0;fontSize=20;fontStyle=1;fontColor=#ffffff;" vertex="1" parent="1">
<mxGeometry x="300" y="20" width="200" height="30" as="geometry" />
</mxCell>
<!-- Graphic Content -->
<!-- Card Example -->
<mxCell id="node1" value="Node Content" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#16213e;strokeColor=#3498db;strokeWidth=2;fontColor=#aaaaaa;fontSize=12;" vertex="1" parent="1">
<mxGeometry x="100" y="80" width="140" height="60" as="geometry" />
</mxCell>
...
</root>
</mxGraphModel>
</diagram>
</mxfile>
Dark Background Color Quick Reference:
| Element | Color Code |
|---|
| Background | |
| Card Background | |
| Title Text | |
| Body Text | / |
| Border | |
| Arrow | |
| Primary Color Border | |
| Success Color | |
| Error Color | |
Step 4: Save File
Save the generated drawio file to the location specified by the user, with the filename ending in
.
Arrow Specifications
Arrow Styles
| Style | Attribute Value |
|---|
| Gray Arrow (Recommended) | strokeColor=#999999 |
| Blue Arrow | strokeColor=#3498db |
| Red Arrow | strokeColor=#e74c3c |
| Purple Arrow | strokeColor=#9b59b6 |
Line Styles
| Style | Application Scenario | Attribute |
|---|
| Solid Line | Main process, correct branch, error branch | dashed=0 |
| Dashed Line | Asynchronous/callback/optional process | dashed=1 |
Important Principle:
- Error branches must use solid lines, distinguished by color (red), not dashed lines
- Dashed lines are only used to represent asynchronous, callback, scheduled task, and other non-synchronous scenarios
Arrow Endpoint Styles
xml
<!-- Classic Arrow -->
endArrow=classic;endFill=1;
<!-- Hollow Arrow -->
endArrow=classicEmpty;endFill=0;
<!-- Diamond Endpoint -->
endArrow=diamond;endFill=1;
Flowchart Specifications
Canvas Size Calculation Rules
Canvas Height = Title Height + Total Content Height + Node Spacing × (Number of Nodes - 1) + Margins
Canvas Width = Margins + Maximum Node Width × Number of Columns + Column Spacing × (Number of Columns - 1) + Margins
Node Arrangement
- Horizontal Process: Nodes arranged horizontally with spacing 40-60px
- Vertical Process: Nodes arranged vertically with spacing 30-50px
Connection Line Types
Straight Connection
xml
<mxCell id="edge1" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;strokeColor=#999999;strokeWidth=2;endArrow=classic;" edge="1" parent="1" source="node1" target="node2">
<mxGeometry relative="1" as="geometry" />
</mxCell>
Polyline Connection (Path Direction Change)
xml
<mxCell id="edge2" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;strokeColor=#999999;strokeWidth=2;endArrow=classic;" edge="1" parent="1" source="node2" target="node3">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<Object x="250" y="180" />
</Array>
</mxGeometry>
</mxCell>
Curve Connection (Loop/Backward)
xml
<mxCell id="edge3" style="edgeStyle=elbowEdgeStyle;rounded=1;html=1;strokeColor=#9b59b6;strokeWidth=2;dashed=1;endArrow=classic;" edge="1" parent="1" source="node3" target="node1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
Branching and Convergence
Diamond Decision Node
xml
<mxCell id="decision" value="Decision Condition" style="rhombus;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#e67e22;strokeWidth=2;fontColor=#333333;fontSize=12;" vertex="1" parent="1">
<mxGeometry x="200" y="150" width="80" height="80" as="geometry" />
</mxCell>
Branch Connection Line Labeling
Add labels next to connection lines:
xml
<mxCell id="label1" value="Yes" style="text;html=1;strokeColor=none;fillColor=none;align=center;fontColor=#666666;fontSize=10;" vertex="1" parent="1">
<mxGeometry x="220" y="230" width="30" height="20" as="geometry" />
</mxCell>
Architecture Diagram Specifications
Layered Structure
Architecture diagrams should adopt layered design, from top to bottom:
- Access Layer (Client, CDN, Load Balancer, Gateway)
- Service Layer (Business Service, Authentication Service, Message Queue)
- Data Layer (Redis, MySQL, MongoDB)
- Infrastructure Layer (Docker, K8s, Monitoring)
Architecture Diagram Component Templates
Service Node
xml
<mxCell id="service1" value="Service Name" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#E8F5E9;strokeColor=#2ecc71;strokeWidth=2;fontColor=#333333;fontSize=12;shadow=1;" vertex="1" parent="1">
<mxGeometry x="150" y="100" width="100" height="40" as="geometry" />
</mxCell>
Database Node
xml
<mxCell id="db1" value="Database" style="shape=cylinder3;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;size=5;fillColor=#FCE4EC;strokeColor=#e74c3c;strokeWidth=2;fontColor=#333333;fontSize=12;" vertex="1" parent="1">
<mxGeometry x="300" y="350" width="60" height="50" as="geometry" />
</mxCell>
Queue Node
xml
<mxCell id="queue1" value="Message Queue" style="shape=hexagon;whiteSpace=wrap;html=1;fillColor=#F3E5F5;strokeColor=#9b59b6;strokeWidth=2;fontColor=#333333;fontSize=12;perimeter=hexagonPerimeter;" vertex="1" parent="1">
<mxGeometry x="400" y="200" width="100" height="40" as="geometry" />
</mxCell>
Arrow Usage Rules
Arrows are optional in layered architecture diagrams:
-
Arrowless Architecture Diagram: When focusing on displaying system hierarchical structure and component layering, arrows can be omitted.
-
Arrowed Architecture Diagram: When it is necessary to represent data flow, call relationships, or processing order, arrows can be added. Arrows should use uniform gray (#999999).
xml
<mxCell id="arrow1" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;strokeColor=#999999;strokeWidth=2;endArrow=classic;endFill=1;" edge="1" parent="1" source="layer1" target="layer2">
<mxGeometry relative="1" as="geometry" />
</mxCell>
Validation Checklist
1. Background Mode Confirmation
Must confirm before generation:
2. Basic Structure Validation
3. Layout Specification Validation
4. Graphic Complete Display Validation
5. Color and Style Validation
Output Description
The generated drawio XML file can directly:
- Be opened, viewed, and edited in drawio
- Be saved as a .drawio file
- Be exported as PNG, SVG, PDF, and other formats
- Be embedded into documents for use
Trigger Conditions
Triggered when users mention:
- XML, drawio, drawing
- Flowchart, relationship diagram, structure diagram, architecture diagram
- Generate a graph, turn text into a graph
- drawio editing
Corresponding Relationship with svg-generator
This skill has exactly the same functionality as svg-generator, with the only difference being the output format:
| svg-generator | xml-diagram |
|---|
| Outputs SVG format | Outputs drawio XML format |
| file | file |
| Can be opened in browsers | Can be edited in drawio |
| Same color scheme | Same color scheme |
| Same layout specifications | Same layout specifications |
| Same validation checklist | Same validation checklist |