UNPKG

10.3 kBTypeScriptView Raw
1import {Chart} from "./chart";
2
3/**
4 * Copyright (c) 2017 ~ present NAVER Corp.
5 * billboard.js project is licensed under the MIT license
6 */
7export interface Axis {
8 /**
9 * Switch x and y axis position.
10 */
11 rotated?: boolean;
12 x?: xAxisConfiguration;
13 y?: yAxisConfiguration;
14 y2?: yAxisConfigurationBase;
15}
16
17export interface AxisConfigurationBase {
18 /**
19 * Show or hide axis.
20 */
21 show?: boolean;
22
23 /**
24 * Set additional axes for Axis
25 */
26 axes?: AxesConfiguration[];
27}
28
29export interface xAxisConfiguration extends AxisConfigurationBase {
30 /**
31 * Set type of x axis (timeseries, category, indexed, log)
32 *
33 * NOTE:
34 * log type:
35 * - the x values specified by `data.x`(or by any equivalent option), must be exclusively-positive.
36 * - x axis min value should be >= 0.
37 */
38 type?: "category" | "indexed" | "log" | "timeseries";
39
40 /**
41 * Set how to treat the timezone of x values.
42 * If true, treat x value as localtime. If false, convert to UTC internally.
43 */
44 localtime?: boolean;
45
46 /**
47 * Set category names on category axis.
48 * This must be an array that includes category names in string.
49 * If category names are included in the date by data.x option, this is not required.
50 */
51 categories?: string[];
52
53 tick?: XTickConfiguration;
54
55 /**
56 * Set max value of x axis range.
57 *
58 * When specified `max.value` is greater than the bound data value, setting `max.fit=true` will make x axis max to be fitted to the bound data max value.
59 */
60 max?: string | number | Date | ({
61 fit?: boolean;
62 value?: string | number | Date;
63 });
64
65 /**
66 * Set min value of x axis range.
67 *
68 * When specified `min.value` is lower than the bound data value, setting `min.fit=true` will make x axis min to be fitted to the bound data min value.
69 */
70 min?: string | number | Date | ({
71 fit?: boolean;
72 value?: string | number | Date;
73 });
74
75 /**
76 * Set padding for x axis.
77 * If this option is set, the range of x axis will increase/decrease according to the values.
78 * If no padding is needed in the ragen of x axis, 0 should be set. On category axis, this option will be ignored.
79 */
80 padding?: {
81 left?: number;
82 right?: number;
83 } | number;
84
85 /**
86 * Set height of x axis.
87 * The height of x axis can be set manually by this option.
88 * If you need more space for x axis, please use this option for that. The unit is pixel.
89 */
90 height?: number;
91
92 /**
93 * Set default extent for subchart and zoom.
94 * This can be an array or function that returns an array.
95 */
96 extent?: number[] | string[] | (
97 (
98 this: Chart,
99 domain: Date|string|number[],
100 scale: (value: any) => number
101 ) => number[]
102 );
103
104 /**
105 * Set label on x axis.
106 * You can set x axis label and change its position by this option.
107 * string and object can be passed and we can change the poisiton by passing object that has position key.
108 *
109 * Available position differs according to the axis direction (vertical or horizontal). If string set, the position will be the default.
110 * - Valid horizontal positions: inner-right (Default), inner-center, inner-left, outer-right, outer-center, outer-left
111 * - Valid vertical positions: inner-top, inner-middle, inner-bottom, outer-top, outer-middle, outer-bottom
112 */
113 label?: string | { text: string; position: string };
114
115 /**
116 * Set clip-path attribute for x axis element.
117 */
118 clipPath?: boolean;
119}
120
121export interface yAxisConfigurationBase extends AxisConfigurationBase {
122 /**
123 * Show y axis inside of the chart.
124 */
125 inner?: boolean;
126
127 /**
128 * Set max value of y axis.
129 */
130 max?: number;
131
132 /**
133 * Set min value of y axis.
134 */
135 min?: number;
136
137 /**
138 * Change the direction of y axis.
139 * If true set, the direction will be from the top to the bottom.
140 */
141 inverted?: boolean;
142
143 /**
144 * Set center value of y axis.
145 */
146 center?: number;
147
148 /**
149 * Set label on y axis. This option works in the same way as axis.x.label.
150 *
151 * - Valid horizontal positions:
152 * - inner-right (Default), inner-center, inner-left, outer-right, outer-center, outer-left
153 * - Valid vertical positions:
154 * - inner-top, inner-middle, inner-bottom, outer-top, outer-middle, outer-bottom
155 */
156 label?: string | { text: string; position: string };
157
158 tick?: YTickConfiguration;
159
160 /**
161 * Set padding for y axis.
162 * You can set padding for y axis to create more space on the edge of the axis.
163 * This option accepts object and it can include top and bottom. top, bottom will be treated as pixels.
164 */
165 padding?: {
166 top?: number;
167 bottom?: number;
168 } | number;
169
170 /**
171 * Set default range of y axis.
172 * This option set the default value for y axis when there is no data on init.
173 */
174 default?: number[];
175}
176
177export interface yAxisConfiguration extends yAxisConfigurationBase {
178 /**
179 * Set clip-path attribute for y axis element.
180 */
181 clipPath?: boolean;
182}
183
184export interface XTickConfiguration {
185 /**
186 * Centerise ticks on category axis
187 */
188 centered?: boolean;
189
190 /**
191 * A function to format tick value. Format string is also available for timeseries data.
192 */
193 format?: string
194 | ((this: Chart, x: number | Date) => string | number)
195 | ((this: Chart, index: number, categoryName: string) => string);
196
197 /**
198 * Setting for culling ticks.
199 * If true is set, the ticks will be culled, then only limitted tick text will be shown.
200 * This option does not hide the tick lines. If false is set, all of ticks will be shown.
201 */
202 culling?: boolean | {
203 /**
204 * The number of tick texts will be adjusted to less than this value.
205 */
206 max?: number;
207 };
208
209 /**
210 * The number of x axis ticks to show.
211 * This option hides tick lines together with tick text. If this option is used on timeseries axis, the ticks position will be determined precisely and not nicely positioned (e.g. it will
212 * have rough second value).
213 */
214 count?: number;
215
216 /**
217 * Fit x axis ticks.
218 * - true: ticks will be positioned nicely to have same intervals.
219 * - false: ticks will be positioned according to x value of the data points.
220 */
221 fit?: boolean;
222
223 /**
224 * Set the x values of ticks manually.
225 * If this option is provided, the position of the ticks will be determined based on those values.
226 * This option works with timeseries data and the x values will be parsed accoding to the type of the value and data.xFormat option.
227 */
228 values?: number[] | string[] | ((this: Chart) => number[]);
229
230 /**
231 * Rotate x axis tick text.
232 * - If you set negative value, it will rotate to opposite direction.
233 * - Applied when 'axis.rotated' option is 'false'.
234 * - As long as `axis_x_tick_fit` is set to `true` it will calculate an overflow for the y2 axis and add this value to the right padding.
235 */
236 rotate?: number;
237
238 /**
239 * Rotate x axis tick text if there is not enough space for 'category' and 'timeseries' type axis.
240 * - **NOTE:** The conditions where `autorotate` is enabled are:
241 * - axis.x.type='category' or 'timeseries
242 * - axis.x.tick.multiline=false
243 * - axis.x.tick.culling=false
244 * - axis.x.tick.fit=true
245 * - **NOTE:** axis.x.tick.clippath=false is necessary for calculating the overflow padding between the end of x axis and the width of the SVG
246 */
247 autorotate?: boolean;
248
249 /**
250 * Show x axis outer tick.
251 */
252 outer?: boolean;
253
254 /**
255 * Set width of x axis tick.
256 */
257 width?: number;
258
259 /**
260 * Set tick text to be multiline
261 * - NOTE: When x tick text contains \n, it's used as line break and 'axis.x.tick.width' option is ignored.
262 */
263 multiline?: boolean;
264
265 /**
266 * Set to display system tooltip(via 'title' attribute) for tick text
267 * - NOTE: Only available for category axis type (axis.x.type='category')
268 */
269 tooltip?: boolean;
270
271 /**
272 * Show or hide tick line.
273 */
274 show?: boolean;
275
276 text?: {
277 /**
278 * Set the x Axis tick text's position relatively its original position
279 */
280 position?: {
281 x?: number;
282 y?: number;
283 };
284
285 /**
286 * Show or hide tick text
287 */
288 show?: boolean;
289 };
290
291 /**
292 * Set axis type (timeseries, category, indexed, log)
293 *
294 * NOTE:
295 * log type:
296 * - the bound data values must be exclusively-positive.
297 * - axis min value should be >= 0.
298 * - `data.groups`(stacked data) option aren't supported.
299 */
300 type?: "indexed" | "log" | "timeseries";
301}
302
303export interface YTickConfiguration {
304 /**
305 * Show or hide outer tick.
306 */
307 outer?: boolean;
308
309 /**
310 * Set the y values of ticks manually.
311 */
312 values?: number[] | ((this: Chart) => number[]);
313
314 /**
315 * Rotate y(or y2) axis tick text.
316 * - If you set negative value, it will rotate to opposite direction.
317 * - Applied when 'axis.rotated' option is 'true'.
318 */
319 rotate?: number;
320
321 /**
322 * The number of y axis ticks to show.
323 * The position of the ticks will be calculated precisely, so the values on the ticks will not be rounded nicely.
324 * In the case, axis.y.tick.format or axis.y.tick.values will be helpful.
325 */
326 count?: number;
327
328 /**
329 * Set formatter for y axis tick text.
330 * This option accepts d3.format object as well as a function you define.
331 */
332 format?(this: Chart, x: number): string;
333
334 /**
335 * Setting for culling ticks.
336 * If true is set, the ticks will be culled, then only limitted tick text will be shown.
337 * This option does not hide the tick lines. If false is set, all of ticks will be shown.
338 */
339 culling?: boolean | {
340 /**
341 * The number of tick texts will be adjusted to less than this value.
342 */
343 max?: number;
344 };
345
346 /**
347 * Set axis tick step(interval) size.
348 * - **NOTE:** Will be ignored if `axis[y|y2].tick.count` or `axis[y|y2].tick.values` options are set.
349 */
350 stepSize?: number;
351
352 /**
353 * Show or hide axis tick line.
354 */
355 show?: boolean;
356
357 text?: {
358 /**
359 * Set the x Axis tick text's position relatively its original position
360 */
361 position?: {
362 x?: number;
363 y?: number;
364 };
365
366 /**
367 * Show or hide axis tick text.
368 */
369 show?: boolean;
370 };
371}
372
373export interface AxesConfiguration {
374 /**
375 * Set the axis domain value
376 * if set, will not be correlated with the main x Axis domain value
377 */
378 domain?: [number, number];
379
380 /**
381 * Set axis tick options
382 */
383 tick?: {
384 /**
385 * Show outer tick
386 */
387 outer?: boolean;
388
389 /**
390 * Set formatter for tick text
391 */
392 format?: (this: Chart, x: string) => string;
393
394 /**
395 * Set the number of y axis ticks
396 */
397 count?: number;
398
399 /**
400 * Set tick values manually
401 */
402 values?: number|string|Date[];
403 };
404}