@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,154 @@
|
|
|
1
|
+
---
|
|
2
|
+
nav: Guide
|
|
3
|
+
group:
|
|
4
|
+
title: Basics
|
|
5
|
+
order: 1
|
|
6
|
+
title: Theme
|
|
7
|
+
order: 3
|
|
8
|
+
toc: content
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
LogicFlow provides a comprehensive theme customization feature that supports multiple ways to set and customize theme styles. Theme configuration allows unified management of styles for all elements in the canvas, including nodes, edges, text, and more.
|
|
12
|
+
|
|
13
|
+
## Theme Configuration Categories
|
|
14
|
+
|
|
15
|
+
Theme configuration supports the following main categories:
|
|
16
|
+
|
|
17
|
+
- **Base Theme**: Common styles for base nodes and edges
|
|
18
|
+
- **Node Theme**: Styles for various nodes (rectangle, circle, diamond, etc.)
|
|
19
|
+
- **Edge Theme**: Styles for various edges (line, polyline, bezier curve, etc.)
|
|
20
|
+
- **Text Theme**: Styles for node text and edge text
|
|
21
|
+
- **Other Elements**: Styles for auxiliary elements like anchors, arrows, and snaplines
|
|
22
|
+
- **Canvas Configuration**: Styles for background and grid
|
|
23
|
+
|
|
24
|
+
For detailed theme configuration parameters, see [Theme API](../../api/logicflow-instance/theme.en.md)
|
|
25
|
+
|
|
26
|
+
## Theme Configuration Methods
|
|
27
|
+
|
|
28
|
+
### Way 1: Initialization Configuration
|
|
29
|
+
|
|
30
|
+
When creating a LogicFlow instance, configure the theme using the `style` parameter.
|
|
31
|
+
|
|
32
|
+
```tsx | pure
|
|
33
|
+
const config = {
|
|
34
|
+
container: document.querySelector('#container'),
|
|
35
|
+
width: 1000,
|
|
36
|
+
height: 800,
|
|
37
|
+
style: { // Set default theme style
|
|
38
|
+
rect: { fill: '#FFFFFF', strokeWidth: 2 }, // Rectangle style
|
|
39
|
+
circle: { r: 15, fill: '#1E90FF' }, // Circle style
|
|
40
|
+
nodeText: { fontSize: 14, color: '#333333' }, // Node text style
|
|
41
|
+
edgeText: { fontSize: 12, color: '#666666' }, // Edge text style
|
|
42
|
+
anchor: { stroke: '#999999', fill: '#FFFFFF' }, // Anchor point style
|
|
43
|
+
},
|
|
44
|
+
themeMode: 'radius', // Set rounded corner theme
|
|
45
|
+
}
|
|
46
|
+
const lf = new LogicFlow(config)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Way 2: Using the setTheme Method
|
|
50
|
+
|
|
51
|
+
After creating a LogicFlow instance, dynamically update the theme configuration by calling the `setTheme` method.
|
|
52
|
+
|
|
53
|
+
```tsx | pure
|
|
54
|
+
// Dynamically configure theme
|
|
55
|
+
lf.setTheme({
|
|
56
|
+
rect: { fill: '#FFFFFF', stroke: '#1890FF' }, // Rectangle style
|
|
57
|
+
circle: { r: 15, fill: '#1890FF' }, // Circle style
|
|
58
|
+
nodeText: { fontSize: 14, color: '#333333' }, // Node text style
|
|
59
|
+
edgeText: { fontSize: 12, color: '#666666' }, // Edge text style
|
|
60
|
+
anchor: { r: 4, fill: '#FFFFFF', stroke: '#1890FF' }, // Anchor point style
|
|
61
|
+
}, 'radius')
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Built-in Theme Modes <Badge>2.0.14新增</Badge>
|
|
65
|
+
|
|
66
|
+
LogicFlow comes with four built-in theme modes that allow you to quickly apply preset styles:
|
|
67
|
+
|
|
68
|
+
- `default`: Default theme
|
|
69
|
+
- `dark`: Dark theme
|
|
70
|
+
- `colorful`: Colorful theme
|
|
71
|
+
- `radius`: Rounded corner theme
|
|
72
|
+
|
|
73
|
+
Applying built-in theme modes:
|
|
74
|
+
|
|
75
|
+
```tsx | pure
|
|
76
|
+
// Set theme mode during initialization
|
|
77
|
+
const lf = new LogicFlow({
|
|
78
|
+
// ... other configurations
|
|
79
|
+
themeMode: 'radius', // Set rounded corner theme
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
// Dynamically switch theme modes
|
|
83
|
+
lf.setTheme({}, 'dark') // Apply dark theme
|
|
84
|
+
lf.setTheme({}, 'colorful') // Apply colorful theme
|
|
85
|
+
|
|
86
|
+
// Apply theme mode with custom styles
|
|
87
|
+
lf.setTheme({
|
|
88
|
+
rect: { fill: '#AECBFA' },
|
|
89
|
+
circle: { fill: '#C9DAF8' }
|
|
90
|
+
}, 'radius')
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Custom Theme Modes <Badge>2.0.14新增</Badge>
|
|
94
|
+
|
|
95
|
+
LogicFlow supports creating and managing custom theme modes. You can add new theme modes using the `addThemeMode` method:
|
|
96
|
+
|
|
97
|
+
```tsx | pure
|
|
98
|
+
// Register custom theme mode
|
|
99
|
+
LogicFlow.addThemeMode('customTheme', {
|
|
100
|
+
baseNode: { fill: '#EFF5FF', stroke: '#4B83FF' },
|
|
101
|
+
rect: { radius: 8 },
|
|
102
|
+
circle: { r: 25 },
|
|
103
|
+
nodeText: { fontSize: 16, color: '#4B83FF' },
|
|
104
|
+
edgeText: { fontSize: 14, background: { fill: '#EEF7FE' } },
|
|
105
|
+
arrow: { offset: 6, verticalLength: 3 },
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
// Apply custom theme
|
|
109
|
+
lf.setTheme({}, 'customTheme')
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Theme Style Priority
|
|
113
|
+
|
|
114
|
+
The priority of theme styles (from low to high):
|
|
115
|
+
|
|
116
|
+
#### Node, Edge, Text and Other Element Style Priority
|
|
117
|
+
1. Built-in base styles (defaultTheme)
|
|
118
|
+
2. Applied theme mode styles (specified via `themeMode` or second parameter of `setTheme`)
|
|
119
|
+
3. Custom styles (specified via `style` or first parameter of `setTheme`)
|
|
120
|
+
|
|
121
|
+
#### Background and Grid Style Priority
|
|
122
|
+
Background and grid configurations have independent update mechanisms, with priority divided into two phases:
|
|
123
|
+
|
|
124
|
+
**Initialization Phase Priority** (from low to high):
|
|
125
|
+
1. Configuration in style: `background` and `grid` configurations in the constructor's `style` parameter
|
|
126
|
+
2. Direct Parameter Configuration: Values set through `background` and `grid` parameters in the constructor (overrides configurations in style)
|
|
127
|
+
|
|
128
|
+
**Runtime Phase Priority** (from low to high):
|
|
129
|
+
1. Current Configuration: `background` and `grid` configurations after initialization
|
|
130
|
+
2. Theme Mode Configuration: When calling `setTheme(style, themeMode)`, background and grid configurations in themeMode will override current configuration
|
|
131
|
+
3. Custom Configuration: `background` and `grid` configurations in the style parameter of `setTheme(style, themeMode)` will override theme mode configuration
|
|
132
|
+
|
|
133
|
+
```tsx | pure
|
|
134
|
+
// Example: Priority application of background and grid
|
|
135
|
+
|
|
136
|
+
// Initialization: Direct parameters > style parameters
|
|
137
|
+
const lf = new LogicFlow({
|
|
138
|
+
style: {
|
|
139
|
+
background: { color: '#f0f0f0' }, // Lower priority
|
|
140
|
+
grid: { size: 15 } // Lower priority
|
|
141
|
+
},
|
|
142
|
+
background: { color: '#f5f5f5' }, // Final effective (overrides style configuration)
|
|
143
|
+
grid: { size: 20 }, // Final effective (overrides style configuration)
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
// Runtime: style parameters > themeMode parameters > current configuration
|
|
147
|
+
lf.setTheme({
|
|
148
|
+
background: { color: '#ffffff' }, // Final effective background configuration
|
|
149
|
+
grid: { size: 10, visible: true }, // Final effective grid configuration
|
|
150
|
+
}, 'dark') // Background and grid configurations in dark theme mode will be overridden by style parameters
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Usage Example
|
|
154
|
+
<code id="graphData" src="../../../src/tutorial/basic/instance/theme"></code>
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
---
|
|
2
|
+
nav: 指南
|
|
3
|
+
group:
|
|
4
|
+
title: 基础
|
|
5
|
+
order: 1
|
|
6
|
+
title: 主题
|
|
7
|
+
order: 3
|
|
8
|
+
toc: content
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
LogicFlow 提供了完整的主题定制功能,支持通过多种方式设置和自定义主题样式。主题配置可以统一管理画布中所有元素的样式,包括节点、边、文本等。
|
|
12
|
+
|
|
13
|
+
## 主题配置项
|
|
14
|
+
|
|
15
|
+
主题配置支持以下主要类别:
|
|
16
|
+
|
|
17
|
+
- **基础主题**:基础节点和边的通用样式
|
|
18
|
+
- **节点主题**:各类节点(矩形、圆形、菱形等)的样式
|
|
19
|
+
- **边主题**:各类边(直线、折线、贝塞尔曲线等)的样式
|
|
20
|
+
- **文本主题**:节点文本、边文本的样式
|
|
21
|
+
- **其他元素**:锚点、箭头、对齐线等辅助元素的样式
|
|
22
|
+
- **画布配置**:背景和网格的样式
|
|
23
|
+
|
|
24
|
+
详细的主题配置参数见[主题 API](../../api/logicflow-instance/theme.zh.md)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## 主题配置方式
|
|
28
|
+
|
|
29
|
+
### 方式一:初始化配置
|
|
30
|
+
|
|
31
|
+
在创建 LogicFlow 实例时,通过 `style` 参数进行初始化配置。
|
|
32
|
+
|
|
33
|
+
```tsx | pure
|
|
34
|
+
const config = {
|
|
35
|
+
container: document.querySelector('#container'),
|
|
36
|
+
width: 1000,
|
|
37
|
+
height: 800,
|
|
38
|
+
style: { // 设置默认主题样式
|
|
39
|
+
rect: { fill: '#FFFFFF', strokeWidth: 2 }, // 矩形样式
|
|
40
|
+
circle: { r: 15, fill: '#1E90FF' }, // 圆形样式
|
|
41
|
+
nodeText: { fontSize: 14, color: '#333333' }, // 节点文本样式
|
|
42
|
+
edgeText: { fontSize: 12, color: '#666666' }, // 边文本样式
|
|
43
|
+
anchor: { stroke: '#999999', fill: '#FFFFFF' }, // 锚点样式
|
|
44
|
+
},
|
|
45
|
+
themeMode: 'radius', // 初始化设置圆角主题
|
|
46
|
+
}
|
|
47
|
+
const lf = new LogicFlow(config)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 方式二:使用 setTheme 方法
|
|
51
|
+
|
|
52
|
+
在 LogicFlow 实例创建后,调用 `setTheme` 方法动态更新主题配置。
|
|
53
|
+
|
|
54
|
+
```tsx | pure
|
|
55
|
+
// 动态配置主题
|
|
56
|
+
lf.setTheme({
|
|
57
|
+
rect: { fill: '#FFFFFF', stroke: '#1890FF' }, // 矩形样式
|
|
58
|
+
circle: { r: 15, fill: '#1890FF' }, // 圆形样式
|
|
59
|
+
nodeText: { fontSize: 14, color: '#333333' }, // 节点文本样式
|
|
60
|
+
edgeText: { fontSize: 12, color: '#666666' }, // 边文本样式
|
|
61
|
+
anchor: { r: 4, fill: '#FFFFFF', stroke: '#1890FF' }, // 锚点样式
|
|
62
|
+
}, 'radius')
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## 内置主题模式<Badge>2.0.14新增</Badge>
|
|
66
|
+
|
|
67
|
+
LogicFlow 内置了四种主题模式,可以快速应用预设样式:
|
|
68
|
+
|
|
69
|
+
- `default`: 默认主题
|
|
70
|
+
- `dark`: 暗黑主题
|
|
71
|
+
- `colorful`: 彩色主题
|
|
72
|
+
- `radius`: 圆角主题
|
|
73
|
+
|
|
74
|
+
应用内置主题模式:
|
|
75
|
+
|
|
76
|
+
```tsx | pure
|
|
77
|
+
// 初始化时设置主题模式
|
|
78
|
+
const lf = new LogicFlow({
|
|
79
|
+
// ... 其他配置
|
|
80
|
+
themeMode: 'radius', // 设置圆角主题
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
// 动态切换主题模式
|
|
84
|
+
lf.setTheme({}, 'dark') // 应用暗黑主题
|
|
85
|
+
lf.setTheme({}, 'colorful') // 应用彩色主题
|
|
86
|
+
|
|
87
|
+
// 应用主题模式并自定义部分样式
|
|
88
|
+
lf.setTheme({
|
|
89
|
+
rect: { fill: '#AECBFA' },
|
|
90
|
+
circle: { fill: '#C9DAF8' }
|
|
91
|
+
}, 'radius')
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## 自定义主题模式 <Badge>2.0.14新增</Badge>
|
|
95
|
+
|
|
96
|
+
LogicFlow 支持创建和管理自定义主题模式。通过 `addThemeMode` 方法可以添加新的主题模式:
|
|
97
|
+
|
|
98
|
+
```tsx | pure
|
|
99
|
+
// 注册自定义主题模式
|
|
100
|
+
LogicFlow.addThemeMode('customTheme', {
|
|
101
|
+
baseNode: { fill: '#EFF5FF', stroke: '#4B83FF' },
|
|
102
|
+
rect: { radius: 8 },
|
|
103
|
+
circle: { r: 25 },
|
|
104
|
+
nodeText: { fontSize: 16, color: '#4B83FF' },
|
|
105
|
+
edgeText: { fontSize: 14, background: { fill: '#EEF7FE' } },
|
|
106
|
+
arrow: { offset: 6, verticalLength: 3 },
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
// 应用自定义主题
|
|
110
|
+
lf.setTheme({}, 'customTheme')
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### 主题样式优先级
|
|
114
|
+
|
|
115
|
+
主题样式的应用优先级(从低到高):
|
|
116
|
+
|
|
117
|
+
#### 节点、边、文本等元素样式优先级
|
|
118
|
+
1. 内置基础样式(defaultTheme)
|
|
119
|
+
2. 应用的主题模式样式(通过 `themeMode` 或 `setTheme` 的第二个参数设置)
|
|
120
|
+
3. 自定义样式(通过 `style` 或 `setTheme` 的第一个参数设置)
|
|
121
|
+
|
|
122
|
+
#### 背景和网格样式优先级
|
|
123
|
+
背景(background)和网格(grid)配置具有独立的更新机制,其优先级分为两个阶段:
|
|
124
|
+
|
|
125
|
+
**初始化阶段优先级**(从低到高):
|
|
126
|
+
1. style 中的配置:通过构造函数 `style` 参数中的 `background` 和 `grid` 配置
|
|
127
|
+
2. 直接参数配置:通过构造函数中的 `background` 和 `grid` 参数设置的值(会覆盖 style 中的配置)
|
|
128
|
+
|
|
129
|
+
**运行时阶段优先级**(从低到高):
|
|
130
|
+
1. 当前配置:初始化后的 `background` 和 `grid` 配置
|
|
131
|
+
2. 主题模式配置:调用 `setTheme(style, themeMode)` 时,themeMode 中的背景和网格配置会覆盖当前配置
|
|
132
|
+
3. 自定义配置:`setTheme(style, themeMode)` 中 style 参数的 `background` 和 `grid` 配置会覆盖主题模式配置
|
|
133
|
+
|
|
134
|
+
```tsx | pure
|
|
135
|
+
// 示例:背景和网格的优先级应用
|
|
136
|
+
|
|
137
|
+
// 初始化时:直接参数 > style 参数
|
|
138
|
+
const lf = new LogicFlow({
|
|
139
|
+
style: {
|
|
140
|
+
background: { color: '#f0f0f0' }, // 优先级较低
|
|
141
|
+
grid: { size: 15 } // 优先级较低
|
|
142
|
+
},
|
|
143
|
+
background: { color: '#f5f5f5' }, // 最终生效(覆盖 style 中的配置)
|
|
144
|
+
grid: { size: 20 }, // 最终生效(覆盖 style 中的配置)
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
// 运行时:style 参数 > themeMode 参数 > 当前配置
|
|
148
|
+
lf.setTheme({
|
|
149
|
+
background: { color: '#ffffff' }, // 最终生效的背景配置
|
|
150
|
+
grid: { size: 10, visible: true }, // 最终生效的网格配置
|
|
151
|
+
}, 'dark') // dark 主题模式的背景和网格配置会被 style 参数覆盖
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## 使用示例
|
|
155
|
+
<code id="graphData" src="../../../src/tutorial/basic/instance/theme"></code>
|
|
156
|
+
|
|
157
|
+
|