Skip to content

Commit 74592a7

Browse files
authored
fix (#43)
* fix: shadow destroy err * fix: clear bug * fix: demo
1 parent e111d20 commit 74592a7

File tree

6 files changed

+31
-3
lines changed

6 files changed

+31
-3
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vesoft-inc/veditor",
3-
"version": "4.4.12",
3+
"version": "4.4.14",
44
"description": "svg flow editor",
55
"main": "./dist/VEditor.js",
66
"types": "./types/index.d.ts",

public/flowChart.html

+20
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<body>
44
<div id="app" style="width:100%;height:300px;box-shadow: 0 0 10px 1px #123"></div>
5+
<button onclick="onChangeLayoutSort()">sort</button>
56
</body>
67
<script src="../dist/VEditor.browser.js"></script>
78
<script>
@@ -88,6 +89,7 @@
8889
// dagre配置
8990
editor.config.dagreOption = {
9091
rankdir: 'TB',
92+
ranksep: 150
9193
}
9294
// async
9395
async function setData() {
@@ -98,6 +100,24 @@
98100
}
99101
setData();
100102

103+
104+
const onChangeLayoutSort = async () => {
105+
editor.config.dagreOption = {
106+
// ...editor.config.dagreOption,
107+
rankdir: editor.config.dagreOption?.rankdir === "TB" ? "BT" : "TB",
108+
ranksep: 150,
109+
};
110+
const isRevert = editor.config.dagreOption?.rankdir === "TB";
111+
for (const key in editor.graph.line.lines) {
112+
const line = editor.graph.line.lines[key];
113+
line.data.fromPoint = isRevert ? 3 : 2;
114+
line.data.toPoint = isRevert ? 2 : 3;
115+
}
116+
editor.schema.format();
117+
editor.controller.autoFit();
118+
};
119+
120+
101121
</script>
102122

103123
</html>

src/Shape/Graph.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ class Graph extends Utils.Event {
158158

159159

160160
initDefs() {
161-
if(document.getElementById("ve-svg-defs")) return;
161+
if (document.getElementById("ve-svg-defs")) {
162+
this.shadow = document.getElementById("ve-svg-defs") as unknown as SVGSVGElement;
163+
return;
164+
};
162165
this.shadow = svgWrapper(
163166
`<svg id="ve-svg-defs" style="position:absolute;left:-9999px;top:-9999px;" xmlns="http://www.w3.org/2000/svg">
164167
<defs>
@@ -193,6 +196,8 @@ class Graph extends Utils.Event {
193196
destroy() {
194197
this.clearGraph();
195198
this.clear();
199+
this.shadow.remove();
200+
this.shadow = undefined;
196201
document.removeEventListener("keydown", this.onKeyDown);
197202
}
198203
}

src/Shape/Line.ts

+2
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ class Line {
246246
line.arrow.remove();
247247
line.arrow = null;
248248
line.dom.remove();
249+
line.label = null;
249250
this.activeLine = null;
250251
}
251252

@@ -591,6 +592,7 @@ class Line {
591592
for (let key in lines) {
592593
this.deleteLine(lines[key].data, true);
593594
}
595+
this.activeLine = null;
594596
}
595597
}
596598
export default Line;

src/Shape/Lines/Line.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ const DefaultLine: LineRender = {
255255
);
256256
}
257257
line.shape.appendChild(line.label.labelGroup);
258-
const { text, textRect, textBBox, oldText, labelGroup } = line.label;
258+
const { text, textBBox, oldText, labelGroup } = line.label;
259259
const x = xPoint + (refX || 0);
260260
const y = yPoint + (refY || 0);
261261
text.textContent = label;

src/Shape/Node.ts

+1
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ class Node {
469469
for (let key in nodes) {
470470
this.deleteNode(nodes[key].data, true);
471471
}
472+
this.actives = {};
472473
}
473474
}
474475
export default Node;

0 commit comments

Comments
 (0)