Я успешно вычисляю новые позиции для узлов, используя dagre , но когда я обновляю позиции узла нав. (
Код: Выделить всё
node.pos_x = pos.x; node.pos_y = pos.y;Я искал документацию Drawflow и исходный код , но я не могу найти способ, чтобы обновление на дисплее, чтобы узлы визуально перемещались на свои новые позиции, сохраняя при этом их соединения. br /> Вот моя текущая функция: < /p>
Код: Выделить всё
function applyDagreLayout(drawflow) {
const nodes = drawflow.drawflow.drawflow.Home.data;
const graph = new dagre.graphlib.Graph();
graph.setGraph({ rankdir: 'LR', nodesep: 50, edgesep: 20, ranksep: 80 });
// Add nodes to Dagre
for (let key in nodes) {
graph.setNode(key, { width: 100, height: 100 });
}
// Add edges to Dagre
for (let key in nodes) {
const node = nodes[key];
if (node.inputs) {
for (let input in node.inputs) {
const sourceNode = input.node;
if (sourceNode) {
graph.setEdge(sourceNode, key);
}
}
}
}
// Compute new layout
dagre.layout(graph);
// Update node positions in Drawflow
for (let key in nodes) {
const node = nodes[key];
const pos = graph.node(key);
node.pos_x = pos.x;
node.pos_y = pos.y;
console.log(`Updated node ${key} position to:`, node.pos_x, node.pos_y);
// Attempted fixes (None of these work so far)
// drawflow.moveNode(key, pos.x, pos.y); // Is what I'd like to do ideally, but it doesn't exist
// drawflow.removeNodeId(key);
// const newNode = drawflow.addNode({ ...node }); // Deleting the node and creating a new one with the same data might work, but then I'll have to create its connections again, and it can introduce other problems as well since the node's id will technically not be the same, I'd rather avoid this and do it the 'proper' way, if such a thing exists in this library
}
// Tried reloading the editor, but this caused there to be duplicate nodes (the new nodes didn't have any connections)
// drawflow.load();
}
< /code>
Что я пробовал: < /h1>
[*] напрямую изменяющую node.pos_x < /code> и `node.pos_y.
[*] Поиск функции, такой как movenode () [*] Снятие узлов и повторного введения с использованием removenodeid () и addnode () .
Вызов trantflow.render ( ) , чтобы заставить перерисовать. Полосы нанесения потока, чтобы отразить новые позиции узла после применения макета Dagre?
Подробнее здесь: https://stackoverflow.com/questions/794 ... gre-layout
Мобильная версия