-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathangular-peity.js
75 lines (50 loc) · 1.37 KB
/
angular-peity.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var angularPeity = angular.module( 'angular-peity', [] );
var buildChartDirective = function(chartType) {
'use strict';
return {
restrict: 'E',
scope: {
data: "=",
options: "="
},
link: function(scope, element, attrs) {
var options = {};
if (scope.options) {
options = scope.options;
}
var span = document.createElement('span');
span.style.display = "none";
span.textContent = scope.data.join();
if (!attrs.class) {
span.className = "";
} else {
span.className = attrs.class;
}
if (element[0].nodeType === 8) {
element.replaceWith(span);
} else {
element[0].appendChild(span);
}
jQuery(span).peity(chartType, options);
var watcher = scope.$watch('data', function(){
span.textContent = scope.data.join();
jQuery( span ).change();
}, true);
scope.$on('$destroy', function(){
watcher();
});
jQuery(window).resize(function() {
jQuery(span).peity(chartType, options);
});
}
};
};
angularPeity.directive( 'pieChart', function () {
return buildChartDirective( "pie" );
} );
angularPeity.directive( 'barChart', function () {
return buildChartDirective( "bar" );
} );
angularPeity.directive( 'lineChart', function () {
return buildChartDirective( "line" );
} );