bansho/app/components/ng-justgage/ng-justgage.js
Thibault Cohen fdab9f7836 Fix gauge on dashboard page
Change-Id: I445b9a4fc82fffbfac618f68dd5060273222a3cc
2015-06-29 16:29:54 -04:00

65 lines
2.3 KiB
JavaScript

/*global JustGage */
'use strict';
angular.module("ngJustGage", [])
.directive('justGage', ['$timeout', function ($timeout) {
return {
restrict: 'EA',
scope: {
id: '@',
class: '@',
min: '=',
max: '=',
title: '@',
value: '=',
options: '='
},
template: '<div id="{{id}}-justgage" class="{{class}}"></div>',
link: function (scope) {
$timeout(function () {
var options, key, graph;
options = {
id: scope.id + '-justgage',
min: scope.min,
max: scope.max,
title: scope.title,
gaugeWidthScale: 0.2,
levelColors: ["#E84C3D", "#E84C3D", "#E84C3D", "#E84C3D", "#E84C3D",
"#E84C3D", "#E84C3D", "#E84C3D", "#E84C3D", "#E84C3D",
"#F9A13B", "#F9A13B", "#F9A13B", "#F9A13B", "#F9A13B",
"#F9A13B", "#F9A13B", "#F9A13B", "#F9A13B",
"#81A854"],
levelColorsGradient: false,
value: scope.value,
donut: true,
symbol: '%'
};
if (scope.options) {
for (key in scope.options) {
if (scope.options.hasOwnProperty(key)) {
options[key] = scope.options[key];
}
}
}
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);
});
}
};
}]);