-
Notifications
You must be signed in to change notification settings - Fork 0
/
bower-conflict.html
254 lines (232 loc) · 8.76 KB
/
bower-conflict.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>bower-conflict</title>
</head>
<style>
.node circle {
fill: #fff;
stroke: steelblue;
stroke-width: 1.5px;
}
.node {
font: 12px sans-serif;
}
.link {
fill: none;
stroke: #ccc;
stroke-width: 1.5px;
}
</style>
<body>
<script src="./node_modules/regularjs/dist/regular.js"></script>
<script src="./node_modules/echarts/build/echarts.js"></script>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script id="template" type="application/tpl">
{#if needAll.allConflict.length}
<h2> 注意,一共有{needAll.allConflict.length}个组件有版本冲突,分别是:{needAll.allConflict | arr2Text}</h2>
{#list needAll.allConflict as item}
<input type="button" value="{item}" on-click={this.doClick(item)} />
{/list}
<input type="button" value="all" on-click={this.doClick('#')} />
{#else}
<h2>好开心!,没有冲突</h2>
{/if}
{#if needAll.allCircularDependency.length}
<h2>注意,一共有{needAll.allCircularDependency.length}个组件循环依赖,分别是:{needAll.allCircularDependency | arr2Text}</h2>
{/if}
</script>
<div id="conclusion"></div>
<script type="text/javascript">
// 路径配置
require.config({
paths: {
echarts: './node_modules/echarts/build',
data: '.'
}
});
var width = 2200,
height = 2000;
var tree = d3.layout.tree()
.size([width, height-200])
.separation(function(a, b) { return (a.parent == b.parent ? 1 : 2); });
var diagonal = d3.svg.diagonal()
.projection(function(d) { return [d.y, d.x]; });
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(40,0)");
require(['data/treeJson'],function(root){
var UI = Regular.extend({
template: '#template'
}).filter({
arr2Text: function(arr){
return arr.join('、');
}
});
new UI({
data: {
needAll: root
},
doClick: function(name){
var text = svg.selectAll(".node text");
text.style("fill", function(d){
if(d.conflict && d.conflict.length && d.name.indexOf(name) != -1){
return 'red'
}else {
return 'black'
}
})
}
}).$inject('#conclusion');
var nodes = tree.nodes(root);
var links = tree.links(nodes);
// console.log(nodes);
// console.log(links);
var link = svg.selectAll(".link")
.data(links)
.enter()
.append("path")
.attr("class", "link")
.attr("d", diagonal);
var node = svg.selectAll(".node")
.data(nodes)
.enter()
.append("g")
.attr("class", "node")
.attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; })
node.append("circle")
.attr("r", 4.5);
node.append("text")
.attr("dx", function(d) {
if(!d.parent){
return 150;
}
return d.children ? -8 : 8;
})
.attr("dy", 3)
.style("text-anchor", function(d) { return d.children ? "end" : "start"; })
.text(function(d) {
if(d.conflict && d.conflict.length){
return d.name + '冲突版本:' + d.conflict.join('、')
}
return d.name;
})
.style("fill", function(d){
if(d.conflict && d.conflict.length){
return 'red'
}
})
})
</script>
<script type="text/javascript">
// 使用
require([
'echarts',
'echarts/chart/chord',
'echarts/chart/force',
'data/needAll'
],
function (ec,chord,force,needAll) {
for (var componentName in needAll) {
var option = {
title: {
text: componentName + '冲突',
x: 'top',
y: 'right'
},
tooltip: {
trigger: 'item',
formatter: function (params) {
if (params.indicator2) { // is edge
return params.indicator2 + ' ' + params.name + ' ' + params.indicator;
} else { // is node
return params.name
}
}
},
toolbox: {
show: true,
feature: {
restore: {show: true},
magicType: {show: true, type: ['force', 'chord']},
saveAsImage: {show: true}
}
},
legend: (function () {
var legend = {
x: 'left',
y: '30',
data: []
};
for (var versionName in needAll[componentName]) {
legend.data.push(versionName);
}
return legend;
})(),
series: [
{
name: '',
type: 'chord',
sort: 'ascending',
sortSub: 'descending',
ribbonType: false,
radius: '60%',
itemStyle: {
normal: {
label: {
rotate: true
}
}
},
minRadius: 7,
maxRadius: 20,
// 使用 nodes links 表达和弦图
nodes: (function () {
var nameArr = [];
for (var versionName in needAll[componentName]) {
nameArr.push({
name: versionName,
symbol: 'star',
value: 1000
});
var arr = needAll[componentName][versionName].split(',');
for (var name in arr) {
nameArr.push({
name: arr[name]
});
}
}
return nameArr;
})(),
links: (function () {
var linkArr = [];
for (var versionName in needAll[componentName]) {
var arr = needAll[componentName][versionName].split(',');
for (var name in arr) {
var link = {
source: versionName,
target: arr[name],
weight: 1,
name: '依赖'
};
linkArr.push(link);
}
}
return linkArr;
})()
}
]
};
var ele = document.createElement('div');
ele.setAttribute('id',componentName);
ele.setAttribute('style',"height:400px;margin:200px 0px");
document.body.appendChild(ele);
var myChart = ec.init(document.getElementById(componentName));
myChart.setOption(option);
}
}
);
</script>
</body>