mirror of
https://gitee.com/antv/g6.git
synced 2024-12-01 11:18:30 +08:00
483 lines
6.2 KiB
TypeScript
483 lines
6.2 KiB
TypeScript
import React, { useEffect } from 'react';
|
|
import G6 from '../../../src';
|
|
import { IGraph } from '../../../src/interface/graph';
|
|
|
|
const data = {
|
|
nodes: [
|
|
{
|
|
id: '0',
|
|
label: '0',
|
|
},
|
|
{
|
|
id: '1',
|
|
label: '1',
|
|
},
|
|
{
|
|
id: '2',
|
|
label: '2',
|
|
},
|
|
{
|
|
id: '3',
|
|
label: '3',
|
|
},
|
|
{
|
|
id: '4',
|
|
label: '4',
|
|
},
|
|
{
|
|
id: '5',
|
|
label: '5',
|
|
},
|
|
{
|
|
id: '6',
|
|
label: '6',
|
|
},
|
|
{
|
|
id: '7',
|
|
label: '7',
|
|
},
|
|
{
|
|
id: '8',
|
|
label: '8',
|
|
},
|
|
{
|
|
id: '9',
|
|
label: '9',
|
|
},
|
|
{
|
|
id: '10',
|
|
label: '10',
|
|
},
|
|
{
|
|
id: '11',
|
|
label: '11',
|
|
},
|
|
{
|
|
id: '12',
|
|
label: '12',
|
|
},
|
|
{
|
|
id: '13',
|
|
label: '13',
|
|
},
|
|
{
|
|
id: '14',
|
|
label: '14',
|
|
},
|
|
{
|
|
id: '15',
|
|
label: '15',
|
|
},
|
|
{
|
|
id: '16',
|
|
label: '16',
|
|
},
|
|
{
|
|
id: '17',
|
|
label: '17',
|
|
},
|
|
{
|
|
id: '18',
|
|
label: '18',
|
|
},
|
|
{
|
|
id: '19',
|
|
label: '19',
|
|
},
|
|
{
|
|
id: '20',
|
|
label: '20',
|
|
},
|
|
{
|
|
id: '21',
|
|
label: '21',
|
|
},
|
|
{
|
|
id: '22',
|
|
label: '22',
|
|
},
|
|
{
|
|
id: '23',
|
|
label: '23',
|
|
},
|
|
{
|
|
id: '24',
|
|
label: '24',
|
|
},
|
|
{
|
|
id: '25',
|
|
label: '25',
|
|
},
|
|
{
|
|
id: '26',
|
|
label: '26',
|
|
},
|
|
{
|
|
id: '27',
|
|
label: '27',
|
|
},
|
|
{
|
|
id: '28',
|
|
label: '28',
|
|
},
|
|
{
|
|
id: '29',
|
|
label: '29',
|
|
},
|
|
{
|
|
id: '30',
|
|
label: '30',
|
|
},
|
|
{
|
|
id: '31',
|
|
label: '31',
|
|
},
|
|
{
|
|
id: '32',
|
|
label: '32',
|
|
},
|
|
{
|
|
id: '33',
|
|
label: '33',
|
|
},
|
|
],
|
|
edges: [
|
|
{
|
|
source: '0',
|
|
target: '1',
|
|
},
|
|
{
|
|
source: '0',
|
|
target: '2',
|
|
},
|
|
{
|
|
source: '0',
|
|
target: '3',
|
|
},
|
|
{
|
|
source: '0',
|
|
target: '4',
|
|
},
|
|
{
|
|
source: '0',
|
|
target: '5',
|
|
},
|
|
{
|
|
source: '0',
|
|
target: '7',
|
|
},
|
|
{
|
|
source: '0',
|
|
target: '8',
|
|
},
|
|
{
|
|
source: '0',
|
|
target: '9',
|
|
},
|
|
{
|
|
source: '0',
|
|
target: '10',
|
|
},
|
|
{
|
|
source: '0',
|
|
target: '11',
|
|
},
|
|
{
|
|
source: '0',
|
|
target: '13',
|
|
},
|
|
{
|
|
source: '0',
|
|
target: '14',
|
|
},
|
|
{
|
|
source: '0',
|
|
target: '15',
|
|
},
|
|
{
|
|
source: '0',
|
|
target: '16',
|
|
},
|
|
{
|
|
source: '2',
|
|
target: '3',
|
|
},
|
|
{
|
|
source: '4',
|
|
target: '5',
|
|
},
|
|
{
|
|
source: '4',
|
|
target: '6',
|
|
},
|
|
{
|
|
source: '5',
|
|
target: '6',
|
|
},
|
|
{
|
|
source: '7',
|
|
target: '13',
|
|
},
|
|
{
|
|
source: '8',
|
|
target: '14',
|
|
},
|
|
{
|
|
source: '9',
|
|
target: '10',
|
|
},
|
|
{
|
|
source: '10',
|
|
target: '22',
|
|
},
|
|
{
|
|
source: '10',
|
|
target: '14',
|
|
},
|
|
{
|
|
source: '10',
|
|
target: '12',
|
|
},
|
|
{
|
|
source: '10',
|
|
target: '24',
|
|
},
|
|
{
|
|
source: '10',
|
|
target: '21',
|
|
},
|
|
{
|
|
source: '10',
|
|
target: '20',
|
|
},
|
|
{
|
|
source: '11',
|
|
target: '24',
|
|
},
|
|
{
|
|
source: '11',
|
|
target: '22',
|
|
},
|
|
{
|
|
source: '11',
|
|
target: '14',
|
|
},
|
|
{
|
|
source: '12',
|
|
target: '13',
|
|
},
|
|
{
|
|
source: '16',
|
|
target: '17',
|
|
},
|
|
{
|
|
source: '16',
|
|
target: '18',
|
|
},
|
|
{
|
|
source: '16',
|
|
target: '21',
|
|
},
|
|
{
|
|
source: '16',
|
|
target: '22',
|
|
},
|
|
{
|
|
source: '17',
|
|
target: '18',
|
|
},
|
|
{
|
|
source: '17',
|
|
target: '20',
|
|
},
|
|
{
|
|
source: '18',
|
|
target: '19',
|
|
},
|
|
{
|
|
source: '19',
|
|
target: '20',
|
|
},
|
|
{
|
|
source: '19',
|
|
target: '33',
|
|
},
|
|
{
|
|
source: '19',
|
|
target: '22',
|
|
},
|
|
{
|
|
source: '19',
|
|
target: '23',
|
|
},
|
|
{
|
|
source: '20',
|
|
target: '21',
|
|
},
|
|
{
|
|
source: '21',
|
|
target: '22',
|
|
},
|
|
{
|
|
source: '22',
|
|
target: '24',
|
|
},
|
|
{
|
|
source: '22',
|
|
target: '25',
|
|
},
|
|
{
|
|
source: '22',
|
|
target: '26',
|
|
},
|
|
{
|
|
source: '22',
|
|
target: '23',
|
|
},
|
|
{
|
|
source: '22',
|
|
target: '28',
|
|
},
|
|
{
|
|
source: '22',
|
|
target: '30',
|
|
},
|
|
{
|
|
source: '22',
|
|
target: '31',
|
|
},
|
|
{
|
|
source: '22',
|
|
target: '32',
|
|
},
|
|
{
|
|
source: '22',
|
|
target: '33',
|
|
},
|
|
{
|
|
source: '23',
|
|
target: '28',
|
|
},
|
|
{
|
|
source: '23',
|
|
target: '27',
|
|
},
|
|
{
|
|
source: '23',
|
|
target: '29',
|
|
},
|
|
{
|
|
source: '23',
|
|
target: '30',
|
|
},
|
|
{
|
|
source: '23',
|
|
target: '31',
|
|
},
|
|
{
|
|
source: '23',
|
|
target: '33',
|
|
},
|
|
{
|
|
source: '32',
|
|
target: '33',
|
|
},
|
|
],
|
|
};
|
|
|
|
const data2 = {
|
|
nodes: [
|
|
{
|
|
id: 'b0',
|
|
label: '0',
|
|
x: 30,
|
|
y: 30,
|
|
},
|
|
{
|
|
id: 'b1',
|
|
label: '1',
|
|
x: 30,
|
|
y: 40,
|
|
},
|
|
{
|
|
id: 'b2',
|
|
label: '2',
|
|
x: 40,
|
|
y: 30,
|
|
},
|
|
{
|
|
id: 'b3',
|
|
label: '3',
|
|
x: 50,
|
|
y: 25,
|
|
},
|
|
{
|
|
id: 'b4',
|
|
label: '4',
|
|
x: 60,
|
|
y: 40,
|
|
},
|
|
{
|
|
id: 'b5',
|
|
label: '5',
|
|
x: 20,
|
|
y: 50,
|
|
},
|
|
],
|
|
edges: [
|
|
{
|
|
id: 'be1',
|
|
source: 'b0',
|
|
target: 'b1',
|
|
},
|
|
{
|
|
id: 'be2',
|
|
source: 'b0',
|
|
target: 'b2',
|
|
},
|
|
{
|
|
id: 'be3',
|
|
source: 'b0',
|
|
target: 'b3',
|
|
},
|
|
{
|
|
id: 'be4',
|
|
source: 'b0',
|
|
target: 'b4',
|
|
},
|
|
{
|
|
id: 'be5',
|
|
source: 'b0',
|
|
target: 'b5',
|
|
},
|
|
],
|
|
};
|
|
|
|
let graph: IGraph = null;
|
|
|
|
const ChangeData = () => {
|
|
const container = React.useRef();
|
|
useEffect(() => {
|
|
if (!graph) {
|
|
const graph = new G6.Graph({
|
|
container: container.current as string | HTMLElement,
|
|
width: 500,
|
|
height: 500,
|
|
// layout: {
|
|
// type: 'force',
|
|
// },
|
|
animate: true,
|
|
});
|
|
graph.data(data);
|
|
graph.render();
|
|
|
|
graph.on('canvas:click', (e) => {
|
|
graph.changeData(data2);
|
|
});
|
|
}
|
|
});
|
|
return <div ref={container}></div>;
|
|
};
|
|
|
|
export default ChangeData;
|