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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
var sunburstGraph = {};
sunburstGraph.refreshGraph = function (skillsdata, divId, settings) {
//先删除div下面的所有child
$('#' + divId).children().remove();
skillsdata.count = 0;
var suburstContent = '<div class="skills-sunburst">'
//+'<div id="explanation" style="visibility: hidden;">'
//+'<span id="percentage"></span><br/>'
//+'<span id="source"></span>'
//+'</div>'
+ '</div>'
+ '<div id="skills-chart-breadcrumb"></div>';
//$('#' + divId).append('<div id="skills-chart-breadcrumb"></div>');
$('#' + divId).append(suburstContent);
//$(suburstContent).appendTo($('#' + divId));
//计算总的日志数量
function count(sourceOjb) {
for (var childname in sourceOjb) {
var child = sourceOjb[childname];
if (child && child[0] >= 0) { //判断是否内容为数字
for (var num in child) {
skillsdata.count = skillsdata.count + child[num];
}
} else {
count(child);
}
}
}
var statisticCount = count(skillsdata);
function getOneBurstName(burst) {
var key = JSON.parse(burst.key);
return key.name;
}
function getDataCount(data) {
var dataCount = 0;
for (var index in data._proficiency) {
dataCount = dataCount + data._proficiency[index];
}
;
return dataCount;
}
function mouseover(data) {
//这里修改vm中的数据对象--selectLogStaInfo ,刷新右边的barGraph.
if (settings.mouseOverCallback) {
settings.mouseOverCallback(data._proficiency);
}
var c = getcrumbpath(data);
var dataCount = getDataCount(data);
var percentage = (100 * dataCount / skillsdata.count).toPrecision(3);
var percentageString = percentage + "%";
if (percentage < 0.1) {
percentageString = "< 0.1%";
}
refreshBreadCrum(c, percentageString);
d3.select("#percentage")
.text(percentageString);
d3.select("#source")
.text(getOneBurstName(data));
d3.select("#explanation")
.style("visibility", "");
d3
.selectAll(".skills-sunburst path")
.style("opacity", .3), sunburst
.selectAll("path")
.filter(function (a) {
return c.indexOf(a) >= 0
})
.style("opacity", 1)
}
function mouseleave() {
d3
.selectAll("path")
.on("mouseover", null);
d3
.selectAll("path")
.transition()
.duration(1e3)
.style("opacity", 1)
.each("end", function () {
d3.select(this).on("mouseover", mouseover)
})
}
function getcrumbpath(a) {
for (var temp = [], c = a; c.parent;) temp.unshift(c), c = c.parent;
return temp
}
function initbreadcrumb() {
d3
.select("#skills-chart-breadcrumb")
.append("svg:svg")
.attr("width", 800)
.attr("height", 30)
.attr("class", "trail")
.append("svg:text")
.attr("id", "endlabel")
.style("fill", "#000");
}
function h(a, d3) {
var c = [];
c.push("0,0");
c.push(r.w + ",0");
c.push(r.w + r.t + "," + r.h / 2);
c.push(r.w + "," + r.h);
c.push("0," + r.h);
d3 > 0 && c.push(r.t + "," + r.h / 2);
return c.join(" ");
}
function refreshBreadCrum(a, percentageString) {
a[a.length - 1]._color, a.length;
var c = d3
.select("#skills-chart-breadcrumb .trail")
.selectAll("g")
.remove();
c = d3
.select("#skills-chart-breadcrumb .trail")
.selectAll("g")
.data(a, function (a) {
return a.key + a.depth
});
var d = c.enter().append("svg:g");
d
.append("svg:polygon")
.attr("points", h)
.style("fill", function (a) {
return a._color
}),
d
.append("svg:text")
.attr("x", r.w / 2 + 2)
.attr("y", r.h / 2)
.attr("dy", "0.50em")
.attr("text-anchor", "middle")
.attr("class", "breadcumb-text")
.style("fill", function (a) {
return getcolor(d3.rgb(a._color)) < 150 ? "#fff" : "#000"
})
.text(function (a) {
return getOneBurstName(a);
}),
c
.attr("transform", function (a, b) {
return "translate(" + b * (r.w + r.s) + ", 0)"
}),
b = {
w: 120, h: 30, s: 10, t: 10
};
//
d3
.select("#skills-chart-breadcrumb .trail")
.select("#endlabel")
.attr("x", (a.length + 0.5) * (b.w + b.s))
.attr("y", b.h / 2)
.attr("dy", "0.35em")
.attr("text-anchor", "middle")
.text(percentageString);
c.exit().remove();
// Now move and update the percentage at the end.
d3.select(".trail").style("visibility", "");
}
function getcolor(color) {
return .299 * color.r + .587 * color.g + .114 * color.b
}
function k(a) {
var color = ["#3399CC", "#FFC65D", "#CDB99C", "#8B4789", "#FF7F50"],
d = [-.1, -.05, 0];
if (1 == a.depth) {
var e = color[coloralternative % 5];
return coloralternative++, e
}
if (a.depth > 1) {
var f = d[a.value % 3];
return d3.rgb(a.parent._color).brighter(.15 * a.depth + f * a.depth)
}
}
var l;
width = settings.width,
height = settings.height,
rad = Math.min(width, height) / Math.PI - 25,
q = k,
r = { //定义每一条面包屑的长、宽、高等
w: 140, //宽度
h: 30, //面包屑的尖角相关。
s: 3,
t: 7
},
sunburst = d3
.select(".skills-sunburst")
.append("svg:svg")
.attr("width", width)
.attr("height", height)
.append("svg:g")
.attr("transform", "translate(" + (width / 2) + "," + height / 2 + ")");
sunburst.append("svg:circle").attr("r", rad).style("opacity", 0);
var mergeAry = function (sourceAry1, sourceAry2) {
var rtnAry = [],
aryLength = sourceAry1.length;
if (sourceAry1.length !== sourceAry2.length) {
rtnAry = sourceAry1.length > sourceAry2.length ? sourceAry1 : sourceAry2;
} else for (var e = 0; aryLength > e; e++) {
//var f = Math.max(sourceAry1[e], sourceAry2[e]) - Math.abs(sourceAry1[e] - sourceAry2[e]) / 8;
rtnAry.push(sourceAry1[e] + sourceAry2[e]);
}
return rtnAry;
},
recursionFindAry = function (a) {
if (a instanceof Array) return a;
var b = [];
return $.each(a, function (a, c) {
b = mergeAry(recursionFindAry(c), b)
}), b
},
countAry = function (data) {
var countAry = 0;
for (var i = 0; i < data.length; i++) {
countAry = countAry + data[i];
}
return countAry;
},
proficiencydata = d3
.layout
.partition()
.sort(null)
.size([2 * Math.PI, rad])
.children(function (a) {
return a.value instanceof Array
? (a._proficiency = a.value, d3.entries([countAry(a.value)]))
: (a._proficiency = recursionFindAry(a.value), isNaN(a.value) ? d3.entries(a.value) : null)
})
.value(function (a) {
return a.value
}),
arc = d3.svg
.arc()
.startAngle(function (a) {//startAngle和endAngle是计算的每个环的每个角的角度,跟大小没有关系。
return a.x
})
.endAngle(function (a) {
return a.x + a.dx - .01 / (a.depth + .4)
})
.innerRadius(function (a) { //里层环线的位置,原来是没有增加20的,这里减少了层次,svg画布和旭日图之间空得太多,因此增加环的大小
return rad / Math.PI * a.depth + 20
})
.outerRadius(function (a) { //外层环线的位置
return rad / Math.PI * (a.depth + 1) + 22
});
var coloralternative = 0
initbreadcrumb();
var path = sunburst
.data(d3.entries(skillsdata))
.selectAll("g")
.data(proficiencydata)
.enter()
.append("svg:g")
.attr("display", function (a) {
return a.depth ? null : "none"
});
path
.append("svg:path")
.attr("d", arc)
.attr("stroke", "#fff")
.attr("fill", function (a) {
return a._color = q(a), a._color
})
.attr("fill-rule", "evenodd").attr("display", function (a) {
return a.children ? null : "none"
})
.on("mouseover", mouseover);
d3
.select(".skills-sunburst")
.on("mouseleave", mouseleave);
//l = path.node().__data__.value;
sunburst
.append("circle")
.attr("r", rad / Math.PI)
.attr("opacity", 0);
sunburst.append("text").transition().duration(1000)
.attr("dx", function (d) {
return 0;
})
.attr("dy", function (d) {
return -10;
})
.attr("id", "percentage")
.text(function (d) {
return '';
});
sunburst.append("text").transition().duration(1000)
.attr("dx", function (d) {
return 0;
})
.attr("dy", function (d) {
return 20;
})
.attr("id", "source")
.text(function (d) {
return '';
});
}
|