Skip to content

Commit 1f258c5

Browse files
committed
add the animationDelay option
1 parent ca9b736 commit 1f258c5

File tree

4 files changed

+45
-24
lines changed

4 files changed

+45
-24
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ angular.module('someModule', ['angular-svg-round-progress'])
4444
| `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 |
4545
| `rounded` | Whether the current progress ending should be rounded or straight. | No | false | Boolean |
4646
| `duration` | The duration of the animation. Pass 0 for no animation. | No | 800 | Integer |
47+
| `animation-delay` | Milliseconds to wait before starting an animation. | No | 0 | Integer |
4748
| `offset` | The margin between the edge of the circle and the SVG element. Mostly used when nesting progressbars. If you pass in "inherit", the offset will be calculated based on the size of the parent progressbar(s) | No | 0 | 'inherit' or Integer |
4849
| `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> |
4950

@@ -64,7 +65,8 @@ angular.module('someModule', ['angular-svg-round-progress'])
6465
clockwise="false"
6566
responsive="false"
6667
duration="800"
67-
animation="easeInOutQuart"></div>
68+
animation="easeInOutQuart"
69+
animation-delay="0"></div>
6870
```
6971

7072
## Browser support

build/index.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ <h2>Sample progressbar</h2>
128128
responsive="responsive"
129129
duration="{{ duration }}"
130130
animation="{{ currentAnimation }}"
131-
offset="{{ offset }}">
131+
offset="{{ offset }}"
132+
animation-delay="{{ animationDelay }}">
132133

133134
<svg>
134135
<linearGradient id="gradient" x1="0" x2="0" y1="0" y2="1">
@@ -208,6 +209,11 @@ <h3>Customize!</h3>
208209
<select id="animation" ng-model="currentAnimation" ng-options="animation for animation in animations"></select>
209210
</div>
210211

212+
<div class="cf">
213+
<label for="delay">Animation delay:</label>
214+
<input id="delay" type="number" ng-model="animationDelay"/>
215+
</div>
216+
211217
<div class="cf">
212218
<label for="color">Color:</label>
213219
<input id="color" type="color" ng-model="currentColor"/>
@@ -295,6 +301,7 @@ <h2>Clock example</h2>
295301
$scope.bgColor = '#eaeaea';
296302
$scope.duration = 800;
297303
$scope.currentAnimation = 'easeOutCubic';
304+
$scope.animationDelay = 0;
298305

299306
$scope.increment = function(amount){
300307
$scope.current+=(amount || 1);

src/roundProgress.js

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ angular.module('angular-svg-round-progress')
2020
stroke: "@",
2121
duration: "@",
2222
animation: "@",
23-
offset: "@"
23+
offset: "@",
24+
animationDelay: "@"
2425
}
2526
};
2627

@@ -39,6 +40,7 @@ angular.module('angular-svg-round-progress')
3940
var background = svg.find('circle').eq(0);
4041
var options = angular.copy(roundProgressConfig);
4142
var lastAnimationId;
43+
var lastTimeoutId;
4244
var parentChangedListener;
4345

4446
scope.getOptions = function(){
@@ -110,36 +112,45 @@ angular.module('angular-svg-round-progress')
110112
var changeInValue = end - start;
111113

112114
var easingAnimation = service.animations[options.animation];
113-
var startTime = new $window.Date();
114115
var duration = +options.duration || 0;
115116
var preventAnimation = preventAnimationOverride || (newValue > max && oldValue > max) || (newValue < 0 && oldValue < 0) || duration < 25;
116117

117118
var radius = options.radius;
118119
var circleSize = radius - (options.stroke/2) - service.getOffset(element, options);
119120
var elementSize = radius*2;
120121
var isSemicircle = options.semi;
122+
var doAnimation = function(){
123+
// stops some expensive animating if the value is above the max or under 0
124+
if(preventAnimation){
125+
service.updateState(end, max, circleSize, ring, elementSize, isSemicircle);
126+
}else{
127+
$window.cancelAnimationFrame(lastAnimationId);
128+
129+
var startTime = new $window.Date();
130+
131+
(function animation(){
132+
var currentTime = $window.Math.min(new Date() - startTime, duration);
133+
134+
service.updateState(
135+
easingAnimation(currentTime, start, changeInValue, duration),
136+
max,
137+
circleSize,
138+
ring,
139+
elementSize,
140+
isSemicircle);
141+
142+
if(currentTime < duration){
143+
lastAnimationId = $window.requestAnimationFrame(animation);
144+
}
145+
})();
146+
}
147+
};
121148

122-
// stops some expensive animating if the value is above the max or under 0
123-
if(preventAnimation){
124-
service.updateState(end, max, circleSize, ring, elementSize, isSemicircle);
149+
if(options.animationDelay > 0){
150+
$window.clearTimeout(lastTimeoutId);
151+
$window.setTimeout(doAnimation, options.animationDelay);
125152
}else{
126-
$window.cancelAnimationFrame(lastAnimationId);
127-
128-
(function animation(){
129-
var currentTime = $window.Math.min(new Date() - startTime, duration);
130-
131-
service.updateState(
132-
easingAnimation(currentTime, start, changeInValue, duration),
133-
max,
134-
circleSize,
135-
ring,
136-
elementSize,
137-
isSemicircle);
138-
139-
if(currentTime < duration){
140-
lastAnimationId = $window.requestAnimationFrame(animation);
141-
}
142-
})();
153+
doAnimation();
143154
}
144155
};
145156

src/roundProgressConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ angular.module('angular-svg-round-progress').constant('roundProgressConfig', {
1212
stroke: 15,
1313
duration: 800,
1414
animation: "easeOutCubic",
15+
animationDelay: 0,
1516
offset: 0
1617
});

0 commit comments

Comments
 (0)