flowchart-generator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseFlowchart Generator
流程图生成器
Create professional flowcharts from structured process definitions. Supports standard flowchart symbols (start/end, process, decision, I/O), swimlanes for multi-actor processes, and multiple export formats.
可通过结构化流程定义创建专业流程图,支持标准流程图符号(开始/结束、处理、判断、输入/输出)、多角色流程适用的泳道,以及多种导出格式。
Quick Start
快速开始
python
from scripts.flowchart_gen import FlowchartGeneratorpython
from scripts.flowchart_gen import FlowchartGeneratorUsing Python DSL
Using Python DSL
flow = FlowchartGenerator()
flow.start("Start")
flow.process("Step 1", id="s1")
flow.decision("Check?", id="d1")
flow.process("Yes Path", id="yes")
flow.process("No Path", id="no")
flow.end("End")
flow.connect("Start", "s1")
flow.connect("s1", "d1")
flow.connect("d1", "yes", label="Yes")
flow.connect("d1", "no", label="No")
flow.connect("yes", "End")
flow.connect("no", "End")
flow.generate().save("flowchart.png")
flow = FlowchartGenerator()
flow.start("Start")
flow.process("Step 1", id="s1")
flow.decision("Check?", id="d1")
flow.process("Yes Path", id="yes")
flow.process("No Path", id="no")
flow.end("End")
flow.connect("Start", "s1")
flow.connect("s1", "d1")
flow.connect("d1", "yes", label="Yes")
flow.connect("d1", "no", label="No")
flow.connect("yes", "End")
flow.connect("no", "End")
flow.generate().save("flowchart.png")
From YAML file
From YAML file
flow = FlowchartGenerator()
flow.from_yaml("process.yaml")
flow.generate().save("process.png")
undefinedflow = FlowchartGenerator()
flow.from_yaml("process.yaml")
flow.generate().save("process.png")
undefinedFeatures
特性
- Multiple Input Sources: Python DSL, YAML, or JSON
- Standard Shapes: Start/End, Process, Decision, Input/Output, Connector
- Swimlanes: Multi-actor/department process diagrams
- Styling Presets: Business, technical, minimal themes
- Layout Options: Top-bottom, left-right, and more
- Export Formats: PNG, SVG, PDF, DOT
- 多输入源:支持Python DSL、YAML、JSON
- 标准形状:开始/结束、处理、判断、输入/输出、连接符
- 泳道:支持多角色/多部门流程图表
- 样式预设:商务、技术、极简主题
- 布局选项:上下布局、左右布局等多种模式
- 导出格式:PNG、SVG、PDF、DOT
API Reference
API参考
Initialization
初始化
python
flow = FlowchartGenerator()python
flow = FlowchartGenerator()Node Creation (DSL)
节点创建(DSL)
python
undefinedpython
undefinedStart node (oval/ellipse)
开始节点(椭圆形)
flow.start("Start")
flow.start("Begin Process", id="start1")
flow.start("Start")
flow.start("Begin Process", id="start1")
End node (oval/ellipse)
结束节点(椭圆形)
flow.end("End")
flow.end("Process Complete", id="end1")
flow.end("End")
flow.end("Process Complete", id="end1")
Process node (rectangle)
处理节点(矩形)
flow.process("Process Data")
flow.process("Calculate Total", id="calc")
flow.process("Process Data")
flow.process("Calculate Total", id="calc")
Decision node (diamond)
判断节点(菱形)
flow.decision("Valid?", id="check")
flow.decision("Amount > 100?", id="d1")
flow.decision("Valid?", id="check")
flow.decision("Amount > 100?", id="d1")
Input/Output node (parallelogram)
输入/输出节点(平行四边形)
flow.input_output("User Input", id="input1")
flow.input_output("Display Result", id="output1")
flow.input_output("User Input", id="input1")
flow.input_output("Display Result", id="output1")
Connector (circle) - for complex flows
连接符(圆形)- 用于复杂流程
flow.connector("A", id="conn_a")
undefinedflow.connector("A", id="conn_a")
undefinedConnections
连接设置
python
undefinedpython
undefinedBasic connection
基础连接
flow.connect("start", "process1")
flow.connect("start", "process1")
With label
带标签的连接
flow.connect("decision1", "yes_path", label="Yes")
flow.connect("decision1", "no_path", label="No")
flow.connect("decision1", "yes_path", label="Yes")
flow.connect("decision1", "no_path", label="No")
Multiple connections from decision
判断节点的多分支连接
flow.decision("Approved?", id="d1")
flow.connect("d1", "approve_path", label="Yes")
flow.connect("d1", "reject_path", label="No")
undefinedflow.decision("Approved?", id="d1")
flow.connect("d1", "approve_path", label="Yes")
flow.connect("d1", "reject_path", label="No")
undefinedLoading from Files
从文件加载配置
python
undefinedpython
undefinedFrom YAML
加载YAML文件
flow.from_yaml("process.yaml")
flow.from_yaml("process.yaml")
From JSON
加载JSON文件
flow.from_json("process.json")
undefinedflow.from_json("process.json")
undefinedSwimlanes
泳道设置
python
undefinedpython
undefinedDefine swimlanes
定义泳道
flow.swimlanes([
"Customer",
"Sales Team",
"Fulfillment"
])
flow.swimlanes([
"Customer",
"Sales Team",
"Fulfillment"
])
Add nodes to specific lanes
将节点添加到指定泳道
flow.process("Place Order", id="order", lane="Customer")
flow.process("Review Order", id="review", lane="Sales Team")
flow.process("Ship Order", id="ship", lane="Fulfillment")
undefinedflow.process("Place Order", id="order", lane="Customer")
flow.process("Review Order", id="review", lane="Sales Team")
flow.process("Ship Order", id="ship", lane="Fulfillment")
undefinedStyling
样式设置
python
undefinedpython
undefinedStyle presets
样式预设
flow.style("business") # Professional blue theme
flow.style("technical") # Gray technical theme
flow.style("minimal") # Clean minimal theme
flow.style("colorful") # Vibrant colors
flow.style("business") # 专业蓝色主题
flow.style("technical") # 灰色技术主题
flow.style("minimal") # 简洁极简主题
flow.style("colorful") # 明亮多彩主题
Layout direction
布局方向
flow.layout("TB") # Top to Bottom (default)
flow.layout("LR") # Left to Right
flow.layout("BT") # Bottom to Top
flow.layout("RL") # Right to Left
flow.layout("TB") # 从上到下(默认)
flow.layout("LR") # 从左到右
flow.layout("BT") # 从下到上
flow.layout("RL") # 从右到左
Custom colors
自定义颜色
flow.node_colors({
'start': '#2ecc71',
'end': '#e74c3c',
'process': '#3498db',
'decision': '#f39c12',
'io': '#9b59b6'
})
undefinedflow.node_colors({
'start': '#2ecc71',
'end': '#e74c3c',
'process': '#3498db',
'decision': '#f39c12',
'io': '#9b59b6'
})
undefinedGeneration and Export
生成与导出
python
undefinedpython
undefinedGenerate
生成流程图
flow.generate()
flow.generate()
Save
保存文件
flow.save("chart.png")
flow.save("chart.svg")
flow.save("chart.pdf")
flow.save("chart.dot") # GraphViz source
flow.save("chart.png")
flow.save("chart.svg")
flow.save("chart.pdf")
flow.save("chart.dot") # GraphViz源码
Get DOT source
获取DOT源码
dot_source = flow.to_dot()
dot_source = flow.to_dot()
Show in viewer
在查看器中展示
flow.show()
undefinedflow.show()
undefinedData Formats
数据格式
YAML Format
YAML格式
yaml
undefinedyaml
undefinedprocess.yaml
process.yaml
title: Order Processing
layout: TB
style: business
nodes:
-
id: start type: start label: Start
-
id: receive type: process label: Receive Order
-
id: check_stock type: decision label: In Stock?
-
id: fulfill type: process label: Fulfill Order
-
id: backorder type: process label: Create Backorder
-
id: notify type: io label: Notify Customer
-
id: end type: end label: End
connections:
-
from: start to: receive
-
from: receive to: check_stock
-
from: check_stock to: fulfill label: "Yes"
-
from: check_stock to: backorder label: "No"
-
from: fulfill to: notify
-
from: backorder to: notify
-
from: notify to: end
undefinedtitle: Order Processing
layout: TB
style: business
nodes:
-
id: start type: start label: Start
-
id: receive type: process label: Receive Order
-
id: check_stock type: decision label: In Stock?
-
id: fulfill type: process label: Fulfill Order
-
id: backorder type: process label: Create Backorder
-
id: notify type: io label: Notify Customer
-
id: end type: end label: End
connections:
-
from: start to: receive
-
from: receive to: check_stock
-
from: check_stock to: fulfill label: "Yes"
-
from: check_stock to: backorder label: "No"
-
from: fulfill to: notify
-
from: backorder to: notify
-
from: notify to: end
undefinedJSON Format
JSON格式
json
{
"title": "Order Processing",
"layout": "TB",
"style": "business",
"nodes": [
{"id": "start", "type": "start", "label": "Start"},
{"id": "process1", "type": "process", "label": "Process Data"},
{"id": "decision1", "type": "decision", "label": "Valid?"},
{"id": "end", "type": "end", "label": "End"}
],
"connections": [
{"from": "start", "to": "process1"},
{"from": "process1", "to": "decision1"},
{"from": "decision1", "to": "end", "label": "Yes"}
]
}json
{
"title": "Order Processing",
"layout": "TB",
"style": "business",
"nodes": [
{"id": "start", "type": "start", "label": "Start"},
{"id": "process1", "type": "process", "label": "Process Data"},
{"id": "decision1", "type": "decision", "label": "Valid?"},
{"id": "end", "type": "end", "label": "End"}
],
"connections": [
{"from": "start", "to": "process1"},
{"from": "process1", "to": "decision1"},
{"from": "decision1", "to": "end", "label": "Yes"}
]
}Swimlane YAML Format
泳道YAML格式
yaml
title: Customer Service Process
layout: LR
swimlanes:
- Customer
- Support Agent
- Technical Team
nodes:
- id: submit
type: start
label: Submit Ticket
lane: Customer
- id: review
type: process
label: Review Ticket
lane: Support Agent
- id: technical
type: decision
label: Technical Issue?
lane: Support Agent
- id: escalate
type: process
label: Escalate
lane: Technical Team
- id: resolve
type: process
label: Resolve
lane: Support Agent
- id: close
type: end
label: Close Ticket
lane: Customer
connections:
- from: submit
to: review
- from: review
to: technical
- from: technical
to: escalate
label: "Yes"
- from: technical
to: resolve
label: "No"
- from: escalate
to: resolve
- from: resolve
to: closeyaml
title: Customer Service Process
layout: LR
swimlanes:
- Customer
- Support Agent
- Technical Team
nodes:
- id: submit
type: start
label: Submit Ticket
lane: Customer
- id: review
type: process
label: Review Ticket
lane: Support Agent
- id: technical
type: decision
label: Technical Issue?
lane: Support Agent
- id: escalate
type: process
label: Escalate
lane: Technical Team
- id: resolve
type: process
label: Resolve
lane: Support Agent
- id: close
type: end
label: Close Ticket
lane: Customer
connections:
- from: submit
to: review
- from: review
to: technical
- from: technical
to: escalate
label: "Yes"
- from: technical
to: resolve
label: "No"
- from: escalate
to: resolve
- from: resolve
to: closeCLI Usage
CLI使用方法
bash
undefinedbash
undefinedFrom YAML
从YAML生成
python flowchart_gen.py --input process.yaml --output flowchart.png
python flowchart_gen.py --input process.yaml --output flowchart.png
From JSON with custom layout
从JSON生成并自定义布局
python flowchart_gen.py --input process.json --layout LR --output flow.png
python flowchart_gen.py --input process.json --layout LR --output flow.png
With style preset
使用样式预设
python flowchart_gen.py --input workflow.yaml --style business --output workflow.svg
python flowchart_gen.py --input workflow.yaml --style business --output workflow.svg
High resolution
高分辨率导出
python flowchart_gen.py --input process.yaml --output chart.png --dpi 300
undefinedpython flowchart_gen.py --input process.yaml --output chart.png --dpi 300
undefinedCLI Arguments
CLI参数
| Argument | Description | Default |
|---|---|---|
| Input YAML or JSON file | Required |
| Output file path | |
| Layout direction (TB, LR, BT, RL) | |
| Style preset | |
| Image resolution | 96 |
| 参数 | 说明 | 默认值 |
|---|---|---|
| 输入YAML或JSON文件 | 必填 |
| 输出文件路径 | |
| 布局方向(TB, LR, BT, RL) | |
| 样式预设 | |
| 图片分辨率 | 96 |
Examples
示例
Simple Linear Flow
简单线性流程
python
flow = FlowchartGenerator()
flow.start("Start")
flow.process("Step 1", id="s1")
flow.process("Step 2", id="s2")
flow.process("Step 3", id="s3")
flow.end("End")
flow.connect("Start", "s1")
flow.connect("s1", "s2")
flow.connect("s2", "s3")
flow.connect("s3", "End")
flow.generate().save("linear.png")python
flow = FlowchartGenerator()
flow.start("Start")
flow.process("Step 1", id="s1")
flow.process("Step 2", id="s2")
flow.process("Step 3", id="s3")
flow.end("End")
flow.connect("Start", "s1")
flow.connect("s1", "s2")
flow.connect("s2", "s3")
flow.connect("s3", "End")
flow.generate().save("linear.png")Decision Flow
判断分支流程
python
flow = FlowchartGenerator()
flow.start("Start")
flow.input_output("Get Input", id="input")
flow.decision("Valid?", id="check")
flow.process("Process", id="proc")
flow.input_output("Show Error", id="error")
flow.end("End")
flow.connect("Start", "input")
flow.connect("input", "check")
flow.connect("check", "proc", label="Yes")
flow.connect("check", "error", label="No")
flow.connect("proc", "End")
flow.connect("error", "input") # Loop back
flow.style("business")
flow.generate().save("decision_flow.png")python
flow = FlowchartGenerator()
flow.start("Start")
flow.input_output("Get Input", id="input")
flow.decision("Valid?", id="check")
flow.process("Process", id="proc")
flow.input_output("Show Error", id="error")
flow.end("End")
flow.connect("Start", "input")
flow.connect("input", "check")
flow.connect("check", "proc", label="Yes")
flow.connect("check", "error", label="No")
flow.connect("proc", "End")
flow.connect("error", "input") # 循环返回
flow.style("business")
flow.generate().save("decision_flow.png")Login Process
登录流程
python
flow = FlowchartGenerator()
flow.start("Start")
flow.input_output("Enter Credentials", id="creds")
flow.process("Validate", id="validate")
flow.decision("Valid?", id="check")
flow.decision("Attempts < 3?", id="attempts")
flow.process("Login Success", id="success")
flow.input_output("Show Error", id="error")
flow.process("Lock Account", id="lock")
flow.end("End")
flow.connect("Start", "creds")
flow.connect("creds", "validate")
flow.connect("validate", "check")
flow.connect("check", "success", label="Yes")
flow.connect("check", "attempts", label="No")
flow.connect("attempts", "creds", label="Yes")
flow.connect("attempts", "lock", label="No")
flow.connect("success", "End")
flow.connect("lock", "End")
flow.layout("TB")
flow.style("technical")
flow.generate().save("login_flow.png")python
flow = FlowchartGenerator()
flow.start("Start")
flow.input_output("Enter Credentials", id="creds")
flow.process("Validate", id="validate")
flow.decision("Valid?", id="check")
flow.decision("Attempts < 3?", id="attempts")
flow.process("Login Success", id="success")
flow.input_output("Show Error", id="error")
flow.process("Lock Account", id="lock")
flow.end("End")
flow.connect("Start", "creds")
flow.connect("creds", "validate")
flow.connect("validate", "check")
flow.connect("check", "success", label="Yes")
flow.connect("check", "attempts", label="No")
flow.connect("attempts", "creds", label="Yes")
flow.connect("attempts", "lock", label="No")
flow.connect("success", "End")
flow.connect("lock", "End")
flow.layout("TB")
flow.style("technical")
flow.generate().save("login_flow.png")Order Processing with Swimlanes
带泳道的订单处理流程
python
flow = FlowchartGenerator()
flow.swimlanes(["Customer", "System", "Warehouse"])
flow.start("Order Placed", id="start", lane="Customer")
flow.process("Validate Order", id="validate", lane="System")
flow.decision("In Stock?", id="stock", lane="System")
flow.process("Reserve Items", id="reserve", lane="Warehouse")
flow.process("Backorder", id="backorder", lane="Warehouse")
flow.process("Process Payment", id="payment", lane="System")
flow.process("Ship Order", id="ship", lane="Warehouse")
flow.end("Complete", id="end", lane="Customer")
flow.connect("start", "validate")
flow.connect("validate", "stock")
flow.connect("stock", "reserve", label="Yes")
flow.connect("stock", "backorder", label="No")
flow.connect("reserve", "payment")
flow.connect("backorder", "payment")
flow.connect("payment", "ship")
flow.connect("ship", "end")
flow.layout("TB")
flow.generate().save("order_swimlane.png")python
flow = FlowchartGenerator()
flow.swimlanes(["Customer", "System", "Warehouse"])
flow.start("Order Placed", id="start", lane="Customer")
flow.process("Validate Order", id="validate", lane="System")
flow.decision("In Stock?", id="stock", lane="System")
flow.process("Reserve Items", id="reserve", lane="Warehouse")
flow.process("Backorder", id="backorder", lane="Warehouse")
flow.process("Process Payment", id="payment", lane="System")
flow.process("Ship Order", id="ship", lane="Warehouse")
flow.end("Complete", id="end", lane="Customer")
flow.connect("start", "validate")
flow.connect("validate", "stock")
flow.connect("stock", "reserve", label="Yes")
flow.connect("stock", "backorder", label="No")
flow.connect("reserve", "payment")
flow.connect("backorder", "payment")
flow.connect("payment", "ship")
flow.connect("ship", "end")
flow.layout("TB")
flow.generate().save("order_swimlane.png")Node Shapes
节点形状
| Type | Shape | Usage |
|---|---|---|
| Oval/Ellipse | Beginning of flow |
| Oval/Ellipse | End of flow |
| Rectangle | Action or step |
| Diamond | Yes/No branch |
| Parallelogram | Input/Output |
| Circle | Page/flow connector |
| 类型 | 形状 | 用途 |
|---|---|---|
| 椭圆形 | 流程起点 |
| 椭圆形 | 流程终点 |
| 矩形 | 操作或步骤 |
| 菱形 | 是/否分支 |
| 平行四边形 | 输入/输出 |
| 圆形 | 页面/流程连接符 |
Style Presets
样式预设
| Preset | Description |
|---|---|
| Professional blue tones |
| Gray/silver technical look |
| Black and white, clean |
| Vibrant multi-color |
| 预设名 | 说明 |
|---|---|
| 专业蓝色调 |
| 灰色科技风 |
| 黑白简洁风格 |
| 明亮多彩风格 |
Dependencies
依赖
graphviz>=0.20.0
PyYAML>=6.0System Requirement: Graphviz must be installed on the system.
- macOS:
brew install graphviz - Ubuntu:
apt-get install graphviz - Windows: Download from graphviz.org
graphviz>=0.20.0
PyYAML>=6.0系统要求:必须在系统中安装Graphviz。
- macOS:
brew install graphviz - Ubuntu:
apt-get install graphviz - Windows: 从graphviz.org下载安装包
Limitations
局限性
- Complex nested decisions may require manual layout adjustments
- Swimlane rendering depends on graphviz subgraph support
- Very large flowcharts (50+ nodes) may be hard to read
- Limited control over exact node positioning
- 复杂的嵌套判断可能需要手动调整布局
- 泳道渲染依赖graphviz的子图支持
- 超大型流程图(50个以上节点)可读性较差
- 节点精确定位的控制能力有限