Skip to content

Commit aee30e9

Browse files
chengweiwDymoneLewis
authored andcommitted
feat: 补充文档和示例
1 parent 5680412 commit aee30e9

File tree

20 files changed

+1925
-13
lines changed

20 files changed

+1925
-13
lines changed

examples/feature-examples/src/pages/layout/custom/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ export default function SelectionSelectExample() {
530530
}
531531

532532
const getData = () => {
533-
console.log('当前data数据', lfRef.current?.getGraphData())
533+
console.log('当前data数据', lfRef.current?.getGraphRawData())
534534
}
535535

536536
// 处理配置项变更

examples/feature-examples/src/pages/layout/custom/registerNodeConfig/nodes/baseNodeComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { SmallDashOutlined } from '@ant-design/icons' // 引入更多图标
77
export default function BaseNodeComponent(props: { node: any; graph: any }) {
88
console.log('组件props', { ...props })
99
const { node, graph } = props
10-
const data = node.getData()
10+
const data = graph.getNodeModelById(node.id)
1111
if (!data.properties) data.properties = {}
1212

1313
const updateJudgeNode = function () {

examples/feature-examples/src/pages/layout/default/index.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -909,11 +909,7 @@ export default function SelectionSelectExample() {
909909
}
910910

911911
const getData = () => {
912-
console.log(
913-
'当前data数据',
914-
lfRef.current?.getDataById('b1bb3a79-0d8e-4d0b-a351-c742d70aab0f')
915-
?.properties,
916-
)
912+
console.log('当前data数据', lfRef.current?.getGraphRawData())
917913
}
918914

919915
// 处理配置项变更

examples/feature-examples/src/pages/layout/default/registerNodeConfig/nodes/baseNodeComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { SmallDashOutlined } from '@ant-design/icons' // 引入更多图标
44
export default function BaseNodeComponent(props: { node: any; graph: any }) {
55
console.log('组件props', props)
66
const { node, graph } = props
7-
const data = node.getData()
7+
const data = graph.getNodeModelById(node.id)
88
if (!data.properties) data.properties = {}
99

1010
const addBranch = () => {

pnpm-lock.yaml

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
nav: Guide
3+
group:
4+
title: Plug-in functionality
5+
order: 3
6+
title: Automatic Layout
7+
order: 7
8+
toc: content
9+
tag: Enhancement
10+
---
11+
12+
In complex flowcharts, manually arranging nodes and edges can be both time-consuming and difficult to keep tidy. LogicFlow provides an automatic layout plugin that can automatically calculate node positions and edge paths, resulting in structured and visually appealing diagrams.
13+
14+
## Installation
15+
16+
```shell
17+
# npm
18+
npm install @logicflow/layout
19+
20+
# yarn
21+
yarn add @logicflow/layout
22+
23+
# pnpm
24+
pnpm add @logicflow/layout
25+
```
26+
27+
## Basic Usage
28+
29+
### Register the Plugin
30+
31+
Like other LogicFlow plugins, Layout supports both global and local registration:
32+
33+
```tsx | pure
34+
import LogicFlow from "@logicflow/core";
35+
import { Dagre } from "@logicflow/layout";
36+
37+
// Global registration
38+
LogicFlow.use(Dagre);
39+
40+
// Local registration
41+
const lf = new LogicFlow({
42+
container: document.getElementById('app'),
43+
plugins: [Dagre]
44+
});
45+
```
46+
47+
### Apply Layout
48+
49+
After registration, you can access the dagre plugin through the LogicFlow instance's extension property:
50+
51+
```tsx | pure
52+
// Use default configuration
53+
lf.extension.dagre.layout();
54+
55+
// Use custom configuration
56+
lf.extension.dagre.layout({
57+
rankdir: 'TB', // Top-to-bottom layout direction
58+
align: 'UL', // Upper-left alignment
59+
nodesep: 60, // Node spacing
60+
ranksep: 70 // Rank spacing
61+
});
62+
```
63+
64+
## Layout Configuration Options
65+
66+
You can customize the appearance and behavior of the layout through various options:
67+
68+
| Parameter | Type | Default | Description |
69+
|-----------|------|---------|-------------|
70+
| rankdir | string | 'LR' | Layout direction: 'LR'(left to right), 'TB'(top to bottom), 'BT'(bottom to top), 'RL'(right to left) |
71+
| align | string | 'UL' | Node alignment: 'UL'(upper left), 'UR'(upper right), 'DL'(down left), 'DR'(down right) |
72+
| nodesep | number | 100 | Horizontal spacing between nodes (pixels) |
73+
| ranksep | number | 150 | Vertical spacing between ranks (pixels) |
74+
| marginx | number | 120 | Horizontal margin of the graph (pixels) |
75+
| marginy | number | 120 | Vertical margin of the graph (pixels) |
76+
| ranker | string | 'tight-tree' | Ranking algorithm: 'network-simplex', 'tight-tree', 'longest-path' |
77+
| edgesep | number | 10 | Horizontal spacing between edges (pixels) |
78+
| acyclicer | string | undefined | If set to 'greedy', uses a greedy heuristic for finding a feedback arc set for making the graph acyclic |
79+
| isDefaultAnchor | boolean | false | Whether to use default anchors: when true, automatically adjusts edge anchors and calculates edge paths based on layout direction |
80+
81+
## Advanced Features
82+
83+
### Auto-fit View After Layout
84+
85+
After adjusting the layout, you may need to adjust the view to show all nodes:
86+
87+
```tsx | pure
88+
// First apply the layout
89+
lf.extension.dagre.layout();
90+
// Then fit the view
91+
lf.fitView();
92+
```
93+
94+
## Live Demonstration
95+
96+
### Default Anchors
97+
98+
If nodes use LogicFlow's default anchors (i.e., top, bottom, left, and right anchors), and anchor information doesn't carry business meaning, you can set isDefaultAnchor to true to adjust connection start and end anchor positions during layout.
99+
100+
<code id="react-portal-1" src="@/src/tutorial/extension/layout"></code>
101+
102+
### Custom Anchors
103+
104+
If nodes use custom anchors, or if anchors have actual business meaning, isDefaultAnchor is false by default, which means the layout will not adjust the connection's start and end anchors.
105+
106+
<code id="react-portal-2" src="@/src/tutorial/extension/layout/custom"></code>
107+
108+
## Usage Recommendations
109+
110+
1. **Complex Graphs**: For large or complex flowcharts, use automatic layout to generate an initial arrangement, then make manual adjustments
111+
2. **Dynamic Updates**: Apply layout after adding/removing nodes to keep the graph tidy
112+
3. **Direction Selection**: Choose a suitable layout direction based on the actual meaning of your business process
113+
4. **Parameter Adjustment**: Find the layout that best suits your diagram by adjusting node spacing and rank spacing
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
nav: 指南
3+
group:
4+
title: 插件功能
5+
order: 3
6+
title: 自动布局 (Layout)
7+
order: 7
8+
toc: content
9+
tag: 增强
10+
---
11+
12+
在复杂的流程图中,手动排列节点和边缘可能既耗时又难以保持整洁。LogicFlow 提供了自动布局插件,能够自动计算节点位置和边的路径,使图表呈现出结构化且美观的效果。
13+
14+
## 安装
15+
16+
```shell
17+
# npm
18+
npm install @logicflow/layout
19+
20+
# yarn
21+
yarn add @logicflow/layout
22+
23+
# pnpm
24+
pnpm add @logicflow/layout
25+
```
26+
27+
## 基本使用
28+
29+
### 注册插件
30+
31+
与其他 LogicFlow 插件一样,Layout 支持全局和局部两种注册方式:
32+
33+
```tsx | pure
34+
import LogicFlow from "@logicflow/core";
35+
import { Dagre } from "@logicflow/layout";
36+
37+
// 全局注册
38+
LogicFlow.use(Dagre);
39+
40+
// 局部注册
41+
const lf = new LogicFlow({
42+
container: document.getElementById('app'),
43+
plugins: [Dagre]
44+
});
45+
```
46+
47+
### 应用布局
48+
49+
注册完成后,您可以通过 LogicFlow 实例的 extension 属性访问 dagre 插件:
50+
51+
```tsx | pure
52+
// 使用默认配置
53+
lf.extension.dagre.layout();
54+
55+
// 使用自定义配置
56+
lf.extension.dagre.layout({
57+
rankdir: 'TB', // 从上到下的布局方向
58+
align: 'UL', // 上左对齐
59+
nodesep: 60, // 节点间距
60+
ranksep: 70 // 层级间距
61+
});
62+
```
63+
64+
## 布局配置选项
65+
66+
通过配置不同的选项,您可以自定义布局的外观和行为。以下是支持的选项:
67+
68+
| 参数名 | 类型 | 默认值 | 说明 |
69+
|-------|-----|-------|------|
70+
| rankdir | string | 'LR' | 布局方向,'LR'(左到右), 'TB'(上到下), 'BT'(下到上), 'RL'(右到左) |
71+
| align | string | 'UL' | 节点对齐方式,'UL'(上左), 'UR'(上右), 'DL'(下左), 'DR'(下右) |
72+
| nodesep | number | 100 | 节点间的水平间距(像素) |
73+
| ranksep | number | 150 | 层级间的垂直间距(像素) |
74+
| marginx | number | 120 | 图的水平边距(像素) |
75+
| marginy | number | 120 | 图的垂直边距(像素) |
76+
| ranker | string | 'tight-tree' | 排名算法,'network-simplex', 'tight-tree', 'longest-path' |
77+
| edgesep | number | 10 | 边之间的水平间距(像素) |
78+
| acyclicer | string | undefined | 如果设置为'greedy',使用贪心算法查找反馈弧集,用于使图变为无环图 |
79+
| isDefaultAnchor | boolean | false | 是否使用默认锚点:true表示会自动调整连线锚点,根据布局方向计算边的路径 |
80+
81+
## 高级功能
82+
83+
### 应用布局后自动适配视图
84+
85+
布局调整后,您可能需要调整视图以显示所有节点:
86+
87+
```tsx | pure
88+
// 先应用布局
89+
lf.extension.dagre.layout();
90+
// 然后适配视图
91+
lf.fitView();
92+
```
93+
94+
## 实际效果演示
95+
96+
### 默认锚点
97+
98+
如果节点是Logicflow的默认锚点(即上下左右4个锚点),且锚点信息并不具备业务含义。那么通过设置isDefaultAnchor 为true,就可以在布局中调整连线起终点锚点的位置。
99+
100+
<code id="react-portal-1" src="@/src/tutorial/extension/layout"></code>
101+
102+
### 自定义锚点
103+
104+
如果节点的锚点是自定义的,或者锚点是具备实际业务含义的,isDefaultAnchor 默认为false,那么布局中就不会调整连线的起终点锚点。
105+
106+
<code id="react-portal-2" src="@/src/tutorial/extension/layout/custom"></code>
107+
108+
## 使用建议
109+
110+
1. **复杂图形**:对于大型或复杂的流程图,先使用自动布局生成初始排列,然后进行手动微调
111+
2. **动态更新**:在添加/删除节点后应用布局,使图形保持整洁
112+
3. **方向选择**:根据业务流程的实际含义选择合适的布局方向
113+
4. **参数调整**:通过调整节点间距和层级间距,找到最适合您图表的布局

sites/docs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"@logicflow/dumi-theme-simple": "^1.0.0",
3535
"@logicflow/extension": "workspace:*",
3636
"@logicflow/react-node-registry": "workspace:*",
37+
"@logicflow/layout": "workspace:*",
3738
"antd": "^5.25.0",
3839
"insert-css": "^2.0.0",
3940
"react": "18.2.0",

0 commit comments

Comments
 (0)