3030
3131angular . module ( 'angular-svg-round-progress' , [ ] ) ;
3232
33+ 'use strict' ;
34+
35+ angular . module ( 'angular-svg-round-progress' ) . constant ( 'roundProgressConfig' , {
36+ max : 50 ,
37+ semi : false ,
38+ radius : 100 ,
39+ color : "#45ccce" ,
40+ bgcolor : "#eaeaea" ,
41+ stroke : 15 ,
42+ iterations : 50 ,
43+ animation : "easeOutCubic"
44+ } ) ;
45+
46+ 'use strict' ;
47+
3348angular . module ( 'angular-svg-round-progress' ) . service ( 'roundProgressService' , [ function ( ) {
3449 var service = { } ;
3550
@@ -243,7 +258,7 @@ angular.module('angular-svg-round-progress').service('roundProgressService', [fu
243258'use strict' ;
244259
245260angular . module ( 'angular-svg-round-progress' )
246- . directive ( 'roundProgress' , [ '$timeout ' , 'roundProgressService ' , function ( $timeout , service ) {
261+ . directive ( 'roundProgress' , [ 'roundProgressService ' , 'roundProgressConfig ' , function ( service , roundProgressConfig ) {
247262
248263 if ( ! service . isSupported ) {
249264 return {
@@ -268,41 +283,38 @@ angular.module('angular-svg-round-progress')
268283 animation : "@"
269284 } ,
270285 link : function ( scope , element , attrs ) {
271-
272286 var ring = element . find ( 'path' ) ,
273287 background = element . find ( 'circle' ) ,
288+ options = angular . copy ( roundProgressConfig ) ,
274289 size ,
275290 resetValue ;
276291
277292 var renderCircle = function ( ) {
278- $timeout ( function ( ) {
279- var isSemicircle = scope . semi ,
280- radius = parseInt ( scope . radius ) ,
281- stroke = parseInt ( scope . stroke ) ;
282-
283- size = radius * 2 + stroke * 2 ;
284-
285- element . attr ( {
286- "width" : size ,
287- "height" : isSemicircle ? size / 2 : size
288- } ) . css ( {
289- "overflow" : "hidden" // on some browsers the background overflows, if in semicircle mode
290- } ) ;
291-
292- ring . attr ( {
293- "stroke" : scope . color ,
294- "stroke-width" : stroke ,
295- "transform" : isSemicircle ? ( 'translate(' + 0 + ',' + size + ') rotate(-90)' ) : ''
296- } ) ;
297-
298- background . attr ( {
299- "cx" : radius ,
300- "cy" : radius ,
301- "transform" : "translate(" + stroke + ", " + stroke + ")" ,
302- "r" : radius ,
303- "stroke" : scope . bgcolor ,
304- "stroke-width" : stroke
305- } ) ;
293+ var isSemicircle = options . semi ,
294+ radius = parseInt ( options . radius ) ,
295+ stroke = parseInt ( options . stroke ) ;
296+
297+ size = radius * 2 + stroke * 2 ;
298+
299+ element . css ( {
300+ "width" : size ,
301+ "height" : isSemicircle ? size / 2 : size ,
302+ "overflow" : "hidden" // on some browsers the background overflows, if in semicircle mode
303+ } ) ;
304+
305+ ring . attr ( {
306+ "stroke" : options . color ,
307+ "stroke-width" : stroke ,
308+ "transform" : isSemicircle ? ( 'translate(' + 0 + ',' + size + ') rotate(-90)' ) : ''
309+ } ) ;
310+
311+ background . attr ( {
312+ "cx" : radius ,
313+ "cy" : radius ,
314+ "transform" : "translate(" + stroke + ", " + stroke + ")" ,
315+ "r" : radius ,
316+ "stroke" : options . bgcolor ,
317+ "stroke-width" : stroke
306318 } ) ;
307319 } ;
308320
@@ -316,19 +328,19 @@ angular.module('angular-svg-round-progress')
316328 return scope . current = 0 ;
317329 } ;
318330
319- if ( newValue > scope . max ) {
331+ if ( newValue > options . max ) {
320332 resetValue = oldValue ;
321- return scope . current = scope . max ;
333+ return scope . current = options . max ;
322334 } ;
323335
324- var max = scope . max ,
325- radius = scope . radius ,
326- isSemicircle = scope . semi ,
327- easingAnimation = service . animations [ scope . animation || 'easeOutCubic' ] ,
336+ var max = options . max ,
337+ radius = options . radius ,
338+ isSemicircle = options . semi ,
339+ easingAnimation = service . animations [ options . animation ] ,
328340 start = oldValue === newValue ? 0 : ( oldValue || 0 ) , // fixes the initial animation
329341 val = newValue - start ,
330342 currentIteration = 0 ,
331- totalIterations = parseInt ( scope . iterations || 50 ) ;
343+ totalIterations = parseInt ( options . iterations ) ;
332344
333345 if ( angular . isNumber ( resetValue ) ) {
334346 // the reset value fixes problems with animation, caused when limiting the scope.current
@@ -353,7 +365,17 @@ angular.module('angular-svg-round-progress')
353365 } ) ( ) ;
354366 } ;
355367
356- scope . $watchCollection ( '[current, max, semi, radius, color, bgcolor, stroke, iterations]' , function ( newValue , oldValue ) {
368+ scope . $watchCollection ( '[current, max, semi, radius, color, bgcolor, stroke, iterations]' , function ( newValue , oldValue , scope ) {
369+
370+ // pretty much the same as angular.extend,
371+ // but this skips undefined values and internal angular keys
372+ angular . forEach ( scope , function ( value , key ) {
373+ // note the scope !== value is because `this` is part of the scope
374+ if ( key . indexOf ( '$' ) && scope !== value && angular . isDefined ( value ) ) {
375+ options [ key ] = value ;
376+ } ;
377+ } ) ;
378+
357379 renderCircle ( ) ;
358380 renderState ( newValue [ 0 ] , oldValue [ 0 ] ) ;
359381 } ) ;
@@ -362,7 +384,7 @@ angular.module('angular-svg-round-progress')
362384 template :[
363385 '<svg class="round-progress" xmlns="http://www.w3.org/2000/svg">' ,
364386 '<circle fill="none"/>' ,
365- '<path fill="none" />' ,
387+ '<path fill="none"/>' ,
366388 '</svg>'
367389 ] . join ( '\n' )
368390 } ;
0 commit comments