2024-03-14 19:43:53 +08:00
|
|
|
import { Graph } from '@antv/g6';
|
2023-02-02 10:31:36 +08:00
|
|
|
|
|
|
|
const container = document.getElementById('container');
|
|
|
|
const descriptionDiv = document.createElement('div');
|
2023-08-28 00:17:22 +08:00
|
|
|
descriptionDiv.innerHTML = 'Doing layout... web-worker is enabled in this demo, so the layout will not block the page.';
|
2023-02-02 10:31:36 +08:00
|
|
|
container.appendChild(descriptionDiv);
|
|
|
|
|
|
|
|
fetch('https://gw.alipayobjects.com/os/basement_prod/7bacd7d1-4119-4ac1-8be3-4c4b9bcbc25f.json')
|
|
|
|
.then((res) => res.json())
|
|
|
|
.then((data) => {
|
2024-03-14 19:43:53 +08:00
|
|
|
const graph = new Graph({
|
2023-08-28 00:17:22 +08:00
|
|
|
container: 'container',
|
2024-03-14 19:43:53 +08:00
|
|
|
data,
|
2023-08-28 00:17:22 +08:00
|
|
|
layout: {
|
|
|
|
type: 'fruchterman',
|
|
|
|
speed: 20,
|
|
|
|
gravity: 1,
|
|
|
|
maxIteration: 10000,
|
|
|
|
workerEnabled: true,
|
|
|
|
},
|
|
|
|
node: {
|
2024-03-14 19:43:53 +08:00
|
|
|
style: {
|
|
|
|
size: 6,
|
2023-08-28 00:17:22 +08:00
|
|
|
},
|
|
|
|
},
|
2024-03-14 19:43:53 +08:00
|
|
|
edge: {
|
|
|
|
style: {
|
|
|
|
stroke: '#ddd',
|
|
|
|
},
|
|
|
|
},
|
2024-03-16 00:39:25 +08:00
|
|
|
behaviors: ['drag-canvas', 'drag-element'],
|
2023-08-28 00:17:22 +08:00
|
|
|
});
|
|
|
|
|
2024-03-14 19:43:53 +08:00
|
|
|
graph.render();
|
|
|
|
|
2023-08-28 00:17:22 +08:00
|
|
|
graph.on('afterlayout', () => {
|
2024-03-14 19:43:53 +08:00
|
|
|
descriptionDiv.innerHTML = 'Layout in Worker, Done!';
|
2023-08-28 00:17:22 +08:00
|
|
|
});
|
2023-02-02 10:31:36 +08:00
|
|
|
});
|