-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradialprogress_svg_vincent.html
154 lines (114 loc) · 5.86 KB
/
radialprogress_svg_vincent.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
<html>
<head>
<style>
body {
background:#bbb89d;
}
</style>
</head>
<body>
<div id="anchor">
</div>
</div>
<script>
var percentage = 75;
/*var radialProgressParameters = {
strokeWidth : 10,
containerHeight : 100,
fontSize: 10,
progressColor: "#0bc30b",
emptyColor: "#69e558"
red
progressColor: "rgb(240 41 41)",
emptyColor: "rgb(245 208 208)"
}*/
var radialProgressParameters = {
strokeWidth : 5,
containerHeight : 70,
fontSize: 15,
textLeftAdjustment: 0,
textTopAdjustment: 0,
progressColor: "rgb(245 184 1)",
emptyColor: "rgb(240 221 165)",
anchorDivId: "anchor",
suffixForIds: "12345"
}
var radialProgressComponent = function(percentageValue){
/*setTimeout(function(circleContainer){anchorDiv.appendChild(circleContainer);}, 1000);*/
/*setTimeout(buildRadialProgressComponent, 2000, percentageValue, parameters);*/
}
var updateProgressOnRadial = function( percentageValue, parameters){
circleRadius = ( parameters.containerHeight / 2 ) - parameters.strokeWidth;
var circleDiv = document.getElementById(parameters.suffixForIds+'_background-circle');
var progressDiv = document.getElementById(parameters.suffixForIds+'_progress-circle');
var percentageValueDiv = document.getElementById(parameters.suffixForIds+'_percentage-value');
var percentageCircleContainer = document.getElementById(parameters.suffixForIds+'_percentage-circle-container');
percentageValueDiv.innerHTML = percentageValue + " %";
progressDiv.style.stroke = parameters.progressColor;
circleDiv.style.stroke = parameters.emptyColor;
if (isNaN(percentageValue)) {
percentageValue = 100;
}
else{
circleDiv.setAttribute('r',circleRadius);
progressDiv.setAttribute('r',circleRadius);
var circonference = Math.PI*circleRadius*2;
if (percentageValue < 0) { percentageValue = 0;}
if (percentageValue > 100) { percentageValue = 100;}
var emptyPathLength = ((100-percentageValue)/100)*circonference;
progressDiv.setAttribute("stroke-dashoffset", emptyPathLength);
window.setTimeout(function() {
progressDiv.style.strokeDashoffset = emptyPathLength;
}, 50)
progressDiv.setAttribute("stroke-dasharray", circonference);
circleDiv.setAttribute("stroke-dasharray", circonference);
}
}
var createProgressElements = function(parameters){
var circleRadius = ( parameters.containerHeight / 2 ) - parameters.strokeWidth;
var anchorDiv = document.getElementById(parameters.anchorDivId);
var w3uri = 'http://www.w3.org/2000/svg';
const circleContainer = document.createElement("div");
circleContainer.setAttribute("id",parameters.suffixForIds+"_percentage-circle-container");
const svgProgressBar = document.createElementNS(w3uri,'svg');
svgProgressBar.setAttributeNS(w3uri,"id",parameters.suffixForIds+"_svg-progress-bar");
svgProgressBar.setAttributeNS(w3uri,"z-index",-1);
const backgroundCircle = document.createElementNS(w3uri,'circle');
backgroundCircle.setAttribute("id",parameters.suffixForIds+"_background-circle");
backgroundCircle.setAttribute("stroke-dashoffset","0");
const progressCircle = document.createElementNS(w3uri,'circle');
progressCircle.setAttribute("id",parameters.suffixForIds+"_progress-circle");
progressCircle.setAttribute("fill","transparent");
progressCircle.setAttribute("stroke-dashoffset","0");
backgroundCircle.setAttribute("cx", parameters.containerHeight/2);
backgroundCircle.setAttribute("cy", parameters.containerHeight/2);
backgroundCircle.setAttribute("stroke-width", parameters.strokeWidth);
backgroundCircle.setAttribute("fill","white");
progressCircle.setAttribute("cx", parameters.containerHeight/2);
progressCircle.setAttribute("cy", parameters.containerHeight/2);
progressCircle.setAttribute("stroke-width", parameters.strokeWidth);
const percentageValue = document.createElement("div");
percentageValue.setAttribute("id",parameters.suffixForIds+"_percentage-value");
percentageValue.innerHTML = "0 %";
var textMarginTop = (-1)*(parameters.containerHeight - parameters.strokeWidth - circleRadius + parameters.fontSize/1.9 + parameters.textTopAdjustment);
var textMarginLeft = (parameters.strokeWidth + circleRadius)/1.5 + parameters.textLeftAdjustment;
/* var roundedMarginTop = Math.round(textMarginTop/100)*100;
var roundedMarginLeft = Math.round(textMarginLeft/100)*100*/
percentageValue.style.marginTop = textMarginTop.toString()+"px";
percentageValue.style.marginLeft = textMarginLeft.toString()+"px";
percentageValue.style.fontSize = parameters.fontSize.toString()+"px";
percentageValue.style.position = "relative";
svgProgressBar.setAttribute("height",parameters.containerHeight);
svgProgressBar.setAttribute("width", parameters.containerHeight);
svgProgressBar.style.transform = "rotate(-90deg)"
svgProgressBar.appendChild(backgroundCircle);
svgProgressBar.appendChild(progressCircle);
circleContainer.appendChild(svgProgressBar);
circleContainer.appendChild(percentageValue);
anchorDiv.appendChild(circleContainer);
}
createProgressElements(radialProgressParameters);
updateProgressOnRadial(percentage, radialProgressParameters);
</script>
</body>
</html>