-
Notifications
You must be signed in to change notification settings - Fork 4
/
dependencies.html
137 lines (126 loc) · 3.33 KB
/
dependencies.html
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Webpack Code Dependencies Analysis</title>
<style>
#main {
width: 100%;
height: 600px;
}
</style>
</head>
<body>
<div id="main"></div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/echarts.min.js"></script>
<script>
const array = <%=data%>;
function getChildNode(resource) {
const childDep = array.find(l => l.resource === resource);
return childDep ? JSON.parse(JSON.stringify(childDep)).children : [];
}
function setChildFlag(datum, index) {
const childDep = array.find(l => l.resource === datum.resource);
childDep && childDep.children.length > 0 && (datum.itemStyle = { color: 'rgba(227, 112, 18, 1)' });
}
/**
* 通过节点的层级数组找到对应的树节点
* @param tree 树结构
* @param array 节点的层级数组
*/
function findNode(tree, array){
let node = [tree];
let theNode;
array.forEach((v, i) => {
if(v.name){
const item = node.find(k => k.name === v.name);
if(i !== array.length - 1){
node = item.children;
} else {
theNode = item;
}
}
})
return theNode;
}
var myChart = echarts.init(document.getElementById('main'));
window.onresize = function () {
myChart.resize();
};
const data = JSON.parse(JSON.stringify(array[0]));
data.children.forEach(setChildFlag);
myChart.setOption(
(option = {
tooltip: {
trigger: 'item',
triggerOn: 'mousemove'
},
series: [
{
type: 'tree',
data: [data],
top: '1%',
left: '7%',
bottom: '1%',
right: '20%',
symbolSize: 7,
symbol: 'circle',
label: {
position: 'left',
verticalAlign: 'middle',
align: 'right',
fontSize: 9
},
leaves: {
label: {
position: 'right',
verticalAlign: 'middle',
align: 'left'
}
},
tooltip: {
formatter: (params) => {
return params.data.resource;
}
},
emphasis: {
focus: 'descendant'
},
expandAndCollapse: true,
animationDuration: 550,
animationDurationUpdate: 750
}
]
})
);
myChart.on('click', function (params) {
console.log(params);
if (params.componentType === 'series') {
// 有itemStyle属性表示有子节点
if (params.data.itemStyle) {
const { treeAncestors } = params;
const node = findNode(data, treeAncestors)
if(params.data.children){
node.collapsed = !params.data.collapsed;
} else {
const children = getChildNode(params.data.resource);
children.forEach(setChildFlag);
node.children = children;
node.collapsed = false;
}
myChart.setOption({
series: [
{
data: [data]
}
]
});
}
}
});
</script>
</body>
</html>