forked from mattlaver/angular-justgage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ng-justgage.js
49 lines (45 loc) · 1.28 KB
/
ng-justgage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
angular.module('ngJustGage', [])
.directive('justGage', ['$timeout', function ($timeout) {
return {
restrict: 'EA',
scope: {
id: '@',
class: '@',
min: '=',
max: '=',
title: '@',
label: '@',
value: '@',
options: '='
},
template: '<div id="{{id}}-justgage" class="{{class}}"></div>',
link: function (scope, element, attrs) {
$timeout(function () {
var options = {
id: scope.id + '-justgage',
min: scope.min || 0,
max: scope.max || 100,
title: scope.title,
label: scope.label || '',
value: scope.value
};
if (scope.options) {
for (var key in scope.options) {
options[key] = scope.options[key];
}
}
var graph = new JustGage(options);
scope.$watch('max', function (updatedMax) {
if (updatedMax !== undefined) {
graph.refresh(scope.value, updatedMax);
}
}, true);
scope.$watch('value', function (updatedValue) {
if (updatedValue !== undefined) {
graph.refresh(updatedValue);
}
}, true);
});
}
};
}]);