aldehyde 0.2.493 → 0.2.495
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/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.css +63 -63
- package/lib/draw-canvas-edit/components/asset-bar/index.less +35 -35
- package/lib/draw-canvas-edit/components/main-header/index.less +23 -23
- package/lib/layout2/page.d.ts +2 -1
- package/lib/layout2/page.d.ts.map +1 -1
- package/lib/layout2/page.js +19 -8
- package/lib/layout2/page.js.map +1 -1
- package/lib/layout2/type/layout-type.d.ts +1 -0
- package/lib/layout2/type/layout-type.d.ts.map +1 -1
- package/lib/lowcode-components/base-table/index.less +61 -61
- package/lib/lowcode-components/base-text/index.less +19 -19
- package/lib/lowcode-components/column-chart/index.js +2 -2
- package/lib/lowcode-components/column-chart/index.js.map +1 -1
- package/lib/lowcode-components/data-number/index.less +10 -10
- package/lib/lowcode-components/date-time/index.less +4 -4
- package/lib/lowcode-components/four-angle-glow-border/index.less +49 -49
- package/lib/lowcode-components/line-bar-chart/index.d.ts.map +1 -1
- package/lib/lowcode-components/line-bar-chart/index.js +6 -2
- package/lib/lowcode-components/line-bar-chart/index.js.map +1 -1
- package/lib/lowcode-components/line-chart/index.d.ts.map +1 -1
- package/lib/lowcode-components/line-chart/index.js +6 -2
- package/lib/lowcode-components/line-chart/index.js.map +1 -1
- package/lib/lowcode-components/lowcode-view/component/font/FontGlobal.css +26 -26
- package/lib/lowcode-components/lowcode-view/component/screen-fit/index.less +13 -13
- package/lib/lowcode-components/text-scroller/index.less +28 -28
- package/lib/module/ltmpl-table.d.ts +7 -0
- package/lib/module/ltmpl-table.d.ts.map +1 -1
- package/lib/module/ltmpl-table.js +12 -16
- package/lib/module/ltmpl-table.js.map +1 -1
- package/lib/routable/dtmpl-route.d.ts.map +1 -1
- package/lib/routable/dtmpl-route.js +8 -2
- package/lib/routable/dtmpl-route.js.map +1 -1
- package/lib/routable/import-route.d.ts.map +1 -1
- package/lib/routable/import-route.js +9 -1
- package/lib/routable/import-route.js.map +1 -1
- package/lib/routable/ltmpl-route.d.ts.map +1 -1
- package/lib/routable/ltmpl-route.js +13 -6
- package/lib/routable/ltmpl-route.js.map +1 -1
- package/lib/routable/splitview-ltmpl-route.d.ts.map +1 -1
- package/lib/routable/splitview-ltmpl-route.js +11 -10
- package/lib/routable/splitview-ltmpl-route.js.map +1 -1
- package/lib/routable/ttmpl-route.d.ts.map +1 -1
- package/lib/routable/ttmpl-route.js +9 -2
- package/lib/routable/ttmpl-route.js.map +1 -1
- package/lib/table/act-table.d.ts +1 -0
- package/lib/table/act-table.d.ts.map +1 -1
- package/lib/table/act-table.js +31 -9
- package/lib/table/act-table.js.map +1 -1
- package/lib/table/page-chart.js +1 -1
- package/lib/table/page-chart.js.map +1 -1
- package/lib/table/row-table.d.ts +6 -0
- package/lib/table/row-table.d.ts.map +1 -1
- package/lib/table/row-table.js +21 -6
- package/lib/table/row-table.js.map +1 -1
- package/lib/tmpl/interface.d.ts +1 -0
- package/lib/tmpl/interface.d.ts.map +1 -1
- package/lib/tree/act-tree.d.ts +1 -0
- package/lib/tree/act-tree.d.ts.map +1 -1
- package/lib/tree/act-tree.js +6 -7
- package/lib/tree/act-tree.js.map +1 -1
- package/lib/tree/tree-utils.d.ts +1 -1
- package/lib/tree/tree-utils.d.ts.map +1 -1
- package/lib/tree/tree-utils.js +4 -4
- package/lib/tree/tree-utils.js.map +1 -1
- package/lib/units/index.d.ts +4 -0
- package/lib/units/index.d.ts.map +1 -1
- package/lib/units/index.js +10 -3
- package/lib/units/index.js.map +1 -1
- package/package.json +1 -1
- package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.css +63 -63
- package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.json +93 -93
- package/src/aldehyde/draw-canvas-edit/components/asset-bar/index.less +35 -35
- package/src/aldehyde/draw-canvas-edit/components/asset-bar/index.tsx +110 -110
- package/src/aldehyde/draw-canvas-edit/components/main-header/index.less +23 -23
- package/src/aldehyde/draw-canvas-edit/components/main-header/index.tsx +263 -263
- package/src/aldehyde/draw-canvas-edit/components/render/draws/index.ts +7 -7
- package/src/aldehyde/draw-canvas-edit/components/render/graphs/base-graph.ts +241 -241
- package/src/aldehyde/draw-canvas-edit/components/render/graphs/circle.ts +699 -699
- package/src/aldehyde/draw-canvas-edit/components/render/graphs/curve.ts +500 -500
- package/src/aldehyde/draw-canvas-edit/components/render/graphs/index.ts +5 -5
- package/src/aldehyde/draw-canvas-edit/components/render/graphs/line.ts +493 -493
- package/src/aldehyde/draw-canvas-edit/components/render/graphs/rect.ts +680 -680
- package/src/aldehyde/draw-canvas-edit/components/render/handlers/drag-handlers.ts +68 -68
- package/src/aldehyde/draw-canvas-edit/components/render/handlers/graph-handlers.ts +113 -113
- package/src/aldehyde/draw-canvas-edit/components/render/handlers/index.ts +9 -9
- package/src/aldehyde/draw-canvas-edit/components/render/handlers/key-move-handlers.ts +49 -49
- package/src/aldehyde/draw-canvas-edit/components/render/handlers/link-handlers.ts +45 -45
- package/src/aldehyde/draw-canvas-edit/components/render/handlers/shutcut-handlers.ts +45 -45
- package/src/aldehyde/draw-canvas-edit/components/render/handlers/text-handlers.ts +81 -81
- package/src/aldehyde/draw-canvas-edit/components/render/handlers/zoom-handlers.ts +59 -59
- package/src/aldehyde/draw-canvas-edit/components/render/tools/align-tool.ts +89 -89
- package/src/aldehyde/draw-canvas-edit/components/render/tools/asset-tool.ts +154 -154
- package/src/aldehyde/draw-canvas-edit/components/render/tools/link-tool.ts +222 -222
- package/src/aldehyde/draw-canvas-edit/components/render/tools/z-index-tool.ts +224 -224
- package/src/aldehyde/draw-canvas-edit/components/render/utils/a-star.ts +116 -116
- package/src/aldehyde/draw-canvas-edit/components/render/utils/bezier-scene-func.ts +72 -72
- package/src/aldehyde/draw-canvas-edit/components/setting-form/imag-upload.tsx +119 -119
- package/src/aldehyde/layout2/page.tsx +17 -9
- package/src/aldehyde/layout2/type/layout-type.ts +1 -0
- package/src/aldehyde/layout4/imgs/user.svg +26 -26
- package/src/aldehyde/lowcode-components/base-color-block/index.tsx +31 -31
- package/src/aldehyde/lowcode-components/base-table/index.less +61 -61
- package/src/aldehyde/lowcode-components/base-text/index.less +19 -19
- package/src/aldehyde/lowcode-components/column-chart/index.tsx +2 -2
- package/src/aldehyde/lowcode-components/data-number/index.less +10 -10
- package/src/aldehyde/lowcode-components/date-time/index.less +4 -4
- package/src/aldehyde/lowcode-components/date-time/index.tsx +64 -64
- package/src/aldehyde/lowcode-components/four-angle-glow-border/index.less +49 -49
- package/src/aldehyde/lowcode-components/four-angle-glow-border/index.tsx +53 -53
- package/src/aldehyde/lowcode-components/line-bar-chart/index.tsx +5 -2
- package/src/aldehyde/lowcode-components/line-chart/index.tsx +5 -2
- package/src/aldehyde/lowcode-components/lowcode-view/component/abstract-controller.ts +64 -64
- package/src/aldehyde/lowcode-components/lowcode-view/component/abstract-definition.ts +77 -77
- package/src/aldehyde/lowcode-components/lowcode-view/component/abstract-designer-loader.ts +36 -36
- package/src/aldehyde/lowcode-components/lowcode-view/component/component-container.tsx +91 -91
- package/src/aldehyde/lowcode-components/lowcode-view/component/font/FontGlobal.css +26 -26
- package/src/aldehyde/lowcode-components/lowcode-view/component/group-layer/controller.ts +36 -36
- package/src/aldehyde/lowcode-components/lowcode-view/component/group-layer/definition.ts +53 -53
- package/src/aldehyde/lowcode-components/lowcode-view/component/group-layer/index.tsx +15 -15
- package/src/aldehyde/lowcode-components/lowcode-view/component/layer-builder.tsx +98 -98
- package/src/aldehyde/lowcode-components/lowcode-view/component/screen-fit/index.less +13 -13
- package/src/aldehyde/lowcode-components/lowcode-view/component/screen-fit/index.tsx +121 -121
- package/src/aldehyde/lowcode-components/placeholder-component/index.tsx +81 -81
- package/src/aldehyde/lowcode-components/text-scroller/index.less +28 -28
- package/src/aldehyde/lowcode-components/text-scroller/index.tsx +173 -173
- package/src/aldehyde/module/ltmpl-table.tsx +14 -15
- package/src/aldehyde/routable/dtmpl-route.tsx +14 -8
- package/src/aldehyde/routable/import-route.tsx +12 -5
- package/src/aldehyde/routable/ltmpl-route.tsx +14 -9
- package/src/aldehyde/routable/splitview-ltmpl-route.tsx +11 -8
- package/src/aldehyde/routable/ttmpl-route.tsx +13 -8
- package/src/aldehyde/table/act-table.tsx +28 -9
- package/src/aldehyde/table/page-chart.tsx +1 -1
- package/src/aldehyde/table/row-table.tsx +29 -6
- package/src/aldehyde/tmpl/interface.tsx +1 -0
- package/src/aldehyde/tree/act-tree.tsx +8 -6
- package/src/aldehyde/tree/tree-utils.tsx +4 -4
- package/src/aldehyde/units/index.tsx +11 -3
|
@@ -1,225 +1,225 @@
|
|
|
1
|
-
import Konva from 'konva';
|
|
2
|
-
import { Render } from '../index';
|
|
3
|
-
import { GraphDraw, LinkDraw, RulerDraw, PreviewDraw } from '../draws';
|
|
4
|
-
|
|
5
|
-
// 层接工具
|
|
6
|
-
|
|
7
|
-
export class ZIndexTool {
|
|
8
|
-
|
|
9
|
-
private render: Render;
|
|
10
|
-
constructor(render: Render) {
|
|
11
|
-
this.render = render;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// 获取移动节点
|
|
15
|
-
getNodes(nodes: Konva.Node[]) {
|
|
16
|
-
const targets: Konva.Node[] = [];
|
|
17
|
-
for (const node of nodes) {
|
|
18
|
-
if (node instanceof Konva.Transformer) {
|
|
19
|
-
// 已选择的节点
|
|
20
|
-
targets.push(...this.render.selectionTool.selectingNodes);
|
|
21
|
-
} else {
|
|
22
|
-
// 未选择的节点
|
|
23
|
-
targets.push(node);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return targets;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// 最大 zIndex
|
|
30
|
-
getMaxZIndex() {
|
|
31
|
-
return Math.max(
|
|
32
|
-
...this.render.layer
|
|
33
|
-
.getChildren((node) => !this.render.ignore(node))
|
|
34
|
-
.map((o) => o.zIndex())
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// 最小 zIndex
|
|
39
|
-
getMinZIndex() {
|
|
40
|
-
return Math.min(
|
|
41
|
-
...this.render.layer
|
|
42
|
-
.getChildren((node) => !this.render.ignore(node))
|
|
43
|
-
.map((o) => o.zIndex())
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// 记录选择期间的 zIndex
|
|
48
|
-
updateSelectingZIndex(nodes: Konva.Node[]) {
|
|
49
|
-
for (const node of nodes) {
|
|
50
|
-
node.setAttrs({
|
|
51
|
-
selectingZIndex: node.zIndex()
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// 恢复选择期间的 zIndex
|
|
57
|
-
resetSelectingZIndex(nodes: Konva.Node[]) {
|
|
58
|
-
nodes.sort((a, b) => a.zIndex() - b.zIndex());
|
|
59
|
-
for (const node of nodes) {
|
|
60
|
-
node.zIndex(node.attrs.selectingZIndex);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// 更新 zIndex 缓存
|
|
65
|
-
updateLastZindex(nodes: Konva.Node[]) {
|
|
66
|
-
for (const node of nodes) {
|
|
67
|
-
node.setAttrs({ lastZIndex: node.zIndex() });
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// 上移
|
|
72
|
-
up(nodes: Konva.Node[]) {
|
|
73
|
-
// 最大zIndex
|
|
74
|
-
const maxZIndex = this.getMaxZIndex();
|
|
75
|
-
const sorted = this.getNodes(nodes).sort((a, b) => b.zIndex() - a.zIndex());
|
|
76
|
-
// 上移
|
|
77
|
-
let lastNode: Konva.Node | null = null;
|
|
78
|
-
if (this.render.selectionTool.selectingNodes.length > 0) {
|
|
79
|
-
this.updateSelectingZIndex(sorted);
|
|
80
|
-
for (const node of sorted) {
|
|
81
|
-
if (
|
|
82
|
-
node.attrs.lastZIndex < maxZIndex &&
|
|
83
|
-
(lastNode === null || node.attrs.lastZIndex < lastNode.attrs.lastZIndex - 1)
|
|
84
|
-
) {
|
|
85
|
-
node.setAttrs({
|
|
86
|
-
lastZIndex: node.attrs.lastZIndex + 1
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
lastNode = node;
|
|
90
|
-
}
|
|
91
|
-
this.resetSelectingZIndex(sorted);
|
|
92
|
-
} else {
|
|
93
|
-
// 直接调整
|
|
94
|
-
for (const node of sorted) {
|
|
95
|
-
if (
|
|
96
|
-
node.zIndex() < maxZIndex &&
|
|
97
|
-
(lastNode === null || node.zIndex() < lastNode.zIndex() - 1)
|
|
98
|
-
) {
|
|
99
|
-
node.zIndex(node.zIndex() + 1);
|
|
100
|
-
}
|
|
101
|
-
lastNode = node;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
this.updateLastZindex(sorted);
|
|
105
|
-
// 更新历史
|
|
106
|
-
this.render.updateHistory();
|
|
107
|
-
// 重绘
|
|
108
|
-
this.render.redraw([
|
|
109
|
-
GraphDraw.NAME,
|
|
110
|
-
LinkDraw.NAME,
|
|
111
|
-
RulerDraw.NAME,
|
|
112
|
-
PreviewDraw.NAME
|
|
113
|
-
]);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// 下移
|
|
118
|
-
down(nodes: Konva.Node[]) {
|
|
119
|
-
// 最小 zIndex
|
|
120
|
-
const minZIndex = this.getMinZIndex();
|
|
121
|
-
const sorted = this.getNodes(nodes).sort((a, b) => a.zIndex() - b.zIndex());
|
|
122
|
-
// 下移
|
|
123
|
-
let lastNode: Konva.Node | null = null;
|
|
124
|
-
|
|
125
|
-
if (this.render.selectionTool.selectingNodes.length > 0) {
|
|
126
|
-
this.updateSelectingZIndex(sorted);
|
|
127
|
-
|
|
128
|
-
for (const node of sorted) {
|
|
129
|
-
if (
|
|
130
|
-
node.attrs.lastZIndex > minZIndex &&
|
|
131
|
-
(lastNode === null || node.attrs.lastZIndex > lastNode.attrs.lastZIndex + 1)
|
|
132
|
-
) {
|
|
133
|
-
node.setAttrs({ lastZIndex: node.attrs.lastZIndex - 1 });
|
|
134
|
-
}
|
|
135
|
-
lastNode = node;
|
|
136
|
-
}
|
|
137
|
-
this.resetSelectingZIndex(sorted);
|
|
138
|
-
} else {
|
|
139
|
-
// 直接调整
|
|
140
|
-
for (const node of sorted) {
|
|
141
|
-
if (
|
|
142
|
-
node.zIndex() > minZIndex &&
|
|
143
|
-
(lastNode === null || node.zIndex() > lastNode.zIndex() + 1)
|
|
144
|
-
) {
|
|
145
|
-
node.zIndex(node.zIndex() - 1);
|
|
146
|
-
}
|
|
147
|
-
lastNode = node;
|
|
148
|
-
}
|
|
149
|
-
this.updateLastZindex(sorted);
|
|
150
|
-
// 更新历史
|
|
151
|
-
this.render.updateHistory();
|
|
152
|
-
// 重绘
|
|
153
|
-
this.render.redraw([
|
|
154
|
-
GraphDraw.NAME,
|
|
155
|
-
LinkDraw.NAME,
|
|
156
|
-
RulerDraw.NAME,
|
|
157
|
-
PreviewDraw.NAME
|
|
158
|
-
]);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// 置顶
|
|
163
|
-
top(nodes: Konva.Node[]) {
|
|
164
|
-
// 最大 zIndex
|
|
165
|
-
let maxZIndex = this.getMaxZIndex();
|
|
166
|
-
const sorted = this.getNodes(nodes).sort((a, b) => b.zIndex() - a.zIndex());
|
|
167
|
-
if (this.render.selectionTool.selectingNodes.length > 0) {
|
|
168
|
-
// 先选中再调整
|
|
169
|
-
this.updateSelectingZIndex(sorted);
|
|
170
|
-
// 置顶
|
|
171
|
-
for (const node of sorted) {
|
|
172
|
-
node.setAttrs({ lastZIndex: maxZIndex-- });
|
|
173
|
-
}
|
|
174
|
-
this.resetSelectingZIndex(sorted);
|
|
175
|
-
} else {
|
|
176
|
-
// 直接调整
|
|
177
|
-
for (const node of sorted) {
|
|
178
|
-
node.zIndex(maxZIndex);
|
|
179
|
-
}
|
|
180
|
-
this.updateLastZindex(sorted);
|
|
181
|
-
// 更新历史
|
|
182
|
-
this.render.updateHistory();
|
|
183
|
-
// 重绘
|
|
184
|
-
this.render.redraw([
|
|
185
|
-
GraphDraw.NAME,
|
|
186
|
-
LinkDraw.NAME,
|
|
187
|
-
RulerDraw.NAME,
|
|
188
|
-
PreviewDraw.NAME
|
|
189
|
-
]);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// 置底
|
|
194
|
-
bottom(nodes: Konva.Node[]) {
|
|
195
|
-
// 最小 zIndex
|
|
196
|
-
let minZIndex = this.getMinZIndex();
|
|
197
|
-
const sorted = this.getNodes(nodes).sort((a, b) => a.zIndex() - b.zIndex());
|
|
198
|
-
if (this.render.selectionTool.selectingNodes.length > 0) {
|
|
199
|
-
// 先选中再调整
|
|
200
|
-
this.updateSelectingZIndex(sorted);
|
|
201
|
-
// 置底
|
|
202
|
-
for (const node of sorted) {
|
|
203
|
-
node.setAttrs({
|
|
204
|
-
lastZIndex: minZIndex++
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
this.resetSelectingZIndex(sorted);
|
|
208
|
-
} else {
|
|
209
|
-
// 直接调整
|
|
210
|
-
for (const node of sorted) {
|
|
211
|
-
node.zIndex(minZIndex);
|
|
212
|
-
}
|
|
213
|
-
this.updateLastZindex(sorted);
|
|
214
|
-
// 更新历史
|
|
215
|
-
this.render.updateHistory();
|
|
216
|
-
// 重绘
|
|
217
|
-
this.render.redraw([
|
|
218
|
-
GraphDraw.NAME,
|
|
219
|
-
LinkDraw.NAME,
|
|
220
|
-
RulerDraw.NAME,
|
|
221
|
-
PreviewDraw.NAME
|
|
222
|
-
]);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
1
|
+
import Konva from 'konva';
|
|
2
|
+
import { Render } from '../index';
|
|
3
|
+
import { GraphDraw, LinkDraw, RulerDraw, PreviewDraw } from '../draws';
|
|
4
|
+
|
|
5
|
+
// 层接工具
|
|
6
|
+
|
|
7
|
+
export class ZIndexTool {
|
|
8
|
+
|
|
9
|
+
private render: Render;
|
|
10
|
+
constructor(render: Render) {
|
|
11
|
+
this.render = render;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// 获取移动节点
|
|
15
|
+
getNodes(nodes: Konva.Node[]) {
|
|
16
|
+
const targets: Konva.Node[] = [];
|
|
17
|
+
for (const node of nodes) {
|
|
18
|
+
if (node instanceof Konva.Transformer) {
|
|
19
|
+
// 已选择的节点
|
|
20
|
+
targets.push(...this.render.selectionTool.selectingNodes);
|
|
21
|
+
} else {
|
|
22
|
+
// 未选择的节点
|
|
23
|
+
targets.push(node);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return targets;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 最大 zIndex
|
|
30
|
+
getMaxZIndex() {
|
|
31
|
+
return Math.max(
|
|
32
|
+
...this.render.layer
|
|
33
|
+
.getChildren((node) => !this.render.ignore(node))
|
|
34
|
+
.map((o) => o.zIndex())
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 最小 zIndex
|
|
39
|
+
getMinZIndex() {
|
|
40
|
+
return Math.min(
|
|
41
|
+
...this.render.layer
|
|
42
|
+
.getChildren((node) => !this.render.ignore(node))
|
|
43
|
+
.map((o) => o.zIndex())
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 记录选择期间的 zIndex
|
|
48
|
+
updateSelectingZIndex(nodes: Konva.Node[]) {
|
|
49
|
+
for (const node of nodes) {
|
|
50
|
+
node.setAttrs({
|
|
51
|
+
selectingZIndex: node.zIndex()
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 恢复选择期间的 zIndex
|
|
57
|
+
resetSelectingZIndex(nodes: Konva.Node[]) {
|
|
58
|
+
nodes.sort((a, b) => a.zIndex() - b.zIndex());
|
|
59
|
+
for (const node of nodes) {
|
|
60
|
+
node.zIndex(node.attrs.selectingZIndex);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 更新 zIndex 缓存
|
|
65
|
+
updateLastZindex(nodes: Konva.Node[]) {
|
|
66
|
+
for (const node of nodes) {
|
|
67
|
+
node.setAttrs({ lastZIndex: node.zIndex() });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// 上移
|
|
72
|
+
up(nodes: Konva.Node[]) {
|
|
73
|
+
// 最大zIndex
|
|
74
|
+
const maxZIndex = this.getMaxZIndex();
|
|
75
|
+
const sorted = this.getNodes(nodes).sort((a, b) => b.zIndex() - a.zIndex());
|
|
76
|
+
// 上移
|
|
77
|
+
let lastNode: Konva.Node | null = null;
|
|
78
|
+
if (this.render.selectionTool.selectingNodes.length > 0) {
|
|
79
|
+
this.updateSelectingZIndex(sorted);
|
|
80
|
+
for (const node of sorted) {
|
|
81
|
+
if (
|
|
82
|
+
node.attrs.lastZIndex < maxZIndex &&
|
|
83
|
+
(lastNode === null || node.attrs.lastZIndex < lastNode.attrs.lastZIndex - 1)
|
|
84
|
+
) {
|
|
85
|
+
node.setAttrs({
|
|
86
|
+
lastZIndex: node.attrs.lastZIndex + 1
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
lastNode = node;
|
|
90
|
+
}
|
|
91
|
+
this.resetSelectingZIndex(sorted);
|
|
92
|
+
} else {
|
|
93
|
+
// 直接调整
|
|
94
|
+
for (const node of sorted) {
|
|
95
|
+
if (
|
|
96
|
+
node.zIndex() < maxZIndex &&
|
|
97
|
+
(lastNode === null || node.zIndex() < lastNode.zIndex() - 1)
|
|
98
|
+
) {
|
|
99
|
+
node.zIndex(node.zIndex() + 1);
|
|
100
|
+
}
|
|
101
|
+
lastNode = node;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
this.updateLastZindex(sorted);
|
|
105
|
+
// 更新历史
|
|
106
|
+
this.render.updateHistory();
|
|
107
|
+
// 重绘
|
|
108
|
+
this.render.redraw([
|
|
109
|
+
GraphDraw.NAME,
|
|
110
|
+
LinkDraw.NAME,
|
|
111
|
+
RulerDraw.NAME,
|
|
112
|
+
PreviewDraw.NAME
|
|
113
|
+
]);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 下移
|
|
118
|
+
down(nodes: Konva.Node[]) {
|
|
119
|
+
// 最小 zIndex
|
|
120
|
+
const minZIndex = this.getMinZIndex();
|
|
121
|
+
const sorted = this.getNodes(nodes).sort((a, b) => a.zIndex() - b.zIndex());
|
|
122
|
+
// 下移
|
|
123
|
+
let lastNode: Konva.Node | null = null;
|
|
124
|
+
|
|
125
|
+
if (this.render.selectionTool.selectingNodes.length > 0) {
|
|
126
|
+
this.updateSelectingZIndex(sorted);
|
|
127
|
+
|
|
128
|
+
for (const node of sorted) {
|
|
129
|
+
if (
|
|
130
|
+
node.attrs.lastZIndex > minZIndex &&
|
|
131
|
+
(lastNode === null || node.attrs.lastZIndex > lastNode.attrs.lastZIndex + 1)
|
|
132
|
+
) {
|
|
133
|
+
node.setAttrs({ lastZIndex: node.attrs.lastZIndex - 1 });
|
|
134
|
+
}
|
|
135
|
+
lastNode = node;
|
|
136
|
+
}
|
|
137
|
+
this.resetSelectingZIndex(sorted);
|
|
138
|
+
} else {
|
|
139
|
+
// 直接调整
|
|
140
|
+
for (const node of sorted) {
|
|
141
|
+
if (
|
|
142
|
+
node.zIndex() > minZIndex &&
|
|
143
|
+
(lastNode === null || node.zIndex() > lastNode.zIndex() + 1)
|
|
144
|
+
) {
|
|
145
|
+
node.zIndex(node.zIndex() - 1);
|
|
146
|
+
}
|
|
147
|
+
lastNode = node;
|
|
148
|
+
}
|
|
149
|
+
this.updateLastZindex(sorted);
|
|
150
|
+
// 更新历史
|
|
151
|
+
this.render.updateHistory();
|
|
152
|
+
// 重绘
|
|
153
|
+
this.render.redraw([
|
|
154
|
+
GraphDraw.NAME,
|
|
155
|
+
LinkDraw.NAME,
|
|
156
|
+
RulerDraw.NAME,
|
|
157
|
+
PreviewDraw.NAME
|
|
158
|
+
]);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// 置顶
|
|
163
|
+
top(nodes: Konva.Node[]) {
|
|
164
|
+
// 最大 zIndex
|
|
165
|
+
let maxZIndex = this.getMaxZIndex();
|
|
166
|
+
const sorted = this.getNodes(nodes).sort((a, b) => b.zIndex() - a.zIndex());
|
|
167
|
+
if (this.render.selectionTool.selectingNodes.length > 0) {
|
|
168
|
+
// 先选中再调整
|
|
169
|
+
this.updateSelectingZIndex(sorted);
|
|
170
|
+
// 置顶
|
|
171
|
+
for (const node of sorted) {
|
|
172
|
+
node.setAttrs({ lastZIndex: maxZIndex-- });
|
|
173
|
+
}
|
|
174
|
+
this.resetSelectingZIndex(sorted);
|
|
175
|
+
} else {
|
|
176
|
+
// 直接调整
|
|
177
|
+
for (const node of sorted) {
|
|
178
|
+
node.zIndex(maxZIndex);
|
|
179
|
+
}
|
|
180
|
+
this.updateLastZindex(sorted);
|
|
181
|
+
// 更新历史
|
|
182
|
+
this.render.updateHistory();
|
|
183
|
+
// 重绘
|
|
184
|
+
this.render.redraw([
|
|
185
|
+
GraphDraw.NAME,
|
|
186
|
+
LinkDraw.NAME,
|
|
187
|
+
RulerDraw.NAME,
|
|
188
|
+
PreviewDraw.NAME
|
|
189
|
+
]);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// 置底
|
|
194
|
+
bottom(nodes: Konva.Node[]) {
|
|
195
|
+
// 最小 zIndex
|
|
196
|
+
let minZIndex = this.getMinZIndex();
|
|
197
|
+
const sorted = this.getNodes(nodes).sort((a, b) => a.zIndex() - b.zIndex());
|
|
198
|
+
if (this.render.selectionTool.selectingNodes.length > 0) {
|
|
199
|
+
// 先选中再调整
|
|
200
|
+
this.updateSelectingZIndex(sorted);
|
|
201
|
+
// 置底
|
|
202
|
+
for (const node of sorted) {
|
|
203
|
+
node.setAttrs({
|
|
204
|
+
lastZIndex: minZIndex++
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
this.resetSelectingZIndex(sorted);
|
|
208
|
+
} else {
|
|
209
|
+
// 直接调整
|
|
210
|
+
for (const node of sorted) {
|
|
211
|
+
node.zIndex(minZIndex);
|
|
212
|
+
}
|
|
213
|
+
this.updateLastZindex(sorted);
|
|
214
|
+
// 更新历史
|
|
215
|
+
this.render.updateHistory();
|
|
216
|
+
// 重绘
|
|
217
|
+
this.render.redraw([
|
|
218
|
+
GraphDraw.NAME,
|
|
219
|
+
LinkDraw.NAME,
|
|
220
|
+
RulerDraw.NAME,
|
|
221
|
+
PreviewDraw.NAME
|
|
222
|
+
]);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
225
|
}
|
|
@@ -1,116 +1,116 @@
|
|
|
1
|
-
export interface Node {
|
|
2
|
-
x: number;
|
|
3
|
-
y: number;
|
|
4
|
-
cost?: number; // 代价
|
|
5
|
-
parent?: Node; // 上一步
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export default function aStar(config: {
|
|
9
|
-
from: Node; // 起点
|
|
10
|
-
to: Node; // 终点
|
|
11
|
-
matrix: number[][]; // 矩阵
|
|
12
|
-
maxCost: number // 作为墙的值
|
|
13
|
-
}): Node[] {
|
|
14
|
-
const { from, to, matrix, maxCost = 1 } = config;
|
|
15
|
-
const grid: Node[][] = matrixToGrid(matrix);
|
|
16
|
-
const start = grid[from.y][from.x];
|
|
17
|
-
const goal = grid[to.y][to.x];
|
|
18
|
-
// 初始化 open 和 closed 列表
|
|
19
|
-
const open: Node[] = [start];
|
|
20
|
-
const closed = new Set<Node>();
|
|
21
|
-
// 初始化每个节点的 f, g, h 值
|
|
22
|
-
const f = new Map<Node, number>();
|
|
23
|
-
const g = new Map<Node, number>();
|
|
24
|
-
const h = new Map<Node, number>();
|
|
25
|
-
g.set(start, 0);
|
|
26
|
-
h.set(start, manhattanDistance(start, goal));
|
|
27
|
-
f.set(start, g.get(start)! + h.get(start)!);
|
|
28
|
-
// A* 算法主循环
|
|
29
|
-
while (open.length > 0) {
|
|
30
|
-
// 从 open 列表中找到 f 值最小的节点
|
|
31
|
-
const current = open.reduce((a, b) => (f.get(a)! < f.get(b)! ? a : b));
|
|
32
|
-
// 如果当前节点是目标节点,返回路径
|
|
33
|
-
if (current === goal) {
|
|
34
|
-
return reconstructPath(goal);
|
|
35
|
-
}
|
|
36
|
-
// 将当前节点从 open 列表中移除,并加入 closed 列表
|
|
37
|
-
open.splice(open.indexOf(current), 1);
|
|
38
|
-
closed.add(current);
|
|
39
|
-
// 遍历当前节点的邻居
|
|
40
|
-
for (const neighbor of getNeighbors(current, grid)) {
|
|
41
|
-
// 如果邻居节点已经在 closed 列表中,跳过
|
|
42
|
-
if (closed.has(neighbor)) {
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
// 计算从起点到邻居节点的距离(转弯距离增加)
|
|
46
|
-
const tentativeG =
|
|
47
|
-
g.get(current)! + // 累计距离
|
|
48
|
-
(neighbor.cost ?? 1) + // 下一步距离
|
|
49
|
-
((current.x === current.parent?.x && current.x !== neighbor.x) ||
|
|
50
|
-
(current.y === current.parent?.y && current.y !== neighbor.y)
|
|
51
|
-
? grid.length + grid[0].length
|
|
52
|
-
: 0);
|
|
53
|
-
// 如果邻居节点不在 open 列表中,或者新的 g 值更小,更新邻居节点的 g, h, f 值,并将其加入 open 列表
|
|
54
|
-
if (!open.includes(neighbor) || tentativeG < g.get(neighbor)!) {
|
|
55
|
-
g.set(neighbor, tentativeG);
|
|
56
|
-
h.set(neighbor, manhattanDistance(neighbor, goal));
|
|
57
|
-
f.set(neighbor, g.get(neighbor)! + h.get(neighbor)!);
|
|
58
|
-
neighbor.parent = current;
|
|
59
|
-
if (!open.includes(neighbor)) {
|
|
60
|
-
open.push(neighbor);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// 如果 open 列表为空,表示无法到达目标节点,返回 null
|
|
67
|
-
return [];
|
|
68
|
-
|
|
69
|
-
// 数据转换
|
|
70
|
-
function matrixToGrid(matrix: number[][]) {
|
|
71
|
-
const mt: Node[][] = [];
|
|
72
|
-
for (let y = 0; y < matrix.length; y++) {
|
|
73
|
-
if (mt[y] === void 0) {
|
|
74
|
-
mt[y] = [];
|
|
75
|
-
}
|
|
76
|
-
for (let x = 0; x < matrix[y].length; x++) {
|
|
77
|
-
mt[y].push({ x, y, cost: matrix[y][x] });
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return mt;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// 从目标节点开始,沿着 parent 指针重构路径
|
|
84
|
-
function reconstructPath(node: Node): Node[] {
|
|
85
|
-
const path = [node];
|
|
86
|
-
while (node.parent) {
|
|
87
|
-
path.push(node.parent);
|
|
88
|
-
node = node.parent;
|
|
89
|
-
}
|
|
90
|
-
return path.reverse();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// 计算曼哈顿距离
|
|
94
|
-
function manhattanDistance(a: Node, b: Node): number {
|
|
95
|
-
return Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// 获取当前节点的邻居
|
|
99
|
-
function getNeighbors(node: Node, grid: Node[][]): Node[] {
|
|
100
|
-
const neighbors = [];
|
|
101
|
-
const { x, y } = node;
|
|
102
|
-
if (x > 0 && (grid[y][x - 1].cost ?? 0) < maxCost) {
|
|
103
|
-
neighbors.push(grid[y][x - 1]);
|
|
104
|
-
}
|
|
105
|
-
if (x < grid[0].length - 1 && (grid[y][x + 1].cost ?? 0) < maxCost) {
|
|
106
|
-
neighbors.push(grid[y][x + 1]);
|
|
107
|
-
}
|
|
108
|
-
if (y > 0 && (grid[y - 1][x].cost ?? 0) < maxCost) {
|
|
109
|
-
neighbors.push(grid[y - 1][x]);
|
|
110
|
-
}
|
|
111
|
-
if (y < grid.length - 1 && (grid[y + 1][x].cost ?? 0) < maxCost) {
|
|
112
|
-
neighbors.push(grid[y + 1][x]);
|
|
113
|
-
}
|
|
114
|
-
return neighbors;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
1
|
+
export interface Node {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
cost?: number; // 代价
|
|
5
|
+
parent?: Node; // 上一步
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default function aStar(config: {
|
|
9
|
+
from: Node; // 起点
|
|
10
|
+
to: Node; // 终点
|
|
11
|
+
matrix: number[][]; // 矩阵
|
|
12
|
+
maxCost: number // 作为墙的值
|
|
13
|
+
}): Node[] {
|
|
14
|
+
const { from, to, matrix, maxCost = 1 } = config;
|
|
15
|
+
const grid: Node[][] = matrixToGrid(matrix);
|
|
16
|
+
const start = grid[from.y][from.x];
|
|
17
|
+
const goal = grid[to.y][to.x];
|
|
18
|
+
// 初始化 open 和 closed 列表
|
|
19
|
+
const open: Node[] = [start];
|
|
20
|
+
const closed = new Set<Node>();
|
|
21
|
+
// 初始化每个节点的 f, g, h 值
|
|
22
|
+
const f = new Map<Node, number>();
|
|
23
|
+
const g = new Map<Node, number>();
|
|
24
|
+
const h = new Map<Node, number>();
|
|
25
|
+
g.set(start, 0);
|
|
26
|
+
h.set(start, manhattanDistance(start, goal));
|
|
27
|
+
f.set(start, g.get(start)! + h.get(start)!);
|
|
28
|
+
// A* 算法主循环
|
|
29
|
+
while (open.length > 0) {
|
|
30
|
+
// 从 open 列表中找到 f 值最小的节点
|
|
31
|
+
const current = open.reduce((a, b) => (f.get(a)! < f.get(b)! ? a : b));
|
|
32
|
+
// 如果当前节点是目标节点,返回路径
|
|
33
|
+
if (current === goal) {
|
|
34
|
+
return reconstructPath(goal);
|
|
35
|
+
}
|
|
36
|
+
// 将当前节点从 open 列表中移除,并加入 closed 列表
|
|
37
|
+
open.splice(open.indexOf(current), 1);
|
|
38
|
+
closed.add(current);
|
|
39
|
+
// 遍历当前节点的邻居
|
|
40
|
+
for (const neighbor of getNeighbors(current, grid)) {
|
|
41
|
+
// 如果邻居节点已经在 closed 列表中,跳过
|
|
42
|
+
if (closed.has(neighbor)) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
// 计算从起点到邻居节点的距离(转弯距离增加)
|
|
46
|
+
const tentativeG =
|
|
47
|
+
g.get(current)! + // 累计距离
|
|
48
|
+
(neighbor.cost ?? 1) + // 下一步距离
|
|
49
|
+
((current.x === current.parent?.x && current.x !== neighbor.x) ||
|
|
50
|
+
(current.y === current.parent?.y && current.y !== neighbor.y)
|
|
51
|
+
? grid.length + grid[0].length
|
|
52
|
+
: 0);
|
|
53
|
+
// 如果邻居节点不在 open 列表中,或者新的 g 值更小,更新邻居节点的 g, h, f 值,并将其加入 open 列表
|
|
54
|
+
if (!open.includes(neighbor) || tentativeG < g.get(neighbor)!) {
|
|
55
|
+
g.set(neighbor, tentativeG);
|
|
56
|
+
h.set(neighbor, manhattanDistance(neighbor, goal));
|
|
57
|
+
f.set(neighbor, g.get(neighbor)! + h.get(neighbor)!);
|
|
58
|
+
neighbor.parent = current;
|
|
59
|
+
if (!open.includes(neighbor)) {
|
|
60
|
+
open.push(neighbor);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 如果 open 列表为空,表示无法到达目标节点,返回 null
|
|
67
|
+
return [];
|
|
68
|
+
|
|
69
|
+
// 数据转换
|
|
70
|
+
function matrixToGrid(matrix: number[][]) {
|
|
71
|
+
const mt: Node[][] = [];
|
|
72
|
+
for (let y = 0; y < matrix.length; y++) {
|
|
73
|
+
if (mt[y] === void 0) {
|
|
74
|
+
mt[y] = [];
|
|
75
|
+
}
|
|
76
|
+
for (let x = 0; x < matrix[y].length; x++) {
|
|
77
|
+
mt[y].push({ x, y, cost: matrix[y][x] });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return mt;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 从目标节点开始,沿着 parent 指针重构路径
|
|
84
|
+
function reconstructPath(node: Node): Node[] {
|
|
85
|
+
const path = [node];
|
|
86
|
+
while (node.parent) {
|
|
87
|
+
path.push(node.parent);
|
|
88
|
+
node = node.parent;
|
|
89
|
+
}
|
|
90
|
+
return path.reverse();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 计算曼哈顿距离
|
|
94
|
+
function manhattanDistance(a: Node, b: Node): number {
|
|
95
|
+
return Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 获取当前节点的邻居
|
|
99
|
+
function getNeighbors(node: Node, grid: Node[][]): Node[] {
|
|
100
|
+
const neighbors = [];
|
|
101
|
+
const { x, y } = node;
|
|
102
|
+
if (x > 0 && (grid[y][x - 1].cost ?? 0) < maxCost) {
|
|
103
|
+
neighbors.push(grid[y][x - 1]);
|
|
104
|
+
}
|
|
105
|
+
if (x < grid[0].length - 1 && (grid[y][x + 1].cost ?? 0) < maxCost) {
|
|
106
|
+
neighbors.push(grid[y][x + 1]);
|
|
107
|
+
}
|
|
108
|
+
if (y > 0 && (grid[y - 1][x].cost ?? 0) < maxCost) {
|
|
109
|
+
neighbors.push(grid[y - 1][x]);
|
|
110
|
+
}
|
|
111
|
+
if (y < grid.length - 1 && (grid[y + 1][x].cost ?? 0) < maxCost) {
|
|
112
|
+
neighbors.push(grid[y + 1][x]);
|
|
113
|
+
}
|
|
114
|
+
return neighbors;
|
|
115
|
+
}
|
|
116
|
+
}
|