g6/packages/site/examples/net/forceDirected/demo/basicFA2.js

35 lines
947 B
JavaScript

import G6 from '@antv/g6';
const container = document.getElementById('container');
const width = container.scrollWidth;
const height = container.scrollHeight || 500;
fetch('https://gw.alipayobjects.com/os/antvdemo/assets/data/relations.json')
.then((res) => res.json())
.then((data) => {
const graph = new G6.Graph({
container: 'container',
width,
height,
transform: ['transform-v4-data'],
modes: {
default: ['zoom-canvas', 'drag-canvas', 'drag-node'],
},
layout: {
type: 'forceAtlas2',
preventOverlap: true,
kr: 2,
center: [250, 250],
},
autoFit: 'view',
data,
});
});
if (typeof window !== 'undefined')
window.onresize = () => {
if (!graph || graph.destroyed) return;
if (!container || !container.scrollWidth || !container.scrollHeight) return;
graph.setSize([container.scrollWidth, container.scrollHeight]);
};