File tree Expand file tree Collapse file tree 3 files changed +145
-0
lines changed
examples/feature-examples
src/pages/extensions/selection-select Expand file tree Collapse file tree 3 files changed +145
-0
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,11 @@ export default defineConfig({
87
87
name : 'Group 插件' ,
88
88
component : './extensions/group' ,
89
89
} ,
90
+ {
91
+ path : '/extension/selection-select' ,
92
+ name : 'SelectionSelect 插件' ,
93
+ component : './extensions/selection-select' ,
94
+ } ,
90
95
] ,
91
96
} ,
92
97
] ,
Original file line number Diff line number Diff line change
1
+ .viewport {
2
+ position : relative ;
3
+ height : 80vh ;
4
+ overflow : hidden ;
5
+ }
Original file line number Diff line number Diff line change
1
+ import LogicFlow from '@logicflow/core'
2
+ import { SelectionSelect } from '@logicflow/extension'
3
+
4
+ import { Card , Button } from 'antd'
5
+ import { useEffect , useRef } from 'react'
6
+ import styles from './index.less'
7
+
8
+ import '@logicflow/core/es/index.css'
9
+ import '@logicflow/extension/es/index.css'
10
+
11
+ const config : Partial < LogicFlow . Options > = {
12
+ isSilentMode : false ,
13
+ stopScrollGraph : true ,
14
+ stopZoomGraph : true ,
15
+ style : {
16
+ rect : {
17
+ rx : 5 ,
18
+ ry : 5 ,
19
+ strokeWidth : 2 ,
20
+ } ,
21
+ circle : {
22
+ fill : '#f5f5f5' ,
23
+ stroke : '#666' ,
24
+ } ,
25
+ ellipse : {
26
+ fill : '#dae8fc' ,
27
+ stroke : '#6c8ebf' ,
28
+ } ,
29
+ polygon : {
30
+ fill : '#d5e8d4' ,
31
+ stroke : '#82b366' ,
32
+ } ,
33
+ diamond : {
34
+ fill : '#ffe6cc' ,
35
+ stroke : '#d79b00' ,
36
+ } ,
37
+ text : {
38
+ color : '#b85450' ,
39
+ fontSize : 12 ,
40
+ } ,
41
+ } ,
42
+ }
43
+
44
+ const data = {
45
+ nodes : [
46
+ {
47
+ id : '1' ,
48
+ type : 'rect' ,
49
+ x : 150 ,
50
+ y : 100 ,
51
+ text : '矩形' ,
52
+ } ,
53
+ {
54
+ id : '2' ,
55
+ type : 'circle' ,
56
+ x : 350 ,
57
+ y : 100 ,
58
+ text : '圆形' ,
59
+ } ,
60
+ {
61
+ id : '3' ,
62
+ type : 'ellipse' ,
63
+ x : 550 ,
64
+ y : 100 ,
65
+ text : '椭圆' ,
66
+ } ,
67
+ {
68
+ id : '4' ,
69
+ type : 'polygon' ,
70
+ x : 150 ,
71
+ y : 250 ,
72
+ text : '多边形' ,
73
+ } ,
74
+ {
75
+ id : '5' ,
76
+ type : 'diamond' ,
77
+ x : 350 ,
78
+ y : 250 ,
79
+ text : '菱形' ,
80
+ } ,
81
+ {
82
+ id : '6' ,
83
+ type : 'text' ,
84
+ x : 550 ,
85
+ y : 250 ,
86
+ text : '纯文本节点' ,
87
+ } ,
88
+ {
89
+ id : '7' ,
90
+ type : 'html' ,
91
+ x : 150 ,
92
+ y : 400 ,
93
+ text : 'html节点' ,
94
+ } ,
95
+ ] ,
96
+ }
97
+
98
+ export default function SelectionSelectExtension ( ) {
99
+ const lfRef = useRef < LogicFlow > ( )
100
+ const containerRef = useRef < HTMLDivElement > ( null )
101
+
102
+ useEffect ( ( ) => {
103
+ if ( ! lfRef . current ) {
104
+ const lf = new LogicFlow ( {
105
+ ...config ,
106
+ container : containerRef . current as HTMLElement ,
107
+ grid : {
108
+ size : 20 ,
109
+ } ,
110
+ plugins : [ SelectionSelect ] ,
111
+ } )
112
+
113
+ lf . render ( data )
114
+ lfRef . current = lf
115
+ }
116
+ } , [ ] )
117
+
118
+ const handleOpenSelectionSelect = ( ) => {
119
+ if ( lfRef . current ) {
120
+ const lf = lfRef . current
121
+ const selectionSelect = lf . extension . selectionSelect as SelectionSelect
122
+ selectionSelect . openSelectionSelect ( )
123
+ lf . once ( 'selection:selected' , ( ) => {
124
+ selectionSelect . closeSelectionSelect ( )
125
+ } )
126
+ }
127
+ }
128
+
129
+ return (
130
+ < Card title = "LogicFlow Extension - SelectionSelect" >
131
+ < Button onClick = { handleOpenSelectionSelect } > 开启选区</ Button >
132
+ < div ref = { containerRef } id = "graph" className = { styles . viewport } > </ div >
133
+ </ Card >
134
+ )
135
+ }
You can’t perform that action at this time.
0 commit comments