-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
49 lines (38 loc) · 1.43 KB
/
test.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
function makesvg(percentage, inner_text=""){
var abs_percentage = Math.abs(percentage).toString();
var percentage_str = percentage.toString();
var classes = ""
if(percentage < 0){
classes = "danger-stroke circle-chart__circle--negative";
}
else if(percentage > 0 && percentage <= 30){
classes = "danger-stroke";
}
else if(percentage > 30 && percentage <= 60){
classes = "warning-stroke";
}
else{
classes = "success-stroke";
}
var svg = '<svg class="circle-chart" viewbox="0 0 33.83098862 33.83098862" xmlns="http://www.w3.org/2000/svg">'
+ '<circle class="circle-chart__background" cx="16.9" cy="16.9" r="15.9" />'
+ '<circle class="circle-chart__circle '+classes+'"'
+ 'stroke-dasharray="'+ abs_percentage+',100" cx="16.9" cy="16.9" r="15.9" />'
+ '<g class="circle-chart__info">'
+ ' <text class="circle-chart__percent" x="17.9" y="15.5">'+inner_text+'</text>';
if(inner_text){
svg += '<text class="circle-chart__subline" x="16.91549431" y="22">'+percentage_str+'%</text>'
}
svg += ' </g></svg>';
return svg
}
(function( $ ) {
$.fn.circlechart = function() {
this.each(function() {
var percentage = $(this).data("percentage");
var inner_text = $(this).text();
$(this).html(makesvg(percentage, inner_text));
});
return this;
};
}( jQuery ));