billboard.js 3.7.5 → 3.8.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/billboard.css +1 -1
  2. package/dist/billboard.js +468 -268
  3. package/dist/billboard.min.css +1 -1
  4. package/dist/billboard.min.js +2 -2
  5. package/dist/billboard.pkgd.js +512 -284
  6. package/dist/billboard.pkgd.min.js +3 -3
  7. package/dist/plugin/billboardjs-plugin-bubblecompare.js +2 -2
  8. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  9. package/dist/plugin/billboardjs-plugin-sparkline.js +36 -19
  10. package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
  11. package/dist/plugin/billboardjs-plugin-stanford.js +35 -19
  12. package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
  13. package/dist/plugin/billboardjs-plugin-tableview.js +32 -18
  14. package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
  15. package/dist/plugin/billboardjs-plugin-textoverlap.js +33 -18
  16. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  17. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.js +45 -17
  18. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.js +80 -35
  19. package/dist/plugin/pkgd/billboardjs-plugin-stanford.js +80 -36
  20. package/dist/plugin/pkgd/billboardjs-plugin-tableview.js +77 -35
  21. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.js +133 -69
  22. package/dist/theme/datalab.css +1 -1
  23. package/dist/theme/datalab.min.css +1 -1
  24. package/dist/theme/graph.css +1 -1
  25. package/dist/theme/graph.min.css +1 -1
  26. package/dist/theme/insight.css +1 -1
  27. package/dist/theme/insight.min.css +1 -1
  28. package/dist-esm/billboard.js +349 -213
  29. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +2 -2
  30. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +10 -11
  31. package/dist-esm/plugin/billboardjs-plugin-stanford.js +6 -11
  32. package/dist-esm/plugin/billboardjs-plugin-tableview.js +7 -12
  33. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +2 -7
  34. package/package.json +28 -28
  35. package/src/Chart/api/focus.ts +4 -4
  36. package/src/Chart/api/grid.ts +206 -0
  37. package/src/Chart/api/load.ts +31 -21
  38. package/src/Chart/api/regions.ts +28 -24
  39. package/src/Chart/api/zoom.ts +18 -3
  40. package/src/ChartInternal/Axis/Axis.ts +1 -0
  41. package/src/ChartInternal/Axis/AxisRenderer.ts +7 -2
  42. package/src/ChartInternal/ChartInternal.ts +1 -1
  43. package/src/ChartInternal/data/convert.ts +6 -3
  44. package/src/ChartInternal/data/data.ts +19 -15
  45. package/src/ChartInternal/data/load.ts +19 -4
  46. package/src/ChartInternal/interactions/eventrect.ts +3 -2
  47. package/src/ChartInternal/interactions/subchart.ts +3 -2
  48. package/src/ChartInternal/interactions/zoom.ts +10 -3
  49. package/src/ChartInternal/internals/clip.ts +3 -2
  50. package/src/ChartInternal/internals/domain.ts +17 -8
  51. package/src/ChartInternal/internals/legend.ts +4 -1
  52. package/src/ChartInternal/internals/redraw.ts +0 -16
  53. package/src/ChartInternal/internals/region.ts +9 -9
  54. package/src/ChartInternal/internals/scale.ts +7 -4
  55. package/src/ChartInternal/internals/size.axis.ts +14 -4
  56. package/src/ChartInternal/internals/size.ts +41 -18
  57. package/src/ChartInternal/internals/transform.ts +1 -1
  58. package/src/ChartInternal/internals/type.ts +10 -0
  59. package/src/ChartInternal/shape/point.ts +3 -2
  60. package/src/Plugin/sparkline/index.ts +9 -1
  61. package/src/config/Options/axis/x.ts +17 -0
  62. package/src/config/Options/axis/y.ts +2 -1
  63. package/src/config/Options/axis/y2.ts +2 -1
  64. package/src/config/Options/common/main.ts +19 -1
  65. package/src/config/resolver/axis.ts +2 -4
  66. package/src/module/browser.ts +13 -5
  67. package/src/module/generator.ts +3 -3
  68. package/src/module/util.ts +2 -2
  69. package/types/axis.d.ts +8 -7
  70. package/types/chart.d.ts +6 -1
  71. package/types/options.d.ts +7 -4
  72. package/src/Chart/api/grid.x.ts +0 -90
  73. package/src/Chart/api/grid.y.ts +0 -92
@@ -50,7 +50,7 @@ export default {
50
50
  const $$ = this;
51
51
  const scale = $$.scale.zoom || getScale($$.axis.getAxisType("x"), min, max);
52
52
 
53
- return $$.getCustomizedScale(
53
+ return $$.getCustomizedXScale(
54
54
  domain ? scale.domain(domain) : scale,
55
55
  offset
56
56
  );
@@ -89,15 +89,16 @@ export default {
89
89
  },
90
90
 
91
91
  /**
92
- * Get customized scale
92
+ * Get customized x axis scale
93
93
  * @param {d3.scaleLinear|d3.scaleTime} scaleValue Scale function
94
94
  * @param {Function} offsetValue Offset getter to be sum
95
95
  * @returns {Function} Scale function
96
96
  * @private
97
97
  */
98
- getCustomizedScale(scaleValue: Function | any, offsetValue): Function {
98
+ getCustomizedXScale(scaleValue: Function | any, offsetValue): Function {
99
99
  const $$ = this;
100
100
  const offset = offsetValue || (() => $$.axis.x.tickOffset());
101
+ const isInverted = $$.config.axis_x_inverted;
101
102
  const scale = function(d, raw) {
102
103
  const v = scaleValue(d) + offset();
103
104
 
@@ -120,7 +121,9 @@ export default {
120
121
  if (!arguments.length) {
121
122
  domain = this.orgDomain();
122
123
 
123
- return [domain[0], domain[1] + 1];
124
+ return isInverted ?
125
+ [domain[0] + 1, domain[1]] :
126
+ [domain[0], domain[1] + 1];
124
127
  }
125
128
 
126
129
  scaleValue.domain(domain);
@@ -29,7 +29,9 @@ export default {
29
29
  const gap = width === 0 ? 0.5 : 0;
30
30
 
31
31
  return width + (
32
- position.isInner ? (20 + gap) : 40
32
+ $$.config.padding?.mode === "fit" ?
33
+ position.isInner ? (10 + gap) : 10 :
34
+ position.isInner ? (20 + gap) : 40
33
35
  );
34
36
  } else {
35
37
  return 40;
@@ -41,7 +43,10 @@ export default {
41
43
  const {config, state} = $$;
42
44
  const {current, rotatedPadding, isLegendRight, isLegendInset} = state;
43
45
  const isRotated = config.axis_rotated;
44
- let h = 30;
46
+ const isFitPadding = config.padding?.mode === "fit";
47
+ const isInner = config[`axis_${id}_inner`];
48
+ const hasLabelText = config[`axis_${id}_label`].text;
49
+ let h = config.padding?.mode === "fit" ? (isInner && !hasLabelText ? (id === "y" ? 1 : 0) : 20) : 30;
45
50
 
46
51
  if (id === "x" && !config.axis_x_show) {
47
52
  return 8;
@@ -58,7 +63,7 @@ export default {
58
63
  }
59
64
 
60
65
  if (id === "y2" && !config.axis_y2_show) {
61
- return rotatedPadding.top;
66
+ return isFitPadding ? 0 : rotatedPadding.top;
62
67
  }
63
68
 
64
69
  const rotate = $$.getAxisTickRotate(id);
@@ -84,7 +89,12 @@ export default {
84
89
  },
85
90
 
86
91
  getEventRectWidth(): number {
87
- return Math.max(0, this.axis.x.tickInterval());
92
+ const $$ = this;
93
+ const {config, axis} = $$;
94
+ const isInverted = config.axis_x_inverted;
95
+ const tickInterval = axis.x.tickInterval();
96
+
97
+ return Math.max(0, isInverted ? Math.abs(tickInterval) : tickInterval);
88
98
  },
89
99
 
90
100
  /**
@@ -69,20 +69,26 @@ export default {
69
69
  const $$ = this;
70
70
  const {config, state: {hasAxis}} = $$;
71
71
  const isRotated = config.axis_rotated;
72
+ const isFitPadding = config.padding?.mode === "fit";
72
73
  const axisId = isRotated ? "x" : "y";
73
74
  const axesLen = hasAxis ? config[`axis_${axisId}_axes`].length : 0;
74
- const axisWidth = hasAxis ? $$.getAxisWidthByAxisId(axisId, withoutRecompute) : 0;
75
- let padding;
75
+ let axisWidth = hasAxis ? $$.getAxisWidthByAxisId(axisId, withoutRecompute) : 0;
76
+
77
+ if (!isFitPadding) {
78
+ axisWidth = ceil10(axisWidth);
79
+ }
80
+
81
+ let padding = config[`axis_${axisId}_inner`] || !config[`axis_${axisId}_show`] ? 0 : axisWidth;
76
82
 
77
83
  if (isValue(config.padding_left)) {
78
- padding = config.padding_left;
84
+ padding = config.padding_left + (isFitPadding && isRotated ? axisWidth : 0);
79
85
  } else if (hasAxis && isRotated) {
80
86
  padding = !config.axis_x_show ?
81
- 1 : Math.max(ceil10(axisWidth), 40);
82
- } else if (hasAxis && (!config.axis_y_show || config.axis_y_inner)) { // && !config.axis_rotated
83
- padding = $$.axis.getAxisLabelPosition("y").isOuter ? 30 : 1;
84
- } else {
85
- padding = ceil10(axisWidth);
87
+ 1 : (isFitPadding ? axisWidth : Math.max(axisWidth, 40));
88
+ }
89
+
90
+ if (hasAxis && (isFitPadding || config[`axis_${axisId}_inner`]) && config[`axis_${axisId}_label`].text) {
91
+ padding += $$.axis.getAxisLabelPosition("y").isOuter ? 20 : 0;
86
92
  }
87
93
 
88
94
  return padding + (axisWidth * axesLen);
@@ -91,25 +97,41 @@ export default {
91
97
  getCurrentPaddingRight(withXAxisTickTextOverflow = false): number {
92
98
  const $$ = this;
93
99
  const {config, state: {hasAxis}} = $$;
94
- const defaultPadding = 10;
100
+ const isRotated = config.axis_rotated;
101
+ const isFitPadding = config.padding?.mode === "fit";
102
+ const defaultPadding = isFitPadding ? 2 : 10;
95
103
  const legendWidthOnRight = $$.state.isLegendRight ? $$.getLegendWidth() + 20 : 0;
96
104
  const axesLen = hasAxis ? config.axis_y2_axes.length : 0;
97
- const axisWidth = hasAxis ? $$.getAxisWidthByAxisId("y2") : 0;
105
+ const axisLabelWidth = $$.axis?.getAxisLabelPosition("y2").isOuter ? 20 : 0;
98
106
  const xAxisTickTextOverflow = withXAxisTickTextOverflow ?
99
107
  $$.axis.getXAxisTickTextY2Overflow(defaultPadding) : 0;
100
- let padding;
108
+ let axisWidth = hasAxis && !config.axis_y2_inner ? $$.getAxisWidthByAxisId("y2") : 1;
109
+
110
+ if (!isFitPadding) {
111
+ axisWidth = ceil10(axisWidth);
112
+ }
113
+
114
+ let padding = isRotated ? 0 : Math.max(axisWidth + legendWidthOnRight, xAxisTickTextOverflow);
101
115
 
102
116
  if (isValue(config.padding_right)) {
103
- padding = config.padding_right + (hasAxis ? 1 : 0); // 1 is needed not to hide tick line
104
- } else if ($$.axis && config.axis_rotated) {
117
+ // padding = config.padding_right + (hasAxis ? 1 : 0); // 1 is needed not to hide tick line
118
+
119
+ padding = config.padding_right +
120
+ (isFitPadding && (isRotated || !config.axis_y2_show ? defaultPadding : padding)) +
121
+ (hasAxis && !isFitPadding ? 1 : 0); // 1 is needed not to hide tick line
122
+ } else if ($$.axis && isRotated) {
105
123
  padding = defaultPadding + legendWidthOnRight;
106
- } else if ($$.axis && (!config.axis_y2_show || config.axis_y2_inner)) { // && !config.axis_rotated
124
+ } else if ($$.axis && (!config.axis_y2_show || config.axis_y2_inner)) {
107
125
  padding = Math.max(
108
- 2 + legendWidthOnRight + ($$.axis.getAxisLabelPosition("y2").isOuter ? 20 : 0),
126
+ (isFitPadding && !config.axis_y2_show ? 2 : 1) + legendWidthOnRight + axisLabelWidth,
109
127
  xAxisTickTextOverflow
110
128
  );
111
- } else {
112
- padding = Math.max(ceil10(axisWidth) + legendWidthOnRight, xAxisTickTextOverflow);
129
+ }
130
+
131
+ if (hasAxis && !isRotated && isFitPadding &&
132
+ config.axis_y2_show && !config.axis_y2_inner && config.axis_y2_label.text
133
+ ) {
134
+ padding += axisLabelWidth;
113
135
  }
114
136
 
115
137
  return padding + (axisWidth * axesLen);
@@ -282,6 +304,7 @@ export default {
282
304
  const {config, state, $el: {legend}} = $$;
283
305
  const isRotated = config.axis_rotated;
284
306
  const isNonAxis = $$.hasArcType() || state.hasTreemap;
307
+ const isFitPadding = config.padding?.mode === "fit";
285
308
 
286
309
  !isInit && $$.setContainerSize();
287
310
 
@@ -311,7 +334,7 @@ export default {
311
334
  bottom: $$.getHorizontalAxisHeight("y") + legendHeightForBottom + padding.bottom,
312
335
  left: subchartHeight + (isNonAxis ? 0 : padding.left)
313
336
  } : {
314
- top: 4 + padding.top, // for top tick text
337
+ top: (isFitPadding ? 0 : 4) + padding.top, // for top tick text
315
338
  right: isNonAxis ? 0 : $$.getCurrentPaddingRight(true),
316
339
  bottom: xAxisHeight + subchartHeight + legendHeightForBottom + padding.bottom,
317
340
  left: isNonAxis ? 0 : padding.left
@@ -37,7 +37,7 @@ export default {
37
37
  y = isRotated ? state.height + padding : 0;
38
38
  } else if (target === "y2") {
39
39
  x = isRotated ? 0 : state.width + padding;
40
- y = isRotated ? 1 - padding : 0;
40
+ y = isRotated && padding ? 1 - padding : 0;
41
41
  } else if (target === "subX") {
42
42
  x = 0;
43
43
  y = isRotated ? 0 : state.height2;
@@ -6,6 +6,16 @@ import {isArray, isNumber, isString} from "../../module/util";
6
6
  import {TYPE, TYPE_BY_CATEGORY} from "../../config/const";
7
7
 
8
8
  export default {
9
+ /**
10
+ * Check if the given chart type is valid
11
+ * @param {string} type Chart type string
12
+ * @returns {boolean}
13
+ * @private
14
+ */
15
+ isValidChartType(type: string): boolean {
16
+ return !!(type && Object.values(TYPE).indexOf(type) > -1);
17
+ },
18
+
9
19
  setTargetType(targetIds: string[], type: string): void {
10
20
  const $$ = this;
11
21
  const {config, state: {withoutFadeIn}} = $$;
@@ -9,6 +9,7 @@ import {
9
9
  import type {d3Selection} from "../../../types/types";
10
10
  import {$CIRCLE, $COMMON, $SELECT} from "../../config/classes";
11
11
  import {document} from "../../module/browser";
12
+ import type {IDataRow} from "../data/IData";
12
13
  import {getBoundingRect, getPointer, getRandom, isFunction, isObject, isObjectType, isUndefined, isValue, toArray, notEmpty} from "../../module/util";
13
14
 
14
15
  const getTransitionName = () => getRandom();
@@ -188,7 +189,7 @@ export default {
188
189
  * @param {object} d Selected data
189
190
  * @private
190
191
  */
191
- showCircleFocus(d?): void {
192
+ showCircleFocus(d?: IDataRow[]): void {
192
193
  const $$ = this;
193
194
  const {config, state: {hasRadar, resizing, toggling, transiting}, $el} = $$;
194
195
  let {circle} = $el;
@@ -202,7 +203,7 @@ export default {
202
203
  if (d) {
203
204
  circle = circle
204
205
  .filter(function(t) {
205
- const data = d.filter(v => v.id === t.id);
206
+ const data = d.filter?.(v => v.id === t.id);
206
207
 
207
208
  return data.length ?
208
209
  d3Select(this).datum(data[0]) : false;
@@ -221,6 +221,11 @@ export default class Sparkline extends Plugin {
221
221
  }
222
222
 
223
223
  $$.state.event = e;
224
+
225
+ if ($$.config.point_focus_only && d) {
226
+ $$.showCircleFocus?.([d]);
227
+ }
228
+
224
229
  $$.setExpand(index, data.id, true);
225
230
  $$.showTooltip([d], e.target);
226
231
  }
@@ -229,7 +234,10 @@ export default class Sparkline extends Plugin {
229
234
  const {$$} = this;
230
235
 
231
236
  $$.state.event = e;
232
- $$.unexpandCircles();
237
+
238
+ $$.config.point_focus_only ?
239
+ $$.hideCircleFocus() : $$.unexpandCircles();
240
+
233
241
  $$.hideTooltip();
234
242
  }
235
243
 
@@ -510,6 +510,23 @@ export default {
510
510
  */
511
511
  axis_x_min: <number|undefined> undefined,
512
512
 
513
+ /**
514
+ * Change the direction of x axis.<br><br>
515
+ * If true set, the direction will be `right -> left`.
516
+ * @name axis․x․inverted
517
+ * @memberof Options
518
+ * @type {boolean}
519
+ * @default false
520
+ * @see [Demo](https://naver.github.io/billboard.js/demo/#Axis.InvertedAxis)
521
+ * @example
522
+ * axis: {
523
+ * x: {
524
+ * inverted: true
525
+ * }
526
+ * }
527
+ */
528
+ axis_x_inverted: false,
529
+
513
530
  /**
514
531
  * Set padding for x axis.<br><br>
515
532
  * If this option is set, the range of x axis will increase/decrease according to the values.
@@ -96,11 +96,12 @@ export default {
96
96
 
97
97
  /**
98
98
  * Change the direction of y axis.<br><br>
99
- * If true set, the direction will be from the top to the bottom.
99
+ * If true set, the direction will be `top -> bottom`.
100
100
  * @name axis․y․inverted
101
101
  * @memberof Options
102
102
  * @type {boolean}
103
103
  * @default false
104
+ * @see [Demo](https://naver.github.io/billboard.js/demo/#Axis.InvertedAxis)
104
105
  * @example
105
106
  * axis: {
106
107
  * y: {
@@ -83,11 +83,12 @@ export default {
83
83
 
84
84
  /**
85
85
  * Change the direction of y2 axis.<br><br>
86
- * If true set, the direction will be from the top to the bottom.
86
+ * If true set, the direction will be `top -> bottom`.
87
87
  * @name axis․y2․inverted
88
88
  * @memberof Options
89
89
  * @type {boolean}
90
90
  * @default false
91
+ * @see [Demo](https://naver.github.io/billboard.js/demo/#Axis.InvertedAxis)
91
92
  * @example
92
93
  * axis: {
93
94
  * y2: {
@@ -114,15 +114,30 @@ export default {
114
114
  * - `false`: Remove padding completely and make shape to fully occupy the container element.
115
115
  * - In this case, axes and subchart will be hidden.
116
116
  * - To adjust some padding from this state, use `axis.[x|y].padding` option.
117
+ * @property {string} [padding.mode] padding mode
118
+ * - `"fit"`: Reduce padding as much as possible to make chart fit to the container element for chart types w/axis.<br>When specified, all padding values will be relative from fitted value.
117
119
  * @property {number} [padding.top] padding on the top of chart
118
120
  * @property {number} [padding.right] padding on the right of chart
119
121
  * @property {number} [padding.bottom] padding on the bottom of chart
120
122
  * @property {number} [padding.left] padding on the left of chart
121
123
  * @see [Demo](https://naver.github.io/billboard.js/demo/#ChartOptions.Padding)
124
+ * @see [Demo: Fit padding](https://naver.github.io/billboard.js/demo/#ChartOptions.FitPadding)
122
125
  * @example
123
126
  * // remove padding completely.
124
127
  * padding: false,
125
128
  *
129
+ * padding: {
130
+ * // specifying mode value, will reduce padding and make fit to the container element.
131
+ * mode: "fit"
132
+ *
133
+ * // when mode is "fit", all padding values will be relative from fitted value.
134
+ * // so, 0 will be initial fitted value.
135
+ * top: 20,
136
+ * right: 20,
137
+ * bottom: 20,
138
+ * left: 20
139
+ * }
140
+ *
126
141
  * // or specify padding value for each side
127
142
  * padding: {
128
143
  * top: 20,
@@ -132,6 +147,7 @@ export default {
132
147
  * }
133
148
  */
134
149
  padding: true,
150
+ padding_mode: <"fit"|undefined> undefined,
135
151
  padding_left: <number|undefined> undefined,
136
152
  padding_right: <number|undefined> undefined,
137
153
  padding_top: <number|undefined> undefined,
@@ -146,7 +162,9 @@ export default {
146
162
  * @property {boolean} [resize.auto=true] Set chart resize automatically on viewport changes.
147
163
  * @property {boolean|number} [resize.timer=true] Set resize timer option.
148
164
  * - **NOTE:**
149
- * - The resize function will be called using: true - `setTimeout()`, false - `requestIdleCallback()`.
165
+ * - The resize function will be called using:
166
+ * - true: `setTimeout()`
167
+ * - false: `requestIdleCallback()`
150
168
  * - Given number(delay in ms) value, resize function will be triggered using `setTimer()` with given delay.
151
169
  * @example
152
170
  * resize: {
@@ -8,8 +8,7 @@
8
8
  // Chart
9
9
  import apiAxis from "../../Chart/api/axis";
10
10
  import apiCategory from "../../Chart/api/category";
11
- import apiXGrid from "../../Chart/api/grid.x";
12
- import apiYGrid from "../../Chart/api/grid.y";
11
+ import apiGrid from "../../Chart/api/grid";
13
12
  import apiGroup from "../../Chart/api/group";
14
13
  import apiRegion from "../../Chart/api/regions";
15
14
  import apiX from "../../Chart/api/x";
@@ -33,9 +32,8 @@ import optGrid from "../Options/common/grid";
33
32
  export const api = [
34
33
  apiAxis,
35
34
  apiCategory,
36
- apiXGrid,
37
- apiYGrid,
38
35
  apiFlow,
36
+ apiGrid,
39
37
  apiGroup,
40
38
  apiRegion,
41
39
  apiX
@@ -7,7 +7,12 @@
7
7
  * @private
8
8
  */
9
9
  /* eslint-disable no-new-func, no-undef */
10
- export {win as window, doc as document};
10
+ export {
11
+ win as window,
12
+ doc as document,
13
+ requestAnimationFrame, cancelAnimationFrame,
14
+ requestIdleCallback, cancelIdleCallback
15
+ };
11
16
 
12
17
  const win = (() => {
13
18
  const root = (typeof globalThis === "object" && globalThis !== null && globalThis.Object === Object && globalThis) ||
@@ -19,9 +24,12 @@ const win = (() => {
19
24
  /* eslint-enable no-new-func, no-undef */
20
25
 
21
26
  // fallback for non-supported environments
22
- win.requestIdleCallback = win.requestIdleCallback || (cb => setTimeout(cb, 1));
23
- // win.cancelIdleCallback = win.cancelIdleCallback || (id => clearTimeout(id));
24
- win.requestAnimationFrame = win.requestAnimationFrame || (cb => setTimeout(cb, 1));
27
+ const hasRAF = typeof win.requestAnimationFrame === "function";
28
+ const hasRIC = typeof win.requestIdleCallback === "function";
25
29
 
26
- const doc = win?.document;
30
+ const requestAnimationFrame = hasRAF ? win.requestAnimationFrame : (cb => setTimeout(cb, 1));
31
+ const cancelAnimationFrame = hasRAF ? win.cancelAnimationFrame : (id => clearTimeout(id));
32
+ const requestIdleCallback = hasRIC ? win.requestIdleCallback : requestAnimationFrame;
33
+ const cancelIdleCallback = hasRIC ? win.cancelIdleCallback : cancelAnimationFrame;
27
34
 
35
+ const doc = win?.document;
@@ -3,7 +3,7 @@
3
3
  * billboard.js project is licensed under the MIT license
4
4
  */
5
5
  import type {d3Transition} from "../../types/types";
6
- import {window} from "./browser";
6
+ import {window, requestIdleCallback} from "./browser";
7
7
  import {isArray, isNumber, isTabVisible, runUntil} from "./util";
8
8
 
9
9
  const {setTimeout, clearTimeout} = window;
@@ -15,14 +15,14 @@ const {setTimeout, clearTimeout} = window;
15
15
  * @private
16
16
  */
17
17
  export function generateResize(option: boolean|number) {
18
- const fn: any[] = [];
18
+ const fn: Function[] = [];
19
19
  let timeout;
20
20
 
21
21
  const callResizeFn = function() {
22
22
  // Delay all resize functions call, to prevent unintended excessive call from resize event
23
23
  callResizeFn.clear();
24
24
 
25
- if (option === false && window.requestIdleCallback) {
25
+ if (option === false) {
26
26
  requestIdleCallback(() => {
27
27
  fn.forEach((f: Function) => f());
28
28
  }, {timeout: 200});
@@ -6,7 +6,7 @@
6
6
  import {pointer as d3Pointer} from "d3-selection";
7
7
  import {brushSelection as d3BrushSelection} from "d3-brush";
8
8
  import type {d3Selection} from "../../types/types";
9
- import {document, window} from "./browser";
9
+ import {document, window, requestAnimationFrame} from "./browser";
10
10
 
11
11
  export {
12
12
  addCssRules,
@@ -808,7 +808,7 @@ function convertInputType(mouse: boolean, touch: boolean): "mouse" | "touch" | n
808
808
  */
809
809
  function runUntil(fn: Function, conditionFn: Function): void {
810
810
  if (conditionFn() === false) {
811
- window.requestAnimationFrame(() => runUntil(fn, conditionFn));
811
+ requestAnimationFrame(() => runUntil(fn, conditionFn));
812
812
  } else {
813
813
  fn();
814
814
  }
package/types/axis.d.ts CHANGED
@@ -24,6 +24,12 @@ export interface AxisConfigurationBase {
24
24
  * Set additional axes for Axis
25
25
  */
26
26
  axes?: AxesConfiguration[];
27
+
28
+ /**
29
+ * Change the direction of axis.
30
+ * If true set, the direction will be from: right -> left for x axis / top -> bottom for y/y2 axis.
31
+ */
32
+ inverted?: boolean;
27
33
  }
28
34
 
29
35
  export interface xAxisConfiguration extends AxisConfigurationBase {
@@ -135,12 +141,6 @@ export interface yAxisConfigurationBase extends AxisConfigurationBase {
135
141
  */
136
142
  min?: number;
137
143
 
138
- /**
139
- * Change the direction of y axis.
140
- * If true set, the direction will be from the top to the bottom.
141
- */
142
- inverted?: boolean;
143
-
144
144
  /**
145
145
  * Set center value of y axis.
146
146
  */
@@ -352,7 +352,8 @@ export interface YTickConfiguration {
352
352
  * Set formatter for y axis tick text.
353
353
  * This option accepts d3.format object as well as a function you define.
354
354
  */
355
- format?: ((this: Chart, x: number) => string | number) | ((this: Chart, x: Date) => string | number);
355
+ format?: ((this: Chart, x: number) => string | number) |
356
+ ((this: Chart, x: Date) => string | number);
356
357
 
357
358
  /**
358
359
  * Setting for culling ticks.
package/types/chart.d.ts CHANGED
@@ -364,6 +364,7 @@ export interface Chart {
364
364
  types?: { [key: string]: string };
365
365
  unload?: boolean | ArrayOrString;
366
366
  done?: (this: Chart) => void;
367
+ resizeAfter?: boolean;
367
368
  }): void;
368
369
 
369
370
  /**
@@ -378,7 +379,11 @@ export interface Chart {
378
379
  * - If you call load API soon after/before unload, unload param of load should be used. Otherwise chart will not be rendered properly because of cancel of animation.
379
380
  * - done will be called after data loaded, but it's not after rendering. It's because rendering will finish after some transition and there is some time lag between loading and rendering.
380
381
  */
381
- unload(this: Chart, targetIds?: TargetIds, done?: (this: Chart) => void): void;
382
+ unload(this: Chart, args?: TargetIds | {
383
+ ids?: TargetIds,
384
+ done?: (this: Chart) => void,
385
+ resizeAfter?: boolean;
386
+ }): void;
382
387
 
383
388
  /**
384
389
  * Flow data to the chart. By this API, you can append new data points to the chart.
@@ -4,9 +4,6 @@
4
4
  */
5
5
  import {Axis} from "./axis";
6
6
  import {ChartTypes, d3Selection, DataItem, PrimitiveArray} from "./types";
7
- import Bubblecompare from "./plugin/bubblecompare/index";
8
- import Stanford from "./plugin/stanford/index";
9
- import TextOverlap from "./plugin/textoverlap/index";
10
7
  import {Chart} from "./chart";
11
8
  import {IArcData, IData, IDataRow} from "../src/ChartInternal/data/IData";
12
9
  import {
@@ -113,6 +110,12 @@ export interface ChartOptions {
113
110
  * - To adjust some padding from this state, use `axis.[x|y].padding` option.
114
111
  */
115
112
  padding?: boolean | {
113
+ /**
114
+ * Padding mode
115
+ * - `"fit"`: Reduce padding as much as possible to make chart fit to the container element for chart types w/axis.<br>When specified, all padding values will be relative from fitted value.
116
+ */
117
+ mode?: "fit";
118
+
116
119
  /**
117
120
  * The padding on the top of the chart.
118
121
  */
@@ -328,7 +331,7 @@ export interface ChartOptions {
328
331
  /**
329
332
  * Set plugins
330
333
  */
331
- plugins?: Array<(Bubblecompare | Stanford | TextOverlap)>;
334
+ plugins?: Array<InstanceType<any>>;
332
335
 
333
336
  /**
334
337
  * Control the render timing
@@ -1,90 +0,0 @@
1
- /**
2
- * Copyright (c) 2017 ~ present NAVER Corp.
3
- * billboard.js project is licensed under the MIT license
4
- */
5
- import {extend} from "../../module/util";
6
-
7
- type GridsParam = {value?: number, class?: string, text?: string}[];
8
-
9
- /**
10
- * Update x grid lines.
11
- * @function xgrids
12
- * @instance
13
- * @memberof Chart
14
- * @param {Array} grids X grid lines will be replaced with this argument. The format of this argument is the same as grid.x.lines.
15
- * @returns {object}
16
- * @example
17
- * // Show 2 x grid lines
18
- * chart.xgrids([
19
- * {value: 1, text: "Label 1"},
20
- * {value: 4, text: "Label 4"}
21
- * ]);
22
- * // --> Returns: [{value: 1, text: "Label 1"}, {value: 4, text: "Label 4"}]
23
- */
24
- const xgrids = function(grids: GridsParam): GridsParam {
25
- const $$ = this.internal;
26
- const {config} = $$;
27
-
28
- if (!grids) {
29
- return config.grid_x_lines;
30
- }
31
-
32
- config.grid_x_lines = grids;
33
- $$.redrawWithoutRescale();
34
-
35
- return config.grid_x_lines;
36
- };
37
-
38
- extend(xgrids, {
39
- /**
40
- * Add x grid lines.<br>
41
- * This API adds new x grid lines instead of replacing like xgrids.
42
- * @function xgrids․add
43
- * @instance
44
- * @memberof Chart
45
- * @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.
46
- * @returns {object}
47
- * @example
48
- * // Add a new x grid line
49
- * chart.xgrids.add(
50
- * {value: 4, text: "Label 4"}
51
- * );
52
- *
53
- * // Add new x grid lines
54
- * chart.xgrids.add([
55
- * {value: 2, text: "Label 2"},
56
- * {value: 4, text: "Label 4"}
57
- * ]);
58
- */
59
- add: function(grids: GridsParam): GridsParam {
60
- return this.xgrids(
61
- this.internal.config.grid_x_lines
62
- .concat(grids || [])
63
- );
64
- },
65
-
66
- /**
67
- * Remove x grid lines.<br>
68
- * This API removes x grid lines.
69
- * @function xgrids․remove
70
- * @instance
71
- * @memberof Chart
72
- * @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.
73
- * @example
74
- * // x grid line on x = 2 will be removed
75
- * chart.xgrids.remove({value: 2});
76
- *
77
- * // x grid lines that have 'grid-A' will be removed
78
- * chart.xgrids.remove({
79
- * class: "grid-A"
80
- * });
81
- *
82
- * // all of x grid lines will be removed
83
- * chart.xgrids.remove();
84
- */
85
- remove: function(params?: GridsParam): void { // TODO: multiple
86
- this.internal.removeGridLines(params, true);
87
- }
88
- });
89
-
90
- export default {xgrids};