g6/packages/site/examples/net/layoutMechanism/demo/layoutTiming.js
Yuxin 98a213ab70
perf: simplify plugin registration; add comments and unit tests (#5352)
* perf: refactor register;add comments and unit tests

* fix: ci

---------

Co-authored-by: yvonneyx <banxuan.zyx@antgroup.com>
2024-01-17 18:59:21 +08:00

52 lines
1.2 KiB
JavaScript

import { Graph } from '@antv/g6';
const tipDiv = document.createElement('div');
const container = document.getElementById('container');
container.appendChild(tipDiv);
const width = container.scrollWidth;
const height = container.scrollHeight || 500;
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',
width,
height,
transforms: [
{
type: 'transform-v4-data',
activeLifecycle: ['read'],
},
],
layout: {
type: 'force',
preventOverlap: true,
nodeSize: 32,
workerEnabled: true,
},
modes: {
default: ['zoom-canvas', 'drag-canvas', 'drag-node', 'click-select'],
},
node: {
keyShape: {
r: 6,
},
},
edge: {
keyShape: {
opacity: 0.3,
},
},
data,
});
graph.on('beforelayout', function () {
tipDiv.innerHTML = 'Doing force-directed layout... the text will be changed after the layout being done.';
});
graph.on('afterlayout', function () {
tipDiv.innerHTML = 'Done!';
});
window.graph = graph;
});