-
Notifications
You must be signed in to change notification settings - Fork 2
/
Custom_Progress_Chart.html
304 lines (230 loc) · 7.54 KB
/
Custom_Progress_Chart.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>D3</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.css" rel="stylesheet">
<link href='https://fonts.googleapis.com/css?family=Roboto:400,700,500' rel='stylesheet' type='text/css'>
<link href="css/style-light.css" rel="stylesheet" type="text/css"/>
<script src="js/d3.js"></script>
<script src="js/utils.js"></script>
<style>
</style>
</head>
<body>
<div class="widget">
<div class="header">Progress Status</div>
<div id="chart" class="chart-container">
</div>
</div>
<script type="text/javascript">
// Util Function
var createShadow=function(svg){
var defs = svg.append("svg:defs");
var inset_shadow = defs.append("svg:filter")
.attr("id", "inset-shadow");
inset_shadow.append("svg:feOffset")
.attr({
dx:0,
dy:0
});
inset_shadow.append("svg:feGaussianBlur")
.attr({
stdDeviation:3,
result:'offset-blur'
});
inset_shadow.append("svg:feComposite")
.attr({
operator:'out',
in:'SourceGraphic',
in2:'offset-blur',
result:'inverse'
});
inset_shadow.append("svg:feFlood")
.attr({
'flood-color':'black',
'flood-opacity':.1,
result:'color'
});
inset_shadow.append("svg:feComposite")
.attr({
operator:'in',
in:'color',
in2:'inverse',
result:'shadow'
});
inset_shadow.append("svg:feComposite")
.attr({
operator:'over',
in:'shadow',
in2:'SourceGraphic'
});
};
var createGradient=function(svg,id,color1,color2){
var defs = svg.append("svg:defs");
var red_gradient = defs.append("svg:linearGradient")
.attr("id", id)
.attr("x1", "0%")
.attr("y1", "0%")
.attr("x2", "50%")
.attr("y2", "100%")
.attr("spreadMethod", "pad");
red_gradient.append("svg:stop")
.attr("offset", "50%")
.attr("stop-color", color1)
.attr("stop-opacity", 1);
red_gradient.append("svg:stop")
.attr("offset", "100%")
.attr("stop-color", color2)
.attr("stop-opacity", 1);
};
var percent = 60;
var pie=d3.layout.pie()
.value(function(d){return d})
.sort(null);
var w=300,h=300;
var outerRadius=(w/2)-10;
var innerRadius=110;
var arcBackground=d3.svg.arc()
.innerRadius(innerRadius)
.outerRadius(outerRadius)
.startAngle(0)
.endAngle(2*Math.PI);
//The circle is following this Dummy Arc
var arcDummy=d3.svg.arc()
.innerRadius(125)
.outerRadius(125)
.startAngle(0);
var arcProgress=d3.svg.arc()
.innerRadius(innerRadius)
.outerRadius(outerRadius)
.cornerRadius(20)
.startAngle(-0.1);
var svg=d3.select("#chart")
.append("svg")
.attr({
width:w,
height:h,
class:'shadow'
}).append('g')
.attr({
transform:'translate('+w/2+','+h/2+')'
});
createShadow(svg);
createGradient(svg,"gradient","#40a6f8","#1a70e7");
//background
var pathBackground=svg.append('path')
.attr({
d:arcBackground
})
.style({
fill:'#f4f3f8',
stroke:'#e2e7eb',
'stroke-width':1
});
var pathForeground=svg.append('path')
.datum({endAngle:0})
.attr({
d:arcProgress
})
.style({
fill:'url(#gradient)',
filter:'url(#inset-shadow)',
stroke:'#3285fb',
'stroke-width':1
});
//line Arc for Circle
var pathDummy=svg.append('path')
.datum({endAngle:0})
.attr({
d:arcDummy
}).style({
fill:'#A92602'
});
var endCircle=svg.append('circle')
.attr({
r:6,
transform:'translate(0,'+ (-outerRadius+16) +')'
})
.style({
stroke:'#0751b7',
'stroke-width':1.5,
'stroke-opacity':.5,
opacity:0,
fill:'#fff',
filter:'url(#inset-shadow)'
});
var startCircle=svg.append('circle')
.attr({
r:6,
transform:'translate(0,'+ (-outerRadius+16) +')'
})
.style({
stroke:'#0751b7',
'stroke-width':1.5,
'stroke-opacity':.2,
fill:'#fff',
filter:'url(#inset-shadow)'
});
var middleTextCount=svg.append('text')
.datum(0)
.text(function(d){
return d+'%';
})
.attr({
class:'middleText',
'text-anchor':'middle',
dy:25,
dx:0
})
.style({
fill:'url(#gradient)',
'font-size':'80px'
});
var arcTween=function(transition,percent,oldValue) {
transition.attrTween("d", function (d) {
var newAngle=(percent/100)*(2*Math.PI);
var interpolateForeground = d3.interpolate(d.endAngle, newAngle);
var interpolateText = d3.interpolate(oldValue, percent);
return function (t) {
d.endAngle = interpolateForeground(t);
middleTextCount.text(Math.floor(interpolateText(t))+'%');
return arcProgress(d);
};
});
};
var arcTweenDummy=function(transition,percent) {
transition.attrTween("d", function (d) {
var newAngle=(percent/100)*(2*Math.PI);
var interpolateCircle = d3.interpolate(d.endAngle, newAngle -.13);
return function (t) {
d.endAngle= interpolateCircle(t);
var pathDummyCircle = arcDummy(d);
var coordinate = pathDummyCircle.split("L")[1].split("A")[0];
if(d.endAngle>.25 && d.endAngle < (2*Math.PI-.14))
endCircle.style('opacity',1);
else
endCircle.style('opacity',0);
endCircle.attr('transform', 'translate(' + coordinate+ ')');
return pathDummyCircle;
};
});
};
var oldValue=0;
var animate=function(){
pathForeground.transition()
.duration(750)
.ease('cubic')
.call(arcTween,percent,oldValue);
pathDummy.transition()
.duration(750)
.ease('cubic')
.call(arcTweenDummy,percent);
oldValue=percent;
percent=(Math.random() * 60) + 20;
setTimeout(animate,3000);
};
setTimeout(animate,0);
</script>
</body>
</html>