Skip to content

Commit a186b81

Browse files
liuziqiboyongjiong
liuziqi
authored andcommitted
feat(extension): 新增渐进连线插件&插件说明文档&增加源码调试示例
1 parent 47700cc commit a186b81

File tree

10 files changed

+889
-9
lines changed

10 files changed

+889
-9
lines changed

examples/feature-examples/.umirc.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ export default defineConfig({
199199
name: 'RectLabelNode 插件',
200200
component: './extensions/rect-label-node',
201201
},
202+
{
203+
path: '/extension/proximity-connect',
204+
name: 'Proximity Connect 插件',
205+
component: './extensions/proximity-connect',
206+
},
202207
],
203208
},
204209
{

examples/feature-examples/src/pages/extensions/control/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useEffect, useRef } from 'react'
66
import styles from './index.less'
77

88
import '@logicflow/core/es/index.css'
9-
// import '@logicflow/extension/es/index.css'
9+
import '@logicflow/extension/es/index.css'
1010

1111
const config: Partial<LogicFlow.Options> = {
1212
isSilentMode: false,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.viewport {
2+
position: relative;
3+
height: 80vh;
4+
overflow: hidden;
5+
}
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
import LogicFlow from '@logicflow/core'
2+
import { ProximityConnect } from '@logicflow/extension'
3+
4+
import {
5+
Space,
6+
Input,
7+
Button,
8+
Card,
9+
Divider,
10+
Row,
11+
Col,
12+
Form,
13+
Switch,
14+
} from 'antd'
15+
import { useEffect, useRef, useState } from 'react'
16+
import styles from './index.less'
17+
18+
import '@logicflow/core/es/index.css'
19+
import '@logicflow/extension/es/index.css'
20+
21+
const config: Partial<LogicFlow.Options> = {
22+
isSilentMode: false,
23+
stopScrollGraph: true,
24+
stopZoomGraph: true,
25+
style: {
26+
rect: {
27+
rx: 5,
28+
ry: 5,
29+
strokeWidth: 2,
30+
},
31+
circle: {
32+
fill: '#f5f5f5',
33+
stroke: '#666',
34+
},
35+
ellipse: {
36+
fill: '#dae8fc',
37+
stroke: '#6c8ebf',
38+
},
39+
polygon: {
40+
fill: '#d5e8d4',
41+
stroke: '#82b366',
42+
},
43+
diamond: {
44+
fill: '#ffe6cc',
45+
stroke: '#d79b00',
46+
},
47+
text: {
48+
color: '#b85450',
49+
fontSize: 12,
50+
},
51+
},
52+
}
53+
54+
const data = {
55+
nodes: [
56+
{
57+
id: '1',
58+
type: 'rect',
59+
x: 150,
60+
y: 100,
61+
text: '矩形',
62+
},
63+
{
64+
id: '2',
65+
type: 'circle',
66+
x: 550,
67+
y: 100,
68+
text: '圆形',
69+
},
70+
{
71+
id: '3',
72+
type: 'ellipse',
73+
x: 950,
74+
y: 100,
75+
text: '椭圆',
76+
},
77+
{
78+
id: '4',
79+
type: 'polygon',
80+
x: 150,
81+
y: 350,
82+
text: '多边形',
83+
},
84+
{
85+
id: '5',
86+
type: 'diamond',
87+
x: 550,
88+
y: 350,
89+
text: '菱形',
90+
},
91+
{
92+
id: '6',
93+
type: 'text',
94+
x: 950,
95+
y: 350,
96+
text: '纯文本节点',
97+
},
98+
{
99+
id: '7',
100+
type: 'html',
101+
x: 150,
102+
y: 600,
103+
text: 'html节点',
104+
},
105+
],
106+
}
107+
108+
export default function ProximityConnectExtension() {
109+
const lfRef = useRef<LogicFlow>()
110+
const containerRef = useRef<HTMLDivElement>(null)
111+
const [distance, setDistance] = useState<number>(100)
112+
const [reverse, setReverse] = useState<boolean>(false)
113+
const [enable, setEnable] = useState<boolean>(true)
114+
useEffect(() => {
115+
if (!lfRef.current) {
116+
const lf = new LogicFlow({
117+
...config,
118+
container: containerRef.current as HTMLElement,
119+
// container: document.querySelector('#graph') as HTMLElement,
120+
grid: {
121+
size: 10,
122+
},
123+
plugins: [ProximityConnect],
124+
pluginsOptions: {
125+
proximityConnect: {
126+
enable,
127+
distance,
128+
reverseDirection: reverse,
129+
},
130+
},
131+
})
132+
133+
lf.render(data)
134+
lfRef.current = lf
135+
}
136+
}, [])
137+
138+
return (
139+
<Card title="LogicFlow Extension - Control">
140+
<Row>
141+
<Col span={8}>
142+
<Form.Item label="连线阈值:">
143+
<Input
144+
value={distance}
145+
style={{ width: '180px' }}
146+
onInput={(e) => {
147+
setDistance(+e.target.value)
148+
}}
149+
/>
150+
<Button
151+
type="primary"
152+
onClick={() => {
153+
if (lfRef.current) {
154+
;(
155+
lfRef.current.extension.proximityConnect as ProximityConnect
156+
).setThresholdDistance(distance)
157+
}
158+
}}
159+
>
160+
Submit
161+
</Button>
162+
</Form.Item>
163+
</Col>
164+
<Col span={8}>
165+
<Form.Item label="连线方向:">
166+
<Switch
167+
value={reverse}
168+
checkedChildren="最近节点 → 拖拽节点"
169+
unCheckedChildren="拖拽节点 → 最近节点"
170+
onChange={(checked) => {
171+
setReverse(checked)
172+
if (lfRef.current) {
173+
;(
174+
lfRef.current.extension.proximityConnect as ProximityConnect
175+
).setReverseDirection(checked)
176+
}
177+
}}
178+
/>
179+
</Form.Item>
180+
</Col>
181+
<Col span={8}>
182+
<Form.Item label="启用状态:">
183+
<Switch
184+
value={enable}
185+
checkedChildren="启用"
186+
unCheckedChildren="禁用"
187+
onChange={(checked) => {
188+
setEnable(checked)
189+
if (lfRef.current) {
190+
;(
191+
lfRef.current.extension.proximityConnect as ProximityConnect
192+
).setEnable(checked)
193+
}
194+
}}
195+
/>
196+
</Form.Item>
197+
</Col>
198+
</Row>
199+
<Space.Compact style={{ width: '100%' }}></Space.Compact>
200+
<Divider />
201+
<div ref={containerRef} id="graph" className={styles.viewport}></div>
202+
</Card>
203+
)
204+
}

packages/extension/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export * from './tools/label'
1919
export * from './tools/snapshot'
2020
export * from './tools/flow-path'
2121
export * from './tools/auto-layout'
22+
export * from './tools/proximity-connect'
2223

2324
// Component -> 流程图中交互组件
2425
export * from './components/control'

0 commit comments

Comments
 (0)