mirror of
https://gitee.com/antv/g6.git
synced 2024-12-02 19:58:46 +08:00
refactor: adjust force params demo
This commit is contained in:
parent
86df0d2a34
commit
d3722e94da
@ -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,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user