Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #43

Merged
merged 4 commits into from
Apr 29, 2024
Merged

fix #43

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vesoft-inc/veditor",
"version": "4.4.12",
"version": "4.4.14",
"description": "svg flow editor",
"main": "./dist/VEditor.js",
"types": "./types/index.d.ts",
Expand Down
20 changes: 20 additions & 0 deletions public/flowChart.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<body>
<div id="app" style="width:100%;height:300px;box-shadow: 0 0 10px 1px #123"></div>
<button onclick="onChangeLayoutSort()">sort</button>
</body>
<script src="../dist/VEditor.browser.js"></script>
<script>
Expand Down Expand Up @@ -88,6 +89,7 @@
// dagre配置
editor.config.dagreOption = {
rankdir: 'TB',
ranksep: 150
}
// async
async function setData() {
Expand All @@ -98,6 +100,24 @@
}
setData();


const onChangeLayoutSort = async () => {
editor.config.dagreOption = {
// ...editor.config.dagreOption,
rankdir: editor.config.dagreOption?.rankdir === "TB" ? "BT" : "TB",
ranksep: 150,
};
const isRevert = editor.config.dagreOption?.rankdir === "TB";
for (const key in editor.graph.line.lines) {
const line = editor.graph.line.lines[key];
line.data.fromPoint = isRevert ? 3 : 2;
line.data.toPoint = isRevert ? 2 : 3;
}
editor.schema.format();
editor.controller.autoFit();
};


</script>

</html>
7 changes: 6 additions & 1 deletion src/Shape/Graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ class Graph extends Utils.Event {


initDefs() {
if(document.getElementById("ve-svg-defs")) return;
if (document.getElementById("ve-svg-defs")) {
this.shadow = document.getElementById("ve-svg-defs") as unknown as SVGSVGElement;
return;
};
this.shadow = svgWrapper(
`<svg id="ve-svg-defs" style="position:absolute;left:-9999px;top:-9999px;" xmlns="http://www.w3.org/2000/svg">
<defs>
Expand Down Expand Up @@ -193,6 +196,8 @@ class Graph extends Utils.Event {
destroy() {
this.clearGraph();
this.clear();
this.shadow.remove();
this.shadow = undefined;
document.removeEventListener("keydown", this.onKeyDown);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Shape/Line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ class Line {
line.arrow.remove();
line.arrow = null;
line.dom.remove();
line.label = null;
this.activeLine = null;
}

Expand Down Expand Up @@ -591,6 +592,7 @@ class Line {
for (let key in lines) {
this.deleteLine(lines[key].data, true);
}
this.activeLine = null;
}
}
export default Line;
2 changes: 1 addition & 1 deletion src/Shape/Lines/Line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ const DefaultLine: LineRender = {
);
}
line.shape.appendChild(line.label.labelGroup);
const { text, textRect, textBBox, oldText, labelGroup } = line.label;
const { text, textBBox, oldText, labelGroup } = line.label;
const x = xPoint + (refX || 0);
const y = yPoint + (refY || 0);
text.textContent = label;
Expand Down
1 change: 1 addition & 0 deletions src/Shape/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ class Node {
for (let key in nodes) {
this.deleteNode(nodes[key].data, true);
}
this.actives = {};
}
}
export default Node;