Skip to content

Commit 4480ceb

Browse files
wangziyueDymoneLewis
authored andcommitted
docs: 修复文档事件说明和自定义锚点报错,补充样式边示例
1 parent 6c5504a commit 4480ceb

11 files changed

Lines changed: 246 additions & 13 deletions

File tree

sites/docs/docs/api/eventCenter.en.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ flowchart. The detailed usage of events is described in [events](../tutorial/bas
3434
| node:drag | Nodes in dragging | data, e |
3535
| node:drop | End of node dragging | data, e |
3636
| node:contextmenu | Right-click on the node | data, e, position |
37-
| node:resize<Badge>2.0 Added</Badge> | Adjust node scaling | preData, data, model, deltaX, deltaY, index |
38-
| node:resize-start<Badge>2.0 Added</Badge> | Start adjusting node scaling | e, data, model |
37+
| node:resize<Badge>2.0 Added</Badge> | Adjust node scaling | preData, data, model, deltaX, deltaY, index |
3938
| node:properties-change<Badge>2.0 Added</Badge> | Node custom properties change | id: Current node id<br/>keys: Set of keys for current changes<br/>preProperties: Properties before change<br/>properties: Properties after change |
4039

4140
The event object contains the following:

sites/docs/docs/api/eventCenter.zh.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ LogicFlow
3535
| node:drop | 节点拖拽放开 | data, e |
3636
| node:contextmenu | 右键点击节点 | data, e, position |
3737
| node:resize<Badge>2.0 新增</Badge> | 调整节点缩放 | preData, data, model, deltaX, deltaY, index |
38-
| node:resize<Badge>2.0 新增</Badge> | 调整节点缩放 | e, data, model |
3938
| node:properties-change<Badge>2.0 新增</Badge> | 节点自定义属性变化 | id: 当前节点的id<br/>keys: 当前变更字段的key的集合<br/>preProperties: 改动前的properties<br/>properties: 改动后的properties |
4039

4140
事件对象包含如下内容:

sites/docs/docs/tutorial/basic/edge.en.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,14 @@ You just need to customize the style class in [edgeModel](../../api/edgeModel.en
4242
:::info{title=提示}
4343
Custom edges also need to be registered using `register`.
4444
:::
45+
## Modify edge style
46+
Similar to node style attributes, edge styles can also be customized via [theme configuration](../../api/theme.en.md). The edge style is then redefined by this.
4547

48+
- If you need to define styles according to the state of the edge, you can put the passed parameters into `properties`, and in `getEdgeStyle`, you can judge the parameters in `properties` and return different styles according to different parameters.
49+
- To achieve the hover effect, you can listen for the `edge:mouseenter` and `edge:mouseleave` events, modify the parameters in `properties`, and then call the `edge.updateStyle()` method to update the edge style.
50+
- It is not recommended to use the `setStyle` method to set the style of the edges. This method is generally used to skip the rendering of custom edges when developing plugins.
51+
52+
<code id="edge-style" src="../../../src/tutorial/basic/edge/style"></code>
4653
## Customize side text position
4754

4855
By default, the position of the text on the edge is the position when the user double-clicks on the

sites/docs/docs/tutorial/basic/edge.zh.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@ import { BezierEdge, BezierEdgeModel } from '@logicflow/core'
4040
:::info{title=提示}
4141
自定义边同样需要使用`register`注册哦。
4242
:::
43+
## 修改边样式
44+
和节点的样式属性一样边样式也支持通过 [主题配置](../../api/theme.zh.md) 自定义边的样式则是它重新定义。
4345

46+
- 如果需要按照边的状态定义样式,可以把传递的参数放入`properties`中,在`getEdgeStyle`中判断`properties`中的参数,根据不同的参数返回不同的样式。
47+
- 如果需要实现hover的效果,可以监听`edge:mouseenter``edge:mouseleave`事件,修改完`properties`中的参数,然后调用`edge.updateStyle()`方法更新边的样式。
48+
- 不建议使用`setStyle`方法设置边的样式,这个方法一般用于插件开发时跳过自定义边的渲染。
49+
50+
<code id="edge-style" src="../../../src/tutorial/basic/edge/style"></code>
4451
## 自定义边文本位置
4552

4653
默认情况下,边上文本的位置是用户双击点击边时的位置。如果是通过 API 的方式给边添加的文本,文本位置按照如下规则。

sites/docs/docs/tutorial/update.en.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Fixed the bug that TextEditTool is invalid, and the reason is noted later
154154
**Optimization**
155155
In version 1.x, the node scaling capability needs to be implemented by introducing the NodeResize plug-in. In version 2.0, we built the resize capability into the basic node; and also supported the configurable node rotation capability.
156156
1. Users can set whether all nodes in the current instance are scalable and rotatable through the global configuration items `allowResize` and `allowRotate`;
157-
2. You can also add `resizable` and `rotatable` parameters in the `properties` of the initial rendering incoming data to control whether a single node is rotatable and scalable. Internally, the node's `resizable` and `rotatable` default to `true`;
157+
2. You can also add `resizable` and `rotatable` parameters in the `properties` of the initial rendering incoming data to control whether a single node is rotatable and scalable(This will only take effect if `allowResize`/`allowRotate` is set to true globally.). Internally, the node's `resizable` and `rotatable` default to `true`;
158158

159159
:::warning{title=Tip}
160160
After the scaling capability is built-in, the NodeResize plug-in will be gradually abandoned

sites/docs/docs/tutorial/update.zh.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ y2 → maxY
130130
### Extension
131131

132132
#### 框选插件
133-
**新能力s**
133+
**新能力**
134134
1. 增加`selection:selected-area`事件,返回框选范围;
135135
2. 框选插件默认启用状态改为不启用,如需初始化时就启用框选,在LogicFlow实例创建后调用`lf.extension.selectionSelect.open()`方法开启框选;
136136
**问题修复**
137137
1. 修复框选启用后,页面滚动事件被阻塞的问题;
138138
2. 修复缩放后,框选边距与外边框宽度计算问题;
139139

140140
#### 小地图插件
141-
**新能力s**
141+
**新能力**
142142
1. 支持配置小地图展示位置;
143143
2. 支持选择是否渲染连线,支持初始化时设置或通过`setShowEdge`方法更新设置;
144144
3. 小地图显示内容优化,目前会有画布元素与视口位置共同决定展示内容;
@@ -153,7 +153,7 @@ y2 → maxY
153153
**优化**
154154
在1.x版本中,节点缩放能力需要通过引入NodeResize插件实现,在2.0版本中,我们将resize能力内置到基础节点上;同时还支持了节点旋转能力可配置。
155155
1. 用户可以通过全局配置项`allowResize``allowRotate`设置当前实例中所有节点是否可缩放、可旋转;
156-
2. 也可以在初始化渲染传入数据的`properties`中增加`resizable``rotatable`参数控制单个节点是否可旋转可缩放,在内部,节点的`resizable``rotatable`默认为`true`;
156+
2. 也可以在初始化渲染传入数据的`properties`中增加`resizable`(需要全局配置`allowResize`为true才会生效)`rotatable`参数控制单个节点是否可旋转可缩放(需要全局配置`allowRotate`为true才会生效),在内部,节点的`resizable``rotatable`默认为`true`;
157157

158158
:::warning{title=Tip}
159159
缩放能力内置后,NodeResize插件会逐步废弃
@@ -176,23 +176,23 @@ y2 → maxY
176176

177177
#### Group插件
178178
在2.0版本里,我们重写了分组插件相关逻辑,将 Group 插件升级为 [Dynamic Group 插件](extension/dynamic-group.zh.md)
179-
**新能力s**
179+
**新能力**
180180
1. 支持分组节点缩放旋转时,内部元素也随之同步缩放旋转;
181181

182182
**优化**
183183
1. 调小 ResizeControl 的范围 30 -> 15,原因是会盖住 Group 折叠的小按钮;
184184
2. 优化允许文本拖动的逻辑判断 -> nodeTextDraggable && draggable 才可以允许拖动;
185185

186186
#### HighLight插件
187-
**新能力s**
187+
**新能力**
188188
1. 支持高亮邻居节点模式;
189189
2. 支持外部传参配置高亮形式;
190190

191191
**ptimizations**
192192
1. 补充功能介绍文档[HighLight 插件](extension/highlight.zh.md)
193193

194194
#### 「New」Label插件
195-
**新能力s**
195+
**新能力**
196196
在2.0版本里,我们新增了一种文本展现形式:Label,这种形式与现有Text形式文本之间的主要区别点在于:
197197
1. 支持一个节点/一条边 上可以添加多个文本,且可以设置文本朝向;
198198
2. 自带富文本编辑能力,支持设置局部文本样式;

sites/docs/src/tutorial/advanced/node/sql/sqlNode.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ class SqlNodeModel extends HtmlNodeModel {
7474
getOutlineStyle() {
7575
const style = super.getOutlineStyle();
7676
style.stroke = 'none';
77-
style.hover.stroke = 'none';
7877
return style;
7978
}
8079

@@ -83,8 +82,6 @@ class SqlNodeModel extends HtmlNodeModel {
8382
const style = super.getAnchorStyle();
8483
if (anchorInfo.type === 'left') {
8584
style.fill = 'red';
86-
style.hover.fill = 'transparent';
87-
style.hover.stroke = 'transpanrent';
8885
style.className = 'lf-hide-default';
8986
} else {
9087
style.fill = 'green';
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { PolylineEdge, PolylineEdgeModel } from '@logicflow/core';
2+
3+
export class PropertyHoverEdgeModel extends PolylineEdgeModel {
4+
initEdgeData(data: any) {
5+
super.initEdgeData(data);
6+
// 初始化 hover 状态
7+
this.properties.isHover = false;
8+
}
9+
10+
// 这个方法可以在需要时读取
11+
getEdgeStyle() {
12+
const style = super.getEdgeStyle();
13+
const { isHover } = this.properties;
14+
15+
if (isHover) {
16+
return {
17+
...style,
18+
stroke: '#ff4d4f',
19+
strokeWidth: 3,
20+
};
21+
}
22+
23+
return {
24+
...style,
25+
stroke: '#999',
26+
strokeWidth: 5,
27+
};
28+
}
29+
}
30+
31+
export const HoverEdge = {
32+
type: 'hover-edge',
33+
view: PolylineEdge,
34+
model: PropertyHoverEdgeModel,
35+
};
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import React, { useEffect, useRef, useState } from 'react';
2+
import LogicFlow from '@logicflow/core';
3+
import '@logicflow/core/dist/index.css';
4+
import StatusButtons from './statusButton';
5+
import { StatusEdge } from './statusEdge';
6+
import { HoverEdge } from './hoverEdge';
7+
const SilentConfig = {
8+
stopScrollGraph: true,
9+
stopMoveGraph: true,
10+
stopZoomGraph: true,
11+
};
12+
const App: React.FC = () => {
13+
const containerRef = useRef<HTMLDivElement>(null);
14+
const [lf, setLf] = useState<LogicFlow | null>(null);
15+
16+
useEffect(() => {
17+
if (!containerRef.current) return;
18+
19+
const lfInstance = new LogicFlow({
20+
container: containerRef.current,
21+
grid: true,
22+
...SilentConfig,
23+
});
24+
lfInstance.register(StatusEdge);
25+
lfInstance.register(HoverEdge);
26+
lfInstance.render({
27+
nodes: [
28+
{
29+
id: 'n1',
30+
type: 'rect',
31+
x: 100,
32+
y: 200,
33+
},
34+
{
35+
id: 'n2',
36+
type: 'rect',
37+
x: 500,
38+
y: 200,
39+
},
40+
{
41+
id: 'n3',
42+
type: 'rect',
43+
x: 100,
44+
y: 300,
45+
},
46+
{
47+
id: 'n4',
48+
type: 'rect',
49+
x: 500,
50+
y: 300,
51+
},
52+
{
53+
id: 'n5',
54+
type: 'rect',
55+
x: 100,
56+
y: 400,
57+
},
58+
{
59+
id: 'n6',
60+
type: 'rect',
61+
x: 500,
62+
y: 400,
63+
},
64+
],
65+
edges: [
66+
{
67+
id: 'e1',
68+
type: 'status-edge',
69+
sourceNodeId: 'n1',
70+
targetNodeId: 'n2',
71+
text: '根据状态渲染的边颜色,先选中这条边',
72+
properties: { status: 'todo' },
73+
},
74+
{
75+
id: 'e2',
76+
type: 'polyline',
77+
text: '内置样式边',
78+
sourceNodeId: 'n3',
79+
targetNodeId: 'n4',
80+
},
81+
{
82+
id: 'e3',
83+
type: 'hover-edge',
84+
text: '鼠标移入hover变化',
85+
sourceNodeId: 'n5',
86+
targetNodeId: 'n6',
87+
},
88+
],
89+
});
90+
lfInstance.translateCenter();
91+
//直接调用model修改style样式 但是不支持 因为属于直接越权操作了 建议还是继承getEdgeStyle方法
92+
const edgeModel = lfInstance.graphModel.getEdgeModelById('e2');
93+
edgeModel?.setStyles({
94+
stroke: '#722ed1',
95+
strokeWidth: 2,
96+
strokeDasharray: '5 5',
97+
});
98+
99+
setLf(lfInstance);
100+
}, []);
101+
lf?.on('edge:mouseenter', ({ data }) => {
102+
if (data.type !== 'hover-edge') {
103+
return;
104+
}
105+
lf.setProperties(data.id, {
106+
isHover: true,
107+
});
108+
});
109+
110+
lf?.on('edge:mouseleave', ({ data }) => {
111+
if (data.type !== 'hover-edge') {
112+
return;
113+
}
114+
lf.setProperties(data.id, {
115+
isHover: false,
116+
});
117+
});
118+
119+
return (
120+
<div style={{ padding: 16 }}>
121+
{lf && <StatusButtons lf={lf} />}
122+
<div
123+
ref={containerRef}
124+
style={{ height: 600, border: '1px solid #eee', marginTop: 12 }}
125+
/>
126+
</div>
127+
);
128+
};
129+
130+
export default App;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from 'react';
2+
import { Button, Space, message } from 'antd';
3+
import LogicFlow from '@logicflow/core';
4+
5+
interface Props {
6+
lf: LogicFlow;
7+
}
8+
9+
const StatusButtons: React.FC<Props> = ({ lf }) => {
10+
const getCurrentEdge = () => {
11+
const { edges } = lf.getSelectElements();
12+
return edges?.[0];
13+
};
14+
15+
const onSetEdgeStatus = (status: 'todo' | 'done') => {
16+
const edge = getCurrentEdge();
17+
if (!edge) {
18+
message.warning('请先选择一条边');
19+
return;
20+
}
21+
22+
// 改变边的properties
23+
lf.setProperties(edge.id, { status });
24+
};
25+
26+
return (
27+
<Space>
28+
<Button danger onClick={() => onSetEdgeStatus('todo')}>
29+
未完成
30+
</Button>
31+
<Button type="primary" onClick={() => onSetEdgeStatus('done')}>
32+
已完成
33+
</Button>
34+
</Space>
35+
);
36+
};
37+
38+
export default StatusButtons;

0 commit comments

Comments
 (0)