• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

naver / billboard.js / 16137267914

08 Jul 2025 07:51AM UTC coverage: 86.941% (-7.2%) from 94.118%
16137267914

push

github

web-flow
chore(deps-dev): update dependency (#4014)

update dependencies to the latest versions

5668 of 7016 branches covered (80.79%)

Branch coverage included in aggregate %.

7487 of 8115 relevant lines covered (92.26%)

11761.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

55.17
/src/Chart/api/grid.ts
1
/**
2
 * Copyright (c) 2017 ~ present NAVER Corp.
3
 * billboard.js project is licensed under the MIT license
4
 */
5
import {extend, isTabVisible} from "../../module/util";
6

7
type GridsParam = {value?: number, class?: string, text?: string}[];
8

9
/**
10
 * Update grid lines.
11
 * @param {Array} grids grid lines to update
12
 * @param {string} axisId axis' id: "x" or "y"
13
 * @returns {Array}
14
 * @private
15
 */
16
function grid(grids: GridsParam, axisId: "x" | "y"): GridsParam {
17
        const $$ = this.internal;
3✔
18
        const {config} = $$;
3✔
19
        const withTransition = config.transition_duration && isTabVisible();
3!
20
        const gridPropLines = `grid_${axisId}_lines`;
3✔
21

22
        if (!grids) {
3!
23
                return config[gridPropLines];
×
24
        }
25

26
        config[gridPropLines] = grids;
3✔
27

28
        $$.updateGrid();
3✔
29
        $$.redrawGrid(withTransition);
3✔
30

31
        return config[gridPropLines];
3✔
32
}
33

34
/**
35
 * Add grid lines.
36
 * @param {Array|object} grids grid lines to add
37
 * @param {string} axisId axis' id: "x" or "y"
38
 * @returns {Array}
39
 * @private
40
 */
41
function add(grids: GridsParam, axisId: "x" | "y"): GridsParam {
42
        const gridPropLines = `grid_${axisId}_lines`;
×
43

44
        return grid.bind(this)(
×
45
                this.internal.config[gridPropLines].concat(grids || []),
×
46
                axisId
47
        );
48
}
49

50
/**
51
 * Remove grid lines.
52
 * @param {object} grids grid lines to remove
53
 * @param {boolean} isXAxis weather is x axis or not
54
 * @private
55
 */
56
function remove(grids: GridsParam | undefined, isXAxis: boolean): void {
57
        this.internal.removeGridLines(grids, isXAxis);
×
58
}
59

60
/**
61
 * Update x grid lines.
62
 * @function xgrids
63
 * @instance
64
 * @memberof Chart
65
 * @param {Array} grids X grid lines will be replaced with this argument. The format of this argument is the same as grid.x.lines.
66
 * @returns {Array}
67
 * @example
68
 *  // Show 2 x grid lines
69
 * chart.xgrids([
70
 *    {value: 1, text: "Label 1"},
71
 *    {value: 4, text: "Label 4"}
72
 * ]);
73
 * // --> Returns: [{value: 1, text: "Label 1"}, {value: 4, text: "Label 4"}]
74
 */
75
const xgrids = function(grids: GridsParam): GridsParam {
228✔
76
        return grid.bind(this)(grids, "x");
3✔
77
};
78

79
extend(xgrids, {
228✔
80
        /**
81
         * Add x grid lines.<br>
82
         * This API adds new x grid lines instead of replacing like xgrids.
83
         * @function xgrids․add
84
         * @instance
85
         * @memberof Chart
86
         * @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.
87
         * @returns {Array}
88
         * @example
89
         *  // Add a new x grid line
90
         * chart.xgrids.add(
91
         *   {value: 4, text: "Label 4"}
92
         * );
93
         *
94
         * // Add new x grid lines
95
         * chart.xgrids.add([
96
         *   {value: 2, text: "Label 2"},
97
         *   {value: 4, text: "Label 4"}
98
         * ]);
99
         */
100
        add(grids: GridsParam): GridsParam {
101
                return add.bind(this)(grids, "x");
×
102
        },
103

104
        /**
105
         * Remove x grid lines.<br>
106
         * This API removes x grid lines.
107
         * @function xgrids․remove
108
         * @instance
109
         * @memberof Chart
110
         * @param {object} grids 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.
111
         * @param {number} [grids.value] target value
112
         * @param {string} [grids.class] target class
113
         * @returns {void}
114
         * @example
115
         * // x grid line on x = 2 will be removed
116
         * chart.xgrids.remove({value: 2});
117
         *
118
         * // x grid lines that have 'grid-A' will be removed
119
         * chart.xgrids.remove({
120
         *   class: "grid-A"
121
         * });
122
         *
123
         * // all of x grid lines will be removed
124
         * chart.xgrids.remove();
125
         */
126
        remove(grids?: GridsParam): void { // TODO: multiple
127
                return remove.bind(this)(grids, true);
×
128
        }
129
});
130

131
/**
132
 * Update y grid lines.
133
 * @function ygrids
134
 * @instance
135
 * @memberof Chart
136
 * @param {Array} grids Y grid lines will be replaced with this argument. The format of this argument is the same as grid.y.lines.
137
 * @returns {object}
138
 * @example
139
 *  // Show 2 y grid lines
140
 * chart.ygrids([
141
 *    {value: 100, text: "Label 1"},
142
 *    {value: 400, text: "Label 4"}
143
 * ]);
144
 * // --> Returns: [{value: 100, text: "Label 1"}, {value: 400, text: "Label 4"}]
145
 */
146
const ygrids = function(grids: GridsParam): GridsParam {
228✔
147
        return grid.bind(this)(grids, "y");
×
148
};
149

150
extend(ygrids, {
228✔
151
        /**
152
         * Add y grid lines.<br>
153
         * This API adds new y grid lines instead of replacing like ygrids.
154
         * @function ygrids․add
155
         * @instance
156
         * @memberof Chart
157
         * @param {Array|object} grids New y grid lines will be added. The format of this argument is the same as grid.y.lines and it's possible to give an Object if only one line will be added.
158
         * @returns {object}
159
         * @example
160
         *  // Add a new x grid line
161
         * chart.ygrids.add(
162
         *   {value: 400, text: "Label 4"}
163
         * );
164
         *
165
         * // Add new x grid lines
166
         * chart.ygrids.add([
167
         *   {value: 200, text: "Label 2"},
168
         *   {value: 400, text: "Label 4"}
169
         * ]);
170
         */
171
        add(grids: GridsParam): GridsParam {
172
                return add.bind(this)(grids, "y");
×
173
        },
174

175
        /**
176
         * Remove y grid lines.<br>
177
         * This API removes x grid lines.
178
         * @function ygrids․remove
179
         * @instance
180
         * @memberof Chart
181
         * @param {object} grids This argument should include value or class. If value is given, the y grid lines that have specified y value will be removed. If class is given, the y grid lines that have specified class will be removed. If args is not given, all of y grid lines will be removed.
182
         * @param {number} [grids.value] target value
183
         * @param {string} [grids.class] target class
184
         * @returns {void}
185
         * @example
186
         * // y grid line on y = 200 will be removed
187
         * chart.ygrids.remove({value: 200});
188
         *
189
         * // y grid lines that have 'grid-A' will be removed
190
         * chart.ygrids.remove({
191
         *   class: "grid-A"
192
         * });
193
         *
194
         * // all of y grid lines will be removed
195
         * chart.ygrids.remove();
196
         */
197
        remove(grids?: GridsParam): void { // TODO: multiple
198
                return remove.bind(this)(grids, false);
×
199
        }
200
});
201

202
export default {xgrids, ygrids};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc