Skip to content

Commit cdf36c3

Browse files
committed
Package naming, performance improvements, coding style improvements.
* Renamed the module to `angular-svg-round-progressbar` in order to match the name on NPM and Bower. * Started using `performance.now` for the animation timing, if the browser supports it. * Removed some styles that were being set twice in a row for some reason. * Fixed some crappy indentation and removed unnecessary quotes. * Switched to using string concatenation instead of joining arrays in order to avoid having to create a whole lot of arrays. * Bumped the version to 0.4.0.
1 parent 0bd0186 commit cdf36c3

File tree

10 files changed

+448
-464
lines changed

10 files changed

+448
-464
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ or
1919
`<script src="http://crisbeto.github.io/angular-svg-round-progressbar/roundProgress.min.js"></script>`
2020

2121

22-
Add `angular-svg-round-progress` to your app's module dependencies:
22+
Add `angular-svg-round-progressbar` to your app's module dependencies:
2323

2424
```javascript
25-
angular.module('someModule', ['angular-svg-round-progress'])
25+
angular.module('someModule', ['angular-svg-round-progressbar'])
2626
```
2727

2828
## Options

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "angular-svg-round-progressbar",
3-
"version": "0.3.10",
3+
"version": "0.4.0",
44
"homepage": "https://github.com/crisbeto/angular-svg-round-progressbar",
55
"authors": [
66
"crisbeto"
77
],
8-
"description": "AngularJS module that uses SVG to create a circular progressar",
8+
"description": "AngularJS module that uses SVG to create a circular progressbar",
99
"keywords": [
1010
"angular",
1111
"progress",

build/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ <h2>Clock example</h2>
285285
<script>
286286
'use strict';
287287

288-
angular.module('demo', ['angular-svg-round-progress']).controller('demoCtrl', ['$scope', '$interval', '$timeout', '$window', 'roundProgressService', function($scope, $interval, $timeout, $window, roundProgressService){
288+
angular.module('demo', ['angular-svg-round-progressbar']).controller('demoCtrl', ['$scope', '$interval', '$timeout', '$window', 'roundProgressService', function($scope, $interval, $timeout, $window, roundProgressService){
289289

290290
$scope.current = 27;
291291
$scope.max = 50;

build/roundProgress.js

Lines changed: 220 additions & 228 deletions
Large diffs are not rendered by default.

build/roundProgress.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "angular-svg-round-progressbar",
3-
"version": "0.3.10",
4-
"description": "AngularJS module that uses SVG to create a circular progressar",
3+
"version": "0.4.0",
4+
"description": "AngularJS module that uses SVG to create a circular progressbar",
55
"main": "build/roundProgress.min.js",
66
"scripts": {},
77
"repository": {

src/module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
angular.module('angular-svg-round-progress', []);
1+
angular.module('angular-svg-round-progressbar', []);

src/roundProgress.js

Lines changed: 184 additions & 193 deletions
Large diffs are not rendered by default.

src/roundProgressConfig.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
'use strict';
22

3-
angular.module('angular-svg-round-progress').constant('roundProgressConfig', {
3+
angular.module('angular-svg-round-progressbar').constant('roundProgressConfig', {
44
max: 50,
55
semi: false,
66
rounded: false,
77
responsive: false,
88
clockwise: true,
99
radius: 100,
10-
color: "#45ccce",
11-
bgcolor: "#eaeaea",
10+
color: '#45ccce',
11+
bgcolor: '#eaeaea',
1212
stroke: 15,
1313
duration: 800,
14-
animation: "easeOutCubic",
14+
animation: 'easeOutCubic',
1515
animationDelay: 0,
1616
offset: 0
1717
});

src/roundProgressService.js

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
'use strict';
22

3-
angular.module('angular-svg-round-progress').service('roundProgressService', [function(){
3+
angular.module('angular-svg-round-progressbar').service('roundProgressService', ['$window', function($window){
44
var service = {};
55
var isNumber = angular.isNumber;
66
var base = document.head.querySelector('base');
77

8+
// credits to http://modernizr.com/ for the feature test
9+
service.isSupported = !!(document.createElementNS && document.createElementNS('http://www.w3.org/2000/svg', "svg").createSVGRect);
10+
811
// fixes issues if the document has a <base> element
912
service.resolveColor = base && base.href ? function(value){
1013
var hashIndex = value.indexOf('#');
@@ -18,19 +21,6 @@ angular.module('angular-svg-round-progress').service('roundProgressService', [fu
1821
return value;
1922
};
2023

21-
// credits to http://modernizr.com/ for the feature test
22-
service.isSupported = !!(document.createElementNS && document.createElementNS('http://www.w3.org/2000/svg', "svg").createSVGRect);
23-
24-
// utility function
25-
var polarToCartesian = function(centerX, centerY, radius, angleInDegrees) {
26-
var angleInRadians = (angleInDegrees - 90) * Math.PI / 180.0;
27-
28-
return {
29-
x: centerX + (radius * Math.cos(angleInRadians)),
30-
y: centerY + (radius * Math.sin(angleInRadians))
31-
};
32-
};
33-
3424
// deals with floats passed as strings
3525
service.toNumber = function(value){
3626
return isNumber(value) ? value : parseFloat((value + '').replace(',', '.'));
@@ -56,29 +46,31 @@ angular.module('angular-svg-round-progress').service('roundProgressService', [fu
5646
return value;
5747
};
5848

59-
// credit to http://stackoverflow.com/questions/5736398/how-to-calculate-the-svg-path-for-an-arc-of-a-circle
60-
service.updateState = function(val, total, R, ring, size, isSemicircle) {
49+
service.getTimestamp = $window.performance && $window.performance.now ? function(){
50+
return $window.performance.now();
51+
} : function(){
52+
return $window.Date.now();
53+
};
6154

62-
if(!size) return ring;
55+
// credit to http://stackoverflow.com/questions/5736398/how-to-calculate-the-svg-path-for-an-arc-of-a-circle
56+
service.updateState = function(current, total, pathRadius, element, elementRadius, isSemicircle) {
57+
if(!elementRadius) return element;
6358

64-
var value = val > 0 ? Math.min(val, total) : 0;
59+
var value = current > 0 ? Math.min(current, total) : 0;
6560
var type = isSemicircle ? 180 : 359.9999;
6661
var perc = total === 0 ? 0 : (value / total) * type;
67-
var x = size/2;
68-
var start = polarToCartesian(x, x, R, perc); // in this case x and y are the same
69-
var end = polarToCartesian(x, x, R, 0);
70-
var arcSweep = (perc <= 180 ? "0" : "1");
71-
var d = [
72-
"M", start.x, start.y,
73-
"A", R, R, 0, arcSweep, 0, end.x, end.y
74-
].join(" ");
75-
76-
return ring.attr('d', d);
62+
var start = polarToCartesian(elementRadius, elementRadius, pathRadius, perc);
63+
var end = polarToCartesian(elementRadius, elementRadius, pathRadius, 0);
64+
var arcSweep = (perc <= 180 ? 0 : 1);
65+
var d = 'M ' + start + ' A ' + pathRadius + ' ' + pathRadius + ' 0 ' + arcSweep + ' 0 ' + end;
66+
67+
return element.attr('d', d);
7768
};
7869

7970
service.isDirective = function(el){
8071
if(el && el.length){
81-
return (typeof el.attr('round-progress') !== 'undefined' || el[0].nodeName.toLowerCase() === 'round-progress');
72+
var directiveName = 'round-progress';
73+
return (typeof el.attr(directiveName) !== 'undefined' || el[0].nodeName.toLowerCase() === directiveName);
8274
}
8375

8476
return false;
@@ -259,5 +251,14 @@ angular.module('angular-svg-round-progress').service('roundProgressService', [fu
259251
}
260252
};
261253

254+
// utility function
255+
function polarToCartesian(centerX, centerY, radius, angleInDegrees) {
256+
var angleInRadians = (angleInDegrees - 90) * Math.PI / 180.0;
257+
var x = centerX + (radius * Math.cos(angleInRadians));
258+
var y = centerY + (radius * Math.sin(angleInRadians));
259+
260+
return x + ' ' + y;
261+
}
262+
262263
return service;
263264
}]);

0 commit comments

Comments
 (0)