2023-08-30 10:59:32 +08:00
|
|
|
import { Graph, Extensions, extend } from '@antv/g6';
|
|
|
|
const ExtGraph = extend(Graph, {
|
|
|
|
nodes: {
|
|
|
|
'sphere-node': Extensions.SphereNode,
|
|
|
|
},
|
|
|
|
behaviors: {
|
|
|
|
'orbit-canvas-3d': Extensions.OrbitCanvas3D,
|
|
|
|
'zoom-canvas-3d': Extensions.ZoomCanvas3D,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const container = document.getElementById('container');
|
|
|
|
const width = container.scrollWidth;
|
|
|
|
const height = container.scrollHeight || 500;
|
|
|
|
|
2023-08-30 14:21:51 +08:00
|
|
|
const getDegrees = (data) => {
|
|
|
|
const degrees = {};
|
|
|
|
data.edges.forEach((edge) => {
|
|
|
|
const { source, target } = edge;
|
|
|
|
degrees[source] = degrees[source] || 0;
|
|
|
|
degrees[target] = degrees[target] || 0;
|
|
|
|
degrees[source]++;
|
|
|
|
degrees[target]++;
|
|
|
|
});
|
|
|
|
return degrees;
|
|
|
|
};
|
|
|
|
|
|
|
|
fetch('https://assets.antv.antgroup.com/g6/eva-3d.json')
|
|
|
|
.then((res) => res.json())
|
|
|
|
.then((data) => {
|
|
|
|
const degrees = getDegrees(data);
|
|
|
|
const graph = new ExtGraph({
|
|
|
|
container: 'container',
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
renderer: 'webgl-3d',
|
|
|
|
modes: {
|
|
|
|
default: ['drag-canvas', 'drag-node', 'zoom-canvas'],
|
2023-08-30 10:59:32 +08:00
|
|
|
},
|
2023-08-30 14:21:51 +08:00
|
|
|
modes: {
|
|
|
|
default: [
|
|
|
|
{
|
|
|
|
type: 'orbit-canvas-3d',
|
|
|
|
trigger: 'drag',
|
|
|
|
},
|
|
|
|
'zoom-canvas-3d',
|
|
|
|
],
|
2023-08-30 10:59:32 +08:00
|
|
|
},
|
2023-08-30 14:21:51 +08:00
|
|
|
theme: {
|
|
|
|
type: 'spec',
|
|
|
|
base: 'dark',
|
|
|
|
specification: {
|
|
|
|
node: {
|
|
|
|
dataTypeField: 'cluster',
|
|
|
|
},
|
2023-08-30 10:59:32 +08:00
|
|
|
},
|
|
|
|
},
|
2023-08-30 14:21:51 +08:00
|
|
|
edge: (innerModel) => {
|
|
|
|
return {
|
|
|
|
...innerModel,
|
|
|
|
data: {
|
|
|
|
...innerModel.data,
|
|
|
|
keyShape: {
|
2023-08-31 18:16:13 +08:00
|
|
|
lineWidth: 0.4,
|
|
|
|
opacity: 0.4,
|
2023-08-30 14:21:51 +08:00
|
|
|
stroke: '#fff',
|
|
|
|
},
|
|
|
|
type: 'line-edge',
|
|
|
|
},
|
|
|
|
};
|
2023-08-30 10:59:32 +08:00
|
|
|
},
|
2023-08-30 14:21:51 +08:00
|
|
|
node: (innerModel) => {
|
|
|
|
return {
|
|
|
|
...innerModel,
|
|
|
|
data: {
|
|
|
|
...innerModel.data,
|
|
|
|
type: 'sphere-node',
|
|
|
|
keyShape: {
|
|
|
|
r: 12 + degrees[innerModel.id] / 2,
|
|
|
|
},
|
|
|
|
labelShape:
|
|
|
|
degrees[innerModel.id] > 20
|
|
|
|
? {
|
|
|
|
text: innerModel.data.label,
|
|
|
|
fontSize: 100,
|
|
|
|
lod: -1,
|
|
|
|
fill: 'rgba(255,255,255,0.85)',
|
|
|
|
wordWrap: false, // FIXME: mesh.getBounds() returns an empty AABB
|
|
|
|
isBillboard: true,
|
|
|
|
}
|
|
|
|
: undefined,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
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 - 160]);
|
|
|
|
};
|
2023-08-30 10:59:32 +08:00
|
|
|
});
|