/
index.js
62 lines (54 loc) · 1.55 KB
/
index.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
import { RSGraph } from '../../../src/layout/index.js';
const data = require('./config/nodes.json');
// sort data.
data.sort((a, b) => (a.title > b.title ? 1 : -1));
// random data.
// data.sort(() => (Math.random() * 10 > 5 ? -1 : 1))
// set node width & height
const width = 50;
const height = 50;
const nodes = data.map(node => {
node.width = width;
node.height = height;
return node;
});
// create node div dom element.
nodes.forEach(node => {
const { title, desc } = node;
const body = document.querySelector('body');
const div = document.createElement('div');
div.setAttribute('data-rsgraph-id', node.id);
div.setAttribute('class', 'item');
div.innerHTML = `<div class="desc">${desc}</div><div class="title">${title}</div>`;
body.appendChild(div);
});
// RSGraph config.
const config = {
data: nodes,
// 可选
zoom: true, // 默认为 false
direction: 'y-axis', // x-axis || y-axis 默认为 y-axis 即纵向拓扑
coreOptions: {
style: {
borderTop: '1px dashed #000',
overflow: 'scroll',
},
line: {
style: {
stroke: 'deepskyblue',
},
arrow: {
style: {
fill: '#888',
},
viewBox: '0 0 18 18',
},
},
linkDot: {
display: 'none',
},
mode: 'link-mode', // set link-mode will not work.
},
};
// create rsgraph instance, just use one statement.
const graph = new RSGraph('#container', config);