-
Notifications
You must be signed in to change notification settings - Fork 353
/
grid.x.ts
90 lines (82 loc) · 2.48 KB
/
grid.x.ts
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
/**
* Copyright (c) 2017 ~ present NAVER Corp.
* billboard.js project is licensed under the MIT license
*/
import {extend} from "../../module/util";
type GridsParam = {value?: number, class?: string, text?: string}[];
/**
* Update x grid lines.
* @function xgrids
* @instance
* @memberof Chart
* @param {Array} grids X grid lines will be replaced with this argument. The format of this argument is the same as grid.x.lines.
* @returns {object}
* @example
* // Show 2 x grid lines
* chart.xgrids([
* {value: 1, text: "Label 1"},
* {value: 4, text: "Label 4"}
* ]);
* // --> Returns: [{value: 1, text: "Label 1"}, {value: 4, text: "Label 4"}]
*/
function xgrids(grids: GridsParam): GridsParam {
const $$ = this.internal;
const {config} = $$;
if (!grids) {
return config.grid_x_lines;
}
config.grid_x_lines = grids;
$$.redrawWithoutRescale();
return config.grid_x_lines;
}
extend(xgrids, {
/**
* Add x grid lines.<br>
* This API adds new x grid lines instead of replacing like xgrids.
* @function xgrids․add
* @instance
* @memberof Chart
* @param {Array|object} grids New x grid lines will be added. The format of this argument is the same as grid.x.lines and it's possible to give an Object if only one line will be added.
* @returns {object}
* @example
* // Add a new x grid line
* chart.xgrids.add(
* {value: 4, text: "Label 4"}
* );
*
* // Add new x grid lines
* chart.xgrids.add([
* {value: 2, text: "Label 2"},
* {value: 4, text: "Label 4"}
* ]);
*/
add: function(grids: GridsParam): GridsParam {
return this.xgrids(
this.internal.config.grid_x_lines
.concat(grids || [])
);
},
/**
* Remove x grid lines.<br>
* This API removes x grid lines.
* @function xgrids․remove
* @instance
* @memberof Chart
* @param {object} params This argument should include value or class. If value is given, the x grid lines that have specified x value will be removed. If class is given, the x grid lines that have specified class will be removed. If args is not given, all of x grid lines will be removed.
* @example
* // x grid line on x = 2 will be removed
* chart.xgrids.remove({value: 2});
*
* // x grid lines that have 'grid-A' will be removed
* chart.xgrids.remove({
* class: "grid-A"
* });
*
* // all of x grid lines will be removed
* chart.xgrids.remove();
*/
remove: function(params?: GridsParam): void { // TODO: multiple
this.internal.removeGridLines(params, true);
}
});
export default {xgrids};