-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathangular-chartjs-line-directive.js
More file actions
107 lines (100 loc) · 4.24 KB
/
angular-chartjs-line-directive.js
File metadata and controls
107 lines (100 loc) · 4.24 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
103
104
105
106
107
/*!
* AngularJS Chart.js Line Directive
*
* Copyright 2013 Stephane Begaudeau
* Released under the MIT license
*/
angular.module('angular.directives-chartjs-line', []).directive('angChartjsLine', [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:'chartjsBezierCurve', value:'bezierCurve', isBoolean: true},
{key:'chartjsPointDot', value:'pointDot', isBoolean: true},
{key:'chartjsPointDotRadius', value:'pointDotRadius', isNumber: true},
{key:'chartjsPointDotWidth', value:'pointDotStrokeWidth', isNumber: true},
{key:'chartjsDatasetStroke', value:'datasetStroke', isBoolean: true},
{key:'chartjsDatasetStrokeWidth', value:'datasetStrokeWidth', isNumber: true},
{key:'chartjsDatasetFill', value:'datasetFill', isBoolean: 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 chartjsLine = {
restrict: 'E',
//compile: compilationFunction,
template: '<canvas class="ang-chartjs-line"></canvas>',
scope: {
chartjsModel: '=',
chartjsWidth: '=',
chartjsHeight: '=',
chartjsScaleOverlay: '=',
chartjsScaleOverride: '=',
chartjsScaleSteps: '=',
chartjsScaleStepWidth: '=',
chartjsScaleStartValue: '=',
chartjsScaleLineColor: '=',
chartjsScaleLineWidth: '=',
chartjsScaleShowLabels: '=',
chartjsScaleLabel: '=',
chartjsScaleFontFamily: '=',
chartjsScaleFontSize: '=',
chartjsScaleFontStyle: '=',
chartjsScaleFontColor: '=',
chartjsScaleShowGridLine: '=',
chartjsScaleGridLineColor: '=',
chartjsScaleGridLineWidth: '=',
chartjsBezierCurve: '=',
chartjsPointDot: '=',
chartjsPointDotRadius: '=',
chartjsDatasetStroke: '=',
chartjsDatasetStrokeWidth: '=',
chartjsDatasetFill: '=',
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.Line(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.Line(newValue, options);
scope.chart = chart;
}
}
}, true);
}
};
return chartjsLine;
}]);