2020-04-24 15:28:03 +08:00
|
|
|
import React, { useEffect } from 'react';
|
|
|
|
import G6 from '../../../src';
|
|
|
|
import { IGraph } from '../../../src/interface/graph';
|
2020-06-09 10:21:12 +08:00
|
|
|
import { GraphData } from '../../../src/types';
|
2020-04-24 15:28:03 +08:00
|
|
|
|
|
|
|
let graph: IGraph = null;
|
|
|
|
|
|
|
|
const colors = {
|
|
|
|
a: '#BDD2FD',
|
|
|
|
b: '#BDEFDB',
|
|
|
|
c: '#C2C8D5',
|
|
|
|
d: '#FBE5A2',
|
|
|
|
e: '#F6C3B7',
|
|
|
|
f: '#B6E3F5',
|
|
|
|
g: '#D3C6EA',
|
|
|
|
h: '#FFD8B8',
|
|
|
|
i: '#AAD8D8',
|
|
|
|
j: '#FFD6E7',
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-06-09 10:21:12 +08:00
|
|
|
const testData: GraphData = {
|
2020-04-24 15:28:03 +08:00
|
|
|
nodes: [
|
2020-04-27 09:40:43 +08:00
|
|
|
// {
|
|
|
|
// id: '0',
|
|
|
|
// label: '0',
|
|
|
|
// comboId: 'a',
|
|
|
|
// x: 100,
|
|
|
|
// y: 100
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// id: '1',
|
|
|
|
// label: '1',
|
|
|
|
// comboId: 'a',
|
|
|
|
// x: 150,
|
|
|
|
// y: 140
|
|
|
|
// },
|
2020-04-24 15:28:03 +08:00
|
|
|
{
|
|
|
|
id: '2',
|
|
|
|
label: '2',
|
|
|
|
comboId: 'b',
|
|
|
|
x: 300,
|
|
|
|
y: 200
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: '3',
|
|
|
|
label: '3',
|
|
|
|
comboId: 'b',
|
|
|
|
x: 370,
|
|
|
|
y: 260
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: '4',
|
|
|
|
label: '4',
|
|
|
|
comboId: 'c',
|
|
|
|
x: 360,
|
|
|
|
y: 510
|
|
|
|
},
|
2020-04-27 09:40:43 +08:00
|
|
|
{
|
|
|
|
id: '5',
|
|
|
|
label: '5',
|
|
|
|
comboId: 'd',
|
|
|
|
x: 120,
|
|
|
|
y: 510
|
|
|
|
},
|
2020-04-24 15:28:03 +08:00
|
|
|
],
|
|
|
|
edges: [
|
|
|
|
// {
|
|
|
|
// source: 'a',
|
|
|
|
// target: 'b',
|
|
|
|
// size: 3,
|
|
|
|
// style: {
|
|
|
|
// stroke: 'red'
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// source: 'b',
|
|
|
|
// target: '1',
|
|
|
|
// size: 3,
|
|
|
|
// style: {
|
|
|
|
// stroke: 'blue'
|
|
|
|
// }
|
|
|
|
// },
|
2020-04-27 09:40:43 +08:00
|
|
|
// {
|
|
|
|
// source: '0',
|
|
|
|
// target: '1',
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// source: '0',
|
|
|
|
// target: '2',
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// source: '0',
|
|
|
|
// target: '3',
|
|
|
|
// },
|
2020-04-24 15:28:03 +08:00
|
|
|
// {
|
|
|
|
// source: '3',
|
|
|
|
// target: '5',
|
|
|
|
// },
|
2020-04-27 09:40:43 +08:00
|
|
|
// {
|
|
|
|
// source: '4',
|
|
|
|
// target: '1',
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// source: '0',
|
|
|
|
// target: '5',
|
|
|
|
// },
|
2020-04-24 15:28:03 +08:00
|
|
|
{
|
2020-04-28 19:09:07 +08:00
|
|
|
source: '5',
|
|
|
|
target: '4',
|
2020-04-27 09:40:43 +08:00
|
|
|
},
|
|
|
|
{
|
2020-04-28 19:09:07 +08:00
|
|
|
source: '3',
|
|
|
|
target: '5',
|
2020-04-27 09:40:43 +08:00
|
|
|
},
|
2020-04-24 15:28:03 +08:00
|
|
|
],
|
2020-04-27 09:40:43 +08:00
|
|
|
combos: [
|
2020-06-09 10:21:12 +08:00
|
|
|
// {
|
|
|
|
// id: 'a',
|
|
|
|
// label: 'combo a'
|
|
|
|
// },
|
|
|
|
{
|
|
|
|
id: 'b',
|
|
|
|
label: 'combo b'
|
|
|
|
}, {
|
|
|
|
id: 'c',
|
|
|
|
label: 'combo c',
|
|
|
|
parentId: 'b'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'd',
|
|
|
|
label: 'combo d',
|
|
|
|
// parentId: 'c'
|
|
|
|
}
|
2020-04-24 15:28:03 +08:00
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
const CollapseExpandVEdge = () => {
|
|
|
|
const container = React.useRef();
|
|
|
|
useEffect(() => {
|
|
|
|
if (!graph) {
|
|
|
|
graph = new G6.Graph({
|
|
|
|
container: container.current as string | HTMLElement,
|
|
|
|
width: 1000,
|
|
|
|
height: 800,
|
|
|
|
fitView: true,
|
|
|
|
modes: {
|
2020-06-09 10:21:12 +08:00
|
|
|
default: ['drag-combo', 'drag-node', 'zoom-canvas', 'collapse-expand-combo'],
|
2020-04-24 15:28:03 +08:00
|
|
|
},
|
|
|
|
defaultEdge: {
|
|
|
|
size: 1,
|
|
|
|
color: '#666',
|
2020-04-28 19:09:07 +08:00
|
|
|
style: {
|
|
|
|
endArrow: true
|
|
|
|
}
|
2020-04-24 15:28:03 +08:00
|
|
|
},
|
|
|
|
defaultCombo: {
|
|
|
|
type: 'circle',
|
|
|
|
//padding: 1
|
|
|
|
},
|
|
|
|
groupByTypes: false,
|
|
|
|
//animate: true
|
|
|
|
});
|
2020-06-09 10:21:12 +08:00
|
|
|
|
2020-04-24 15:28:03 +08:00
|
|
|
graph.node(node => {
|
|
|
|
const color = colors[node.comboId as string];
|
|
|
|
return {
|
|
|
|
size: 20,
|
|
|
|
style: {
|
|
|
|
lineWidth: 2,
|
|
|
|
stroke: '#ccc',
|
|
|
|
fill: color,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
});
|
|
|
|
graph.combo(combo => {
|
|
|
|
const color = colors[combo.id as string];
|
|
|
|
return {
|
|
|
|
// size: 80,
|
|
|
|
style: {
|
|
|
|
lineWidth: 2,
|
|
|
|
stroke: color,
|
|
|
|
fillOpacity: 0.8
|
|
|
|
},
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-04-28 19:09:07 +08:00
|
|
|
graph.get('canvas').set('localRefresh', false);
|
2020-04-24 15:28:03 +08:00
|
|
|
graph.data(testData);//testData_pos
|
|
|
|
graph.render();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return <div ref={container}></div>;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default CollapseExpandVEdge;
|