@logicflow/core 2.2.1 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/docs/api/logicflow-constructor/index.en.md +106 -0
- package/dist/docs/api/logicflow-constructor/index.zh.md +106 -0
- package/dist/docs/api/logicflow-constructor/use.en.md +61 -0
- package/dist/docs/api/logicflow-constructor/use.zh.md +61 -0
- package/dist/docs/api/logicflow-instance/canvas.en.md +197 -0
- package/dist/docs/api/logicflow-instance/canvas.zh.md +199 -0
- package/dist/docs/api/logicflow-instance/edge.en.md +273 -0
- package/dist/docs/api/logicflow-instance/edge.zh.md +273 -0
- package/dist/docs/api/logicflow-instance/edit-config.en.md +59 -0
- package/dist/docs/api/logicflow-instance/edit-config.zh.md +59 -0
- package/dist/docs/api/logicflow-instance/element.en.md +375 -0
- package/dist/docs/api/logicflow-instance/element.zh.md +379 -0
- package/dist/docs/api/logicflow-instance/event.en.md +326 -0
- package/dist/docs/api/logicflow-instance/event.zh.md +406 -0
- package/dist/docs/api/logicflow-instance/history.en.md +38 -0
- package/dist/docs/api/logicflow-instance/history.zh.md +38 -0
- package/dist/docs/api/logicflow-instance/index.en.md +41 -0
- package/dist/docs/api/logicflow-instance/index.zh.md +41 -0
- package/dist/docs/api/logicflow-instance/node.en.md +308 -0
- package/dist/docs/api/logicflow-instance/node.zh.md +308 -0
- package/dist/docs/api/logicflow-instance/register.en.md +76 -0
- package/dist/docs/api/logicflow-instance/register.zh.md +76 -0
- package/dist/docs/api/logicflow-instance/render-and-data.en.md +179 -0
- package/dist/docs/api/logicflow-instance/render-and-data.zh.md +181 -0
- package/dist/docs/api/logicflow-instance/text.en.md +60 -0
- package/dist/docs/api/logicflow-instance/text.zh.md +60 -0
- package/dist/docs/api/logicflow-instance/theme.en.md +179 -0
- package/dist/docs/api/logicflow-instance/theme.zh.md +179 -0
- package/dist/docs/api/runtime-model/edgeModel.en.md +29 -0
- package/dist/docs/api/runtime-model/edgeModel.zh.md +325 -0
- package/dist/docs/api/runtime-model/graphModel.en.md +275 -0
- package/dist/docs/api/runtime-model/graphModel.zh.md +1153 -0
- package/dist/docs/api/runtime-model/nodeModel.en.md +37 -0
- package/dist/docs/api/runtime-model/nodeModel.zh.md +644 -0
- package/dist/docs/api/type/MainTypes.en.md +598 -0
- package/dist/docs/api/type/MainTypes.zh.md +867 -0
- package/dist/docs/api/type/Theme.en.md +187 -0
- package/dist/docs/api/type/Theme.zh.md +187 -0
- package/dist/docs/api/type/canvas-types.en.md +25 -0
- package/dist/docs/api/type/canvas-types.zh.md +25 -0
- package/dist/docs/api/type/index.en.md +96 -0
- package/dist/docs/api/type/index.zh.md +99 -0
- package/dist/docs/api/type/node-types.en.md +21 -0
- package/dist/docs/api/type/node-types.zh.md +21 -0
- package/dist/docs/api/type/plugin-types.en.md +24 -0
- package/dist/docs/api/type/plugin-types.zh.md +24 -0
- package/dist/docs/index.md +11 -0
- package/dist/docs/tutorial/about.en.md +38 -0
- package/dist/docs/tutorial/about.zh.md +65 -0
- package/dist/docs/tutorial/advanced/dnd.en.md +62 -0
- package/dist/docs/tutorial/advanced/dnd.zh.md +52 -0
- package/dist/docs/tutorial/advanced/edge.en.md +64 -0
- package/dist/docs/tutorial/advanced/edge.zh.md +66 -0
- package/dist/docs/tutorial/advanced/keyboard.en.md +70 -0
- package/dist/docs/tutorial/advanced/keyboard.zh.md +67 -0
- package/dist/docs/tutorial/advanced/node.en.md +338 -0
- package/dist/docs/tutorial/advanced/node.zh.md +338 -0
- package/dist/docs/tutorial/advanced/react.en.md +106 -0
- package/dist/docs/tutorial/advanced/react.zh.md +114 -0
- package/dist/docs/tutorial/advanced/silent-mode.en.md +75 -0
- package/dist/docs/tutorial/advanced/silent-mode.zh.md +71 -0
- package/dist/docs/tutorial/advanced/snapline.en.md +54 -0
- package/dist/docs/tutorial/advanced/vue.en.md +249 -0
- package/dist/docs/tutorial/advanced/vue.zh.md +248 -0
- package/dist/docs/tutorial/ai.en.md +64 -0
- package/dist/docs/tutorial/ai.zh.md +64 -0
- package/dist/docs/tutorial/basic/background.en.md +50 -0
- package/dist/docs/tutorial/basic/canvas.en.md +164 -0
- package/dist/docs/tutorial/basic/canvas.zh.md +183 -0
- package/dist/docs/tutorial/basic/class.en.md +106 -0
- package/dist/docs/tutorial/basic/class.zh.md +103 -0
- package/dist/docs/tutorial/basic/edge.en.md +151 -0
- package/dist/docs/tutorial/basic/edge.zh.md +152 -0
- package/dist/docs/tutorial/basic/event.en.md +70 -0
- package/dist/docs/tutorial/basic/event.zh.md +66 -0
- package/dist/docs/tutorial/basic/grid.en.md +77 -0
- package/dist/docs/tutorial/basic/node.en.md +358 -0
- package/dist/docs/tutorial/basic/node.zh.md +318 -0
- package/dist/docs/tutorial/basic/theme.en.md +154 -0
- package/dist/docs/tutorial/basic/theme.zh.md +157 -0
- package/dist/docs/tutorial/extension/adapter.en.md +446 -0
- package/dist/docs/tutorial/extension/adapter.zh.md +429 -0
- package/dist/docs/tutorial/extension/bpmn-element.en.md +1427 -0
- package/dist/docs/tutorial/extension/bpmn-element.zh.md +1472 -0
- package/dist/docs/tutorial/extension/control.en.md +117 -0
- package/dist/docs/tutorial/extension/control.zh.md +118 -0
- package/dist/docs/tutorial/extension/curved-edge.en.md +46 -0
- package/dist/docs/tutorial/extension/curved-edge.zh.md +46 -0
- package/dist/docs/tutorial/extension/custom.en.md +142 -0
- package/dist/docs/tutorial/extension/custom.zh.md +138 -0
- package/dist/docs/tutorial/extension/dnd-panel.en.md +109 -0
- package/dist/docs/tutorial/extension/dnd-panel.zh.md +109 -0
- package/dist/docs/tutorial/extension/dynamic-group.en.md +606 -0
- package/dist/docs/tutorial/extension/dynamic-group.zh.md +606 -0
- package/dist/docs/tutorial/extension/group.en.md +217 -0
- package/dist/docs/tutorial/extension/group.zh.md +209 -0
- package/dist/docs/tutorial/extension/highlight.en.md +50 -0
- package/dist/docs/tutorial/extension/highlight.zh.md +50 -0
- package/dist/docs/tutorial/extension/insert-node-in-polyline.en.md +52 -0
- package/dist/docs/tutorial/extension/insert-node-in-polyline.zh.md +47 -0
- package/dist/docs/tutorial/extension/intro.en.md +72 -0
- package/dist/docs/tutorial/extension/intro.zh.md +95 -0
- package/dist/docs/tutorial/extension/label.en.md +136 -0
- package/dist/docs/tutorial/extension/label.zh.md +135 -0
- package/dist/docs/tutorial/extension/layout.en.md +156 -0
- package/dist/docs/tutorial/extension/layout.zh.md +156 -0
- package/dist/docs/tutorial/extension/menu.en.md +319 -0
- package/dist/docs/tutorial/extension/menu.zh.md +377 -0
- package/dist/docs/tutorial/extension/minimap.en.md +164 -0
- package/dist/docs/tutorial/extension/minimap.zh.md +180 -0
- package/dist/docs/tutorial/extension/node-resize.en.md +199 -0
- package/dist/docs/tutorial/extension/node-resize.zh.md +221 -0
- package/dist/docs/tutorial/extension/pool.en.md +227 -0
- package/dist/docs/tutorial/extension/pool.zh.md +227 -0
- package/dist/docs/tutorial/extension/proximity-connect.en.md +104 -0
- package/dist/docs/tutorial/extension/proximity-connect.zh.md +107 -0
- package/dist/docs/tutorial/extension/selection.en.md +166 -0
- package/dist/docs/tutorial/extension/selection.zh.md +150 -0
- package/dist/docs/tutorial/extension/snapshot.en.md +276 -0
- package/dist/docs/tutorial/extension/snapshot.zh.md +276 -0
- package/dist/docs/tutorial/get-started.en.md +501 -0
- package/dist/docs/tutorial/get-started.zh.md +139 -0
- package/dist/docs/tutorial/update.en.md +213 -0
- package/dist/docs/tutorial/update.zh.md +212 -0
- package/package.json +5 -3
- package/scripts/postinstall-ai-prompt.js +67 -0
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
---
|
|
2
|
+
nav: Guide
|
|
3
|
+
group:
|
|
4
|
+
title: Basics
|
|
5
|
+
order: 1
|
|
6
|
+
title: Node
|
|
7
|
+
order: 1
|
|
8
|
+
toc: content
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
LogicFlow has built-in some basic nodes, and developers can, in practical application scenarios,
|
|
12
|
+
define nodes that fit their business logic based on these basic nodes.
|
|
13
|
+
|
|
14
|
+
## Understanding Basic Nodes
|
|
15
|
+
|
|
16
|
+
LogicFlow is a flowchart editing framework based on SVG. Therefore, our nodes and connections are
|
|
17
|
+
basic SVG shapes. Modifying the style of LogicFlow nodes is essentially modifying the SVG basic
|
|
18
|
+
shapes. There are seven types of basic nodes built into LogicFlow, namely:
|
|
19
|
+
|
|
20
|
+
1. <a href="https://developer.mozilla.org/en/docs/Web/SVG/Element/rect" target="_blank">rect</a>
|
|
21
|
+
2. <a href="https://developer.mozilla.org/en/docs/Web/SVG/Element/circle" target="_blank">circle</a>
|
|
22
|
+
3. <a href="https://developer.mozilla.org/en/docs/Web/SVG/Element/ellipse" target="_blank">
|
|
23
|
+
ellipse</a>
|
|
24
|
+
4. <a href="https://developer.mozilla.org/en/docs/Web/SVG/Element/polygon" target="_blank">
|
|
25
|
+
polygon</a>
|
|
26
|
+
5. `diamond`
|
|
27
|
+
6. <a href="https://developer.mozilla.org/en/docs/Web/SVG/Element/text" target="_blank">text</a>
|
|
28
|
+
7. `html`
|
|
29
|
+
|
|
30
|
+
<code id="node-shapes" src="../../../src/tutorial/basic/node/shapes"></code>
|
|
31
|
+
|
|
32
|
+
The basic nodes in LogicFlow are relatively simple, but in business scenarios, there may be various
|
|
33
|
+
requirements for the appearance of nodes. LogicFlow provides a powerful custom node feature that
|
|
34
|
+
supports developers in creating various custom nodes. The following is an introduction to custom
|
|
35
|
+
nodes based on inheritance.
|
|
36
|
+
|
|
37
|
+
## Custom nodes
|
|
38
|
+
|
|
39
|
+
LogicFlow implements custom nodes and edges based on inheritance. Developers can inherit the
|
|
40
|
+
built-in nodes of LogicFlow and then use
|
|
41
|
+
object-oriented <a href="https://baike.baidu.com/item/%E9%87%8D%E5%86%99/9355942?fr=aladdin" target="_blanl">overriding</a>
|
|
42
|
+
mechanisms. By overriding methods related to node styles, developers can achieve the effect of
|
|
43
|
+
customizing node styles.
|
|
44
|
+
|
|
45
|
+

|
|
46
|
+
|
|
47
|
+
:::warning
|
|
48
|
+
LogicFlow recommends that in practical application scenarios, all nodes use custom nodes, and the
|
|
49
|
+
node types are defined with names that align with the project's business meaning, rather than using
|
|
50
|
+
shapes like circles or rectangles that only represent appearance.
|
|
51
|
+
:::
|
|
52
|
+
|
|
53
|
+
### Node `model` and `view`
|
|
54
|
+
|
|
55
|
+
`model`: Data layer containing various styles (such as borders, colors), shapes (dimensions, vertex
|
|
56
|
+
positions), and business properties of nodes.
|
|
57
|
+
|
|
58
|
+
`view`: View layer controlling the final rendering effects of nodes. By modifying the `model`,
|
|
59
|
+
custom nodes can be created, while more complex SVG elements can be customized on the `view`.
|
|
60
|
+
|
|
61
|
+
LogicFlow is based on the MVVM pattern. When customizing a node, we can redefine its `model`
|
|
62
|
+
and `view`. This involves overriding methods in the `model` to obtain style-related information and
|
|
63
|
+
overriding `getShape` in the `view` to define complex node appearances.
|
|
64
|
+
|
|
65
|
+
Here's an example of customizing a node by inheriting and overriding the `model`. Customizing nodes
|
|
66
|
+
can be achieved using different approaches 😊.
|
|
67
|
+
|
|
68
|
+
<code id="node-custom" src="../../../src/tutorial/basic/node/custom"></code>
|
|
69
|
+
|
|
70
|
+
[lf.register](../../api/logicflow-instance/register.en.md#register): Register custom nodes. After registration,
|
|
71
|
+
custom nodes can be used.
|
|
72
|
+
|
|
73
|
+
:::info
|
|
74
|
+
|
|
75
|
+
LogicFlow in order to develop the development experience and now front-end popular development
|
|
76
|
+
experience alignment, but also in order to better understand the code level, so that more people can
|
|
77
|
+
participate in, we based on preact, mobx to MVVM mode development. If you are familiar with react
|
|
78
|
+
development, you can directly read our source code, you can find the whole project to read the
|
|
79
|
+
difficulty, and you develop your own project is about the same. **We welcome you to join us.**
|
|
80
|
+
|
|
81
|
+
:::
|
|
82
|
+
|
|
83
|
+
There are 7 kinds of base nodes in LogicFlow, you can choose any one of them to inherit when you
|
|
84
|
+
customize the node, and then take a name that meets your business meaning. Take the scalable node
|
|
85
|
+
provided in @logicflow/extension as an example: LogicFlow base node does not support node scaling,
|
|
86
|
+
so LogicFlow encapsulates the logic of node scaling based on the base node in the extension package,
|
|
87
|
+
and then releases it. So LogicFlow encapsulates the logic of node scaling based on the base node in
|
|
88
|
+
the extension package and releases it.
|
|
89
|
+
|
|
90
|
+
```tsx | pure
|
|
91
|
+
import { RectResize } from "@logicflow/extension";
|
|
92
|
+
|
|
93
|
+
class CustomNodeModel extends RectResize.model {
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
class CustomNode extends RectResize.view {
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Customizing node `model`
|
|
101
|
+
|
|
102
|
+
LogicFlow categorizes custom node appearance into two ways: `custom node style attribute`
|
|
103
|
+
and `custom node shape attribute`. For more details on how to define them,
|
|
104
|
+
see [NodeModelApi](../../api/runtime-model/nodeModel.en.md)。
|
|
105
|
+
|
|
106
|
+
#### 1. style attributes
|
|
107
|
+
|
|
108
|
+
In LogicFlow, the appearance attributes represent the control of the node's `border`, `color`, and
|
|
109
|
+
other appearance-oriented attributes. These properties can be controlled directly
|
|
110
|
+
through [theme-configuration](../../api/logicflow-instance/theme.en.md). Customizing node styles can be seen as
|
|
111
|
+
redefining the theme based on the current node type.
|
|
112
|
+
|
|
113
|
+
For example, if all `rect` nodes in the theme have their border color defined as red `stroke: red`,
|
|
114
|
+
then you can redefine `UserTask` to have a blue `stroke: blue` border when customizing the
|
|
115
|
+
node `UserTask`. For more granular node style control,
|
|
116
|
+
see [API Style Attributes](../../api/runtime-model/nodeModel.en.md#style-attributes).
|
|
117
|
+
|
|
118
|
+
```tsx | pure
|
|
119
|
+
class UserTaskModel extends RectNodeModel {
|
|
120
|
+
getNodeStyle() {
|
|
121
|
+
const style = super.getNodeStyle();
|
|
122
|
+
style.stroke = 'blue';
|
|
123
|
+
return style;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
#### 2. Shape attributes
|
|
129
|
+
|
|
130
|
+
In LogicFlow, shape properties refer to attributes that control the final appearance of nodes, such
|
|
131
|
+
as `width` and `height` for dimensions, `radius` for rounded rectangles, `r` for circles (radius),
|
|
132
|
+
and `points` for polygons (vertices). These properties are crucial as LogicFlow calculates anchor
|
|
133
|
+
points for nodes and start/end points for connections based on them. Customizing shape properties
|
|
134
|
+
requires modification within the `setAttributes` method or `initNodeData` method.
|
|
135
|
+
|
|
136
|
+
LogicFlow has some shape attributes specific to each base node.
|
|
137
|
+
See [API Shape Attributes](../../api/runtime-model/nodeModel.en.md#shape-attributes) for details.
|
|
138
|
+
|
|
139
|
+
```tsx | pure
|
|
140
|
+
class customRectModel extends RectNodeModel {
|
|
141
|
+
initNodeData(data) {
|
|
142
|
+
super.initNodeData(data);
|
|
143
|
+
this.width = 200;
|
|
144
|
+
this.height = 80;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// or
|
|
148
|
+
setAttributes() {
|
|
149
|
+
this.width = 200;
|
|
150
|
+
this.height = 80;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
:::warning
|
|
156
|
+
|
|
157
|
+
If you don't set the shape attribute in `model`, but directly define the shape attribute such as
|
|
158
|
+
width and height of the generated graphic directly in `view`, the anchor position and outline size
|
|
159
|
+
will be incorrect. Also, the position of the connecting lines may be misplaced.
|
|
160
|
+
|
|
161
|
+
:::
|
|
162
|
+
|
|
163
|
+
#### 3. Customizing node styles based on properties attributes
|
|
164
|
+
|
|
165
|
+
In the previous LogicFlow example, it was mentioned that both nodes and edges in the `graph data`
|
|
166
|
+
retain a properties field. This field allows developers not only to modify elements' `styles`
|
|
167
|
+
and `shapes`, but also to store their own `business` attributes. Therefore, when customizing node
|
|
168
|
+
styles, developers can use properties from
|
|
169
|
+
the [properties](../../api/runtime-model/nodeModel.en.md#data-properties) to control how nodes display different
|
|
170
|
+
styles.
|
|
171
|
+
|
|
172
|
+
<code id="custom-rect" src="../../../src/tutorial/basic/node/properties"></code>
|
|
173
|
+
|
|
174
|
+
:::info
|
|
175
|
+
|
|
176
|
+
If you don't understand why `this.properties` prints out as a Proxy object, you can't see the
|
|
177
|
+
properties. Please check the <a href="https://github.com/didi/LogicFlow/issues/530" target="_blank">issue</a>, Printing a Proxy
|
|
178
|
+
object using `{ ...this.properties }`.
|
|
179
|
+
|
|
180
|
+
:::
|
|
181
|
+
|
|
182
|
+
### Customizing node `view`
|
|
183
|
+
|
|
184
|
+
LogicFlow can define the basic shape, style and other attributes of a node when customizing the
|
|
185
|
+
node's `model`. However, when you need a more complex node, you can use the custom node `view`
|
|
186
|
+
provided by LogicFlow.
|
|
187
|
+
|
|
188
|
+
The following is an example of a node `view`. Click `node1` several times to try it out.
|
|
189
|
+
|
|
190
|
+
<code id="node-custom-view" src="../../../src/tutorial/basic/node/custom-view"></code>
|
|
191
|
+
|
|
192
|
+
Here the `h function` is used for the return of `Shape`. The `h` method is a rendering function
|
|
193
|
+
exposed by LogicFlow, and its usage is the same as `react` and `vue`'
|
|
194
|
+
s <a href="https://v2.vuejs.org/v2/guide/render-function#createElement-Arguments" target="_blank">createElement</a> .
|
|
195
|
+
But here we need to create `SVG` tags, so some basic knowledge of SVG is required.
|
|
196
|
+
|
|
197
|
+
To give a few simple examples.
|
|
198
|
+
|
|
199
|
+
```tsx | pure
|
|
200
|
+
h(nodeName, attributes, [...children])
|
|
201
|
+
|
|
202
|
+
// <text x="100" y="100">Text content</text>
|
|
203
|
+
h('text', { x: 100, y: 100 }, ['Text content'])
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* <g>
|
|
207
|
+
* <rect x="100" y="100" stroke="#000000" strokeDasharray="3 3"></rect>
|
|
208
|
+
* <text x="100" y="100">Text content</text>
|
|
209
|
+
* </g>
|
|
210
|
+
*/
|
|
211
|
+
|
|
212
|
+
h('g', {}, [
|
|
213
|
+
h('rect', { x: 100, y: 100, stroke: "#000000", strokeDasharray: "3 3" }),
|
|
214
|
+
h('text', { x: 100, y: 100 }, ['Text content'])
|
|
215
|
+
])
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
#### The `getShape` method
|
|
219
|
+
|
|
220
|
+
This method defines the final rendered shape, and LogicFlow internally inserts its return into the
|
|
221
|
+
svg DOM. Developers do not necessarily need to override this method, but should only use it if they
|
|
222
|
+
want to change the svg DOM of the final rendered shape. In the example above, the final rendered svg
|
|
223
|
+
DOM of the `rect` node is just a rectangle. But when we want to add an icon to it, we need to change
|
|
224
|
+
the svg DOM of the final rendered graphic, which is done by overriding `getShape`.
|
|
225
|
+
|
|
226
|
+
LogicFlow defines the appearance of a node in three ways, namely **theme**, **custom node model**, *
|
|
227
|
+
*custom node view**. These three approaches are prioritized
|
|
228
|
+
as `theme < custom node mod < custom node view`.Their differences:
|
|
229
|
+
|
|
230
|
+
- Theme: defines common styles for all nodes of this base type, e.g. defines border color, width,
|
|
231
|
+
etc. for all `rect` nodes.
|
|
232
|
+
- Custom node model: Defines the data for this registered type of node, storing and managing
|
|
233
|
+
attributes such as style, shape, and business-related information of the node.
|
|
234
|
+
- Custom node view: Defines the `SVG DOM` for this registered type of node, visualizing the data
|
|
235
|
+
from the `model` based on its attributes, rendering the information into a graphical form visible
|
|
236
|
+
to the user.
|
|
237
|
+
|
|
238
|
+
:::warning
|
|
239
|
+
Although `custom node view` has the highest priority and the most complete function, theoretically
|
|
240
|
+
we can realize any effect we want through `custom node view`, but there are still some limitations
|
|
241
|
+
in this way.<br>
|
|
242
|
+
|
|
243
|
+
1. The shape attributes of the final graphic generated by the `custom node view` must be the same as
|
|
244
|
+
the shape attributes in the `model`, because the anchor points and borders of the nodes are
|
|
245
|
+
generated based on the `width` and `height` of the node's model.<br>
|
|
246
|
+
2. `Custom node view` must be consistent with the inherited base shape, not `rect` which is
|
|
247
|
+
inherited, but the final shape returned by getShape will be round. This is because LogicFlow will
|
|
248
|
+
base on the base graph for adjusting the lines on the nodes, generating anchor points, and so on.
|
|
249
|
+
:::
|
|
250
|
+
|
|
251
|
+
#### Some thoughts 🤔️
|
|
252
|
+
|
|
253
|
+
##### 1. Why the `x`,`y` of `rect` is not `x`,`y` directly from `model`?
|
|
254
|
+
|
|
255
|
+
In all the base nodes of LogicFlow, `x`,`y` inside `model` are uniformly representing the center
|
|
256
|
+
point. However, the `getShape` method gives us a way to generate the svg dom directly, and in the
|
|
257
|
+
svg, there is a difference in controlling the position of the shape:
|
|
258
|
+
|
|
259
|
+
- `rect`: the position of the shape is represented by `x`, `y`, but it is represented by the
|
|
260
|
+
coordinates of the top left corner of the shape. So generally the upper-left corner coordinates
|
|
261
|
+
are calculated by centering and subtracting half the width and height of the node.
|
|
262
|
+
|
|
263
|
+
```tsx | pure
|
|
264
|
+
const { x, y, width, height, radius } = this.props.model;
|
|
265
|
+
// svg dom <rect x="100" y="100" width="100" height="80">
|
|
266
|
+
h("rect", {
|
|
267
|
+
...style,
|
|
268
|
+
x: x - width / 2,
|
|
269
|
+
y: y - height / 2,
|
|
270
|
+
rx: radius, // Notice it's rx and not radius.
|
|
271
|
+
ry: radius,
|
|
272
|
+
width,
|
|
273
|
+
height
|
|
274
|
+
})
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
- `circle` and `ellipse`: indicate the position of the figure by `cx`, `cy`, meaning the coordinates
|
|
278
|
+
of the center point.
|
|
279
|
+
|
|
280
|
+
```tsx | pure
|
|
281
|
+
const { x, y, r } = this.props.model;
|
|
282
|
+
// svg dom <circle cx="100", cy="100", r="20">
|
|
283
|
+
h("circle", {
|
|
284
|
+
...style,
|
|
285
|
+
r,
|
|
286
|
+
cx: x,
|
|
287
|
+
cy: y,
|
|
288
|
+
})
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
```tsx
|
|
292
|
+
const { x, y, rx, ry } = this.props.model;
|
|
293
|
+
// svg dom <ellipse cx="100", cy="100", rx="20" ry="10">
|
|
294
|
+
h("ellipse", {
|
|
295
|
+
...style,
|
|
296
|
+
cx: x,
|
|
297
|
+
cy: y,
|
|
298
|
+
rx,
|
|
299
|
+
ry
|
|
300
|
+
})
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
- `polygon`: All vertex coordinates already contain positions
|
|
304
|
+
|
|
305
|
+
```tsx | pure
|
|
306
|
+
const { x, y, points } = this.props.model;
|
|
307
|
+
const pointStr = points.map((point) => {
|
|
308
|
+
return `${point[0] + x}, ${point[1] + y}`
|
|
309
|
+
}).join(" ");
|
|
310
|
+
// svg dom <polygon points="100,10 250,150 200,110" >
|
|
311
|
+
h("polygon", {
|
|
312
|
+
...style,
|
|
313
|
+
points: pointStr,
|
|
314
|
+
})
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
:::info{title=Customize the view of the rectangle with the radius setting.}
|
|
318
|
+
In `model`, `radius` is the shape attribute of the rectangle node. But when customizing `view`, you
|
|
319
|
+
need to note that svg doesn't use `radius` to set the rounded corners of the rectangle,
|
|
320
|
+
but <a href="https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/rx" target="_blank">rx</a>, ry. So when
|
|
321
|
+
customizing `view`'s rectangle, you need to assign the value of `radius` in the model to `rx`
|
|
322
|
+
and `ry`. you need to assign `radius` to `rx` and `ry` in the model when customizing the rectangle
|
|
323
|
+
of `view`, otherwise the rounded corners won't take effect.
|
|
324
|
+
:::
|
|
325
|
+
|
|
326
|
+
##### 2. How does props work?
|
|
327
|
+
|
|
328
|
+
LogicFlow is developed based on `preact`, when we customize the node view, we can get the data
|
|
329
|
+
passed from the parent component through `this.props`. The `this.props` object contains two
|
|
330
|
+
properties, they are.
|
|
331
|
+
|
|
332
|
+
- `model`: represents the model of the custom node
|
|
333
|
+
- [graphModel](../../api/runtime-model/graphModel.en.md): the model for the entire graph of logicflow
|
|
334
|
+
|
|
335
|
+
##### 3. How to get the path of an icon?
|
|
336
|
+
|
|
337
|
+
Generally, for icons we can look for the UI or go to <a href="https://www.iconfont.cn/?lang=en-us" target="_blank">iconfont.co.uk</a> to
|
|
338
|
+
get a file in svg format. Then open it as text in IDE and format it to see the code. The code is
|
|
339
|
+
usually an outermost svg tag with one or more paths inside. at this point, we can just use the `h`
|
|
340
|
+
method mentioned earlier to implement the code in the svg file.
|
|
341
|
+
|
|
342
|
+
The svg tag typically includes the following attributes:
|
|
343
|
+
|
|
344
|
+
- `viewBox`: The <a href="https://developer.mozilla.org/zh-CN/docs/Web/SVG/Attribute/viewBox" target="_blank">viewBox</a>
|
|
345
|
+
attribute allows a given set of graphic stretches to be specified to fit a particular container
|
|
346
|
+
element. It is generally sufficient to copy the value of the `viewBox` attribute from the svg tag.
|
|
347
|
+
- `width` and `height`: This doesn't need to use the `width` and `height` on the svg tag, just write
|
|
348
|
+
the width and height you expect.
|
|
349
|
+
|
|
350
|
+
The path tag attribute:
|
|
351
|
+
|
|
352
|
+
- `d`: This attribute defines a path. You can copy the svg code directly, you don't need to worry
|
|
353
|
+
about the meaning of d.
|
|
354
|
+
- `fill`: fill color of the path, generally consistent with the node's border color, but can also be
|
|
355
|
+
customized according to business needs.
|
|
356
|
+
|
|
357
|
+
This chapter introduces the basic nodes here, if there are more needs for the node please move to
|
|
358
|
+
the [advanced-node](../advanced/node.en.md) to view.
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
---
|
|
2
|
+
nav: 指南
|
|
3
|
+
group:
|
|
4
|
+
title: 基础
|
|
5
|
+
order: 1
|
|
6
|
+
title: 节点
|
|
7
|
+
order: 1
|
|
8
|
+
toc: content
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
本页从内置节点出发,介绍如何定义符合业务语义的自定义节点。更复杂的连接规则、锚点和框架节点方案,会在 [进阶节点](../advanced/node.zh.md) 中继续展开。
|
|
12
|
+
|
|
13
|
+
::::info{title=阅读提示}
|
|
14
|
+
- 适合已经跑通过 [快速上手](../get-started.zh.md) 和 [实例与图数据](class.zh.md) 的读者
|
|
15
|
+
- 前置知识:知道 `graphData`、`render` 和基础节点类型
|
|
16
|
+
- 本页不展开连接规则、锚点、React/Vue 节点方案,这些内容请继续阅读 [进阶节点](../advanced/node.zh.md)
|
|
17
|
+
- 相关 API:[`nodeModel`](../../api/runtime-model/nodeModel.zh.md)、[`graphModel`](../../api/runtime-model/graphModel.zh.md)、[`主题`](../../api/logicflow-instance/theme.zh.md)
|
|
18
|
+
::::
|
|
19
|
+
|
|
20
|
+
LogicFlow 内置了一些基础节点,开发者在实际应用场景中,可以基于这些基础节点,定义符合自己业务逻辑的节点。
|
|
21
|
+
|
|
22
|
+
## 认识基础节点
|
|
23
|
+
|
|
24
|
+
LogicFlow是基于svg做的流程图编辑框架,所以我们的节点和连线都是svg基本形状,对LogicFlow节点样式的修改,也就是对svg基本形状的修改。LogicFlow内部存在7种基础节点,分别为:
|
|
25
|
+
|
|
26
|
+
1. 矩形 --- <a href="https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/rect" target="_blank">rect</a>
|
|
27
|
+
2. 圆形 --- <a href="https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/circle" target="_blank">circle</a>
|
|
28
|
+
3. 椭圆 --- <a href="https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/ellipse" target="_blank">ellipse</a>
|
|
29
|
+
4. 多边形 --- <a href="https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/polygon" target="_blank">polygon</a>
|
|
30
|
+
5. 菱形 --- `diamond`(基于 <a href="https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/polygon" target="_blank">polygon</a>)
|
|
31
|
+
6. 文本 --- <a href="https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/text" target="_blank">text</a>
|
|
32
|
+
7. HTML --- `html`
|
|
33
|
+
|
|
34
|
+
<code id="node-shapes" src="../../../src/tutorial/basic/node/shapes"></code>
|
|
35
|
+
|
|
36
|
+
LogicFlow的基础节点是比较简单的,但是在业务中对节点外观要求可能有各种情况。LogicFlow提供了非常强大的自定义节点功能,可以支持开发者自定义各种节点。下面是基于继承的自定义节点介绍。
|
|
37
|
+
|
|
38
|
+
## 自定义节点
|
|
39
|
+
|
|
40
|
+
LogicFlow是基于继承来实现自定义节点、边。开发者可以继承LogicFlow内置的节点,然后利用面向对象的机制<a href="https://baike.baidu.com/item/%E9%87%8D%E5%86%99/9355942?fr=aladdin" target="_blank">
|
|
41
|
+
重写</a>
|
|
42
|
+
|
|
43
|
+

|
|
44
|
+
|
|
45
|
+
:::warning{title=注意}
|
|
46
|
+
LogicFlow推荐在实际应用场景中,所有的节点都使用自定义节点,将节点的type定义为符合项目业务意义的名称。而不是使用圆形、矩形这种仅表示外观的节点。
|
|
47
|
+
:::
|
|
48
|
+
|
|
49
|
+
### 节点`model`和`view`
|
|
50
|
+
|
|
51
|
+
`model`: 数据层,包含节点各种样式(边框、颜色)、形状(宽高、顶点位置)、业务属性等。
|
|
52
|
+
|
|
53
|
+
`view`: 视图层,控制节点的最终渲染效果,通过改变`model`就可以满足自定义节点,同时可以在`view`
|
|
54
|
+
上定制更加复杂的`svg`元素。
|
|
55
|
+
|
|
56
|
+
LogicFlow基于MVVM模式实现的,在自定义一个节点的时候,我们可以重新定义节点的`model`和`view`
|
|
57
|
+
,通过重写定义在`model`上获取样式相关的方法和重写`view`上的`getShape`来定义复杂的节点外观。
|
|
58
|
+
|
|
59
|
+
这是一个基于继承内置节点并重写`model`的自定义节点例子👇,节点自定义采用了不同的方式实现😊。
|
|
60
|
+
|
|
61
|
+
<code id="node-custom" src="../../../src/tutorial/basic/node/custom"></code>
|
|
62
|
+
|
|
63
|
+
[lf.register](../../api/logicflow-instance/register.zh.md#register):注册自定义节点,注册后才能使用自定义节点。
|
|
64
|
+
|
|
65
|
+
:::info{title=提示}
|
|
66
|
+
|
|
67
|
+
LogicFlow为了开发的时候将开发体验和现在前端流行的开发体验对齐,也为了在代码层面更好的理解,让更多的人可以参与进来,我们基于preact、mobx以MVVM模式进行开发。如果大家熟悉react开发的话,可以直接阅读我们的源码,你们可以发现整个项目阅读起来难度和你自己开发的项目差不多。
|
|
68
|
+
**我们欢迎大家一起参与进来。**
|
|
69
|
+
|
|
70
|
+
:::
|
|
71
|
+
|
|
72
|
+
LogicFlow 内部存在 7 种基础节点, 自定义节点的时候可以基于需要选择任意一种来继承,
|
|
73
|
+
然后取一个符合自己业务意义的名字。以@logicflow/extension中提供的可缩放节点为例:LogicFlow
|
|
74
|
+
基础节点不支持节点缩放,于是 LogicFlow
|
|
75
|
+
在extension包中,基于基础节点,封装了对节点缩放的逻辑,然后发布出去。这样开发者可以直接基于extension中的可缩放节点进行自定义。
|
|
76
|
+
|
|
77
|
+
```tsx | pure
|
|
78
|
+
import { RectResize } from "@logicflow/extension";
|
|
79
|
+
class CustomNodeModel extends RectResize.model {}
|
|
80
|
+
class CustomNode extends RectResize.view {}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 自定义节点`model`
|
|
84
|
+
|
|
85
|
+
LogicFlow把自定义节点外观分为了`自定义节点样式属性`和`自定义节点形状属性`
|
|
86
|
+
两种方式。更多详细定义方法,请查看[NodeModel](../../api/runtime-model/nodeModel.zh.md)。
|
|
87
|
+
|
|
88
|
+
#### 1. 样式属性
|
|
89
|
+
|
|
90
|
+
在LogicFlow中,外观属性表示控制着节点`边框`、`颜色`
|
|
91
|
+
这类偏外观的属性。这些属性是可以直接通过[主题配置](../../api/logicflow-instance/theme.zh.md)
|
|
92
|
+
来控制。自定义节点样式可以看做在主题的基础上基于当前节点的类型进行再次定义。
|
|
93
|
+
|
|
94
|
+
例如:在主题中对所有`rect`节点都定义其边框颜色为红色`stroke: red`,那么可以在自定义节点`UserTask`
|
|
95
|
+
的时候,重新定义`UserTask`边框为蓝色`stroke: blue`
|
|
96
|
+
。更细粒度的节点样式控制方法,详情见[API 样式属性](../../api/runtime-model/nodeModel.zh.md#样式属性)。
|
|
97
|
+
|
|
98
|
+
```tsx | pure
|
|
99
|
+
class UserTaskModel extends RectNodeModel {
|
|
100
|
+
getNodeStyle() {
|
|
101
|
+
const style = super.getNodeStyle();
|
|
102
|
+
style.stroke = 'blue';
|
|
103
|
+
return style;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
#### 2. 形状属性
|
|
109
|
+
|
|
110
|
+
在 LogicFlow 中,形状属性表示节点的宽 `width`、高 `height`,矩形的圆角 `radius`、圆形的半径 `r`、
|
|
111
|
+
多边形的顶点`points`
|
|
112
|
+
等这些控制着节点最终形状的属性。因为LogicFlow在计算节点的锚点、连线的起点终点的时候,会基于形状属性进行计算。对于形状属性的自定义,需要在`setAttributes`
|
|
113
|
+
方法或`initNodeData`方法中进行。
|
|
114
|
+
|
|
115
|
+
LogicFlow对于不同的基础节点,存在一些各基础节点自己特有的形状属性。详情见[API 形状属性](../../api/runtime-model/nodeModel.zh.md#形状属性)。
|
|
116
|
+
|
|
117
|
+
```tsx | pure
|
|
118
|
+
class customRectModel extends RectNodeModel {
|
|
119
|
+
initNodeData(data) {
|
|
120
|
+
super.initNodeData(data);
|
|
121
|
+
this.width = 200;
|
|
122
|
+
this.height = 80;
|
|
123
|
+
this.radius = 20; // 矩形特有
|
|
124
|
+
}
|
|
125
|
+
// or
|
|
126
|
+
setAttributes() {
|
|
127
|
+
this.width = 200;
|
|
128
|
+
this.height = 80;
|
|
129
|
+
this.radius = 20; // 矩形特有
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
:::warning{title=注意}
|
|
135
|
+
|
|
136
|
+
如果不在`model`中设置形状属性,而是直接在`view`
|
|
137
|
+
中直接定义生成图形的宽高这种形状属性,会出现锚点位置、outline大小不正确的情况。同时,连线的位置也可能会出现错乱。
|
|
138
|
+
|
|
139
|
+
:::
|
|
140
|
+
|
|
141
|
+
#### 3. 基于properties属性自定义节点样式
|
|
142
|
+
|
|
143
|
+
在上一节LogicFlow的实例中的`图数据`
|
|
144
|
+
里提到,不论是节点还是边,LogicFlow都保留了properties字段,不仅可以修改元素的`样式`、`形状`
|
|
145
|
+
属性,可以用于给开发者存放自己的`业务`
|
|
146
|
+
属性。所以在自定义节点样式的时候,可以基于 [properties](../../api/runtime-model/nodeModel.zh.md#数据属性)
|
|
147
|
+
中的属性来控制节点显示不同的样式。
|
|
148
|
+
|
|
149
|
+
<code id="custom-rect" src="../../../src/tutorial/basic/node/properties"></code>
|
|
150
|
+
|
|
151
|
+
:::info{title=提示}
|
|
152
|
+
|
|
153
|
+
如果不了解为什么`this.properties`打印出来是一个Proxy对象,
|
|
154
|
+
无法看到属性。请查看 <a href="https://github.com/didi/LogicFlow/issues/530" target="_blank">issue</a> ,
|
|
155
|
+
可以使用`{ ...this.properties }`打印Proxy对象。
|
|
156
|
+
|
|
157
|
+
:::
|
|
158
|
+
|
|
159
|
+
### 自定义节点`view`
|
|
160
|
+
|
|
161
|
+
LogicFlow在自定义节点的`model`
|
|
162
|
+
时,可以定义节点的基础形状、样式等属性。但是当开发者需要一个更加复杂的节点时,可以使用LogicFlow提供的自定义节点`view`
|
|
163
|
+
的方式:重写`getShape`方法。
|
|
164
|
+
|
|
165
|
+
下面这个例子就是关于节点`view`的设置,多次点击`节点1`试试呢~
|
|
166
|
+
|
|
167
|
+
<code id="node-custom-view" src="../../../src/tutorial/basic/node/custom-view"></code>
|
|
168
|
+
|
|
169
|
+
这里对于`getShape`的方法返回用到了`h函数`。`h`函数是 LogicFlow 对外暴露的渲染函数,其用法与 `react`、`vue`
|
|
170
|
+
的 <a href="https://v2.cn.vuejs.org/v2/guide/render-function.html#createElement-%E5%8F%82%E6%95%B0" target="_blank">createElement</a>
|
|
171
|
+
一致。但是这里我们需要创建的是 `svg` 标签,所以需要有一定的 `svg` 基础知识。
|
|
172
|
+
|
|
173
|
+
如果你希望直接使用 React/Vue 组件渲染节点,建议优先阅读进阶教程中的
|
|
174
|
+
[React 节点](../advanced/react.zh.md) 和 [Vue 节点](../advanced/vue.zh.md)。
|
|
175
|
+
|
|
176
|
+
举几个简单的例子:
|
|
177
|
+
|
|
178
|
+
```tsx | pure
|
|
179
|
+
h(nodeName, attributes, [...children])
|
|
180
|
+
|
|
181
|
+
// <text x="100" y="100">文本内容</text>
|
|
182
|
+
h('text', { x: 100, y: 100 }, ['文本内容'])
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* <g>
|
|
186
|
+
* <rect x="100" y="100" stroke="#000000" strokeDasharray="3 3"></rect>
|
|
187
|
+
* <text x="100" y="100">文本内容</text>
|
|
188
|
+
* </g>
|
|
189
|
+
*/
|
|
190
|
+
|
|
191
|
+
h('g',{}, [
|
|
192
|
+
h('rect', { x: 100, y: 100, stroke: "#000000", strokeDasharray: "3 3"}),
|
|
193
|
+
h('text', { x: 100, y: 100 }, ['文本内容'])
|
|
194
|
+
])
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
#### `getShape`方法
|
|
198
|
+
|
|
199
|
+
此方法作用就是定义最终渲染的图形, LogicFlow内部会将其返回的内容插入到svg
|
|
200
|
+
DOM上。开发者不是一定需要重写此方法,只有在期望改变最终渲染图形svg
|
|
201
|
+
DOM的时候才使用此方法。以上面是例子来说,`rect`节点最终渲染的svg
|
|
202
|
+
DOM只是一个矩形。但是当我们想要在上面加一个图标的时候,那边必定需要修改到最终渲染图形的svg
|
|
203
|
+
DOM了,这个时候就需要通过重写`getShape`来实现了。
|
|
204
|
+
|
|
205
|
+
LogicFlow定义一个节点的外观有三种方式,分别为**主题**、**自定义节点model**、**自定义节点view**
|
|
206
|
+
。这三种方式优先级为`主题 < 自定义节点model < 自定义节点view`。他们的差异是:
|
|
207
|
+
|
|
208
|
+
- 主题:定义所有此基础类型节点的通用样式,例如定义所有`rect`节点的边框颜色、宽度等。
|
|
209
|
+
- 自定义节点model:定义此注册类型节点的数据,存储和管理该节点样式、形状、业务等数据属性信息。
|
|
210
|
+
- 自定义节点view: 定义此注册类型节点`svg dom`,基于 `model` 的属性可视化呈现,将 `model`
|
|
211
|
+
中的数据渲染成用户可以看到的图形化形式。
|
|
212
|
+
|
|
213
|
+
:::warning{title=注意}
|
|
214
|
+
虽然`自定义节点view`优先级最高,功能也最完善,理论上我们可以完全通过`自定义节点view`
|
|
215
|
+
实现任何我们想要的效果,但是此方式还是存在一些限制。<br>
|
|
216
|
+
|
|
217
|
+
1. `自定义节点view`最终生成的图形的形状属性必须和`model`
|
|
218
|
+
中形状属性的一致,因为节点的锚点、外边框都是基于节点model中的`width`和`height`生成。<br>
|
|
219
|
+
2. `自定义节点view`最终生成的图形整体轮廓必须和继承的基础图形一致,不能继承`rect`
|
|
220
|
+
而在getShape的时候返回的最终图形轮廓变成了`circle`。因为LogicFlow对于节点上的连线调整、锚点生成等会基于基础图形进行计算。
|
|
221
|
+
:::
|
|
222
|
+
|
|
223
|
+
#### 一些思考🤔️
|
|
224
|
+
|
|
225
|
+
##### 1. 为什么`rect`的`x`,`y`不是直接从`model`中获取的`x`, `y`?
|
|
226
|
+
|
|
227
|
+
在LogicFlow所有的基础节点中,`model`里面的`x`,`y`都是统一表示元素中心点坐标。`getShape`方法给我们提供直接生成svg
|
|
228
|
+
dom的方式,但在svg中, 不同元素类型`x`,`y`表示的坐标位置不同:
|
|
229
|
+
|
|
230
|
+
- `rect`: 通过`x`, `y`表示图形的位置,但是表示的是图形左上角坐标。 所以一般通过中心点,然后减去节点的宽高的一半计算出左上角坐标。
|
|
231
|
+
|
|
232
|
+
```tsx | pure
|
|
233
|
+
const { x, y, width, height, radius } = this.props.model
|
|
234
|
+
// svg dom <rect x="100" y="100" width="100" height="80">
|
|
235
|
+
h('rect', {
|
|
236
|
+
...style,
|
|
237
|
+
x: x - width / 2,
|
|
238
|
+
y: y - height / 2,
|
|
239
|
+
rx: radius, // 注意这里是rx属性而不是radius
|
|
240
|
+
ry: radius,
|
|
241
|
+
width,
|
|
242
|
+
height,
|
|
243
|
+
})
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
- `circle`和`ellipse`: 通过`cx`, `cy`表示图形的位置,含义为中心点的坐标,这里就不需要改变。
|
|
247
|
+
|
|
248
|
+
```tsx | pure
|
|
249
|
+
const { x, y, r } = this.props.model;
|
|
250
|
+
// svg dom <circle cx="100", cy="100", r="20">
|
|
251
|
+
h("circle", {
|
|
252
|
+
...style,
|
|
253
|
+
r, // 半径保持不变
|
|
254
|
+
cx: x,
|
|
255
|
+
cy: y,
|
|
256
|
+
})
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
```tsx | pure
|
|
260
|
+
// 椭圆
|
|
261
|
+
const { x, y, rx, ry } = this.props.model
|
|
262
|
+
// svg dom <ellipse cx="100", cy="100", rx="20" ry="10">
|
|
263
|
+
h('ellipse', {
|
|
264
|
+
...style,
|
|
265
|
+
cx: x,
|
|
266
|
+
cy: y,
|
|
267
|
+
rx,
|
|
268
|
+
ry,
|
|
269
|
+
})
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
- `polygon`: 所有的顶点坐标已包含位置。
|
|
273
|
+
|
|
274
|
+
```tsx | pure
|
|
275
|
+
const { x, y, points } = this.props.model
|
|
276
|
+
const pointStr = points.map((point) => {
|
|
277
|
+
return `${point[0] + x}, ${point[1] + y}`
|
|
278
|
+
}).join(' ')
|
|
279
|
+
// svg dom <polygon points="100,10 250,150 200,110" >
|
|
280
|
+
h('polygon', {
|
|
281
|
+
...style,
|
|
282
|
+
points: pointStr,
|
|
283
|
+
})
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
:::info{title=自定义矩形的view时radius设置}
|
|
287
|
+
在`model`中,`radius`是矩形节点的形状属性。但是在自定义`view`
|
|
288
|
+
时需要注意,svg里面设置矩形的圆角并不是用`radius`
|
|
289
|
+
,而是使用 <a href="https://developer.mozilla.org/zh-CN/docs/Web/SVG/Attribute/rx" target="_blank">rx</a> , ry。所以在自定义`view`
|
|
290
|
+
的矩形时,需要将model中`radius`的赋值给`rx`和`ry`,否则圆角将不生效。
|
|
291
|
+
:::
|
|
292
|
+
|
|
293
|
+
##### 2. props怎么用?
|
|
294
|
+
|
|
295
|
+
LogicFlow是基于`preact`开发的,我们自定义节点view的时候,可以通过`this.props`
|
|
296
|
+
获取父组件传递过来的数据。`this.props`对象包含两个属性,分别为:
|
|
297
|
+
|
|
298
|
+
- `model`: 表示自定义节点的model
|
|
299
|
+
- [graphModel](../../api/runtime-model/graphModel.zh.md): 表示logicflow整个图的model
|
|
300
|
+
|
|
301
|
+
##### 3. 图标的path如何获取?
|
|
302
|
+
|
|
303
|
+
一般情况下,图标我们可以找UI或者去 <a href="https://www.iconfont.cn/" target="_blank">iconfont.cn</a>
|
|
304
|
+
获得一个svg格式的文件。然后再IDE中以文本的方式打开,然后格式化,就可以看到代码。代码中一般是最外层一个svg标签,里面是一个或者多个path。这个时候,我们使用前面提到的`h`
|
|
305
|
+
方法来实现svg文件中的代码即可。
|
|
306
|
+
|
|
307
|
+
svg标签一般包括如下属性:
|
|
308
|
+
|
|
309
|
+
- `viewBox`: <a href="https://developer.mozilla.org/zh-CN/docs/Web/SVG/Attribute/viewBox" target="_blank">viewBox</a>
|
|
310
|
+
属性允许指定一个给定的一组图形伸展以适应特定的容器元素。一般把svg标签上的`viewBox`属性值复制过来就行。
|
|
311
|
+
- `width`和`height`: 这个不需要使用svg标签上的`width`和`height`, 直接写成你期望的宽高就行。
|
|
312
|
+
|
|
313
|
+
path标签属性:
|
|
314
|
+
|
|
315
|
+
- `d`: 该属性定义了一个路径。直接复制svg代码过来即可, 不需要去关系d具体内容表示的含义。
|
|
316
|
+
- `fill`: 路径的填充颜色, 一般和节点的边框颜色一致,但是也可以按照业务需求自定义。
|
|
317
|
+
|
|
318
|
+
本章基础节点就介绍到这里,如果有对节点更多需求请移步至[进阶-节点](../advanced/node.zh.md)进行查看。
|