billboard.js 3.9.3 → 3.10.0-next.1

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 (91) hide show
  1. package/README.md +2 -2
  2. package/dist/billboard.css +2 -2
  3. package/dist/billboard.js +2687 -2541
  4. package/dist/billboard.min.css +2 -2
  5. package/dist/billboard.min.js +2 -2
  6. package/dist/billboard.pkgd.js +3493 -3331
  7. package/dist/billboard.pkgd.min.js +4 -4
  8. package/dist/plugin/billboardjs-plugin-bubblecompare.js +15 -15
  9. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  10. package/dist/plugin/billboardjs-plugin-sparkline.js +215 -196
  11. package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
  12. package/dist/plugin/billboardjs-plugin-stanford.js +244 -239
  13. package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
  14. package/dist/plugin/billboardjs-plugin-tableview.js +184 -164
  15. package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
  16. package/dist/plugin/billboardjs-plugin-textoverlap.js +170 -151
  17. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  18. package/dist/plugin/pkgd/{billboardjs-plugin-bubblecompare.js → billboardjs-plugin-bubblecompare.pkgd.js} +664 -634
  19. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +12 -0
  20. package/dist/plugin/pkgd/{billboardjs-plugin-sparkline.js → billboardjs-plugin-sparkline.pkgd.js} +861 -812
  21. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +12 -0
  22. package/dist/plugin/pkgd/{billboardjs-plugin-stanford.js → billboardjs-plugin-stanford.pkgd.js} +926 -892
  23. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +12 -0
  24. package/dist/plugin/pkgd/{billboardjs-plugin-tableview.js → billboardjs-plugin-tableview.pkgd.js} +830 -780
  25. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +12 -0
  26. package/dist/plugin/pkgd/{billboardjs-plugin-textoverlap.js → billboardjs-plugin-textoverlap.pkgd.js} +929 -889
  27. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +12 -0
  28. package/dist/theme/dark.css +5 -4
  29. package/dist/theme/dark.min.css +2 -2
  30. package/dist/theme/datalab.css +5 -4
  31. package/dist/theme/datalab.min.css +2 -2
  32. package/dist/theme/graph.css +5 -4
  33. package/dist/theme/graph.min.css +2 -2
  34. package/dist/theme/insight.css +5 -4
  35. package/dist/theme/insight.min.css +2 -2
  36. package/dist-esm/billboard.js +591 -462
  37. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +3 -3
  38. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +13 -7
  39. package/dist-esm/plugin/billboardjs-plugin-stanford.js +21 -28
  40. package/dist-esm/plugin/billboardjs-plugin-tableview.js +17 -11
  41. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +13 -7
  42. package/package.json +27 -27
  43. package/src/Chart/api/axis.ts +4 -0
  44. package/src/Chart/api/category.ts +8 -4
  45. package/src/Chart/api/export.ts +1 -2
  46. package/src/Chart/api/subchart.ts +162 -89
  47. package/src/Chart/api/zoom.ts +69 -79
  48. package/src/ChartInternal/Axis/AxisRendererHelper.ts +0 -8
  49. package/src/ChartInternal/data/IData.ts +4 -1
  50. package/src/ChartInternal/data/convert.helper.ts +1 -15
  51. package/src/ChartInternal/data/data.ts +8 -2
  52. package/src/ChartInternal/interactions/eventrect.ts +0 -1
  53. package/src/ChartInternal/interactions/flow.ts +1 -7
  54. package/src/ChartInternal/interactions/interaction.ts +10 -4
  55. package/src/ChartInternal/interactions/subchart.ts +36 -30
  56. package/src/ChartInternal/interactions/zoom.ts +13 -3
  57. package/src/ChartInternal/internals/category.ts +2 -2
  58. package/src/ChartInternal/internals/clip.ts +4 -4
  59. package/src/ChartInternal/internals/domain.ts +46 -10
  60. package/src/ChartInternal/internals/grid.ts +57 -86
  61. package/src/ChartInternal/internals/redraw.ts +0 -5
  62. package/src/ChartInternal/internals/region.ts +35 -12
  63. package/src/ChartInternal/internals/text.ts +1 -26
  64. package/src/ChartInternal/internals/title.ts +10 -48
  65. package/src/ChartInternal/internals/tooltip.ts +47 -51
  66. package/src/ChartInternal/shape/arc.ts +2 -2
  67. package/src/ChartInternal/shape/candlestick.ts +2 -17
  68. package/src/ChartInternal/shape/shape.ts +50 -4
  69. package/src/ChartInternal/shape/treemap.ts +2 -2
  70. package/src/Plugin/bubblecompare/index.ts +1 -1
  71. package/src/Plugin/stanford/Elements.ts +10 -2
  72. package/src/Plugin/stanford/index.ts +1 -24
  73. package/src/Plugin/tableview/index.ts +2 -2
  74. package/src/config/Options/axis/x.ts +1 -0
  75. package/src/config/Options/common/main.ts +12 -2
  76. package/src/config/Options/common/tooltip.ts +10 -10
  77. package/src/config/Options/data/axis.ts +3 -1
  78. package/src/config/Options/data/data.ts +10 -2
  79. package/src/config/Store/State.ts +3 -0
  80. package/src/module/Cache.ts +7 -5
  81. package/src/module/browser.ts +34 -14
  82. package/src/module/util.ts +8 -4
  83. package/src/module/worker.ts +24 -13
  84. package/src/scss/billboard.scss +4 -2
  85. package/src/scss/theme/dark.scss +4 -2
  86. package/src/scss/theme/datalab.scss +4 -2
  87. package/src/scss/theme/graph.scss +4 -2
  88. package/src/scss/theme/insight.scss +4 -2
  89. package/types/chart.d.ts +11 -0
  90. package/types/options.d.ts +3 -3
  91. package/types/types.d.ts +15 -1
@@ -46,6 +46,9 @@ export default class State {
46
46
  cssRule: {},
47
47
 
48
48
  current: {
49
+ // current domain value. Assigned when is zoom is called
50
+ domain: undefined,
51
+
49
52
  // chart whole dimension
50
53
  width: 0,
51
54
  height: 0,
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) 2017 ~ present NAVER Corp.
3
3
  * billboard.js project is licensed under the MIT license
4
4
  */
5
- import {isValue, toArray} from "./util";
5
+ import {isString, isValue} from "./util";
6
6
  import type {DataRow} from "../../types/types";
7
7
 
8
8
  /**
@@ -45,7 +45,8 @@ export default class Cache {
45
45
  * @private
46
46
  */
47
47
  remove(key: string | string[]) {
48
- toArray(key).forEach(v => delete this.cache[v]);
48
+ (isString(key) ? [key] : key)
49
+ .forEach(v => delete this.cache[v]);
49
50
  }
50
51
 
51
52
  /**
@@ -55,8 +56,9 @@ export default class Cache {
55
56
  * @returns {*}
56
57
  * @private
57
58
  */
58
- get(key: string, isDataType = false): any | null {
59
- if (isDataType) {
59
+ get(key: string|string[], isDataType = false): any | null {
60
+ // when is isDataType, key should be string array
61
+ if (isDataType && Array.isArray(key)) {
60
62
  const targets: any[] = [];
61
63
 
62
64
  for (let i = 0, id; (id = key[i]); i++) {
@@ -67,7 +69,7 @@ export default class Cache {
67
69
 
68
70
  return targets;
69
71
  } else {
70
- const value = this.cache[key];
72
+ const value = this.cache[key as string];
71
73
 
72
74
  return isValue(value) ? value : null;
73
75
  }
@@ -14,22 +14,42 @@ export {
14
14
  requestIdleCallback, cancelIdleCallback
15
15
  };
16
16
 
17
- const win = (() => {
18
- const root = (typeof globalThis === "object" && globalThis !== null && globalThis.Object === Object && globalThis) ||
17
+ /**
18
+ * Get global object
19
+ * @returns {object} window object
20
+ * @private
21
+ */
22
+ function getGlobal() {
23
+ return (typeof globalThis === "object" && globalThis !== null && globalThis.Object === Object && globalThis) ||
19
24
  (typeof global === "object" && global !== null && global.Object === Object && global) ||
20
- (typeof self === "object" && self !== null && self.Object === Object && self);
21
-
22
- return root || Function("return this")();
23
- })();
24
- /* eslint-enable no-new-func, no-undef */
25
+ (typeof self === "object" && self !== null && self.Object === Object && self) ||
26
+ Function("return this")();
27
+ }
25
28
 
26
- // fallback for non-supported environments
27
- const hasRAF = typeof win.requestAnimationFrame === "function";
28
- const hasRIC = typeof win.requestIdleCallback === "function";
29
+ /**
30
+ * Get fallback object
31
+ * @param {object} w global object
32
+ * @returns {Array} fallback object array
33
+ * @private
34
+ */
35
+ function getFallback(w) {
36
+ const hasRAF = typeof w?.requestAnimationFrame === "function";
37
+ const hasRIC = typeof w?.requestIdleCallback === "function";
29
38
 
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;
39
+ return [
40
+ hasRAF ? w.requestAnimationFrame : (cb => setTimeout(cb, 1)),
41
+ hasRAF ? w.cancelAnimationFrame : (id => clearTimeout(id)),
42
+ hasRIC ? w.requestIdleCallback : requestAnimationFrame,
43
+ hasRIC ? w.cancelIdleCallback : cancelAnimationFrame
44
+ ];
45
+ }
34
46
 
47
+ const win = getGlobal();
35
48
  const doc = win?.document;
49
+
50
+ const [
51
+ requestAnimationFrame,
52
+ cancelAnimationFrame,
53
+ requestIdleCallback,
54
+ cancelIdleCallback
55
+ ] = getFallback(win);
@@ -53,7 +53,7 @@ export {
53
53
  notEmpty,
54
54
  parseDate,
55
55
  runUntil,
56
- sanitise,
56
+ sanitize,
57
57
  setTextValue,
58
58
  sortValue,
59
59
  toArray,
@@ -168,9 +168,9 @@ function endall(transition, cb: Function): void {
168
168
  * @returns {string}
169
169
  * @private
170
170
  */
171
- function sanitise(str: string): string {
171
+ function sanitize(str: string): string {
172
172
  return isString(str) ?
173
- str.replace(/</g, "&lt;").replace(/>/g, "&gt;") : str;
173
+ str.replace(/<(script|img)?/ig, "&lt;").replace(/(script)?>/ig, "&gt;") : str;
174
174
  }
175
175
 
176
176
  /**
@@ -266,7 +266,11 @@ function getPathBox(
266
266
  */
267
267
  function getPointer(event, element?: Element): number[] {
268
268
  const touches = event && (event.touches || (event.sourceEvent && event.sourceEvent.touches))?.[0];
269
- const pointer = d3Pointer(touches || event, element);
269
+ let pointer = [0, 0];
270
+
271
+ try {
272
+ pointer = d3Pointer(touches || event, element);
273
+ } catch (e) {}
270
274
 
271
275
  return pointer.map(v => (isNaN(v) ? 0 : v));
272
276
  }
@@ -35,6 +35,24 @@ function getObjectURL(fn: Function, depsFn?: Function[]): string {
35
35
  return window.URL.createObjectURL(blob[key]);
36
36
  }
37
37
 
38
+ /**
39
+ * Get WebWorker instance
40
+ * @param {string} src URL object as string
41
+ * @returns {object} WebWorker instance
42
+ * @private
43
+ */
44
+ function getWorker(src) {
45
+ const worker = new window.Worker(src);
46
+
47
+ // handle error
48
+ worker.onerror = function(e) {
49
+ // eslint-disable-next-line no-console
50
+ console.error ? console.error(e) : console.log(e);
51
+ };
52
+
53
+ return worker;
54
+ }
55
+
38
56
  /**
39
57
  * Create and run on Web Worker
40
58
  * @param {boolean} useWorker Use Web Worker
@@ -61,11 +79,15 @@ function getObjectURL(fn: Function, depsFn?: Function[]): string {
61
79
  export function runWorker(
62
80
  useWorker = true, fn: Function, callback: Function, depsFn?: Function[]
63
81
  ): Function {
64
- let runFn;
82
+ let runFn = function(...args) {
83
+ const res = fn(...args);
84
+
85
+ callback(res);
86
+ };
65
87
 
66
88
  if (window.Worker && useWorker) {
67
89
  const src = getObjectURL(fn, depsFn);
68
- const worker = new window.Worker(src);
90
+ const worker = getWorker(src);
69
91
 
70
92
  runFn = function(...args) {
71
93
  // trigger worker
@@ -79,22 +101,11 @@ export function runWorker(
79
101
  return callback(e.data);
80
102
  };
81
103
 
82
- // handle error
83
- worker.onerror = function(e) {
84
- console.error(e);
85
- };
86
-
87
104
  // return new Promise((resolve, reject) => {
88
105
  // worker.onmessage = ({data}) => resolve(data);
89
106
  // worker.onerror = reject;
90
107
  // });
91
108
  };
92
- } else {
93
- runFn = function(...args) {
94
- const res = fn(...args);
95
-
96
- callback(res);
97
- };
98
109
  }
99
110
 
100
111
  return runFn;
@@ -136,8 +136,10 @@
136
136
  }
137
137
  /*-- Region --*/
138
138
  .bb-region {
139
- fill: steelblue;
140
- fill-opacity: .1;
139
+ rect {
140
+ fill: steelblue;
141
+ fill-opacity: .1;
142
+ }
141
143
  }
142
144
 
143
145
  /*-- Zoom region --*/
@@ -162,8 +162,10 @@ rect.bb-circle, use.bb-circle {
162
162
 
163
163
  /*-- Region --*/
164
164
  .bb-region {
165
- fill: steelblue;
166
- fill-opacity: 0.5;
165
+ rect {
166
+ fill: steelblue;
167
+ fill-opacity: 0.5;
168
+ }
167
169
 
168
170
  &.selected rect {
169
171
  fill: rgb(39, 201, 3);
@@ -147,8 +147,10 @@ $text-font-size: 11px;
147
147
 
148
148
  /*-- Region --*/
149
149
  .bb-region {
150
- fill: steelblue;
151
- fill-opacity: 0.1;
150
+ rect {
151
+ fill: steelblue;
152
+ fill-opacity: 0.1;
153
+ }
152
154
 
153
155
  &.selected rect {
154
156
  fill: rgb(39, 201, 3);
@@ -158,8 +158,10 @@ rect.bb-circle, use.bb-circle {
158
158
 
159
159
  /*-- Region --*/
160
160
  .bb-region {
161
- fill: steelblue;
162
- fill-opacity: 0.1;
161
+ rect {
162
+ fill: steelblue;
163
+ fill-opacity: 0.1;
164
+ }
163
165
 
164
166
  &.selected rect {
165
167
  fill: rgb(39, 201, 3);
@@ -154,8 +154,10 @@ rect.bb-circle, use.bb-circle {
154
154
 
155
155
  /*-- Region --*/
156
156
  .bb-region {
157
- fill: steelblue;
158
- fill-opacity: 0.1;
157
+ rect {
158
+ fill: steelblue;
159
+ fill-opacity: 0.1;
160
+ }
159
161
 
160
162
  &.selected rect {
161
163
  fill: rgb(39, 201, 3);
package/types/chart.d.ts CHANGED
@@ -251,6 +251,12 @@ export interface Chart {
251
251
  };
252
252
 
253
253
  subchart: {
254
+ /**
255
+ * Select subchart by giving x domain range.
256
+ * @param domain If domain range is given, the subchart will be seleted to the given domain. If no argument is given, the current subchart selection domain will be returned.
257
+ */
258
+ (domain?: Array<Date|number|string>): Array<Date|number>;
259
+
254
260
  /**
255
261
  * Hide generated subchart
256
262
  * - **NOTE:** for ESM imports, needs to import 'subchart' exports and instantiate it by calling `subchart()`.
@@ -268,6 +274,11 @@ export interface Chart {
268
274
  * - **NOTE:** for ESM imports, needs to import 'subchart' exports and instantiate it by calling `subchart()`.
269
275
  */
270
276
  toggle(): void;
277
+
278
+ /**
279
+ * Reset subchart selection
280
+ */
281
+ reset(): void;
271
282
  };
272
283
 
273
284
  tooltip: {
@@ -646,14 +646,14 @@ export interface TooltipOptions {
646
646
  /**
647
647
  * Set x Axis index to be shown at the initialization.
648
648
  */
649
- x?: number;
649
+ x?: number | string;
650
650
 
651
651
  /**
652
652
  * Set the position of tooltip at the initialization.
653
653
  */
654
654
  position?: {
655
- top?: string;
656
- left?: string;
655
+ top?: number | string;
656
+ left?: number | string;
657
657
  }
658
658
  };
659
659
 
package/types/types.d.ts CHANGED
@@ -54,7 +54,7 @@ export interface DataItem<T=number> {
54
54
 
55
55
  export type DataArray = DataRow[];
56
56
 
57
- export interface RegionsType {
57
+ export interface DataRegionsType {
58
58
  [key: string]: {
59
59
  start?: number;
60
60
  end?: number;
@@ -63,3 +63,17 @@ export interface RegionsType {
63
63
  }
64
64
  };
65
65
  }
66
+
67
+ export interface RegionsType {
68
+ axis?: "x" | "y" | "y2";
69
+ start?: number;
70
+ end?: number;
71
+ class?: string;
72
+ label?: {
73
+ text: string;
74
+ x?: number;
75
+ y?: number;
76
+ color?: string;
77
+ rotated?: boolean;
78
+ };
79
+ }