@@ -278,17 +278,7 @@ angular.module('angular-svg-round-progress')
278278 var base = {
279279 restrict : "EA" ,
280280 replace : true ,
281- transclude : true
282- } ;
283-
284- if ( ! service . isSupported ) {
285- return angular . extend ( base , {
286- // placeholder element to keep the structure
287- template : '<div class="round-progress" ng-transclude></div>'
288- } ) ;
289- }
290-
291- return angular . extend ( base , {
281+ transclude : true ,
292282 scope :{
293283 current : "=" ,
294284 max : "=" ,
@@ -302,11 +292,21 @@ angular.module('angular-svg-round-progress')
302292 stroke : "@" ,
303293 duration : "@" ,
304294 animation : "@"
305- } ,
295+ }
296+ } ;
297+
298+ if ( ! service . isSupported ) {
299+ return angular . extend ( base , {
300+ // placeholder element to keep the structure
301+ template : '<div class="round-progress" ng-transclude></div>'
302+ } ) ;
303+ }
304+
305+ return angular . extend ( base , {
306306 link : function ( scope , element ) {
307- var svg = angular . element ( element [ 0 ] . querySelector ( 'svg' ) ) ;
308- var ring = svg . find ( 'path' ) ;
309- var background = svg . find ( 'circle' ) ;
307+ var svg = element . find ( 'svg' ) . eq ( 0 ) ;
308+ var ring = svg . find ( 'path' ) . eq ( 0 ) ;
309+ var background = svg . find ( 'circle' ) . eq ( 0 ) ;
310310 var options = angular . copy ( roundProgressConfig ) ;
311311 var lastAnimationId ;
312312
@@ -366,15 +366,19 @@ angular.module('angular-svg-round-progress')
366366 var easingAnimation = service . animations [ options . animation ] ;
367367 var startTime = new Date ( ) ;
368368 var duration = parseInt ( options . duration ) ;
369+ var preventAnimation = ( newValue > max && oldValue > max ) || ( newValue < 0 && oldValue < 0 ) || duration < 25 ;
369370
370371 var radius = options . radius ;
371372 var circleSize = radius - ( options . stroke / 2 ) ;
372373 var elementSize = radius * 2 ;
374+ var isSemicircle = options . semi ;
373375
374- $window . cancelAnimationFrame ( lastAnimationId ) ;
376+ // stops some expensive animating if the value is above the max or under 0
377+ if ( preventAnimation ) {
378+ service . updateState ( end , max , circleSize , ring , elementSize , isSemicircle ) ;
379+ } else {
380+ $window . cancelAnimationFrame ( lastAnimationId ) ;
375381
376- // below 25ms stuff starts to break
377- if ( duration > 25 ) {
378382 ( function animation ( ) {
379383 var currentTime = new Date ( ) - startTime ;
380384
@@ -384,19 +388,16 @@ angular.module('angular-svg-round-progress')
384388 circleSize ,
385389 ring ,
386390 elementSize ,
387- options . semi ) ;
391+ isSemicircle ) ;
388392
389393 if ( currentTime < duration ) {
390394 lastAnimationId = $window . requestAnimationFrame ( animation ) ;
391395 }
392396 } ) ( ) ;
393- } else {
394- service . updateState ( end , max , circleSize , ring , elementSize , options . semi ) ;
395397 }
396398 } ;
397399
398- scope . $watchCollection ( '[current, max, semi, rounded, clockwise, radius, color, bgcolor, stroke, duration, responsive]' , function ( newValue , oldValue , scope ) {
399-
400+ scope . $watchCollection ( '[' + Object . keys ( base . scope ) . join ( ',' ) + ']' , function ( newValue , oldValue , scope ) {
400401 // pretty much the same as angular.extend,
401402 // but this skips undefined values and internal angular keys
402403 angular . forEach ( scope , function ( value , key ) {
0 commit comments