mirror of
https://gitee.com/antv/g6.git
synced 2024-12-14 09:30:48 +08:00
bdc3a6cbeb
* test: add fruchterman layout test * docs: add fruchterman demo * fix: eslint error * chore: fix cr * chore: remove unused code * chore: fix cr
40 lines
1009 B
TypeScript
40 lines
1009 B
TypeScript
import { Graph } from '@antv/g6';
|
|
|
|
const container = document.getElementById('container');
|
|
const descriptionDiv = document.createElement('div');
|
|
descriptionDiv.innerHTML = 'Doing layout... web-worker is enabled in this demo, so the layout will not block the page.';
|
|
container.appendChild(descriptionDiv);
|
|
|
|
fetch('https://gw.alipayobjects.com/os/basement_prod/7bacd7d1-4119-4ac1-8be3-4c4b9bcbc25f.json')
|
|
.then((res) => res.json())
|
|
.then((data) => {
|
|
const graph = new Graph({
|
|
container: 'container',
|
|
data,
|
|
layout: {
|
|
type: 'fruchterman',
|
|
speed: 20,
|
|
gravity: 1,
|
|
maxIteration: 10000,
|
|
workerEnabled: true,
|
|
},
|
|
node: {
|
|
style: {
|
|
size: 6,
|
|
},
|
|
},
|
|
edge: {
|
|
style: {
|
|
stroke: '#ddd',
|
|
},
|
|
},
|
|
behaviors: ['drag-canvas', 'drag-node'],
|
|
});
|
|
|
|
graph.render();
|
|
|
|
graph.on('afterlayout', () => {
|
|
descriptionDiv.innerHTML = 'Layout in Worker, Done!';
|
|
});
|
|
});
|