Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
vue-flow-editor
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
hookehuyr
2024-07-18 14:48:18 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
608dbedcb5a2cfc93738f809011489c034075a66
608dbedc
1 parent
c9559cbf
fix 居中功能作为toolbar上面的功能
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
31 deletions
doc/index.vue
doc/index.vue
View file @
608dbed
...
...
@@ -396,6 +396,12 @@
<span style="font-size: 12px; transform: scale(0.8); margin-top: 2px;">排序</span>
</div>
</el-tooltip>
<el-tooltip content="图层居中">
<div class="vue-flow-editor-toolbar-item" @click="setMapCenter">
<i class="el-icon-rank" style=" margin-top: 4px;" />
<span style="font-size: 12px; transform: scale(0.8); margin-top: 2px;">居中</span>
</div>
</el-tooltip>
<!-- <el-tooltip content="保存流程图数据">
<div class="vue-flow-editor-toolbar-item" @click="saveData">
<i class="el-icon-coin" style=" margin-top: 4px;" />
...
...
@@ -953,37 +959,6 @@ export default {
// 内部刷新graph数据
nextTick(() => {
editor.editorState.graph.read(flowData.value);
// TAG: 自动位移中心点位置
const point = {
x: 600,
y: 400
};
const width = editor.editorState.graph.get('width');
const height = editor.editorState.graph.get('height');
// 找到视口中心
const viewCenter = {
x: width / 2,
y: height / 2
};
const modelCenter = editor.editorState.graph.getPointByCanvas(viewCenter.x, viewCenter.y);
const viewportMatrix = editor.editorState.graph.get('group').getMatrix();
// 画布平移的目标位置,最终目标是graph.translate(dx, dy);
const dx = (modelCenter.x - point.x) * viewportMatrix[0];
const dy = (modelCenter.y - point.y) * viewportMatrix[4];
let lastX = 0;
let lastY = 0;
let newX = void 0;
let newY = void 0;
// 动画每次平移一点,直到目标位置
editor.editorState.graph.get('canvas').animate({
onFrame: function onFrame(ratio) {
newX = dx * ratio;
newY = dy * ratio;
editor.editorState.graph.translate(newX - lastX, newY - lastY);
lastX = newX;
lastY = newY;
}
}, 100, 'easeCubic');
});
}
...
...
@@ -2358,6 +2333,43 @@ export default {
state.dialogSortVisible = true;
}
/**
* 图层居中
*/
const setMapCenter = () => {
// TAG: 自动位移中心点位置
const point = {
x: 700,
y: 400
};
const width = editor.editorState.graph.get('width');
const height = editor.editorState.graph.get('height');
// 找到视口中心
const viewCenter = {
x: width / 2,
y: height / 2
};
const modelCenter = editor.editorState.graph.getPointByCanvas(viewCenter.x, viewCenter.y);
const viewportMatrix = editor.editorState.graph.get('group').getMatrix();
// 画布平移的目标位置,最终目标是graph.translate(dx, dy);
const dx = (modelCenter.x - point.x) * viewportMatrix[0];
const dy = (modelCenter.y - point.y) * viewportMatrix[4];
let lastX = 0;
let lastY = 0;
let newX = void 0;
let newY = void 0;
// 动画每次平移一点,直到目标位置
editor.editorState.graph.get('canvas').animate({
onFrame: function onFrame(ratio) {
newX = dx * ratio;
newY = dy * ratio;
editor.editorState.graph.translate(newX - lastX, newY - lastY);
lastX = newX;
lastY = newY;
}
}, 100, 'easeCubic');
}
const confirmSort = async () => {
state.dialogSortVisible = false;
...
...
@@ -2684,6 +2696,7 @@ export default {
onConfirmUserView,
sortData,
setMapCenter,
confirmSort,
copyData,
saveData,
...
...
Please
register
or
login
to post a comment