billboard.js 3.4.0 → 3.5.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 (70) hide show
  1. package/README.md +11 -4
  2. package/dist/billboard.css +1 -1
  3. package/dist/billboard.js +3901 -1451
  4. package/dist/billboard.min.css +1 -1
  5. package/dist/billboard.min.js +2 -2
  6. package/dist/billboard.pkgd.js +8350 -5297
  7. package/dist/billboard.pkgd.min.js +3 -2
  8. package/dist/plugin/billboardjs-plugin-bubblecompare.js +29 -13
  9. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  10. package/dist/plugin/billboardjs-plugin-sparkline.js +377 -92
  11. package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
  12. package/dist/plugin/billboardjs-plugin-stanford.js +447 -109
  13. package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
  14. package/dist/plugin/billboardjs-plugin-tableview.js +341 -74
  15. package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
  16. package/dist/plugin/billboardjs-plugin-textoverlap.js +337 -75
  17. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  18. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.js +4233 -3792
  19. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.js +4635 -3889
  20. package/dist/plugin/pkgd/billboardjs-plugin-stanford.js +4823 -3937
  21. package/dist/plugin/pkgd/billboardjs-plugin-tableview.js +4594 -3866
  22. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.js +4606 -3874
  23. package/dist/theme/datalab.css +1 -1
  24. package/dist/theme/datalab.min.css +1 -1
  25. package/dist/theme/graph.css +1 -1
  26. package/dist/theme/graph.min.css +1 -1
  27. package/dist/theme/insight.css +1 -1
  28. package/dist/theme/insight.min.css +1 -1
  29. package/dist-esm/billboard.js +796 -387
  30. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +47 -75
  31. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +68 -86
  32. package/dist-esm/plugin/billboardjs-plugin-stanford.js +52 -77
  33. package/dist-esm/plugin/billboardjs-plugin-tableview.js +49 -76
  34. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +49 -76
  35. package/package.json +40 -40
  36. package/src/Chart/api/chart.ts +4 -1
  37. package/src/Chart/api/data.ts +2 -2
  38. package/src/Chart/api/flow.ts +125 -115
  39. package/src/ChartInternal/Axis/AxisRenderer.ts +29 -3
  40. package/src/ChartInternal/ChartInternal.ts +55 -18
  41. package/src/ChartInternal/data/IData.ts +2 -2
  42. package/src/ChartInternal/data/convert.helper.ts +226 -0
  43. package/src/ChartInternal/data/convert.ts +43 -210
  44. package/src/ChartInternal/data/load.ts +5 -4
  45. package/src/ChartInternal/interactions/zoom.ts +17 -4
  46. package/src/ChartInternal/internals/color.ts +59 -36
  47. package/src/ChartInternal/internals/grid.ts +5 -3
  48. package/src/ChartInternal/internals/redraw.ts +5 -2
  49. package/src/ChartInternal/internals/scale.ts +3 -1
  50. package/src/ChartInternal/internals/size.axis.ts +5 -2
  51. package/src/ChartInternal/internals/text.ts +118 -17
  52. package/src/ChartInternal/shape/area.ts +14 -7
  53. package/src/ChartInternal/shape/bar.ts +19 -10
  54. package/src/ChartInternal/shape/point.ts +15 -9
  55. package/src/ChartInternal/shape/polar.ts +1 -1
  56. package/src/Plugin/sparkline/index.ts +22 -11
  57. package/src/Plugin/stanford/index.ts +10 -7
  58. package/src/Plugin/textoverlap/index.ts +4 -1
  59. package/src/config/Options/Options.ts +2 -0
  60. package/src/config/Options/common/boost.ts +31 -0
  61. package/src/config/Options/common/main.ts +15 -1
  62. package/src/config/Options/common/tooltip.ts +1 -1
  63. package/src/config/Options/data/data.ts +11 -3
  64. package/src/config/Options/shape/area.ts +6 -1
  65. package/src/config/Store/State.ts +3 -0
  66. package/src/module/browser.ts +2 -1
  67. package/src/module/generator.ts +18 -16
  68. package/src/module/util.ts +115 -1
  69. package/types/chart.d.ts +2 -2
  70. package/types/options.d.ts +45 -8
@@ -119,16 +119,26 @@ export default class Sparkline extends Plugin {
119
119
 
120
120
  config.legend_show = false;
121
121
  config.resize_auto = false;
122
-
123
122
  config.axis_x_show = false;
124
- config.axis_x_padding = {
125
- left: 15,
126
- right: 15,
127
- unit: "px"
128
- };
123
+
124
+ // set default axes padding
125
+ if (config.padding !== false) {
126
+ const hasOption = o => Object.keys(o || {}).length > 0;
127
+
128
+ if (hasOption(config.axis_x_padding)) {
129
+ config.axis_x_padding = {
130
+ left: 15,
131
+ right: 15,
132
+ unit: "px"
133
+ };
134
+ }
135
+
136
+ if (hasOption(config.axis_y_padding)) {
137
+ config.axis_y_padding = 5;
138
+ }
139
+ }
129
140
 
130
141
  config.axis_y_show = false;
131
- config.axis_y_padding = 5;
132
142
 
133
143
  if (!config.tooltip_position) {
134
144
  config.tooltip_position = function(data, width, height) {
@@ -150,8 +160,7 @@ export default class Sparkline extends Plugin {
150
160
  }
151
161
 
152
162
  $init(): void {
153
- const {$$} = this;
154
- const {$el} = $$;
163
+ const {$$: {$el}} = this;
155
164
 
156
165
  // make disable-ish main chart element
157
166
  $el.chart
@@ -159,7 +168,7 @@ export default class Sparkline extends Plugin {
159
168
  .style("height", "0")
160
169
  .style("pointer-events", "none");
161
170
 
162
- document.body.appendChild($el.tooltip.node());
171
+ $el.tooltip?.node() && document.body.appendChild($el.tooltip.node());
163
172
  }
164
173
 
165
174
  $afterInit(): void {
@@ -178,7 +187,9 @@ export default class Sparkline extends Plugin {
178
187
  * @private
179
188
  */
180
189
  bindEvents(bind = true): void {
181
- if (this.$$.config.interaction_enabled) {
190
+ const {$$: {config}} = this;
191
+
192
+ if (config.interaction_enabled && config.tooltip_show) {
182
193
  const method = `${bind ? "add" : "remove"}EventListener`;
183
194
 
184
195
  this.element
@@ -228,20 +228,23 @@ export default class Stanford extends Plugin {
228
228
 
229
229
  if (isEmpty(config.tooltip_contents)) {
230
230
  config.tooltip_contents = function(d, defaultTitleFormat, defaultValueFormat, color) {
231
+ const {data_x} = config;
231
232
  let html = `<table class="${$TOOLTIP.tooltip}"><tbody>`;
232
233
 
233
234
  d.forEach(v => {
235
+ const {id = "", value = 0, epochs = 0, x = ""} = v;
236
+
234
237
  html += `<tr>
235
- <th>${defaultTitleFormat(config.data_x)}</th>
236
- <th class="value">${defaultValueFormat(v.x)}</th>
238
+ <th>${data_x || ""}</th>
239
+ <th class="value">${defaultTitleFormat(x)}</th>
237
240
  </tr>
238
241
  <tr>
239
- <th>${defaultTitleFormat(v.id)}</th>
240
- <th class="value">${defaultValueFormat(v.value)}</th>
242
+ <th>${v.id}</th>
243
+ <th class="value">${defaultValueFormat(value)}</th>
241
244
  </tr>
242
- <tr class="${$TOOLTIP.tooltipName}-${v.id}">
243
- <td class="name"><span style="background-color:${color(v)}"></span>${defaultTitleFormat("Epochs")}</td>
244
- <td class="value">${defaultValueFormat(v.epochs)}</td>
245
+ <tr class="${$TOOLTIP.tooltipName}-${id}">
246
+ <td class="name"><span style="background-color:${color(v)}"></span>Epochs</td>
247
+ <td class="value">${defaultValueFormat(epochs)}</td>
245
248
  </tr>`;
246
249
  });
247
250
 
@@ -91,7 +91,10 @@ export default class TextOverlap extends Plugin {
91
91
 
92
92
  return d3Delaunay
93
93
  .from(points)
94
- .voronoi([...min, ...max]); // bounds = [xmin, ymin, xmax, ymax], default value: [0, 0, 960, 500]
94
+ .voronoi([
95
+ ...min as [number, number],
96
+ ...max as [number, number]
97
+ ]); // bounds = [xmin, ymin, xmax, ymax], default value: [0, 0, 960, 500]
95
98
  }
96
99
 
97
100
  /**
@@ -4,6 +4,7 @@
4
4
  */
5
5
  // common
6
6
  import main from "./common/main";
7
+ import boost from "./common/boost";
7
8
  import data from "./data/data";
8
9
  import color from "./common/color";
9
10
  import interaction from "./interaction/interaction";
@@ -30,6 +31,7 @@ export default class Options {
30
31
  constructor() {
31
32
  return deepClone(
32
33
  main,
34
+ boost,
33
35
  data,
34
36
  color,
35
37
  interaction,
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Copyright (c) 2017 ~ present NAVER Corp.
3
+ * billboard.js project is licensed under the MIT license
4
+ */
5
+ /**
6
+ * boost config options
7
+ */
8
+ export default {
9
+ /**
10
+ * Set boost options
11
+ * @name boost
12
+ * @memberof Options
13
+ * @type {object}
14
+ * @property {object} boost boost object
15
+ * @property {boolean} [boost.useCssRule=false] Avoid setting inline styles for each shape elements.
16
+ * - **NOTE:**
17
+ * - Will append &lt;style> to the head tag and will add shpes' CSS rules dynamically.
18
+ * - For now, covers colors related properties (fill, stroke, etc.) only.
19
+ * @property {boolean} [boost.useWorker=false] Use Web Worker as possible for processing.
20
+ * - **NOTE:**
21
+ * - For now, only applies for data conversion at the initial time.
22
+ * - As of Web Worker's async nature, handling chart instance synchrously is not recommended.
23
+ * @example
24
+ * boost: {
25
+ * useCssRule: true,
26
+ * useWorker: false
27
+ * }
28
+ */
29
+ boost_useCssRule: false,
30
+ boost_useWorker: false
31
+ };
@@ -144,12 +144,26 @@ export default {
144
144
  * @type {object}
145
145
  * @property {object} [resize] resize object
146
146
  * @property {boolean} [resize.auto=true] Set chart resize automatically on viewport changes.
147
+ * @property {boolean|number} [resize.timer=true] Set resize timer option.
148
+ * - **NOTE:**
149
+ * - The resize function will be called using: true - `setTimeout()`, false - `requestIdleCallback()`.
150
+ * - Given number(delay in ms) value, resize function will be triggered using `setTimer()` with given delay.
147
151
  * @example
148
152
  * resize: {
149
- * auto: false
153
+ * auto: false,
154
+ *
155
+ * // set resize function will be triggered using `setTimer()`
156
+ * timer: true,
157
+ *
158
+ * // set resize function will be triggered using `requestIdleCallback()`
159
+ * timer: false,
160
+ *
161
+ * // set resize function will be triggered using `setTimer()` with a delay of `100ms`.
162
+ * timer: 100
150
163
  * }
151
164
  */
152
165
  resize_auto: true,
166
+ resize_timer: true,
153
167
 
154
168
  /**
155
169
  * Set a callback to execute when the chart is clicked.
@@ -39,7 +39,7 @@ export default {
39
39
  * - **Note:**
40
40
  * - defaultTitleFormat:
41
41
  * - if `axis.x.tick.format` option will be used if set.
42
- * - otherwise, will return funciton based on tick format type(category, timeseries).
42
+ * - otherwise, will return function based on tick format type(category, timeseries).
43
43
  * - defaultValueFormat:
44
44
  * - for Arc type (except gauge, radar), the function will return value from `(ratio * 100).toFixed(1)`.
45
45
  * - for Axis based types, will be used `axis.[y|y2].tick.format` option value if is set.
@@ -45,6 +45,7 @@ export default {
45
45
 
46
46
  /**
47
47
  * Set custom data name.
48
+ * If a name is set to `null`, the series is omitted from the legend.
48
49
  * @name data․names
49
50
  * @memberof Options
50
51
  * @type {object}
@@ -58,7 +59,7 @@ export default {
58
59
  * }
59
60
  * }
60
61
  */
61
- data_names: <{[key: string]: string}> {},
62
+ data_names: <{[key: string]: string|null}> {},
62
63
 
63
64
  /**
64
65
  * Set custom data class.<br><br>
@@ -311,6 +312,8 @@ export default {
311
312
  * @property {object} [data.labels.position] Set each dataset position, relative the original.
312
313
  * @property {number} [data.labels.position.x=0] x coordinate position, relative the original.
313
314
  * @property {number} [data.labels.position.y=0] y coordinate position, relative the original.
315
+ * @property {object} [data.labels.rotate] Rotate label text. Specify degree value in a range of `0 ~ 360`.
316
+ * - **NOTE:** Depend on rotate value, text position need to be adjusted manually(using `data.labels.position` option) to be shown nicely.
314
317
  * @memberof Options
315
318
  * @type {object}
316
319
  * @default {}
@@ -320,6 +323,7 @@ export default {
320
323
  * @see [Demo: label multiline](https://naver.github.io/billboard.js/demo/#Data.DataLabelMultiline)
321
324
  * @see [Demo: label overlap](https://naver.github.io/billboard.js/demo/#Data.DataLabelOverlap)
322
325
  * @see [Demo: label position](https://naver.github.io/billboard.js/demo/#Data.DataLabelPosition)
326
+ * @see [Demo: label rotate](https://naver.github.io/billboard.js/demo/#Data.DataLabelRotate)
323
327
  * @example
324
328
  * data: {
325
329
  * labels: true,
@@ -378,7 +382,10 @@ export default {
378
382
  * position: {
379
383
  * data1: {x: 5, y: 5},
380
384
  * data2: {x: 10, y: -20}
381
- * }
385
+ * },
386
+ *
387
+ * // rotate degree for label text
388
+ * rotate: 90
382
389
  * }
383
390
  * }
384
391
  */
@@ -387,7 +394,8 @@ export default {
387
394
  centered?: boolean;
388
395
  format?: Function;
389
396
  colors?: string|{[key: string]: string};
390
- position?: {[key: string]: number}|{[key: string]: {x?: number; y?: number;}}
397
+ position?: {[key: string]: number}|{[key: string]: {x?: number; y?: number;}};
398
+ rotate?: number;
391
399
  }> {},
392
400
  data_labels_backgroundColors: <string|{[key: string]: string}|undefined> undefined,
393
401
  data_labels_colors: <string|object|Function|undefined> undefined,
@@ -12,7 +12,9 @@ export default {
12
12
  * @memberof Options
13
13
  * @type {object}
14
14
  * @property {object} area Area object
15
- * @property {boolean} [area.above=false] Set background area above the data chart line.
15
+ * @property {boolean} [area.above=false] Set background area `above` the data chart line.
16
+ * @property {boolean} [area.below=false] Set background area `below` the data chart line.
17
+ * - **NOTE**: Can't be used along with `above` option. When above & below options are set to true, `above` will be prioritized.
16
18
  * @property {boolean} [area.front=true] Set area node to be positioned over line node.
17
19
  * @property {boolean|object} [area.linearGradient=false] Set the linear gradient on area.<br><br>
18
20
  * Or customize by giving below object value:
@@ -23,10 +25,12 @@ export default {
23
25
  * @see [MDN's &lt;linearGradient>](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/linearGradient), [&lt;stop>](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/stop)
24
26
  * @see [Demo](https://naver.github.io/billboard.js/demo/#Chart.AreaChart)
25
27
  * @see [Demo: above](https://naver.github.io/billboard.js/demo/#AreaChartOptions.Above)
28
+ * @see [Demo: below](https://naver.github.io/billboard.js/demo/#AreaChartOptions.Below)
26
29
  * @see [Demo: linearGradient](https://naver.github.io/billboard.js/demo/#AreaChartOptions.LinearGradient)
27
30
  * @example
28
31
  * area: {
29
32
  * above: true,
33
+ * below: false,
30
34
  * zerobased: false,
31
35
  *
32
36
  * // <g class='bb-areas'> will be positioned behind the line <g class='bb-lines'> in stacking order
@@ -58,6 +62,7 @@ export default {
58
62
  * }
59
63
  */
60
64
  area_above: false,
65
+ area_below: false,
61
66
  area_front: true,
62
67
  area_linearGradient: <
63
68
  boolean|{x?: number[]; y?: number[]; stops?: [number, string|Function|null, number]}
@@ -41,6 +41,9 @@ export default class State {
41
41
  hasAxis: false,
42
42
  hasRadar: false,
43
43
 
44
+ // for data CSS rule index (used when boost.useCssRule is true)
45
+ colorRule: {},
46
+
44
47
  current: {
45
48
  // chart whole dimension
46
49
  width: 0,
@@ -20,7 +20,8 @@ const win = (() => {
20
20
 
21
21
  // fallback for non-supported environments
22
22
  win.requestIdleCallback = win.requestIdleCallback || (cb => setTimeout(cb, 1));
23
- win.cancelIdleCallback = win.cancelIdleCallback || (id => clearTimeout(id));
23
+ // win.cancelIdleCallback = win.cancelIdleCallback || (id => clearTimeout(id));
24
+ win.requestAnimationFrame = win.requestAnimationFrame || (cb => setTimeout(cb, 1));
24
25
 
25
26
  const doc = win?.document;
26
27
 
@@ -4,16 +4,17 @@
4
4
  */
5
5
  import {d3Transition} from "../../types/types";
6
6
  import {window} from "./browser";
7
- import {isArray, isTabVisible} from "./util";
7
+ import {isArray, isNumber, isTabVisible, runUntil} from "./util";
8
8
 
9
9
  const {setTimeout, clearTimeout} = window;
10
10
 
11
11
  /**
12
12
  * Generate resize queue function
13
+ * @param {boolean|number} option Resize option
13
14
  * @returns {Fucntion}
14
15
  * @private
15
16
  */
16
- export function generateResize() {
17
+ export function generateResize(option: boolean|number) {
17
18
  const fn: any[] = [];
18
19
  let timeout;
19
20
 
@@ -21,9 +22,15 @@ export function generateResize() {
21
22
  // Delay all resize functions call, to prevent unintended excessive call from resize event
22
23
  callResizeFn.clear();
23
24
 
24
- timeout = setTimeout(() => {
25
- fn.forEach((f: Function) => f());
26
- }, 200);
25
+ if (option === false && window.requestIdleCallback) {
26
+ requestIdleCallback(() => {
27
+ fn.forEach((f: Function) => f());
28
+ }, {timeout: 200});
29
+ } else {
30
+ timeout = setTimeout(() => {
31
+ fn.forEach((f: Function) => f());
32
+ }, isNumber(option) ? option : 200);
33
+ }
27
34
  };
28
35
 
29
36
  callResizeFn.clear = () => {
@@ -51,13 +58,12 @@ export function generateWait() {
51
58
 
52
59
  // 'f' is called as selection.call(f, ...);
53
60
  const f = function(selection: d3Transition, callback: Function) {
54
- let timer;
55
-
56
61
  /**
57
62
  * Check if transition is complete
63
+ * @returns {boolean} Whether transition is complete
58
64
  * @private
59
65
  */
60
- function loop() {
66
+ function loop(): boolean {
61
67
  let done = 0;
62
68
 
63
69
  for (let i = 0, t; (t = transitionsToWait[i]); i++) {
@@ -79,16 +85,12 @@ export function generateWait() {
79
85
  }
80
86
  }
81
87
 
82
- timer && clearTimeout(timer);
83
-
84
- if (done === transitionsToWait.length) {
85
- callback?.();
86
- } else {
87
- timer = setTimeout(loop, 50);
88
- }
88
+ return done === transitionsToWait.length;
89
89
  }
90
90
 
91
- loop();
91
+ runUntil(() => {
92
+ callback?.();
93
+ }, loop);
92
94
  };
93
95
 
94
96
  f.add = function(t: Transition | Transition[]) {
@@ -9,6 +9,7 @@ import {d3Selection} from "../../types/types";
9
9
  import {document, window} from "./browser";
10
10
 
11
11
  export {
12
+ addCssRules,
12
13
  asHalfPixel,
13
14
  brushEmpty,
14
15
  callFn,
@@ -51,6 +52,8 @@ export {
51
52
  mergeObj,
52
53
  notEmpty,
53
54
  parseDate,
55
+ runUntil,
56
+ runWorker,
54
57
  sanitise,
55
58
  setTextValue,
56
59
  sortValue,
@@ -254,6 +257,7 @@ function getPathBox(
254
257
  };
255
258
  }
256
259
 
260
+
257
261
  /**
258
262
  * Get event's current position coordinates
259
263
  * @param {object} event Event object
@@ -457,6 +461,28 @@ function camelize(str: string, separator = "-"): string {
457
461
  */
458
462
  const toArray = (v: CSSStyleDeclaration | any): any => [].slice.call(v);
459
463
 
464
+ /**
465
+ * Add CSS rules
466
+ * @param {object} style Style object
467
+ * @param {string} selector Selector string
468
+ * @param {Array} prop Prps arrary
469
+ * @returns {number} Newely added rule index
470
+ * @private
471
+ */
472
+ function addCssRules(style, selector: string, prop: string[]): number {
473
+ const {rootSelctor, sheet} = style;
474
+ const getSelector = s => s
475
+ .replace(/\s?(bb-)/g, ".$1")
476
+ .replace(/\.+/g, ".");
477
+
478
+ const rule = `${rootSelctor} ${getSelector(selector)} {${prop.join(";")}}`;
479
+
480
+ return sheet[sheet.insertRule ? "insertRule" : "addRule"](
481
+ rule,
482
+ sheet.cssRules.length
483
+ );
484
+ }
485
+
460
486
  /**
461
487
  * Get css rules for specified stylesheets
462
488
  * @param {Array} styleSheets The stylesheets to get the rules from
@@ -768,5 +794,93 @@ function convertInputType(mouse: boolean, touch: boolean): "mouse" | "touch" | n
768
794
  const hasMouse = mouse && ["any-hover:hover", "any-pointer:fine"]
769
795
  .some(v => matchMedia?.(`(${v})`).matches);
770
796
 
771
- return (hasMouse && "mouse") || (hasTouch && "touch") || null;
797
+ // fallback to 'mouse' if no input type is detected.
798
+ return (hasMouse && "mouse") || (hasTouch && "touch") || "mouse";
799
+ }
800
+
801
+ /**
802
+ * Create and run on Web Worker
803
+ * @param {boolean} useWorker Use Web Worker
804
+ * @param {Function} fn Function to be executed in worker
805
+ * @param {Function} callback Callback function to receive result from worker
806
+ * @param {Array} depsFn Dependency functions to run given function(fn).
807
+ * @returns {object}
808
+ * @example
809
+ * const worker = runWorker(function(arg) {
810
+ * // do some tasks...
811
+ * console.log("param:", A(arg));
812
+ *
813
+ * return 1234;
814
+ * }, function(data) {
815
+ * // callback after worker is done
816
+ * console.log("result:", data);
817
+ * },
818
+ * [function A(){}]
819
+ * );
820
+ *
821
+ * worker(11111);
822
+ * @private
823
+ */
824
+ function runWorker(
825
+ useWorker = true, fn: Function, callback: Function, depsFn?: Function[]
826
+ ): Function {
827
+ let runFn;
828
+
829
+ if (window.Worker && useWorker) {
830
+ // Web Worker body
831
+ const blob = new Blob([
832
+ `${depsFn?.map(String).join(";") ?? ""}
833
+
834
+ self.onmessage=function({data}) {
835
+ const result = (${fn.toString()}).apply(null, data);
836
+ self.postMessage(result);
837
+ };`
838
+ ], {
839
+ type: "text/javascript"
840
+ });
841
+ const worker = new Worker(URL.createObjectURL(blob));
842
+
843
+ runFn = function(...args) {
844
+ // trigger worker
845
+ worker.postMessage(args);
846
+
847
+ // listen worker
848
+ worker.onmessage = function(e) {
849
+ return callback(e.data);
850
+ };
851
+
852
+ // handle error
853
+ worker.onerror = function(e) {
854
+ console.error(e);
855
+ };
856
+
857
+ // return new Promise((resolve, reject) => {
858
+ // worker.onmessage = ({data}) => resolve(data);
859
+ // worker.onerror = reject;
860
+ // });
861
+ };
862
+ } else {
863
+ runFn = function(...args) {
864
+ const res = fn(...args);
865
+
866
+ callback(res);
867
+ };
868
+ }
869
+
870
+ return runFn;
772
871
  }
872
+
873
+ /**
874
+ * Run function until given condition function return true
875
+ * @param {Function} fn Function to be executed when condition is true
876
+ * @param {Function} conditionFn Condition function to check if condition is true
877
+ * @private
878
+ */
879
+ function runUntil(fn: Function, conditionFn: Function): void {
880
+ if (conditionFn() === false) {
881
+ window.requestAnimationFrame(() => runUntil(fn, conditionFn));
882
+ } else {
883
+ fn();
884
+ }
885
+ }
886
+
package/types/chart.d.ts CHANGED
@@ -347,7 +347,7 @@ export interface Chart {
347
347
  load(this: Chart, args: {
348
348
  append?: boolean;
349
349
  url?: string;
350
- json?: [{ [key: string]: string | number }] | {[key: string]: Array<string|number>};
350
+ json?: Array<{[key: string]: string | number }> | {[key: string]: Array<string | number>};
351
351
  rows?: PrimitiveArray[];
352
352
  columns?: PrimitiveArray[];
353
353
  data?: Array<{ [key: string]: number }>;
@@ -358,7 +358,7 @@ export interface Chart {
358
358
  axes?: { [key: string]: string | string[] };
359
359
  colors?: { [key: string]: string };
360
360
  headers?: { [key: string]: string };
361
- keys?: { [key: string]: string };
361
+ keys?: { [key: string]: string | string[] };
362
362
  mimeType?: string;
363
363
  type?: string;
364
364
  types?: { [key: string]: string };
@@ -8,7 +8,7 @@ import Bubblecompare from "./plugin/bubblecompare/index";
8
8
  import Stanford from "./plugin/stanford/index";
9
9
  import TextOverlap from "./plugin/textoverlap/index";
10
10
  import {Chart} from "./chart";
11
- import {IData} from "../src/ChartInternal/data/IData";
11
+ import {IArcData, IData, IDataRow} from "../src/ChartInternal/data/IData";
12
12
 
13
13
  export interface ChartOptions {
14
14
  /**
@@ -49,6 +49,24 @@ export interface ChartOptions {
49
49
  imgUrl?: string;
50
50
  };
51
51
 
52
+ boost?: {
53
+ /**
54
+ * Avoid setting inline styles for each shape elements.
55
+ * - **NOTE:**
56
+ * - Will append <style> to the head tag and will add shpes' CSS rules dynamically.
57
+ * - For now, covers colors related properties (fill, stroke, etc.) only.
58
+ */
59
+ useCssRule?: boolean;
60
+
61
+ /**
62
+ * Use Web Worker as possible for processing.
63
+ * - **NOTE:**
64
+ * - For now, only applies for data conversion at the initial time.
65
+ * - As of Web Worker's async nature, handling chart instance synchrously is not recommended.
66
+ */
67
+ useWorker?: boolean;
68
+ };
69
+
52
70
  size?: {
53
71
  /**
54
72
  * The desired width of the chart element.
@@ -99,6 +117,14 @@ export interface ChartOptions {
99
117
  * Indicate if the chart should automatically get resized when the window gets resized.
100
118
  */
101
119
  auto?: boolean;
120
+
121
+ /**
122
+ * Set resize timer option.
123
+ * - **NOTE:**
124
+ * - The resize function will be called using: true - `setTimeout()`, false - `requestIdleCallback()`.
125
+ * - Given number(delay in ms) value, resize function will be triggered using `setTimer()` with given delay.
126
+ */
127
+ timer?: boolean | number;
102
128
  };
103
129
 
104
130
  color?: {
@@ -254,6 +280,12 @@ export interface ChartOptions {
254
280
  */
255
281
  above?: boolean;
256
282
 
283
+ /**
284
+ * Set background area `below` the data chart line.
285
+ * - **NOTE**: Can't be used along with `above` option. When above & below options are set to true, `above` will be prioritized.
286
+ */
287
+ below?: boolean;
288
+
257
289
  /**
258
290
  * Set area node to be positioned over line node.
259
291
  */
@@ -1082,10 +1114,10 @@ export interface TooltipOptions {
1082
1114
  */
1083
1115
  contents?: ((
1084
1116
  this: Chart,
1085
- data: any,
1086
- defaultTitleFormat: string,
1087
- defaultValueFormat: string,
1088
- color: any
1117
+ data: IDataRow[],
1118
+ defaultTitleFormat: (x: Date|number|string) => number|string,
1119
+ defaultValueFormat: (value: number, ratio: number|undefined, id: string) => number|string,
1120
+ color: (d: IDataRow|IArcData|string) => string
1089
1121
  ) => string) | {
1090
1122
  /**
1091
1123
  * Set CSS selector or element reference to bind tooltip.
@@ -1193,7 +1225,7 @@ export interface SubchartOptions {
1193
1225
  * Use custom format for x axis ticks - see 'axis.x.tick.format' option for details.
1194
1226
  */
1195
1227
  format?: string
1196
- | ((this: Chart, x: number | Date) => string | number)
1228
+ | ((this: Chart, x: Date) => string | number)
1197
1229
  | ((this: Chart, index: number, categoryName: string) => string);
1198
1230
  /**
1199
1231
  * Show or hide x axis tick line.
@@ -1520,7 +1552,7 @@ export interface Data {
1520
1552
  /**
1521
1553
  * Set custom data name.
1522
1554
  */
1523
- names?: { [key: string]: string };
1555
+ names?: { [key: string]: string|null };
1524
1556
  /**
1525
1557
  * Set custom data class.
1526
1558
  * If this option is specified, the element g for the data has an additional class that has the prefix billboard-target- (e.g. billboard-target-additional-data1-class).
@@ -1613,7 +1645,12 @@ export interface Data {
1613
1645
  */
1614
1646
  y?: number;
1615
1647
  };
1616
- }
1648
+ };
1649
+
1650
+ /**
1651
+ * Rotate label text. Specify degree value in a range of `0 ~ 360`.
1652
+ */
1653
+ rotate?: number;
1617
1654
  };
1618
1655
 
1619
1656
  /**