g6/packages/site/examples/performance/perf/demo/moreData.js

64 lines
1.6 KiB
JavaScript
Raw Normal View History

2023-08-29 21:58:37 +08:00
import { Graph, Extensions, extend } from '@antv/g6';
const ExtGraph = extend(Graph, {
behaviors: {
'brush-select': Extensions.BrushSelect,
},
});
2023-02-02 10:31:36 +08:00
const container = document.getElementById('container');
const descriptionDiv = document.createElement('div');
descriptionDiv.innerHTML = `正在渲染大规模数据,请稍等……`;
container.appendChild(descriptionDiv);
const width = container.scrollWidth;
const height = container.scrollHeight || 500;
2023-08-29 21:58:37 +08:00
const graph = new ExtGraph({
2023-02-02 10:31:36 +08:00
container: 'container',
width,
height,
2023-08-31 10:59:52 +08:00
renderer: 'canvas',
transform: ['transform-v4-data'],
2023-02-02 10:31:36 +08:00
modes: {
default: [
{
type: 'zoom-canvas',
enableOptimize: true,
optimizeZoom: 0.9,
},
{
type: 'drag-canvas',
enableOptimize: true,
},
'drag-node',
'brush-select',
],
},
2023-08-31 10:59:52 +08:00
node: {
keyShape: {
r: 2,
},
},
edge: {
keyShape: {
opacity: 0.3,
},
},
2023-02-02 10:31:36 +08:00
});
fetch('https://gw.alipayobjects.com/os/bmw-prod/f1565312-d537-4231-adf5-81cb1cd3a0e8.json')
.then((res) => res.json())
.then((data) => {
2023-08-31 10:59:52 +08:00
data.edges.forEach((edge) => (edge.id = `edge-${Math.random()}`));
2023-08-29 21:58:37 +08:00
graph.read(data);
2023-08-31 10:59:52 +08:00
const nodeLen = data.nodes.length;
const edgeLen = data.edges.length;
2023-08-29 21:58:37 +08:00
descriptionDiv.innerHTML = `节点数量:${nodeLen}, 边数量:${edgeLen}, 图元数量:${nodeLen + edgeLen}`;
2023-02-02 10:31:36 +08:00
});
if (typeof window !== 'undefined')
window.onresize = () => {
2023-08-31 10:59:52 +08:00
if (!graph || graph.destroyed) return;
2023-02-02 10:31:36 +08:00
if (!container || !container.scrollWidth || !container.scrollHeight) return;
2023-08-31 10:59:52 +08:00
graph.setSize([container.scrollWidth, container.scrollHeight]);
2023-02-02 10:31:36 +08:00
};