-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathangular-chartjs-bar-directive.js
More file actions
102 lines (95 loc) · 3.97 KB
/
angular-chartjs-bar-directive.js
File metadata and controls
102 lines (95 loc) · 3.97 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*!
* AngularJS Chart.js Bar Directive
*
* Copyright 2013 Stephane Begaudeau
* Released under the MIT license
*/
angular.module('angular.directives-chartjs-bar', []).directive('angChartjsBar', [function () {
var getOptionsFromScope = function (scope) {
var options = {};
var potentialOptions = [
{key:'chartjsScaleOverlay', value:'scaleOverlay', isBoolean: true},
{key:'chartjsScaleOverride', value:'scaleOverride', isBoolean: true},
{key:'chartjsScaleSteps', value:'scaleSteps', isNumber: true},
{key:'chartjsScaleStepWidth', value:'scaleStepWidth', isNumber: true},
{key:'chartjsScaleStartValue', value:'scaleStartValue', isNumber: true},
{key:'chartjsScaleLineColor', value:'scaleLineColor'},
{key:'chartjsScaleLineWidth', value:'scaleLineWidth', isNumber: true},
{key:'chartjsScaleShowLabels', value:'scaleShowLabels', isBoolean: true},
{key:'chartjsScaleLabel', value:'scaleLabel'},
{key:'chartjsScaleFontFamily', value:'scaleFontFamily'},
{key:'chartjsScaleFontSize', value:'scaleFontSize', isNumber: true},
{key:'chartjsScaleFontStyle', value:'scaleFontStyle'},
{key:'chartjsScaleFontColor', value:'scaleFontColor'},
{key:'chartjsScaleShowGridLines', value:'scaleShowGridLines', isBoolean: true},
{key:'chartjsScaleGridLineColor', value:'scaleGridLineColor'},
{key:'chartjsScaleGridLineWidth', value:'scaleGridLineWidth', isNumber: true},
{key:'chartjsBarShowStroke', value:'barShowStroke', isBoolean: true},
{key:'chartjsBarStrokeWidth', value:'barStrokeWidth', isNumber: true},
{key:'chartjsBarValueSpacing', value:'barValueSpacing', isNumber: true},
{key:'chartjsBarDatasetSpacing', value:'barDatasetSpacing', isNumber: true},
{key:'chartjsAnimation', value:'animation', isBoolean: true},
{key:'chartjsAnimationSteps', value:'animationSteps', isNumber: true},
{key:'chartjsAnimationEasing', value:'animationEasing'}
];
for (var i = 0; i < potentialOptions.length; i++) {
if (scope.hasOwnProperty(potentialOptions[i].key) && scope[potentialOptions[i].key] !== undefined) {
options[potentialOptions[i].value] = scope[potentialOptions[i].key];
}
}
return options;
};
var chartjsBar = {
restrict: 'E',
//compile: compilationFunction,
template: '<canvas class="ang-chartjs-bar"></canvas>',
scope: {
chartjsModel: '=',
chartjsWidth: '=',
chartjsHeight: '=',
chartjsScaleOverlay: '=',
chartjsScaleOverride: '=',
chartjsScaleSteps: '=',
chartjsScaleStepWidth: '=',
chartjsScaleStartValue: '=',
chartjsScaleLineColor: '=',
chartjsScaleLineWidth: '=',
chartjsScaleShowLabels: '=',
chartjsScaleLabel: '=',
chartjsScaleFontFamily: '=',
chartjsScaleFontSize: '=',
chartjsScaleFontStyle: '=',
chartjsScaleFontColor: '=',
chartjsScaleShowGridLine: '=',
chartjsScaleGridLineColor: '=',
chartjsScaleGridLineWidth: '=',
chartjsBarShowStroke: '=',
chartjsBarStrokeWidth: '=',
chartjsBarValueSpacing: '=',
chartjsBarDatasetSpacing: '=',
chartjsAnimation: '=',
chartjsAnimationSteps: '=',
chartjsAnimationEasing: '='
},
link: function (scope, elements, attributes) {
scope.$watch('chartjsModel', function (newValue) {
if (newValue !== undefined) {
var options = getOptionsFromScope(scope);
if (scope.chart !== undefined) {
scope.chart.Bar(newValue, options);
} else {
var width = scope.chartjsWidth || '400';
var height = scope.chartjsHeight || '400';
var canvas = elements[0].children[0];
canvas.setAttribute('width', width);
canvas.setAttribute('height', height);
var chart = new Chart(canvas.getContext('2d'));
chart.Bar(newValue, options);
scope.chart = chart;
}
}
}, true);
}
};
return chartjsBar;
}]);