-
Notifications
You must be signed in to change notification settings - Fork 0
/
old-g6.js
96 lines (89 loc) · 2.1 KB
/
old-g6.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import data from './json/demo-format.json';
import { getAttr, getMaxDepth } from './tool';
export default function () {
const lineAttr = getAttr(data);
const maxDepth = getMaxDepth(data);
const width = document.getElementById('container').scrollWidth;
const height = document.getElementById('container').scrollHeight || 500;
const graph = new G6.TreeGraph({
container: 'container',
width,
height,
pixelRatio: 2,
renderer: 'svg',
modes: {
default: ['collapse-expand', 'drag-canvas', 'zoom-canvas'],
},
defaultNode: {
size: 26,
anchorPoints: [
[0, 0.5],
[1, 0.5],
],
style: {
fill: '#C6E5FF',
stroke: '#5B8FF9',
},
},
defaultEdge: {
shape: 'cubic-horizontal',
style: {
stroke: '#A3B1BF',
},
},
layout: {
type: 'compactBox',
direction: 'LR',
getId: function getId(d) {
return d.id;
},
getHeight: function getHeight() {
return 16;
},
getVGap: function getVGap(node) {
return 300 / node.level;
},
getHGap: function getHGap() {
return 100;
},
getWidth: function getWidth(...args) {
return 16;
},
},
});
graph.edge((edge) => {
const targetId = edge.target._cfg.id;
return {
id: edge.id,
type: 'cubic-horizontal',
style: {
stroke: lineAttr[targetId].lineColor,
lineWidth: maxDepth + 25 - lineAttr[targetId].level * 2.5,
},
};
});
graph.node((node) => {
return {
label: node.label,
labelCfg: {
offset: 10,
position: node.children && node.children.length > 0 ? 'left' : 'right',
},
style: {
fill: node.nodeColor,
stroke: node.nodeColor,
r: node.nodeSize || 10,
},
};
});
graph.data(data);
graph.render();
graph.fitView();
function download() {
graph.downloadImage();
}
document.querySelector('.type-select').style.display = 'none';
document
.querySelector('.download-button')
.addEventListener('click', download);
}