-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathringui.js
More file actions
58 lines (49 loc) · 2.35 KB
/
ringui.js
File metadata and controls
58 lines (49 loc) · 2.35 KB
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
function RingUI()
{
this.changePercent = function(ringdiv, _percent)
{
let circumf = parseFloat( ringdiv.attr('ring-circumf') );
let myCircle = ringdiv.find(".ring_ui-circle");
myCircle.attr("stroke-dasharray", ""+circumf+" "+circumf);
myCircle.attr("stroke-dashoffset", ""+(circumf - _percent * 0.01 * circumf));
ringdiv.attr('percent', _percent);
}
this.changeContent = function(ringdiv, _content)
{
ringdiv.find('.ring_ui-content').html(_content);
}
this.init = function()
{
$('.ring_ui').each(function()
{
let item = $(this);
let content = item.html();
let cSize = parseInt(item.attr('ring-size')) || 160;
let cThickness = parseInt( item.attr('ring-thickness') ) || 5;
let cFontsize = parseInt( item.attr('ring-fontsize') ) || 40;
let cFrontcolor = item.attr('ring-frontcolor') || "black";
let cBackcolor = item.attr('ring-backcolor') || "#777";
let cFontcolor = item.attr('ring-fontcolor') || "black";
let circumf = ((cSize*0.5)-(cThickness * 2)) * 2 * Math.PI;
item.attr('ring-circumf', circumf);
item.css({width: cSize, height: cSize});
item.html( getRingHTML(cSize, cThickness, cBackcolor, cFrontcolor, cFontsize, cFontcolor, content) );
ringUI.changePercent(item, parseInt( item.attr('ring-percent') ));
});
}
let getRingHTML = function(in_size, in_strokeWidth, in_backLineColor, in_frontLineColor, in_fontSize, in_fontColor, in_content)
{
return "<svg height='"+in_size+"' width='"+in_size+"' >"+
"<circle fill='transparent' stroke='"+in_backLineColor+"' stroke-width='"+in_strokeWidth+"' "+
" r='"+((in_size*0.5)-(in_strokeWidth * 2))+"' cx='"+(in_size*0.5)+"' cy='"+(in_size*0.5)+"' /> "+
"<circle class='ring_ui-circle' fill='transparent' stroke='"+in_frontLineColor+"' stroke-width='"+in_strokeWidth+"' "+
" r='"+((in_size*0.5)-(in_strokeWidth * 2))+"' cx='"+(in_size*0.5)+"' cy='"+(in_size*0.5)+"' /> "+
"</svg> " +
"<div class='ring_ui-content' style='font-size: "+in_fontSize+"px; color: "+in_fontColor+"'>"+in_content+"</span></div>";
}
}
$( document ).ready(function()
{
window.ringUI = new RingUI();
window.ringUI.init();
});