Skip to content

Commit a169ef7

Browse files
committed
docs: html node
1 parent 373db63 commit a169ef7

File tree

8 files changed

+178
-2
lines changed

8 files changed

+178
-2
lines changed

docs/guide/advance/customNode.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,3 +419,53 @@ lf.render({
419419
420420
在上面的代码中,`getShape`方法返回了一个包含图标的标签,Logic Flow 拿到这个返回值后会直接在`graph`中进行渲染。SVG 元素需要 model 中的实时数据才可以正常显示并使用,现在我们可以通过[getAttributes](/guide/advance/customNode.html#getattributes)方法获取到 model 中的[数据属性](/api/nodeApi.md#数据属性)和[样式属性](/api/nodeApi.html#样式属性)。
421421
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+
```

docs/guide/basic/node.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ LogicFlow 的内置节点包括:
77
- 菱形(diamond)
88
- 多边形(polygon)
99
- 文本(text)
10+
- html节点(html)
1011

1112
## 节点属性
1213

@@ -59,6 +60,11 @@ type Point = [number, number]
5960
| fontSize | number | ✅ | 字体大小 |
6061
| fontFamily | string | ✅ | 字体类型 |
6162
| fontWeight | number / string | ✅ | 字体粗细 |
63+
64+
### html节点
65+
66+
html节点无特殊属性,定制效果需要去view中自己控制。详情请参考自定义节点。
67+
6268
## 创建节点
6369
LogicFlow 支持三种创建节点的方式:
6470
- 数据配置
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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;

examples/src/routes.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import Anchor from './pages/advance/custom-node/anchor';
2525
import Triangle from './pages/advance/custom-node/triangle';
2626
import Rule from './pages/advance/custom-node/rule';
2727
import Shape from './pages/advance/custom-node/shape';
28+
import Html from './pages/advance/custom-node/html';
2829
import Process from './pages/advance/custom-edge';
2930
import Event from './pages/advance/event';
3031
import Approve from './pages/usage/approve';
@@ -52,6 +53,7 @@ export default (
5253
<Route path="/advance/custom-node/rule" exact component={Rule} />
5354
<Route path="/advance/custom-node/shape" exact component={Shape} />
5455
<Route path="/advance/custom-edge/process" exact component={Process} />
56+
<Route path="/advance/custom-node/html" exact component={Html} />
5557
<Route path="/extension/snapshot" exact component={Snapshot} />
5658
<Route path="/extension/components/control" exact component={Control} />
5759
<Route path="/extension/components/menu" exact component={Menu} />

packages/core/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@
110110
}
111111
class UmlNode extends HtmlNode {
112112
setHtml(rootEl) {
113-
console.log(111)
114113
const el = document.createElement('div');
115114
el.className = 'uml-wrapper';
116115
const html = `

packages/core/src/model/node/HtmlNodeModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class HtmlNodeModel extends BaseNodeModel {
1010
@observable radius = defaultTheme.rect.radius;
1111

1212
constructor(data, graphModel: GraphModel) {
13-
super(data, graphModel, 'rect');
13+
super(data, graphModel, 'html');
1414
}
1515

1616
@computed get anchors(): Point[] {

0 commit comments

Comments
 (0)