This repository was archived by the owner on Jun 14, 2022. It is now read-only.
forked from paulcpederson/angular-dimple
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathy.js
63 lines (59 loc) · 1.91 KB
/
y.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
angular.module('angular-dimple.y', [])
.directive('y', [function () {
return {
restrict: 'E',
replace: true,
require: ['y', '^graph'],
controller: ['$scope', '$element', '$attrs', function($scope, $element, $attrs) {
}],
link: function($scope, $element, $attrs, $controllers) {
var graphController = $controllers[1];
var chart = graphController.getChart();
function addAxis () {
if ($attrs.groupBy) {
if ($attrs.type == 'Category') {
y = chart.addCategoryAxis('y', $attrs.field);
} else if ($attrs.type == 'Percent') {
y = chart.addPctAxis('y', $attrs.field);
} else if ($attrs.type == 'Time') {
y = chart.addTimeAxis('x', $attrs.field);
if ($attrs.format) {
y.tickFormat = $attrs.format;
}
} else {
y = chart.addMeasureAxis('y', $attrs.field);
}
if ($attrs.orderBy) {
y.addGroupOrderRule($attrs.orderBy);
}
} else {
if ($attrs.type == 'Category') {
y = chart.addCategoryAxis('y', $attrs.field);
} else if ($attrs.type == 'Percent') {
y = chart.addPctAxis('y', $attrs.field);
} else if ($attrs.type == 'Time') {
y = chart.addTimeAxis('x', $attrs.field);
if ($attrs.format) {
y.tickFormat = $attrs.format;
}
} else {
y = chart.addMeasureAxis('y', $attrs.field);
}
if ($attrs.orderBy) {
y.addOrderRule($attrs.orderBy);
}
}
if ($attrs.title && $attrs.title !== "null") {
y.title = $attrs.title;
} else if ($attrs.title == "null") {
y.title = null;
}
}
$scope.$watch('dataReady', function(newValue, oldValue) {
if (newValue === true) {
addAxis();
}
});
}
};
}]);