-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
90 lines (75 loc) · 2.19 KB
/
script.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
function sliceSize(dataNum, dataTotal) {
return (dataNum / dataTotal) * 360;
}
function addSlice(id, sliceSize, pieElement, offset, sliceID, color) {
$(pieElement).append("<div class='slice "+ sliceID + "'><span></span></div>");
var offset = offset - 1;
var sizeRotation = -179 + sliceSize;
$(id + " ." + sliceID).css({
"transform": "rotate(" + offset + "deg) translate3d(0,0,0)"
});
$(id + " ." + sliceID + " span").css({
"transform" : "rotate(" + sizeRotation + "deg) translate3d(0,0,0)",
"background-color": color
});
}
function iterateSlices(id, sliceSize, pieElement, offset, dataCount, sliceCount, color) {
var
maxSize = 179,
sliceID = "s" + dataCount + "-" + sliceCount;
if( sliceSize <= maxSize ) {
addSlice(id, sliceSize, pieElement, offset, sliceID, color);
} else {
addSlice(id, maxSize, pieElement, offset, sliceID, color);
iterateSlices(id, sliceSize-maxSize, pieElement, offset+maxSize, dataCount, sliceCount+1, color);
}
}
function createPie(id) {
var
listData = [],
listTotal = 0,
offset = 0,
i = 0,
pieElement = id + " .pie-chart__pie"
dataElement = id + " .pie-chart__legend"
color = [
"cornflowerblue",
"olivedrab",
"orange",
"tomato",
"crimson",
"purple",
"turquoise",
"forestgreen",
"navy"
];
color = shuffle( color );
$(dataElement+" span").each(function() {
listData.push(Number($(this).html()));
});
for(i = 0; i < listData.length; i++) {
listTotal += listData[i];
}
for(i=0; i < listData.length; i++) {
var size = sliceSize(listData[i], listTotal);
iterateSlices(id, size, pieElement, offset, i, 0, color[i]);
$(dataElement + " li:nth-child(" + (i + 1) + ")").css("border-color", color[i]);
offset += size;
}
}
function shuffle(a) {
var j, x, i;
for (i = a.length; i; i--) {
j = Math.floor(Math.random() * i);
x = a[i - 1];
a[i - 1] = a[j];
a[j] = x;
}
return a;
}
function createPieCharts() {
createPie('.pieID--micro-skills' );
createPie('.pieID--categories' );
createPie('.pieID--operations' );
}
createPieCharts();