hookehuyr

处理渲染定位显示可能的问题,自动位移中心点位置

......@@ -952,7 +952,38 @@ export default {
flowData.value = { nodes, edges }; // 获取已存在的数据
// 内部刷新graph数据
nextTick(() => {
editor.editorState.graph.read(flowData.value)
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');
});
}
......@@ -1622,7 +1653,10 @@ export default {
addItem: any
removeItem: any
save: () => { nodes: any; edges: any }
read: any
read: any,
get: any,
getPointByCanvas: any,
translate: any,
}
}
}
......