File tree Expand file tree Collapse file tree 22 files changed +388
-27
lines changed
pages/advance/custom-node/html Expand file tree Collapse file tree 22 files changed +388
-27
lines changed Original file line number Diff line number Diff line change @@ -419,3 +419,53 @@ lf.render({
419
419
420
420
在上面的代码中, ` getShape ` 方法返回了一个包含图标的标签,Logic Flow 拿到这个返回值后会直接在 ` graph ` 中进行渲染。SVG 元素需要 model 中的实时数据才可以正常显示并使用,现在我们可以通过[getAttributes](/guide/advance/customNode.html#getattributes)方法获取到 model 中的[数据属性](/api/nodeApi.md#数据属性)和[样式属性](/api/nodeApi.html#样式属性)。
421
421
422
+ ## 自定义HTML节点
423
+
424
+ LogicFlow内置了基础的HTML节点,我们可以利用LogicFlow的自定义机制,实现各种形态的HTML节点,而且HTML节点内部可以使用任意框架进行渲染。
425
+
426
+ <example
427
+ :height="280"
428
+ iframeId="iframe-6"
429
+ href="/examples/#/advance/custom-node/html"
430
+ />
431
+
432
+ ` ` ` ts
433
+ class UmlModel extends HtmlNodeModel {
434
+ setAttributes() {
435
+ this .text .editable = false ; // 禁止节点文本编辑
436
+ // 设置节点宽高和锚点
437
+ const width = 200 ;
438
+ const height = 130 ;
439
+ this .width = width ;
440
+ this .height = height ;
441
+ this .anchorsOffset = [
442
+ [width / 2 , 0 ],
443
+ [0 , height / 2 ],
444
+ [- width / 2 , 0 ],
445
+ [0 , - height / 2 ],
446
+ ]
447
+ }
448
+ }
449
+ class UmlNode extends HtmlNode {
450
+ // 重新setHtml方法,想html节点插入任何你想要插入的节点
451
+ setHtml(rootEl : HTMLElement ) {
452
+ const el = document .createElement (' div' );
453
+ el .className = ' uml-wrapper' ;
454
+ const html = `
455
+ <div>
456
+ <div class="uml-head">Head</div>
457
+ <div class="uml-body">
458
+ <div>+ $Name</div>
459
+ <div>+ $Body</div>
460
+ </div>
461
+ <div class="uml-footer">
462
+ <div>+ setHead(Head $head)</div>
463
+ <div>+ setBody(Body $body)</div>
464
+ </div>
465
+ </div>
466
+ `
467
+ el .innerHTML = html ;
468
+ rootEl .appendChild (el );
469
+ }
470
+ }
471
+ ` ` `
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ LogicFlow 的内置节点包括:
7
7
- 菱形(diamond)
8
8
- 多边形(polygon)
9
9
- 文本(text)
10
+ - html节点(html)
10
11
11
12
## 节点属性
12
13
@@ -59,6 +60,11 @@ type Point = [number, number]
59
60
| fontSize | number | ✅ | 字体大小 |
60
61
| fontFamily | string | ✅ | 字体类型 |
61
62
| fontWeight | number / string | ✅ | 字体粗细 |
63
+
64
+ ### html节点
65
+
66
+ html节点无特殊属性,定制效果需要去view中自己控制。详情请参考自定义节点。
67
+
62
68
## 创建节点
63
69
LogicFlow 支持三种创建节点的方式:
64
70
- 数据配置
Original file line number Diff line number Diff line change 3
3
All notable changes to this project will be documented in this file.
4
4
See [ Conventional Commits] ( https://conventionalcommits.org ) for commit guidelines.
5
5
6
+ ## [ 0.5.14] ( https://github.com/towersxu/logicflow/compare/examples@0.5.11...examples@0.5.14 ) (2021-06-16)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * ** docs:** docs fix ([ 13d29e4] ( https://github.com/towersxu/logicflow/commit/13d29e49fa47189e3e0953a5cdd1ea26c4647ced ) )
12
+ * ** textension:** rename function getShapeReise to getResizeShape ([ 88d6d53] ( https://github.com/towersxu/logicflow/commit/88d6d531dd6232a2abb952468fae0086813bce78 ) )
13
+
14
+
15
+ ### Features
16
+
17
+ * ** docs:** add docs and example for InserNodeInPolyline ([ e83b998] ( https://github.com/towersxu/logicflow/commit/e83b998c33b6354463f08d4cd45eac4103138e66 ) )
18
+ * ** extension:** node resize update ([ 5434840] ( https://github.com/towersxu/logicflow/commit/5434840692f741dfb71e385e07f1fe539f3355b1 ) )
19
+
20
+
21
+
22
+
23
+
6
24
## [ 0.5.13] ( https://github.com/towersxu/logicflow/compare/examples@0.5.11...examples@0.5.13 ) (2021-06-09)
7
25
8
26
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " examples" ,
3
- "version" : " 0.5.13 " ,
3
+ "version" : " 0.5.14 " ,
4
4
"private" : true ,
5
5
"dependencies" : {
6
6
"@ant-design/icons" : " ^4.3.0" ,
7
7
"@babel/core" : " 7.12.3" ,
8
- "@logicflow/core" : " ^0.4.13 " ,
9
- "@logicflow/extension" : " ^0.4.13 " ,
8
+ "@logicflow/core" : " ^0.4.14 " ,
9
+ "@logicflow/extension" : " ^0.4.14 " ,
10
10
"@pmmmwh/react-refresh-webpack-plugin" : " 0.4.2" ,
11
11
"@svgr/webpack" : " 5.4.0" ,
12
12
"@testing-library/jest-dom" : " ^5.11.4" ,
Original file line number Diff line number Diff line change
1
+ import React , { useEffect } from 'react' ;
2
+ import LogicFlow from '@logicflow/core' ;
3
+ import ExampleHeader from '../../../../components/example-header' ;
4
+ import Uml from './uml' ;
5
+
6
+ const config = {
7
+ stopScrollGraph : true ,
8
+ stopZoomGraph : true ,
9
+ style : {
10
+ circle : {
11
+ r : 40
12
+ }
13
+ }
14
+ } ;
15
+
16
+ const data = {
17
+ nodes : [
18
+ {
19
+ id : 10 ,
20
+ type : 'uml' ,
21
+ x : 150 ,
22
+ y : 90 ,
23
+ } ,
24
+ ]
25
+ } ;
26
+
27
+ export default function CustomNodeAnchorExample ( ) {
28
+
29
+ useEffect ( ( ) => {
30
+ const lf = new LogicFlow ( {
31
+ ...config ,
32
+ container : document . querySelector ( '#graph_html' ) as HTMLElement
33
+ } ) ;
34
+ lf . register ( Uml ) ;
35
+ lf . render ( data ) ;
36
+ } , [ ] ) ;
37
+
38
+ return (
39
+ < >
40
+ < ExampleHeader
41
+ content = "自定义HTML节点"
42
+ githubPath = "/advance/custom-node/html/index.tsx"
43
+ />
44
+ < div id = "graph_html" className = "viewport" />
45
+ </ >
46
+ )
47
+ }
Original file line number Diff line number Diff line change
1
+ .uml-wrapper {
2
+ background : # 68FCE2 ;
3
+ width : 100% ;
4
+ height : 100% ;
5
+ border-radius : 10px ;
6
+ border : 2px solid # 838382 ;
7
+ box-sizing : border-box;
8
+ }
9
+ .uml-head {
10
+ text-align : center;
11
+ line-height : 30px ;
12
+ font-size : 16px ;
13
+ font-weight : bold;
14
+ }
15
+ .uml-body {
16
+ border-top : 1px solid # 838382 ;
17
+ border-bottom : 1px solid # 838382 ;
18
+ padding : 5px 10px ;
19
+ font-size : 12px ;
20
+ }
21
+ .uml-footer {
22
+ padding : 5px 10px ;
23
+ font-size : 14px ;
24
+ }
Original file line number Diff line number Diff line change
1
+ import { HtmlNodeModel , HtmlNode } from '@logicflow/core' ;
2
+ // import HtmlNode from '@logicflow/core';
3
+ import './uml.css' ;
4
+
5
+ class UmlModel extends HtmlNodeModel {
6
+ setAttributes ( ) {
7
+ this . text . editable = false ;
8
+ const width = 200 ;
9
+ const height = 130 ;
10
+ this . width = width ;
11
+ this . height = height ;
12
+ this . anchorsOffset = [
13
+ [ width / 2 , 0 ] ,
14
+ [ 0 , height / 2 ] ,
15
+ [ - width / 2 , 0 ] ,
16
+ [ 0 , - height / 2 ] ,
17
+ ]
18
+ }
19
+ }
20
+ class UmlNode extends HtmlNode {
21
+ setHtml ( rootEl : HTMLElement ) {
22
+ console . log ( 111 )
23
+ const el = document . createElement ( 'div' ) ;
24
+ el . className = 'uml-wrapper' ;
25
+ const html = `
26
+ <div>
27
+ <div class="uml-head">Head</div>
28
+ <div class="uml-body">
29
+ <div>+ $Name</div>
30
+ <div>+ $Body</div>
31
+ </div>
32
+ <div class="uml-footer">
33
+ <div>+ setHead(Head $head)</div>
34
+ <div>+ setBody(Body $body)</div>
35
+ </div>
36
+ </div>
37
+ `
38
+ el . innerHTML = html ;
39
+ rootEl . appendChild ( el ) ;
40
+ }
41
+ }
42
+
43
+ const uml = {
44
+ type : 'uml' ,
45
+ view : UmlNode ,
46
+ model : UmlModel
47
+ }
48
+ export default uml ;
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import Anchor from './pages/advance/custom-node/anchor';
25
25
import Triangle from './pages/advance/custom-node/triangle' ;
26
26
import Rule from './pages/advance/custom-node/rule' ;
27
27
import Shape from './pages/advance/custom-node/shape' ;
28
+ import Html from './pages/advance/custom-node/html' ;
28
29
import Process from './pages/advance/custom-edge' ;
29
30
import Event from './pages/advance/event' ;
30
31
import Approve from './pages/usage/approve' ;
@@ -52,6 +53,7 @@ export default (
52
53
< Route path = "/advance/custom-node/rule" exact component = { Rule } />
53
54
< Route path = "/advance/custom-node/shape" exact component = { Shape } />
54
55
< Route path = "/advance/custom-edge/process" exact component = { Process } />
56
+ < Route path = "/advance/custom-node/html" exact component = { Html } />
55
57
< Route path = "/extension/snapshot" exact component = { Snapshot } />
56
58
< Route path = "/extension/components/control" exact component = { Control } />
57
59
< Route path = "/extension/components/menu" exact component = { Menu } />
Original file line number Diff line number Diff line change 3
3
All notable changes to this project will be documented in this file.
4
4
See [ Conventional Commits] ( https://conventionalcommits.org ) for commit guidelines.
5
5
6
+ ## [ 0.4.14] ( https://github.com/towersxu/logicflow/compare/@logicflow/core@0.4.11...@logicflow/core@0.4.14 ) (2021-06-16)
7
+
8
+ ** Note:** Version bump only for package @logicflow/core
9
+
10
+
11
+
12
+
13
+
6
14
## [ 0.4.13] ( https://github.com/towersxu/logicflow/compare/@logicflow/core@0.4.11...@logicflow/core@0.4.13 ) (2021-06-09)
7
15
8
16
** Note:** Version bump only for package @logicflow/core
Original file line number Diff line number Diff line change 43
43
border : 2px solid # 000 ;
44
44
background : # fff ;
45
45
}
46
+ .uml-wrapper {
47
+ background : # 68FCE2 ;
48
+ width : 100% ;
49
+ height : 100% ;
50
+ border-radius : 10px ;
51
+ border : 2px solid # 838382 ;
52
+ box-sizing : border-box;
53
+ }
54
+ .uml-head {
55
+ text-align : center;
56
+ line-height : 30px ;
57
+ font-size : 16px ;
58
+ font-weight : bold;
59
+ }
60
+ .uml-body {
61
+ border-top : 1px solid # 838382 ;
62
+ border-bottom : 1px solid # 838382 ;
63
+ padding : 5px 10px ;
64
+ font-size : 12px ;
65
+ }
66
+ .uml-footer {
67
+ padding : 5px 10px ;
68
+ font-size : 14px ;
69
+ }
46
70
</ style >
47
71
</ head >
48
72
70
94
71
95
<!-- 自定义节点 -->
72
96
< script >
97
+ class UmlModel extends HtmlNodeModel {
98
+ setAttributes ( ) {
99
+ const width = 200 ;
100
+ const height = 130 ;
101
+ this . width = width ;
102
+ this . height = height ;
103
+ this . anchorsOffset = [
104
+ [ width / 2 , 0 ] ,
105
+ [ 0 , height / 2 ] ,
106
+ [ - width / 2 , 0 ] ,
107
+ [ 0 , - height / 2 ] ,
108
+ ]
109
+ }
110
+ }
111
+ class UmlNode extends HtmlNode {
112
+ setHtml ( rootEl ) {
113
+ const el = document . createElement ( 'div' ) ;
114
+ el . className = 'uml-wrapper' ;
115
+ const html = `
116
+ <div>
117
+ <div class="uml-head">Head</div>
118
+ <div class="uml-body">
119
+ <div>+ $Name</div>
120
+ <div>+ $Body</div>
121
+ </div>
122
+ <div class="uml-footer">
123
+ <div>+ setHead(Head $head)</div>
124
+ <div>+ setBody(Body $body)</div>
125
+ </div>
126
+ </div>
127
+ `
128
+ el . innerHTML = html ;
129
+ rootEl . appendChild ( el ) ;
130
+ }
131
+ }
73
132
// square
74
133
class SquareModel extends RectNodeModel {
75
134
setAttributes ( ) {
275
334
view : Connection ,
276
335
model : LineEdgeModel ,
277
336
} )
278
-
337
+ lf . register ( {
338
+ type : 'uml' ,
339
+ view : UmlNode ,
340
+ model : UmlModel ,
341
+ } )
279
342
lf . setTheme ( { } ) ;
280
343
lf . setDefaultEdgeType ( 'polyline' ) ;
281
344
282
345
lf . render ( {
283
346
nodes : [
284
347
{
285
- type : 'rect ' ,
348
+ type : 'uml ' ,
286
349
x : 100 ,
287
350
y : 100 ,
288
351
id : 10 ,
378
441
}
379
442
]
380
443
} ) ;
381
-
382
- // console.log(lf.graphModel);
383
- // lf.createEdge({
384
- // sourceNodeId: 10,
385
- // targetNodeId: 11,
386
- // // text: '222',
387
- // });
388
- // lf.updateText('edge_2222', '你是打算啊')
389
- // lf.createEdge({
390
- // sourceNodeId: 10,
391
- // targetNodeId: 50,
392
- // text: '222',
393
- // type: 'bezier'
394
- // });
395
- // console.log(lf.graphModel);
396
444
}
397
445
</ script >
398
446
You can’t perform that action at this time.
0 commit comments