Skip to content

Commit 4959516

Browse files
committed
Merge pull request #7 from ingameio/master
Added param 'iterations' to directive
2 parents 08873c9 + 0358398 commit 4959516

File tree

3 files changed

+48
-40
lines changed

3 files changed

+48
-40
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ angular.module('someModule', ['angular-svg-round-progress'])
3030
* `bgcolor` hex background color, example: `#eaeaea`
3131
* `stroke` specifies the thickness of the line
3232
* `semi` boolean, specifies whether the progressbar should be a semicircle or a full circle
33+
* `iterations` number of iterations for the animation. Set it to 1 for *no animation* and increase for slower animation. *(Optional, 50 by default)*
3334
* To manually trigger a complete re-render of the progressbar, broadcast a "renderCircle" from a parent scope:
3435

3536
```javascript
@@ -39,13 +40,13 @@ $rootScope.$broadcast('renderCircle');
3940
### Example:
4041

4142
```html
42-
<div
43-
round-progress
44-
max="max"
45-
current="current"
46-
color="#45ccce"
47-
bgcolor="#eaeaea"
48-
radius="100"
43+
<div
44+
round-progress
45+
max="max"
46+
current="current"
47+
color="#45ccce"
48+
bgcolor="#eaeaea"
49+
radius="100"
4950
stroke="20"
5051
semi="true">
5152
</div>

demo.html

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858
form{
5959
text-align: left;
60-
width: 250px;
60+
width: 270px;
6161
margin:20px auto;
6262
}
6363

@@ -84,15 +84,16 @@
8484
<h2>Sample progressbar</h2>
8585
<div class="progress-wrapper" ng-style="{'font-size': ((radius + stroke)/(isSemi ? 3.5 : 3))+'px'}">
8686
<div class="progress">{{ current }}/{{ max }}</div>
87-
<div
88-
round-progress
89-
max="max"
90-
current="current"
91-
color="{{ currentColor }}"
92-
bgcolor="{{ bgColor }}"
93-
radius="{{ radius }}"
87+
<div
88+
round-progress
89+
max="max"
90+
current="current"
91+
color="{{ currentColor }}"
92+
bgcolor="{{ bgColor }}"
93+
radius="{{ radius }}"
9494
semi="isSemi"
95-
stroke="{{ stroke }}">
95+
stroke="{{ stroke }}"
96+
iterations="{{ iterations }}">
9697
</div>
9798
</div>
9899

@@ -122,37 +123,42 @@ <h3>Customize!</h3>
122123

123124
<div class="cf">
124125
<label>Stroke:</label>
125-
<input type="number" ng-model="stroke"/>
126+
<input type="number" ng-model="stroke"/>
126127
</div>
127128

128129
<div class="cf">
129130
<label>Radius:</label>
130131
<input type="number" ng-model="radius"/>
131-
</div>
132+
</div>
132133

133134
<div class="cf">
134135
<label>Color:</label>
135-
<input type="color" ng-model="currentColor"/>
136+
<input type="color" ng-model="currentColor"/>
136137
</div>
137138

138139
<div class="cf">
139140
<label>Background color:</label>
140141
<input type="color" ng-model="bgColor"/>
141-
</div>
142+
</div>
143+
144+
<div class="cf">
145+
<label>Iterations:</label>
146+
<input type="number" ng-model="iterations"/>
147+
</div>
142148
</form>
143149
</div>
144150

145151
<div class="container" ng-controller="demoCtrl">
146152
<h2>Upload progress example</h2>
147153
<div class="progress-wrapper">
148154
<div class="progress">{{ ((uploadCurrent/100)*100) | number:0 }}%</div>
149-
<div
150-
round-progress
151-
max="100"
152-
current="uploadCurrent"
153-
color="#45ccce"
154-
bgcolor="#eaeaea"
155-
radius="100"
155+
<div
156+
round-progress
157+
max="100"
158+
current="uploadCurrent"
159+
color="#45ccce"
160+
bgcolor="#eaeaea"
161+
radius="100"
156162
semi="isSemi"
157163
stroke="15">
158164
</div>
@@ -188,7 +194,7 @@ <h2>Upload progress example</h2>
188194
$scope.current+=(amount || 1);
189195
};
190196

191-
$scope.$watchCollection('[max, stroke, radius, isSemi, currentColor, bgColor]', function(newValue, oldValue){
197+
$scope.$watchCollection('[max, stroke, radius, isSemi, currentColor, bgColor, iterations]', function(newValue, oldValue){
192198
$rootScope.$broadcast('renderCircle');
193199
});
194200

roundProgress.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ angular.module('angular-svg-round-progress', [])
3333
return id;
3434
};
3535
}
36-
36+
3737
if (!window.cancelAnimationFrame){
3838
window.cancelAnimationFrame = function(id) {
3939
clearTimeout(id);
4040
};
4141
}
42-
42+
4343
}());
4444

4545

@@ -51,7 +51,7 @@ angular.module('angular-svg-round-progress', [])
5151
y: centerY + (radius * Math.sin(angleInRadians))
5252
};
5353
}
54-
54+
5555
var updateState = function(value, total, R, ring, size, isSemicircle) {
5656
if(!size){
5757
return;
@@ -67,7 +67,7 @@ angular.module('angular-svg-round-progress', [])
6767
// arcSweep = endAngle - startAngle <= 180 ? "0" : "1",
6868
arcSweep = (perc <= 180 ? "0" : "1"),
6969
d = [
70-
"M", start.x, start.y,
70+
"M", start.x, start.y,
7171
"A", R, R, 0, arcSweep, 0, end.x, end.y
7272
].join(" ");
7373

@@ -77,8 +77,8 @@ angular.module('angular-svg-round-progress', [])
7777
var easeOutCubic = function(currentIteration, startValue, changeInValue, totalIterations) {
7878
// credits to http://www.kirupa.com/forum/showthread.php?378287-Robert-Penner-s-Easing-Equations-in-Pure-JS-(no-jQuery)
7979
return changeInValue * (Math.pow(currentIteration / totalIterations - 1, 3) + 1) + startValue;
80-
};
81-
80+
};
81+
8282
return {
8383
restrict:'EA',
8484
scope:{
@@ -88,7 +88,8 @@ angular.module('angular-svg-round-progress', [])
8888
radius: "@",
8989
color: "@",
9090
bgcolor: "@",
91-
stroke: "@"
91+
stroke: "@",
92+
iterations: "@"
9293
},
9394
link: function (scope, element, attrs) {
9495
var ring = element.find('path'),
@@ -151,7 +152,7 @@ angular.module('angular-svg-round-progress', [])
151152
start = oldValue === newValue ? 0 : (oldValue || 0), // fixes the initial animation
152153
val = newValue - start,
153154
currentIteration = 0,
154-
totalIterations = 50;
155+
totalIterations = scope.iterations || 50;
155156

156157
if(angular.isNumber(resetValue)){
157158
// the reset value fixes problems with animation, caused when limiting the scope.current
@@ -163,9 +164,9 @@ angular.module('angular-svg-round-progress', [])
163164
(function animation(){
164165
if(currentIteration <= totalIterations){
165166
updateState(
166-
easeOutCubic(currentIteration, start, val, totalIterations),
167-
max,
168-
radius,
167+
easeOutCubic(currentIteration, start, val, totalIterations),
168+
max,
169+
radius,
169170
ring,
170171
size,
171172
isSemicircle
@@ -174,7 +175,7 @@ angular.module('angular-svg-round-progress', [])
174175
requestAnimationFrame(animation);
175176
currentIteration++;
176177
};
177-
})();
178+
})();
178179
};
179180

180181
scope.$on('renderCircle', renderCircle);

0 commit comments

Comments
 (0)