File tree Expand file tree Collapse file tree 8 files changed +178
-2
lines changed
pages/advance/custom-node/html Expand file tree Collapse file tree 8 files changed +178
-2
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
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 110
110
}
111
111
class UmlNode extends HtmlNode {
112
112
setHtml ( rootEl ) {
113
- console . log ( 111 )
114
113
const el = document . createElement ( 'div' ) ;
115
114
el . className = 'uml-wrapper' ;
116
115
const html = `
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ class HtmlNodeModel extends BaseNodeModel {
10
10
@observable radius = defaultTheme . rect . radius ;
11
11
12
12
constructor ( data , graphModel : GraphModel ) {
13
- super ( data , graphModel , 'rect ' ) ;
13
+ super ( data , graphModel , 'html ' ) ;
14
14
}
15
15
16
16
@computed get anchors ( ) : Point [ ] {
You can’t perform that action at this time.
0 commit comments