@logicflow/core 2.2.1 → 2.2.3
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/README.md +32 -0
- 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,501 @@
|
|
|
1
|
+
---
|
|
2
|
+
nav: Guide
|
|
3
|
+
group:
|
|
4
|
+
title: Introduce
|
|
5
|
+
title: Getting Started
|
|
6
|
+
order: 1
|
|
7
|
+
toc: content
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
Welcome to the Quickstart, in this section you will learn:
|
|
11
|
+
- How to install LogicFlow dependencies for your project
|
|
12
|
+
- How to create a flowchart canvas using LogicFlow.
|
|
13
|
+
- How to add functionality to a flowchart canvas using the LogicFlow plugin.
|
|
14
|
+
- LogicFlow input and output data formats and how to do data conversion.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
### Command Installation
|
|
19
|
+
|
|
20
|
+
You can install using npm, yarn, or pnpm.
|
|
21
|
+
|
|
22
|
+
:::code-group
|
|
23
|
+
|
|
24
|
+
```bash [npm]
|
|
25
|
+
npm install @logicflow/core --save
|
|
26
|
+
|
|
27
|
+
# Plugin package (not needed if plugins are not used)
|
|
28
|
+
npm install @logicflow/extension --save
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```bash [yarn]
|
|
32
|
+
yarn add @logicflow/core
|
|
33
|
+
|
|
34
|
+
# Plugin package (not needed if plugins are not used)
|
|
35
|
+
yarn add @logicflow/extension
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```bash [pnpm]
|
|
39
|
+
pnpm add @logicflow/core
|
|
40
|
+
|
|
41
|
+
# Plugin package (not needed if plugins are not used)
|
|
42
|
+
pnpm add @logicflow/extension
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
:::
|
|
46
|
+
|
|
47
|
+
If you use AI coding tools, read [AI Programming Support](ai.en.md) and provide your Agent with LogicFlow's local docs location and official-capability-first rule.
|
|
48
|
+
|
|
49
|
+
### Using CDN
|
|
50
|
+
|
|
51
|
+
LogicFlow requires including CSS files for its built-in styles in addition to the JS files.
|
|
52
|
+
|
|
53
|
+
:::code-group
|
|
54
|
+
|
|
55
|
+
```html [introduce under v2.0]
|
|
56
|
+
|
|
57
|
+
<!-- Import the core package and corresponding css -->
|
|
58
|
+
<script src="https://cdn.jsdelivr.net/npm/@logicflow/core/dist/index.min.js"></script>
|
|
59
|
+
<link href="https://cdn.jsdelivr.net/npm/@logicflow/core/lib/style/index.min.css" rel="stylesheet">
|
|
60
|
+
|
|
61
|
+
<!-- Import extension packages and corresponding css (not necessary when not using plugins) -->
|
|
62
|
+
<script src="https://cdn.jsdelivr.net/npm/@logicflow/extension/dist/index.min.js"></script>
|
|
63
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@logicflow/extension/lib/style/index.min.css" />
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
```html [introduce under v1.0]
|
|
68
|
+
|
|
69
|
+
<!-- Import the core package and corresponding css -->
|
|
70
|
+
<script src="https://cdn.jsdelivr.net/npm/@logicflow/core@1.2.27/dist/logic-flow.js"></script>
|
|
71
|
+
<link href="https://cdn.jsdelivr.net/npm/@logicflow/core@1.2.27/dist/style/index.css" rel="stylesheet">
|
|
72
|
+
|
|
73
|
+
<!-- Import extension packages and corresponding css (not necessary when not using plugins) -->
|
|
74
|
+
<!-- Tip: version 1.0, the plug-in script package is exported separately, so the introduction of a component, the reference path needs to be specific to the name of the package, like the following introduction of the Menu plug-in so 👇🏻 -->
|
|
75
|
+
<script src="https://cdn.jsdelivr.net/npm/@logicflow/extension@1.2.27/lib/Menu.js"></script>
|
|
76
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@logicflow/extension@1.2.27/lib/style/index.css" />
|
|
77
|
+
```
|
|
78
|
+
:::
|
|
79
|
+
|
|
80
|
+
By default, the CDN will include the latest version. To include a different version, refer to the specific package information here:
|
|
81
|
+
<a href="https://www.jsdelivr.com/package/npm/@logicflow/core" target="_blank">core package</a>
|
|
82
|
+
<a href="https://www.jsdelivr.com/package/npm/@logicflow/extension" target="_blank">extension package</a>, and adjust the CDN path accordingly.
|
|
83
|
+
|
|
84
|
+
## Getting Started
|
|
85
|
+
|
|
86
|
+
Let's get started with LogicFlow now!
|
|
87
|
+
|
|
88
|
+
### 1. Using in Native JS
|
|
89
|
+
|
|
90
|
+
It's easy to create and display an instance of LogicFlow, you just need to write a piece of code that looks like this:
|
|
91
|
+
|
|
92
|
+
``` javascript
|
|
93
|
+
// Initialising instances
|
|
94
|
+
const lf = new LogicFlow({
|
|
95
|
+
container: document.querySelector('#container'),
|
|
96
|
+
// Other options
|
|
97
|
+
})
|
|
98
|
+
// Render data
|
|
99
|
+
lf.render({
|
|
100
|
+
// Data to be rendered
|
|
101
|
+
})
|
|
102
|
+
```
|
|
103
|
+
Developers can initialise LogicFlow instances and render data according to their actual needs.
|
|
104
|
+
LogicFlow itself is packaged in umd as a pure JS package, so it can be used in both vue and react. Below are some examples of how to introduce and use LogicFlow in both native and framework environments for reference.
|
|
105
|
+
|
|
106
|
+
<iframe src="/original-usage.html" style="border: none; width: 100%; height: 400px; margin: auto;"></iframe>
|
|
107
|
+
|
|
108
|
+
:::code-group
|
|
109
|
+
|
|
110
|
+
``` html [Origin environment]
|
|
111
|
+
<html>
|
|
112
|
+
<head>
|
|
113
|
+
<title>Original Usage</title>
|
|
114
|
+
</head>
|
|
115
|
+
<body>
|
|
116
|
+
<!-- 引入 core 包和对应 css-->
|
|
117
|
+
<script src="https://cdn.jsdelivr.net/npm/@logicflow/core/dist/index.min.js"></script>
|
|
118
|
+
<link href="https://cdn.jsdelivr.net/npm/@logicflow/core/lib/style/index.min.css" rel="stylesheet">
|
|
119
|
+
|
|
120
|
+
<!-- 创建画布容器 -->
|
|
121
|
+
<div id="container"></div>
|
|
122
|
+
</body>
|
|
123
|
+
<script>
|
|
124
|
+
// 引入继承节点,引入 core 包后,会自动挂载 window.Core
|
|
125
|
+
// const { RectNode, RectNodeModel } = Core;
|
|
126
|
+
|
|
127
|
+
// 准备图数据
|
|
128
|
+
const data = {
|
|
129
|
+
// 节点数据
|
|
130
|
+
nodes: [
|
|
131
|
+
{
|
|
132
|
+
id: '21', // 节点ID,需要全局唯一,不传入内部会自动生成一个ID
|
|
133
|
+
type: 'rect', // 节点类型,可以传入LogicFlow内置的7种节点类型,也可以注册自定义节点后传入自定义类型
|
|
134
|
+
x: 100, // 节点形状中心在x轴位置
|
|
135
|
+
y: 100, // 节点形状中心在y轴的位置
|
|
136
|
+
text: 'Origin Usage-rect', // 节点文本
|
|
137
|
+
properties: { // 自定义属性,用于存储需要这个节点携带的信息,可以传入宽高以重设节点的宽高
|
|
138
|
+
width: 160,
|
|
139
|
+
height: 80,
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
id: '50',
|
|
144
|
+
type: 'circle',
|
|
145
|
+
x: 300,
|
|
146
|
+
y: 300,
|
|
147
|
+
text: 'Origin Usage-circle',
|
|
148
|
+
properties: {
|
|
149
|
+
r: 60,
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
// 边数据
|
|
154
|
+
edges: [
|
|
155
|
+
{
|
|
156
|
+
id: 'rect-2-circle', // 边ID,性质与节点ID一样
|
|
157
|
+
type: 'polyline', // 边类型
|
|
158
|
+
sourceNodeId: '50', // 起始节点Id
|
|
159
|
+
targetNodeId: '21', // 目标节点Id
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// 创建画布实例,也可以 new Core.LogicFLow
|
|
165
|
+
const lf = new Core.default({
|
|
166
|
+
container: document.querySelector('#container'),
|
|
167
|
+
// width: 700, // 宽高和容器存一即可
|
|
168
|
+
// height: 500, // 如果二者同时存在,会优先取设置的宽高
|
|
169
|
+
grid: true,
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
// 渲染画布实例
|
|
173
|
+
lf.render(data)
|
|
174
|
+
</script>
|
|
175
|
+
</html>
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
``` jsx [React]
|
|
179
|
+
import LogicFlow from '@logicflow/core';
|
|
180
|
+
import '@logicflow/core/dist/index.css';
|
|
181
|
+
import { useEffect, useRef } from 'react';
|
|
182
|
+
|
|
183
|
+
export default function App() {
|
|
184
|
+
const refContainer = useRef(null);
|
|
185
|
+
const data = {
|
|
186
|
+
// 节点数据
|
|
187
|
+
nodes: [
|
|
188
|
+
{
|
|
189
|
+
id: '21', // 节点ID,需要全局唯一,不传入内部会自动生成一个ID
|
|
190
|
+
type: 'rect', // 节点类型,可以传入LogicFlow内置的7种节点类型,也可以注册自定义节点后传入自定义类型
|
|
191
|
+
x: 100, // 节点形状中心在x轴位置
|
|
192
|
+
y: 100, // 节点形状中心在y轴的位置
|
|
193
|
+
text: 'Origin Usage-rect', // 节点文本
|
|
194
|
+
properties: { // 自定义属性,用于存储需要这个节点携带的信息,可以传入宽高以重设节点的宽高
|
|
195
|
+
width: 160,
|
|
196
|
+
height: 80,
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
id: '50',
|
|
201
|
+
type: 'circle',
|
|
202
|
+
x: 300,
|
|
203
|
+
y: 300,
|
|
204
|
+
text: 'Origin Usage-circle',
|
|
205
|
+
properties: {
|
|
206
|
+
r: 60,
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
// 边数据
|
|
211
|
+
edges: [
|
|
212
|
+
{
|
|
213
|
+
id: 'rect-2-circle', // 边ID,性质与节点ID一样
|
|
214
|
+
type: 'polyline', // 边类型
|
|
215
|
+
sourceNodeId: '50', // 起始节点Id
|
|
216
|
+
targetNodeId: '21', // 目标节点Id
|
|
217
|
+
},
|
|
218
|
+
],
|
|
219
|
+
};
|
|
220
|
+
useEffect(() => {
|
|
221
|
+
const lf = new LogicFlow({
|
|
222
|
+
container: refContainer.current,
|
|
223
|
+
grid: true,
|
|
224
|
+
height: 200,
|
|
225
|
+
});
|
|
226
|
+
lf.render(data);
|
|
227
|
+
lf.translateCenter();
|
|
228
|
+
}, []);
|
|
229
|
+
|
|
230
|
+
return <div className="App" ref={refContainer}></div>;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
``` vue [Vue]
|
|
236
|
+
<template>
|
|
237
|
+
<div class="container" ref="container"></div>
|
|
238
|
+
</template>
|
|
239
|
+
|
|
240
|
+
<script>
|
|
241
|
+
import LogicFlow from "@logicflow/core";
|
|
242
|
+
import "@logicflow/core/lib/style/index.css";
|
|
243
|
+
|
|
244
|
+
export default {
|
|
245
|
+
name: 'lf-Demo',
|
|
246
|
+
data() {
|
|
247
|
+
return {
|
|
248
|
+
renderData: {
|
|
249
|
+
// 节点数据
|
|
250
|
+
nodes: [
|
|
251
|
+
{
|
|
252
|
+
id: '21', // 节点ID,需要全局唯一,不传入内部会自动生成一个ID
|
|
253
|
+
type: 'rect', // 节点类型,可以传入LogicFlow内置的7种节点类型,也可以注册自定义节点后传入自定义类型
|
|
254
|
+
x: 100, // 节点形状中心在x轴位置
|
|
255
|
+
y: 100, // 节点形状中心在y轴的位置
|
|
256
|
+
text: 'Origin Usage-rect', // 节点文本
|
|
257
|
+
properties: { // 自定义属性,用于存储需要这个节点携带的信息,可以传入宽高以重设节点的宽高
|
|
258
|
+
width: 160,
|
|
259
|
+
height: 80,
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
id: '50',
|
|
264
|
+
type: 'circle',
|
|
265
|
+
x: 300,
|
|
266
|
+
y: 300,
|
|
267
|
+
text: 'Origin Usage-circle',
|
|
268
|
+
properties: {
|
|
269
|
+
r: 60,
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
],
|
|
273
|
+
// 边数据
|
|
274
|
+
edges: [
|
|
275
|
+
{
|
|
276
|
+
id: 'rect-2-circle', // 边ID,性质与节点ID一样
|
|
277
|
+
type: 'polyline', // 边类型
|
|
278
|
+
sourceNodeId: '50', // 起始节点Id
|
|
279
|
+
targetNodeId: '21', // 目标节点Id
|
|
280
|
+
},
|
|
281
|
+
],
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
mounted() {
|
|
286
|
+
this.lf = new LogicFlow({
|
|
287
|
+
container: this.$refs.container,
|
|
288
|
+
grid: true,
|
|
289
|
+
});
|
|
290
|
+
this.lf.render(renderData);
|
|
291
|
+
},
|
|
292
|
+
};
|
|
293
|
+
</script>
|
|
294
|
+
|
|
295
|
+
<style scoped>
|
|
296
|
+
.container {
|
|
297
|
+
width: 1000px;
|
|
298
|
+
height: 500px;
|
|
299
|
+
}
|
|
300
|
+
</style>
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
``` ts [Angular]
|
|
304
|
+
// demo.component.html
|
|
305
|
+
// <div class="container" #lfdom></div>
|
|
306
|
+
|
|
307
|
+
//demo.component.ts
|
|
308
|
+
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
|
|
309
|
+
import LogicFlow from '@logicflow/core'
|
|
310
|
+
import { Router } from '@angular/router';
|
|
311
|
+
|
|
312
|
+
@Component({
|
|
313
|
+
selector: 'app-demo',
|
|
314
|
+
templateUrl: './demo.component.html',
|
|
315
|
+
styleUrls: ['./demo.component.css']
|
|
316
|
+
})
|
|
317
|
+
export class DemoComponent implements OnInit {
|
|
318
|
+
|
|
319
|
+
@ViewChild('lfdom', { static: true }) lfdom: any;
|
|
320
|
+
|
|
321
|
+
constructor(private router: Router) { }
|
|
322
|
+
|
|
323
|
+
ngOnInit(): void {
|
|
324
|
+
const lf = new LogicFlow({
|
|
325
|
+
container: this.lfdom.nativeElement,
|
|
326
|
+
grid: true,
|
|
327
|
+
width: 1000,
|
|
328
|
+
height: 500
|
|
329
|
+
});
|
|
330
|
+
lf.render({
|
|
331
|
+
nodes: [
|
|
332
|
+
{
|
|
333
|
+
id: '21', // 节点ID,需要全局唯一,不传入内部会自动生成一个ID
|
|
334
|
+
type: 'rect', // 节点类型,可以传入LogicFlow内置的7种节点类型,也可以注册自定义节点后传入自定义类型
|
|
335
|
+
x: 100, // 节点形状中心在x轴位置
|
|
336
|
+
y: 100, // 节点形状中心在y轴的位置
|
|
337
|
+
text: 'Origin Usage-rect', // 节点文本
|
|
338
|
+
properties: { // 自定义属性,用于存储需要这个节点携带的信息,可以传入宽高以重设节点的宽高
|
|
339
|
+
width: 160,
|
|
340
|
+
height: 80,
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
id: '50',
|
|
345
|
+
type: 'circle',
|
|
346
|
+
x: 300,
|
|
347
|
+
y: 300,
|
|
348
|
+
text: 'Origin Usage-circle',
|
|
349
|
+
properties: {
|
|
350
|
+
r: 60,
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
],
|
|
354
|
+
// 边数据
|
|
355
|
+
edges: [
|
|
356
|
+
{
|
|
357
|
+
id: 'rect-2-circle', // 边ID,性质与节点ID一样
|
|
358
|
+
type: 'polyline', // 边类型
|
|
359
|
+
sourceNodeId: '50', // 起始节点Id
|
|
360
|
+
targetNodeId: '21', // 目标节点Id
|
|
361
|
+
},
|
|
362
|
+
],
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
}
|
|
368
|
+
```
|
|
369
|
+
:::
|
|
370
|
+
|
|
371
|
+
:::warning{title=Tip}
|
|
372
|
+
LogicFlow supports not passing the canvas width and height when initializing, in this case the default width and height of the DOM node passed by the container parameter is taken.
|
|
373
|
+
|
|
374
|
+
In order to ensure the canvas can be rendered normally, please initialize LogicFlow instance after making sure the corresponding container already exists and has the width and height.
|
|
375
|
+
:::
|
|
376
|
+
|
|
377
|
+
### 2. Using in Frameworks
|
|
378
|
+
|
|
379
|
+
If a plugin is required, the developer needs to bring in the `@logicflow/extension` dependency package and introduce the plugin according to their own requirements.
|
|
380
|
+
|
|
381
|
+
Below is an example of using the functionality of a control panel plugin that provides the ability to zoom in and out or adapt to the canvas, and also has built-in `redo` and `undo` functionality.
|
|
382
|
+
|
|
383
|
+
<iframe src="/control-extension-usage.html" style="border: none; width: 100%; height: 400px; margin: auto;"></iframe>
|
|
384
|
+
|
|
385
|
+
:::code-group
|
|
386
|
+
|
|
387
|
+
```html | pure [CDN]
|
|
388
|
+
<!-- Import extension-->
|
|
389
|
+
|
|
390
|
+
<script src="https://cdn.jsdelivr.net/npm/@logicflow/extension/dist/index.min.js"></script>
|
|
391
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@logicflow/extension/lib/style/index.min.css" />
|
|
392
|
+
<!-- create graph container -->
|
|
393
|
+
<div id="container"></div>
|
|
394
|
+
<script>
|
|
395
|
+
// The Extension CDN throws an Extension variable that contains all the plugins, the plugins used need to be taken from the Extension
|
|
396
|
+
const { Control } = Extension
|
|
397
|
+
// Writeup for globally installing control panel plugins::
|
|
398
|
+
Core.default.use(Control);
|
|
399
|
+
//Writeup for single instance installing control panel plugins:
|
|
400
|
+
const lf = new Core.default({
|
|
401
|
+
..., // Other options
|
|
402
|
+
plugins: [Control],
|
|
403
|
+
})
|
|
404
|
+
</script>
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
```js [npm/yarn/pnpm]
|
|
408
|
+
import LogicFlow from "@logicflow/core";
|
|
409
|
+
import { Control } from "@logicflow/extension";
|
|
410
|
+
|
|
411
|
+
// Global use, every LogicFlow instance has Control
|
|
412
|
+
LogicFlow.use(Control);
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
:::
|
|
416
|
+
|
|
417
|
+
To learn more about the plugin's features, you can visit [Plugin Introduction](extension/intro.en.md).
|
|
418
|
+
|
|
419
|
+
### 3. Using Plugins
|
|
420
|
+
#### 数据输入
|
|
421
|
+
The rendering data that LogicFlow's flowchart requires as input is structured like this:
|
|
422
|
+
```json
|
|
423
|
+
{
|
|
424
|
+
nodes: [ // node data
|
|
425
|
+
{
|
|
426
|
+
id, // node ID, optional, internally generated if not passed.
|
|
427
|
+
type, // node type, mandatory
|
|
428
|
+
x, // x coordinate of the node, mandatory
|
|
429
|
+
y, // y coordinate of the node, mandatory
|
|
430
|
+
text, // node text, optional
|
|
431
|
+
properties, // custom properties
|
|
432
|
+
// ...Other properties
|
|
433
|
+
}
|
|
434
|
+
],
|
|
435
|
+
edges: [ // edge data
|
|
436
|
+
{
|
|
437
|
+
id, // edge id, optional, will be generated if not passed.
|
|
438
|
+
type, // type of the edge, mandatory
|
|
439
|
+
sourceNodeId, // start node id, mandatory
|
|
440
|
+
targetNodeId, // target node id, mandatory.
|
|
441
|
+
// ...Other properties
|
|
442
|
+
}
|
|
443
|
+
],
|
|
444
|
+
}
|
|
445
|
+
```
|
|
446
|
+
When calling `lf.render`, you can easily render a flowchart canvas with initial data by just passing in an object in the above format, the full data format can be found in [GraphConfigData](../api/type/MainTypes.en.md#graphconfigdata) for more information.
|
|
447
|
+
#### Data Output
|
|
448
|
+
|
|
449
|
+
LogicFlow provides two methods to output canvas data: `getGraphData` and `getGraphRawData`.
|
|
450
|
+
- [getGraphRawData](../api/logicflow-instance/render-and-data.en.md#getgraphrawdata) method can return the raw data of the flowchart on the `LogicFlow` canvas, developers can directly call the method to get the graph data, the format of the returned data can be found in the type definition [GraphData](../api/type/MainTypes.en.md#graphdata)
|
|
451
|
+
|
|
452
|
+
- [getGraphData](../api/logicflow-instance/render-and-data.en.md#getgraphdata) method returns the processed data of the flowchart, which first calls `getGraphRawData` to get the raw data, and then calls the instance-mounted data conversion method `adapterOut` to process and return the processed data.
|
|
453
|
+
:::info{title=Tip}
|
|
454
|
+
By default LogicFlow instances do not have the adapterOut method mounted on them, so the data output from getGraphData is the data returned by getGraphRawData.
|
|
455
|
+
:::
|
|
456
|
+
|
|
457
|
+
This is an example of calling `getGraphData` and `getGraphRawData` to get data:
|
|
458
|
+
|
|
459
|
+
<iframe src="/getGraphData-usage.html" style="border: none; width: 100%; height: 400px; margin: auto;"></iframe>
|
|
460
|
+
|
|
461
|
+
In this example, the raw data part of the presentation is the data returned by the `getGraphRawData` method, and the converted and processed data presentation is the data returned by the `getGraphData` method, in which the conversion logic is realized by defining the `lf.adapterOut` method, and the main action is to take only some of the fields of the nodes and edges, and adding the tip field:
|
|
462
|
+
|
|
463
|
+
```javascript
|
|
464
|
+
// Critical codes
|
|
465
|
+
// Defining export data conversion functions
|
|
466
|
+
lf.adapterOut = (data) => {
|
|
467
|
+
const { nodes, edges } = data
|
|
468
|
+
return {
|
|
469
|
+
nodes: nodes.map(node => {
|
|
470
|
+
const { properties, x, y, width, height } = node
|
|
471
|
+
return {
|
|
472
|
+
x,
|
|
473
|
+
y,
|
|
474
|
+
width,
|
|
475
|
+
height,
|
|
476
|
+
tips: 'Customizing exported node'
|
|
477
|
+
}
|
|
478
|
+
}),
|
|
479
|
+
edges: edges.map(edge => {
|
|
480
|
+
const { type, sourceNodeId, targetNodeId } = edge
|
|
481
|
+
return {
|
|
482
|
+
type,
|
|
483
|
+
sourceNodeId,
|
|
484
|
+
targetNodeId,
|
|
485
|
+
// Adding customized properties
|
|
486
|
+
tips: 'Customizing exported edge',
|
|
487
|
+
}
|
|
488
|
+
}),
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
// 获取画布数据
|
|
492
|
+
const rawData = lf.getGraphRawData()
|
|
493
|
+
const exportData = lf.getGraphData()
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
#### Data Conversion
|
|
497
|
+
In some scenarios where the data format is required, the data format of LogicFlow can't meet the business requirements, so we add `adapterIn` and `adapterOut` methods to LogicFlow instances to support developers to convert data. Developers can define `adapterIn` and `adapterOut` methods to customize the conversion logic according to their needs.
|
|
498
|
+
|
|
499
|
+
For data in bpmn format, you can directly use our [built-in data conversion](extension/adapter.en.md#use-built-in-data-conversion-tool) plugin to convert data generated by LogicFlow to data generated by bpmn-js.
|
|
500
|
+
|
|
501
|
+
To dive into more data conversion features, see [Data Conversion](extension/adapter.en.md).
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
---
|
|
2
|
+
nav: 指南
|
|
3
|
+
group:
|
|
4
|
+
title: 介绍
|
|
5
|
+
title: 快速上手
|
|
6
|
+
order: 1
|
|
7
|
+
toc: content
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
这页只回答一个问题:**我怎样在几分钟内把 LogicFlow 跑起来,并知道下一步该看什么。**
|
|
11
|
+
|
|
12
|
+
::::info{title=本页适合谁读}
|
|
13
|
+
- 第一次接触 LogicFlow,想先跑通一个最小示例
|
|
14
|
+
- 想先理解 `new LogicFlow(...)` 和 `lf.render(...)` 的最基本用法
|
|
15
|
+
|
|
16
|
+
本页不展开插件、数据适配、框架集成和复杂自定义;这些内容请在跑通后按文末推荐顺序继续阅读。
|
|
17
|
+
::::
|
|
18
|
+
|
|
19
|
+
## 你将完成什么
|
|
20
|
+
|
|
21
|
+
完成本页后,你会得到一个最小可运行的 LogicFlow 画布,并理解三件事:
|
|
22
|
+
|
|
23
|
+
1. 如何安装依赖
|
|
24
|
+
2. 如何创建 `LogicFlow` 实例
|
|
25
|
+
3. 如何通过 `lf.render(graphData)` 渲染一张图
|
|
26
|
+
|
|
27
|
+
## 安装
|
|
28
|
+
|
|
29
|
+
推荐使用包管理器安装 `@logicflow/core`。只有在你准备使用现成插件时,才需要额外安装 `@logicflow/extension`。
|
|
30
|
+
|
|
31
|
+
:::code-group
|
|
32
|
+
|
|
33
|
+
```bash [npm]
|
|
34
|
+
npm install @logicflow/core --save
|
|
35
|
+
|
|
36
|
+
# 需要插件时再安装
|
|
37
|
+
npm install @logicflow/extension --save
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
```bash [yarn]
|
|
41
|
+
yarn add @logicflow/core
|
|
42
|
+
|
|
43
|
+
# 需要插件时再安装
|
|
44
|
+
yarn add @logicflow/extension
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```bash [pnpm]
|
|
48
|
+
pnpm add @logicflow/core
|
|
49
|
+
|
|
50
|
+
# 需要插件时再安装
|
|
51
|
+
pnpm add @logicflow/extension
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
::::
|
|
55
|
+
|
|
56
|
+
如果你在无构建工具的场景下接入,也可以使用 CDN,但第一次上手更推荐先从包管理器方式开始。
|
|
57
|
+
|
|
58
|
+
如果你使用 AI 编程工具,可以阅读 [AI 编程支持](ai.zh.md),把 LogicFlow 的本地文档位置和官方能力优先规则提供给 Agent。
|
|
59
|
+
|
|
60
|
+
## 最小示例
|
|
61
|
+
|
|
62
|
+
先准备一个挂载容器:
|
|
63
|
+
|
|
64
|
+
:::code-group
|
|
65
|
+
|
|
66
|
+
```html [HTML]
|
|
67
|
+
<div id="container"></div>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
```css [CSS]
|
|
71
|
+
#container {
|
|
72
|
+
width: 100%;
|
|
73
|
+
height: 480px;
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
::::
|
|
78
|
+
|
|
79
|
+
然后初始化一个实例并渲染最小图数据:
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import LogicFlow from '@logicflow/core'
|
|
83
|
+
import '@logicflow/core/es/index.css'
|
|
84
|
+
|
|
85
|
+
const lf = new LogicFlow({
|
|
86
|
+
container: document.querySelector('#container') as HTMLDivElement,
|
|
87
|
+
grid: true,
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
lf.render({
|
|
91
|
+
nodes: [
|
|
92
|
+
{
|
|
93
|
+
id: 'node_1',
|
|
94
|
+
type: 'rect',
|
|
95
|
+
x: 200,
|
|
96
|
+
y: 160,
|
|
97
|
+
text: '开始使用 LogicFlow',
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
edges: [],
|
|
101
|
+
})
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
如果你使用 React、Vue 或其他框架,本质上仍然是同样的初始化过程,只是把 `container` 换成对应的挂载节点。
|
|
105
|
+
|
|
106
|
+
## `graphData` 是什么
|
|
107
|
+
|
|
108
|
+
`lf.render(...)` 接收的核心数据结构叫 `graphData`。它由 `nodes` 和 `edges` 两部分组成:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
const graphData = {
|
|
112
|
+
nodes: [
|
|
113
|
+
{
|
|
114
|
+
id: 'node_1',
|
|
115
|
+
type: 'rect',
|
|
116
|
+
x: 200,
|
|
117
|
+
y: 160,
|
|
118
|
+
text: '节点 1',
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
edges: [],
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
- `nodes` 表示节点数组
|
|
126
|
+
- `edges` 表示边数组
|
|
127
|
+
- 更完整的类型说明可以查看 [类型导览](../api/type/index.zh.md)
|
|
128
|
+
|
|
129
|
+
如果你想继续理解 `LogicFlow` 实例本身、初始化选项和图数据字段,下一篇建议阅读 [实例与图数据](basic/class.zh.md)。
|
|
130
|
+
|
|
131
|
+
## 下一步阅读
|
|
132
|
+
|
|
133
|
+
跑通最小示例后,推荐按这个顺序继续:
|
|
134
|
+
|
|
135
|
+
1. [实例与图数据](basic/class.zh.md):理解 `LogicFlow` 实例、`graphData` 和 `render`
|
|
136
|
+
2. [主题](basic/theme.zh.md) / [事件](basic/event.zh.md):掌握样式和交互监听
|
|
137
|
+
3. [节点](basic/node.zh.md) / [边](basic/edge.zh.md):开始进入真正的业务建模
|
|
138
|
+
4. [插件简介](extension/intro.zh.md):按目标选择现成插件
|
|
139
|
+
5. [API 导览](../api/logicflow-instance/index.zh.md):需要精确查参数时再进入参考文档
|