forked from jettro/c3-angular-directive
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaxis-y-tick-directive.js
95 lines (87 loc) · 2.6 KB
/
axis-y-tick-directive.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
angular.module('gridshore.c3js.chart')
.directive('chartAxisYTick', ChartAxisYTick);
/**
* @ngdoc directive
* @name chartAxisYTick
* @description
* `chart-axis-y-tick` is used to customize the y or y2 axis tick properties. You can change the amount of ticks, the format of the tick, culling, rotating.
*
* Restrict To:
* Element
*
* Parent Element:
* chart-axis-y
*
* @param {Number} tick-count Specify the number of ticks on the x axis.
*
* {@link http://c3js.org/reference.html#axis-y-tick-count| c3js doc}
*
* @param {Boolean} tick-outer Default is not to show the outer tick, setting this to true will show the outer tick.
*
* {@link http://c3js.org/reference.html#axis-y-tick-outer| c3js doc}
*
* @param {Array} tick-values An array containing the exact values to present a tick for.
*
* {@link http://c3js.org/reference.html#axis-y-tick-values| c3js doc}
*
* @param {Function} tick-format Provide a d3 based format for the tick value.
* format: '$,'
*
* {@link http://c3js.org/reference.html#axis-x-tick-format| c3js doc}
*
* @param {Function} tick-format-function Provide a function to format the tick value.
*
* {@link http://c3js.org/reference.html#axis-y-tick-format| c3js doc}
*
* @example
* Usage:
* <chart-axis-y-tick tick-outer="..." tick-count="..."/>
*
* Example:
* {@link http://jettro.github.io/c3-angular-directive/#examples}
*
*/
function ChartAxisYTick() {
var tickLinker = function (scope, element, attrs, chartCtrl) {
var tick = {};
var count = attrs.tickCount;
if (count) {
tick.count = count;
}
var outer = attrs.tickOuter;
if (outer) {
outer = angular.lowercase(outer);
if (outer === 'true') {
tick.outer = true;
}
else if (outer === 'false') {
tick.outer = false;
}
}
var tickValues = attrs.tickValues;
if (tickValues) {
if (tickValues.indexOf(',') > -1) {
tick.values = tickValues.split(',');
} else {
tick.values = tickValues;
}
}
var format = attrs.tickFormat;
if (format) {
tick.format = d3.format(format);
}
chartCtrl.addYTick(tick);
if (attrs.tickFormatFunction) {
chartCtrl.addYTickFormatFunction(scope.tickFormatFunction());
}
};
return {
"require": "^c3chart",
"restrict": "E",
"scope": {
"tickFormatFunction": "&"
},
"replace": true,
"link": tickLinker
};
}