Skip to content

Commit e83b998

Browse files
author
lvhongxin
committed
feat(docs): add docs and example for InserNodeInPolyline
1 parent 07ae536 commit e83b998

File tree

5 files changed

+124
-0
lines changed

5 files changed

+124
-0
lines changed

docs/.vuepress/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const guide = [
3636
'extension/adapter',
3737
'extension/bpmn-element',
3838
'extension/extension-node-resize',
39+
'extension/extension-insert-node-in-polyline.md',
3940
{
4041
title: '组件',
4142
collapsable: true,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# 连线上插入节点
2+
## 功能
3+
拖动节点到连线中间,自动成为连线中间的点。
4+
举例:存在一条节点A到节点B的折线E,拖拽一个节点N到折线E上,当节点N的中心点恰好在折线E的路径上时松开鼠标,这时节点N就成为A与B的中间节点,原来的连线E被删除,生成两条新的折线,分别是A到N,N到B。示例如下。
5+
<example href="/examples/#/extension/InserNodeInPolyline" :height="450" ></example>
6+
7+
## 支持
8+
目前仅支持折线
9+
10+
## 使用
11+
```js
12+
import LogicFlow from '@logicflow/core';
13+
import { InsertNodeInPolyline } from '@logicflow/extension';
14+
import '@logicflow/extension/lib/style/index.css'
15+
LogicFlow.use(InsertNodeInPolyline);
16+
```
17+
## 个性化配置
18+
节点拖拽分为2种情况:
19+
- 第一种是从控制面板拖拽到画布中,调用Dnd的Api进行节点添加,本插件默认支持。关闭此功能设置如下:
20+
```js
21+
InsertNodeInPolyline.dndAdd = false;
22+
```
23+
- 第二种是画布中的游离节点,即与其他节点没有连线的节点,拖拽调整位置到连线上,本插件默认支持。关闭此功能设置如下:
24+
```js
25+
InsertNodeInPolyline.dropAdd = false;
26+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.circle .lf-dnd-shape {
2+
display: inline-block;
3+
width: 25px;
4+
height: 25px;
5+
border: 2px solid black;
6+
border-radius: 20px;
7+
}
8+
.rect .lf-dnd-shape {
9+
display: inline-block;
10+
width: 25px;
11+
height: 25px;
12+
border: 2px solid black;
13+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import React, { useEffect } from 'react';
2+
import LogicFlow from '@logicflow/core';
3+
import { InsertNodeInPolyline, DndPanel, SelectionSelect } from '@logicflow/extension';
4+
import ExampleHeader from '../../../components/example-header';
5+
import 'antd/lib/button/style/index.css';
6+
import './index.css';
7+
8+
const config = {
9+
grid: {
10+
type: 'dot',
11+
size: 20,
12+
},
13+
}
14+
15+
const data = {
16+
nodes: [
17+
{
18+
id: 10,
19+
type: 'rect',
20+
x: 150,
21+
y: 70,
22+
text: '矩形'
23+
},
24+
{
25+
id: 20,
26+
type: 'circle',
27+
x: 400,
28+
y: 70,
29+
text: '圆形'
30+
}
31+
],
32+
edges: [
33+
{
34+
type: 'polyline',
35+
sourceNodeId: 10,
36+
targetNodeId: 20,
37+
}
38+
]
39+
};
40+
41+
const contentStyle = {
42+
display: 'flex',
43+
alignItems: 'center'
44+
}
45+
46+
let lf: LogicFlow;
47+
48+
export default function SnapshotExample() {
49+
50+
useEffect(() => {
51+
LogicFlow.use(InsertNodeInPolyline);
52+
LogicFlow.use(DndPanel);
53+
LogicFlow.use(SelectionSelect);
54+
lf = new LogicFlow({
55+
...config,
56+
container: document.querySelector('#graph') as HTMLElement
57+
});
58+
lf.setPatternItems([
59+
{
60+
type: 'circle',
61+
text: '圆形',
62+
className: 'circle'
63+
},
64+
{
65+
type: 'rect',
66+
text: '矩形',
67+
className: 'rect'
68+
},
69+
]);
70+
lf.render(data)
71+
}, []);
72+
73+
return (
74+
<>
75+
<ExampleHeader contentStyle={contentStyle}>
76+
拖拽节点到线中间进行节点插入:
77+
</ExampleHeader>
78+
<div id="graph" className="viewport" />
79+
</>
80+
)
81+
}
82+

examples/src/routes.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import Approve from './pages/usage/approve';
3131
import ApprovePreview from './pages/usage/approvePreview';
3232
import BpmnElements from './pages/extension/bpmn/Elements';
3333
import AdapterExample from './pages/extension/adapter';
34+
import InserNodeInPolyline from './pages/extension/InserNodeInPolyline';
3435

3536

3637
export default (
@@ -62,6 +63,7 @@ export default (
6263
<Route path="/extension/bpmn-elements" exact component={BpmnElements} />
6364
<Route path="/extension/adapter" exact component={AdapterExample} />
6465
<Route path="/extension/node-resize" exact component={NodeResizeExample} />
66+
<Route path="/extension/InserNodeInPolyline" exact component={InserNodeInPolyline} />
6567
<Route path="/usage/bpmn" exact component={Bpmn} />
6668
<Route path="/usage/approve" exact component={Approve} />
6769
<Route path="/usage/approve/preview" exact component={ApprovePreview} />

0 commit comments

Comments
 (0)