Skip to content

Commit ecbc8ad

Browse files
author
crisbeto
committed
bump the version, update the docs and demo, concatenate and minify the files
1 parent 4ae422f commit ecbc8ad

File tree

6 files changed

+45
-36
lines changed

6 files changed

+45
-36
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ angular.module('someModule', ['angular-svg-round-progress'])
3838
| `clockwise` | Whether the progressbar should rotate clockwise or counter-clockwise. | No | true | Boolean |
3939
| `responsive` | Whether the progressbar should fit inside its parent container. **Note** Turning this option on will override the specified radius in order to make the circle fit in its parent. The radius to stroke ratio won't change. | No | false | Boolean |
4040
| `rounded` | Whether the current progress ending should be rounded or straight. | No | false | Boolean |
41-
| `iterations` | Number of iterations for the animation. Set it to 1 for no animation and increase for slower animation. | No | 50 | Integer |
41+
| `duration` | The duration of the animation. Pass 0 for no animation. | No | 800 | Integer |
4242
| `animation` | The easing function that will be used when animating. | No | easeOutCubic | linearEase <br> easeInQuad <br> easeOutQuad <br> easeInOutQuad <br> easeInCubic <br> easeOutCubic <br> easeInOutCubic <br> easeInQuart <br> easeOutQuart <br> easeInOutQuart <br> easeInQuint <br> easeOutQuint <br> easeInOutQuint <br> easeInSine <br> easeOutSine <br> easeInOutSine <br> easeInExpo <br> easeOutExpo <br> easeInOutExpo <br> easeInCirc <br> easeOutCirc <br> easeInOutCirc <br> easeInElastic <br> easeOutElastic <br> easeInOutElastic <br> easeInBack <br> easeOutBack <br> easeInOutBack <br> easeInBounce <br> easeOutBounce <br> easeInOutBounce <br> |
4343

4444

@@ -57,7 +57,7 @@ angular.module('someModule', ['angular-svg-round-progress'])
5757
rounded="true"
5858
clockwise="false"
5959
responsive="false"
60-
iterations="50"
60+
duration="800"
6161
animation="easeInOutQuart"></div>
6262
```
6363

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-svg-round-progressbar",
3-
"version": "0.2.11",
3+
"version": "0.3.0",
44
"homepage": "https://github.com/crisbeto/angular-svg-round-progressbar",
55
"authors": [
66
"crisbeto"

build/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ <h2>Sample progressbar</h2>
106106
stroke="{{ stroke }}"
107107
clockwise="clockwise"
108108
responsive="responsive"
109-
iterations="{{ iterations }}"
109+
duration="{{ duration }}"
110110
animation="{{ currentAnimation }}">
111111

112112
<svg>
@@ -173,8 +173,8 @@ <h3>Customize!</h3>
173173
</div>
174174

175175
<div class="cf">
176-
<label for="iterations">Iterations:</label>
177-
<input id="iterations" type="number" ng-model="iterations"/>
176+
<label for="duration">Duration:</label>
177+
<input id="duration" type="number" ng-model="duration"/>
178178
</div>
179179

180180
<div class="cf">
@@ -234,7 +234,7 @@ <h2>Clock example</h2>
234234
$scope.clockwise = true;
235235
$scope.currentColor = '#45ccce';
236236
$scope.bgColor = '#eaeaea';
237-
$scope.iterations = 50;
237+
$scope.duration = 800;
238238
$scope.currentAnimation = 'easeOutCubic';
239239

240240
$scope.increment = function(amount){

build/roundProgress.js

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ angular.module('angular-svg-round-progress').constant('roundProgressConfig', {
4444
color: "#45ccce",
4545
bgcolor: "#eaeaea",
4646
stroke: 15,
47-
iterations: 50,
47+
duration: 800,
4848
animation: "easeOutCubic"
4949
});
5050

@@ -98,10 +98,10 @@ angular.module('angular-svg-round-progress').service('roundProgressService', [fu
9898

9999
service.animations = {
100100

101-
// t: Current iteration
102-
// b: Start value
103-
// c: Change in value
104-
// d: Total iterations
101+
// t: is the current time (or position) of the tween. This can be seconds or frames, steps, seconds, ms, whatever – as long as the unit is the same as is used for the total time.
102+
// b: is the beginning value of the property.
103+
// c: is the change between the beginning and destination value of the property.
104+
// d: is the total time of the tween.
105105
// jshint eqeqeq: false, -W041: true
106106

107107
linearEase: function(t, b, c, d) {
@@ -300,14 +300,15 @@ angular.module('angular-svg-round-progress')
300300
color: "@",
301301
bgcolor: "@",
302302
stroke: "@",
303-
iterations: "@",
303+
duration: "@",
304304
animation: "@"
305305
},
306306
link: function(scope, element){
307307
var svg = angular.element(element[0].querySelector('svg'));
308308
var ring = svg.find('path');
309309
var background = svg.find('circle');
310310
var options = angular.copy(roundProgressConfig);
311+
var lastAnimationId;
311312

312313
var renderCircle = function(){
313314
var isSemicircle = options.semi;
@@ -358,35 +359,43 @@ angular.module('angular-svg-round-progress')
358359

359360
var renderState = function(newValue, oldValue){
360361
var max = service.toNumber(options.max || 0);
361-
var current = newValue > max ? max : (newValue < 0 || !newValue ? 0 : newValue);
362-
var start = (oldValue === current || oldValue < 0) ? 0 : (oldValue || 0); // fixes the initial animation
363-
var changeInValue = current - start;
362+
var end = newValue > max ? max : (newValue < 0 || !newValue ? 0 : newValue);
363+
var start = (oldValue === end || oldValue < 0) ? 0 : (oldValue || 0); // fixes the initial animation
364+
var changeInValue = end - start;
364365

365366
var easingAnimation = service.animations[options.animation];
366-
var currentIteration = 0;
367-
var totalIterations = parseInt(options.iterations);
367+
var startTime = new Date();
368+
var duration = parseInt(options.duration);
368369

369370
var radius = options.radius;
370371
var circleSize = radius - (options.stroke/2);
371372
var elementSize = radius*2;
372373

373-
(function animation(){
374-
service.updateState(
375-
easingAnimation(currentIteration, start, changeInValue, totalIterations),
376-
max,
377-
circleSize,
378-
ring,
379-
elementSize,
380-
options.semi);
381-
382-
if(currentIteration < totalIterations){
383-
$window.requestAnimationFrame(animation);
384-
currentIteration++;
385-
}
386-
})();
374+
$window.cancelAnimationFrame(lastAnimationId);
375+
376+
// below 25ms stuff starts to break
377+
if(duration > 25){
378+
(function animation(){
379+
var currentTime = new Date() - startTime;
380+
381+
service.updateState(
382+
easingAnimation(currentTime, start, changeInValue, duration),
383+
max,
384+
circleSize,
385+
ring,
386+
elementSize,
387+
options.semi);
388+
389+
if(currentTime < duration){
390+
lastAnimationId = $window.requestAnimationFrame(animation);
391+
}
392+
})();
393+
}else{
394+
service.updateState(end, max, circleSize, ring, elementSize, options.semi);
395+
}
387396
};
388397

389-
scope.$watchCollection('[current, max, semi, rounded, clockwise, radius, color, bgcolor, stroke, iterations, responsive]', function(newValue, oldValue, scope){
398+
scope.$watchCollection('[current, max, semi, rounded, clockwise, radius, color, bgcolor, stroke, duration, responsive]', function(newValue, oldValue, scope){
390399

391400
// pretty much the same as angular.extend,
392401
// but this skips undefined values and internal angular keys

0 commit comments

Comments
 (0)