Skip to content

Commit d4ba85e

Browse files
author
crisbeto
committed
add a constant for default values and bump version
1 parent 3b3e4ab commit d4ba85e

File tree

10 files changed

+117
-76
lines changed

10 files changed

+117
-76
lines changed

Gruntfile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module.exports = function(grunt) {
22
var files = [
33
'src/shim.js',
44
'src/module.js',
5+
'src/roundProgressConfig.js',
56
'src/roundProgressService.js',
67
'src/roundProgress.js',
78
];
@@ -42,4 +43,4 @@ module.exports = function(grunt) {
4243

4344
grunt.registerTask('default', ['concat:build', 'uglify:build']);
4445
grunt.registerTask('deploy', ['default', 'gh-pages:deploy']);
45-
};
46+
};

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@ angular.module('someModule', ['angular-svg-round-progress'])
2323

2424
## Options
2525

26+
* To edit the default values, change the options in the `roundProgressConfig` constant
2627
* `current` current progress, some value on the scope or a number
27-
* `max` maximum value, some value on the scope or a number
28-
* `radius` radius of the circle
29-
* `color` hex color for the `current` value, example: `#45ccce`
30-
* `bgcolor` hex background color, example: `#eaeaea`
31-
* `stroke` specifies the thickness of the line
32-
* `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)*
34-
* `animation` the easing function that will be used. Default value is `easeOutCubic`, possible values:
28+
* `max` maximum value, some value on the scope or a number *(Defaults to `50`)*
29+
* `radius` radius of the circle *(Defaults to `50`)*
30+
* `color` hex color for the `current` value, example: `#45ccce` *(Defaults to `#45ccce`)*
31+
* `bgcolor` hex background color, example: `#eaeaea` *(Defaults to `#eaeaea`)*
32+
* `stroke` specifies the thickness of the line *(Defaults to `15`)*
33+
* `semi` boolean, specifies whether the progressbar should be a semicircle or a full circle *(Defaults to `false`)*
34+
* `iterations` number of iterations for the animation. Set it to 1 for *no animation* and increase for slower animation. *(Defaults to `50`)*
35+
* `animation` the easing function that will be used. *(Defaults to `easeOutCubic`)* possible values:
3536
* linearEase
3637
* easeInQuad
3738
* easeOutQuad

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.1",
3+
"version": "0.2.2",
44
"homepage": "https://github.com/crisbeto/angular-svg-round-progressbar",
55
"authors": [
66
"crisbeto"

build/index.html

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,7 @@ <h2>Sample progressbar</h2>
8787
<div
8888
round-progress
8989
max="max"
90-
current="current"
91-
color="{{ currentColor }}"
92-
bgcolor="{{ bgColor }}"
93-
radius="{{ radius }}"
94-
semi="isSemi"
95-
stroke="{{ stroke }}"
96-
iterations="{{ iterations }}"
97-
animation="{{ currentAnimation }}">
90+
current="current">
9891
</div>
9992
</div>
10093

@@ -177,7 +170,7 @@ <h2>Upload progress example</h2>
177170

178171

179172
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular.js"></script>
180-
<script src="roundProgress.js"></script>
173+
<script src="roundProgress.min.js"></script>
181174
<script>
182175
angular.module('demo', ['angular-svg-round-progress'])
183176
.controller('demoCtrl', ['$scope', '$timeout', 'roundProgressService', function($scope, $timeout, roundProgressService){

build/roundProgress.js

Lines changed: 61 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@
3030

3131
angular.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+
3348
angular.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

245260
angular.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

Comments
 (0)