2023-08-31 21:29:06 +08:00
|
|
|
import { Graph } from '@antv/g6';
|
2023-02-02 10:31:36 +08:00
|
|
|
|
2023-08-31 21:29:06 +08:00
|
|
|
const container = document.getElementById('container');
|
|
|
|
const width = container.scrollWidth;
|
|
|
|
const height = container.scrollHeight || 500;
|
2023-02-02 10:31:36 +08:00
|
|
|
|
2023-08-31 21:29:06 +08:00
|
|
|
const graph = new Graph({
|
2023-02-02 10:31:36 +08:00
|
|
|
container: 'container',
|
|
|
|
width,
|
|
|
|
height,
|
2023-08-31 21:29:06 +08:00
|
|
|
stackCfg: {
|
|
|
|
ignoreStateChange: true,
|
2023-02-02 10:31:36 +08:00
|
|
|
},
|
2023-08-31 21:29:06 +08:00
|
|
|
node: {
|
|
|
|
labelShape: {
|
|
|
|
position: 'center',
|
|
|
|
text: {
|
|
|
|
fields: ['id'],
|
|
|
|
formatter: (model) => model.id,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
animates: {
|
|
|
|
update: [
|
|
|
|
{
|
|
|
|
fields: ['opacity'],
|
|
|
|
shapeId: 'haloShape',
|
|
|
|
},
|
|
|
|
],
|
2023-02-02 10:31:36 +08:00
|
|
|
},
|
|
|
|
},
|
2023-08-31 21:29:06 +08:00
|
|
|
combo: (model) => {
|
|
|
|
return {
|
|
|
|
id: model.id,
|
|
|
|
data: {
|
|
|
|
type: 'rect-combo',
|
|
|
|
...model.data,
|
|
|
|
keyShape: {
|
|
|
|
padding: [10, 20, 30, 40],
|
|
|
|
r: 50,
|
|
|
|
},
|
|
|
|
labelShape: {
|
|
|
|
text: model.id,
|
|
|
|
},
|
2023-02-02 10:31:36 +08:00
|
|
|
|
2023-08-31 21:29:06 +08:00
|
|
|
animates: {
|
|
|
|
buildIn: [
|
|
|
|
{
|
|
|
|
fields: ['opacity'],
|
|
|
|
duration: 500,
|
|
|
|
delay: 500 + Math.random() * 500,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
buildOut: [
|
|
|
|
{
|
|
|
|
fields: ['opacity'],
|
|
|
|
duration: 200,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
update: [
|
|
|
|
{
|
|
|
|
fields: ['lineWidth', 'r'],
|
|
|
|
shapeId: 'keyShape',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fields: ['opacity'],
|
|
|
|
shapeId: 'haloShape',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
data: {
|
|
|
|
nodes: [
|
|
|
|
{ id: 'node1', data: { x: 250, y: 150, parentId: 'combo1' } },
|
|
|
|
{ id: 'node2', data: { x: 350, y: 150, parentId: 'combo1' } },
|
|
|
|
{ id: 'node3', data: { x: 250, y: 300, parentId: 'combo2' } },
|
|
|
|
],
|
|
|
|
edges: [],
|
|
|
|
combos: [
|
|
|
|
{ id: 'combo1', data: { parentId: 'combo2' } },
|
|
|
|
{ id: 'combo2', data: {} },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
modes: {
|
|
|
|
default: [
|
|
|
|
'collapse-expand-combo',
|
|
|
|
{
|
|
|
|
type: 'drag-node',
|
|
|
|
enableTransient: false,
|
|
|
|
updateComboStructure: false,
|
|
|
|
},
|
|
|
|
'drag-canvas',
|
|
|
|
{
|
|
|
|
type: 'click-select',
|
|
|
|
itemTypes: ['node', 'edge', 'combo'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'hover-activate',
|
|
|
|
itemTypes: ['node', 'edge', 'combo'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'drag-combo',
|
|
|
|
enableTransient: true,
|
|
|
|
updateComboStructure: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2023-02-02 10:31:36 +08:00
|
|
|
});
|
|
|
|
|
2023-08-31 21:29:06 +08:00
|
|
|
if (typeof window !== 'undefined')
|
|
|
|
window.onresize = () => {
|
|
|
|
if (!graph || graph.destroyed) return;
|
|
|
|
if (!container || !container.scrollWidth || !container.scrollHeight) return;
|
|
|
|
graph.setSize([container.scrollWidth, container.scrollHeight]);
|
|
|
|
};
|