refactor: adjust force params demo

This commit is contained in:
Chushen 2023-11-13 16:40:13 +08:00
parent 86df0d2a34
commit d3722e94da

View File

@ -20,7 +20,7 @@ const graph = new G6.Graph({
},
},
modes: {
default: ['zoom-canvas', 'drag-canvas', 'click-select'],
default: ['zoom-canvas', 'drag-canvas', 'click-select', 'drag-node'],
},
data: {
nodes: [
@ -63,31 +63,9 @@ const graph = new G6.Graph({
},
});
graph.on('node:dragstart', function (e) {
graph.stopLayout();
});
graph.on('node:drag', function (e) {
refreshDragedNodePosition(e);
});
graph.on('node:dragend', (e) => {
graph.layout();
});
if (typeof window !== 'undefined')
window.onresize = () => {
if (!graph || graph.destroyed) return;
if (!container || !container.scrollWidth || !container.scrollHeight) return;
graph.setSize([container.scrollWidth, container.scrollHeight]);
};
function refreshDragedNodePosition(e) {
graph.updateData('node', {
id: e.itemId,
data: {
fx: e.canvas.x,
fy: e.canvas.y,
x: e.canvas.x,
y: e.canvas.y,
},
});
}