billboard.js 4.0.3 → 4.1.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 (271) hide show
  1. package/README.md +82 -7
  2. package/dist/billboard.css +1 -1
  3. package/dist/billboard.js +1848 -494
  4. package/dist/billboard.min.css +1 -1
  5. package/dist/billboard.min.js +19 -24
  6. package/dist/billboard.pkgd.js +1844 -679
  7. package/dist/billboard.pkgd.min.js +24 -29
  8. package/dist/billboard.react.js +205 -0
  9. package/dist/billboard.react.min.js +9 -0
  10. package/dist/billboard.worker.js +10 -0
  11. package/dist/plugin/billboardjs-plugin-bubblecompare.js +5 -3
  12. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  13. package/dist/plugin/billboardjs-plugin-sparkline.js +6 -3
  14. package/dist/plugin/billboardjs-plugin-sparkline.min.js +3 -3
  15. package/dist/plugin/billboardjs-plugin-stanford.js +6 -3
  16. package/dist/plugin/billboardjs-plugin-stanford.min.js +3 -3
  17. package/dist/plugin/billboardjs-plugin-tableview.js +59 -27
  18. package/dist/plugin/billboardjs-plugin-tableview.min.js +5 -5
  19. package/dist/plugin/billboardjs-plugin-textoverlap.js +75 -55
  20. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  21. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +5 -3
  22. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +2 -2
  23. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +6 -3
  24. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +3 -3
  25. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +6 -3
  26. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +2 -2
  27. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +59 -27
  28. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +11 -11
  29. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +68 -3557
  30. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +8 -8
  31. package/dist/theme/dark.css +1 -1
  32. package/dist/theme/dark.min.css +1 -1
  33. package/dist/theme/datalab.css +1 -1
  34. package/dist/theme/datalab.min.css +1 -1
  35. package/dist/theme/graph.css +1 -1
  36. package/dist/theme/graph.min.css +1 -1
  37. package/dist/theme/insight.css +1 -1
  38. package/dist/theme/insight.min.css +1 -1
  39. package/dist/theme/modern.css +1 -1
  40. package/dist/theme/modern.min.css +1 -1
  41. package/dist-esm/Chart/Chart.js +134 -152
  42. package/dist-esm/Chart/api/axis.js +217 -237
  43. package/dist-esm/Chart/api/category.js +54 -54
  44. package/dist-esm/Chart/api/chart.js +172 -215
  45. package/dist-esm/Chart/api/color.js +21 -21
  46. package/dist-esm/Chart/api/data.js +172 -173
  47. package/dist-esm/Chart/api/export.js +242 -262
  48. package/dist-esm/Chart/api/flow.js +198 -254
  49. package/dist-esm/Chart/api/focus.js +136 -143
  50. package/dist-esm/Chart/api/grid.js +191 -190
  51. package/dist-esm/Chart/api/group.js +31 -34
  52. package/dist-esm/Chart/api/legend.js +54 -63
  53. package/dist-esm/Chart/api/load.js +237 -257
  54. package/dist-esm/Chart/api/regions.js +148 -168
  55. package/dist-esm/Chart/api/selection.js +181 -139
  56. package/dist-esm/Chart/api/show.js +133 -147
  57. package/dist-esm/Chart/api/stubs.js +43 -42
  58. package/dist-esm/Chart/api/subchart.js +155 -172
  59. package/dist-esm/Chart/api/tooltip.js +132 -177
  60. package/dist-esm/Chart/api/x.js +67 -71
  61. package/dist-esm/Chart/api/zoom.js +183 -220
  62. package/dist-esm/ChartInternal/Axis/Axis.js +1059 -1266
  63. package/dist-esm/ChartInternal/Axis/AxisRenderer.js +408 -540
  64. package/dist-esm/ChartInternal/Axis/AxisRendererHelper.js +113 -149
  65. package/dist-esm/ChartInternal/ChartInternal.js +573 -749
  66. package/dist-esm/ChartInternal/data/convert.helper.js +133 -159
  67. package/dist-esm/ChartInternal/data/convert.js +200 -229
  68. package/dist-esm/ChartInternal/data/data.js +967 -1153
  69. package/dist-esm/ChartInternal/data/load.js +145 -197
  70. package/dist-esm/ChartInternal/interactions/drag.js +86 -122
  71. package/dist-esm/ChartInternal/interactions/eventrect.js +455 -621
  72. package/dist-esm/ChartInternal/interactions/flow.js +151 -215
  73. package/dist-esm/ChartInternal/interactions/interaction.js +214 -252
  74. package/dist-esm/ChartInternal/interactions/subchart.js +425 -300
  75. package/dist-esm/ChartInternal/interactions/zoom.js +321 -440
  76. package/dist-esm/ChartInternal/internals/category.js +18 -18
  77. package/dist-esm/ChartInternal/internals/class.js +89 -99
  78. package/dist-esm/ChartInternal/internals/clip.js +88 -119
  79. package/dist-esm/ChartInternal/internals/color.js +233 -288
  80. package/dist-esm/ChartInternal/internals/domain.js +452 -588
  81. package/dist-esm/ChartInternal/internals/format.js +64 -77
  82. package/dist-esm/ChartInternal/internals/grid.js +333 -457
  83. package/dist-esm/ChartInternal/internals/legend.js +675 -927
  84. package/dist-esm/ChartInternal/internals/redraw.js +200 -289
  85. package/dist-esm/ChartInternal/internals/region.js +106 -159
  86. package/dist-esm/ChartInternal/internals/scale.js +186 -215
  87. package/dist-esm/ChartInternal/internals/selection.js +132 -159
  88. package/dist-esm/ChartInternal/internals/size.axis.js +92 -139
  89. package/dist-esm/ChartInternal/internals/size.js +286 -394
  90. package/dist-esm/ChartInternal/internals/style.js +39 -41
  91. package/dist-esm/ChartInternal/internals/subchart.util.js +49 -0
  92. package/dist-esm/ChartInternal/internals/text.arc.js +155 -219
  93. package/dist-esm/ChartInternal/internals/text.js +368 -528
  94. package/dist-esm/ChartInternal/internals/text.util.js +179 -239
  95. package/dist-esm/ChartInternal/internals/title.js +96 -121
  96. package/dist-esm/ChartInternal/internals/tooltip.js +450 -586
  97. package/dist-esm/ChartInternal/internals/transform.js +79 -97
  98. package/dist-esm/ChartInternal/internals/type.js +285 -236
  99. package/dist-esm/ChartInternal/shape/arc.js +825 -1112
  100. package/dist-esm/ChartInternal/shape/area.js +73 -94
  101. package/dist-esm/ChartInternal/shape/bar.js +227 -288
  102. package/dist-esm/ChartInternal/shape/bubble.js +9 -8
  103. package/dist-esm/ChartInternal/shape/candlestick.js +110 -138
  104. package/dist-esm/ChartInternal/shape/core/barRadius.js +197 -133
  105. package/dist-esm/ChartInternal/shape/core/bubble.js +64 -73
  106. package/dist-esm/ChartInternal/shape/core/candlestick.js +93 -86
  107. package/dist-esm/ChartInternal/shape/core/dataRegion.js +68 -75
  108. package/dist-esm/ChartInternal/shape/core/geometry.js +112 -112
  109. package/dist-esm/ChartInternal/shape/core/path.js +142 -115
  110. package/dist-esm/ChartInternal/shape/core/point.js +105 -125
  111. package/dist-esm/ChartInternal/shape/core/treemap.js +83 -88
  112. package/dist-esm/ChartInternal/shape/funnel.js +310 -338
  113. package/dist-esm/ChartInternal/shape/gauge.js +71 -103
  114. package/dist-esm/ChartInternal/shape/line.js +208 -278
  115. package/dist-esm/ChartInternal/shape/point.js +310 -425
  116. package/dist-esm/ChartInternal/shape/polar.js +84 -109
  117. package/dist-esm/ChartInternal/shape/radar.js +228 -318
  118. package/dist-esm/ChartInternal/shape/shape.js +782 -843
  119. package/dist-esm/ChartInternal/shape/treemap.js +152 -190
  120. package/dist-esm/canvas/CanvasAxisRenderer.js +1180 -1328
  121. package/dist-esm/canvas/CanvasEngine.js +148 -166
  122. package/dist-esm/canvas/CanvasPainter.js +395 -411
  123. package/dist-esm/canvas/CanvasRenderer.js +1584 -1834
  124. package/dist-esm/canvas/CanvasTheme.js +899 -802
  125. package/dist-esm/canvas/HitDetector.js +394 -463
  126. package/dist-esm/canvas/axisTicks.js +672 -786
  127. package/dist-esm/canvas/classes.js +19 -17
  128. package/dist-esm/canvas/color.js +40 -59
  129. package/dist-esm/canvas/geometry.js +38 -38
  130. package/dist-esm/canvas/labels.js +318 -371
  131. package/dist-esm/canvas/pointPattern.js +578 -580
  132. package/dist-esm/canvas/util.js +242 -262
  133. package/dist-esm/config/Options/Options.js +29 -32
  134. package/dist-esm/config/Options/axis/axis.js +101 -101
  135. package/dist-esm/config/Options/axis/x.js +759 -755
  136. package/dist-esm/config/Options/axis/y.js +525 -522
  137. package/dist-esm/config/Options/axis/y2.js +501 -485
  138. package/dist-esm/config/Options/common/boost.js +93 -32
  139. package/dist-esm/config/Options/common/color.js +88 -87
  140. package/dist-esm/config/Options/common/grid.js +74 -73
  141. package/dist-esm/config/Options/common/legend.js +180 -179
  142. package/dist-esm/config/Options/common/main.js +474 -473
  143. package/dist-esm/config/Options/common/point.js +160 -159
  144. package/dist-esm/config/Options/common/title.js +47 -46
  145. package/dist-esm/config/Options/common/tooltip.js +253 -252
  146. package/dist-esm/config/Options/data/axis.js +173 -172
  147. package/dist-esm/config/Options/data/data.js +958 -957
  148. package/dist-esm/config/Options/data/selection.js +131 -130
  149. package/dist-esm/config/Options/interaction/interaction.js +53 -52
  150. package/dist-esm/config/Options/interaction/subchart.js +164 -73
  151. package/dist-esm/config/Options/interaction/zoom.js +86 -85
  152. package/dist-esm/config/Options/shape/arc.js +150 -149
  153. package/dist-esm/config/Options/shape/area.js +69 -68
  154. package/dist-esm/config/Options/shape/bar.js +147 -146
  155. package/dist-esm/config/Options/shape/bubble.js +35 -34
  156. package/dist-esm/config/Options/shape/candlestick.js +61 -60
  157. package/dist-esm/config/Options/shape/donut.js +181 -180
  158. package/dist-esm/config/Options/shape/funnel.js +49 -48
  159. package/dist-esm/config/Options/shape/gauge.js +237 -236
  160. package/dist-esm/config/Options/shape/line.js +58 -57
  161. package/dist-esm/config/Options/shape/pie.js +185 -184
  162. package/dist-esm/config/Options/shape/polar.js +167 -166
  163. package/dist-esm/config/Options/shape/radar.js +76 -75
  164. package/dist-esm/config/Options/shape/scatter.js +36 -36
  165. package/dist-esm/config/Options/shape/spline.js +46 -46
  166. package/dist-esm/config/Options/shape/treemap.js +80 -79
  167. package/dist-esm/config/Store/Element.js +64 -62
  168. package/dist-esm/config/Store/State.js +189 -200
  169. package/dist-esm/config/Store/Store.js +25 -26
  170. package/dist-esm/config/classes.js +157 -155
  171. package/dist-esm/config/config.js +26 -35
  172. package/dist-esm/config/const.js +120 -128
  173. package/dist-esm/config/resolver/axis.core.js +25 -25
  174. package/dist-esm/config/resolver/axis.js +26 -27
  175. package/dist-esm/config/resolver/canvas.js +2071 -2472
  176. package/dist-esm/config/resolver/canvasShape.js +201 -177
  177. package/dist-esm/config/resolver/category.js +26 -27
  178. package/dist-esm/config/resolver/export.js +24 -26
  179. package/dist-esm/config/resolver/flow.js +29 -31
  180. package/dist-esm/config/resolver/grid.js +34 -35
  181. package/dist-esm/config/resolver/interaction/selection.js +17 -17
  182. package/dist-esm/config/resolver/interaction/subchart.js +17 -17
  183. package/dist-esm/config/resolver/interaction/zoom.js +17 -17
  184. package/dist-esm/config/resolver/regions.js +30 -31
  185. package/dist-esm/config/resolver/shape/arc.helpers.js +19 -19
  186. package/dist-esm/config/resolver/shape/area.js +17 -17
  187. package/dist-esm/config/resolver/shape/axis.helpers.js +28 -25
  188. package/dist-esm/config/resolver/shape/bar.js +13 -13
  189. package/dist-esm/config/resolver/shape/bubble.js +18 -14
  190. package/dist-esm/config/resolver/shape/candlestick.js +13 -13
  191. package/dist-esm/config/resolver/shape/donut.js +11 -11
  192. package/dist-esm/config/resolver/shape/funnel.js +11 -11
  193. package/dist-esm/config/resolver/shape/gauge.js +12 -12
  194. package/dist-esm/config/resolver/shape/line.js +10 -10
  195. package/dist-esm/config/resolver/shape/pie.js +11 -11
  196. package/dist-esm/config/resolver/shape/polar.js +12 -12
  197. package/dist-esm/config/resolver/shape/radar.js +22 -14
  198. package/dist-esm/config/resolver/shape/scatter.js +13 -13
  199. package/dist-esm/config/resolver/shape/treemap.js +11 -11
  200. package/dist-esm/core.js +208 -211
  201. package/dist-esm/index.canvas.js +14 -13
  202. package/dist-esm/index.esm.js +25 -24
  203. package/dist-esm/module/Cache.js +117 -129
  204. package/dist-esm/module/browser.js +30 -35
  205. package/dist-esm/module/dsv.js +107 -127
  206. package/dist-esm/module/error.js +45 -52
  207. package/dist-esm/module/generator.js +75 -83
  208. package/dist-esm/module/sanitize.js +302 -399
  209. package/dist-esm/module/util/brush.js +27 -38
  210. package/dist-esm/module/util/dom.js +288 -348
  211. package/dist-esm/module/util/object.js +277 -341
  212. package/dist-esm/module/util/type-checks.js +21 -25
  213. package/dist-esm/module/worker.js +312 -130
  214. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +185 -198
  215. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +442 -450
  216. package/dist-esm/plugin/billboardjs-plugin-stanford.js +813 -950
  217. package/dist-esm/plugin/billboardjs-plugin-tableview.js +708 -788
  218. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +344 -301
  219. package/dist-esm/react/index.js +157 -0
  220. package/package.json +28 -8
  221. package/src/Chart/api/selection.ts +130 -5
  222. package/src/ChartInternal/Axis/Axis.ts +164 -65
  223. package/src/ChartInternal/Axis/AxisRenderer.ts +41 -8
  224. package/src/ChartInternal/Axis/AxisRendererHelper.ts +1 -1
  225. package/src/ChartInternal/ChartInternal.ts +1 -1
  226. package/src/ChartInternal/data/convert.ts +54 -4
  227. package/src/ChartInternal/data/data.ts +4 -1
  228. package/src/ChartInternal/interactions/eventrect.ts +8 -2
  229. package/src/ChartInternal/interactions/subchart.ts +437 -66
  230. package/src/ChartInternal/internals/color.ts +2 -2
  231. package/src/ChartInternal/internals/domain.ts +15 -3
  232. package/src/ChartInternal/internals/grid.ts +21 -1
  233. package/src/ChartInternal/internals/scale.ts +9 -2
  234. package/src/ChartInternal/internals/selection.ts +1 -1
  235. package/src/ChartInternal/internals/subchart.util.ts +55 -0
  236. package/src/ChartInternal/internals/text.arc.ts +3 -1
  237. package/src/ChartInternal/internals/text.ts +18 -5
  238. package/src/ChartInternal/internals/transform.ts +8 -2
  239. package/src/ChartInternal/internals/type.ts +105 -1
  240. package/src/ChartInternal/shape/IShape.ts +6 -3
  241. package/src/ChartInternal/shape/bar.ts +62 -31
  242. package/src/ChartInternal/shape/core/barRadius.ts +129 -0
  243. package/src/ChartInternal/shape/core/candlestick.ts +1 -1
  244. package/src/ChartInternal/shape/core/path.ts +76 -9
  245. package/src/ChartInternal/shape/funnel.ts +2 -3
  246. package/src/ChartInternal/shape/point.ts +2 -2
  247. package/src/ChartInternal/shape/shape.ts +149 -17
  248. package/src/Plugin/stanford/index.ts +0 -4
  249. package/src/Plugin/tableview/index.ts +85 -3
  250. package/src/Plugin/textoverlap/index.ts +9 -15
  251. package/src/canvas/CanvasAxisRenderer.ts +184 -36
  252. package/src/canvas/CanvasRenderer.ts +247 -160
  253. package/src/canvas/CanvasTheme.ts +212 -0
  254. package/src/canvas/axisTicks.ts +122 -40
  255. package/src/config/Options/axis/y2.ts +13 -0
  256. package/src/config/Options/common/boost.ts +64 -4
  257. package/src/config/Options/common/color.ts +2 -2
  258. package/src/config/Options/interaction/subchart.ts +98 -1
  259. package/src/config/Options/shape/gauge.ts +1 -1
  260. package/src/config/Options/shape/treemap.ts +2 -2
  261. package/src/config/Store/Element.ts +3 -1
  262. package/src/config/Store/State.ts +1 -0
  263. package/src/config/classes.ts +1 -0
  264. package/src/config/resolver/canvas.ts +92 -10
  265. package/src/module/util/type-checks.ts +3 -1
  266. package/src/module/voronoi.ts +119 -0
  267. package/src/module/worker.entry.ts +61 -0
  268. package/src/module/worker.ts +346 -63
  269. package/src/react/index.ts +193 -0
  270. package/types/options.d.ts +206 -3
  271. package/types/react/index.d.ts +27 -0
@@ -12,9 +12,9 @@ export default {
12
12
  * @memberof Options
13
13
  * @type {object}
14
14
  * @property {object} color color object
15
- * @property {string|object|((this: Chart, d: DataItem) => string)} [color.onover] Set the color value for each data point when mouse/touch onover event occurs.
15
+ * @property {string|object|function(DataItem): string} [color.onover] Set the color value for each data point when mouse/touch onover event occurs.
16
16
  * @property {Array|null} [color.pattern=[]] Set custom color pattern. Passing `null` will not set a color for these elements, which requires the usage of custom CSS-based theming to work.
17
- * @property {(this: Chart) => SVGPathElement[]} [color.tiles] if defined, allows use svg's patterns to fill data area. It should return an array of [SVGPatternElement](https://developer.mozilla.org/en-US/docs/Web/API/SVGPatternElement).
17
+ * @property {function(): Array.<SVGPatternElement>} [color.tiles] if defined, allows use svg's patterns to fill data area. It should return an array of [SVGPatternElement](https://developer.mozilla.org/en-US/docs/Web/API/SVGPatternElement).
18
18
  * - **NOTE:** The pattern element's id will be defined as `bb-colorize-pattern-$COLOR-VALUE`.<br>
19
19
  * ex. When color pattern value is `['red', '#fff']` and defined 2 patterns,then ids for pattern elements are:<br>
20
20
  * - `bb-colorize-pattern-red`
@@ -2,13 +2,15 @@
2
2
  * Copyright (c) 2017 ~ present NAVER Corp.
3
3
  * billboard.js project is licensed under the MIT license
4
4
  */
5
+ import type {ChartTypes} from "../../../../types/types";
6
+
5
7
  /**
6
8
  * x Axis config options
7
9
  */
8
10
  export default {
9
11
  /**
10
12
  * Set subchart options.
11
- * - **NOTE:** Not supported for `bubble`, `scatter` and non-Axis based(pie, donut, gauge, radar) types.
13
+ * - **NOTE:** Not supported for non-Axis based(pie, donut, gauge, radar) types.
12
14
  * @name subchart
13
15
  * @memberof Options
14
16
  * @type {object}
@@ -16,11 +18,45 @@ export default {
16
18
  * @property {boolean} [subchart.show=false] Show sub chart on the bottom of the chart.
17
19
  * - **NOTE:** for ESM imports, needs to import 'subchart' exports and instantiate it by calling `subchart()`.
18
20
  * - `show: subchart()`
21
+ * @property {string} [subchart.type] Set chart type for the subchart. Defaults to data.type.
22
+ * @property {object} [subchart.types] Set chart type for each data in the subchart. Defaults to data.types.
23
+ * @property {boolean} [subchart.brush.enabled=true] Enable subchart brush interaction.
19
24
  * @property {boolean} [subchart.showHandle=false] Show sub chart's handle.
25
+ * @property {boolean|object} [subchart.grid.focus=true] Show x focus grid line in subchart when subchart brush is disabled.
26
+ * @property {boolean} [subchart.grid.focus.continuous=false] Render x focus grid line as one continuous line across main chart and subchart when subchart brush is disabled.
20
27
  * @property {boolean} [subchart.axis.x.show=true] Show or hide x axis.
21
28
  * @property {boolean} [subchart.axis.x.tick.show=true] Show or hide x axis tick line.
29
+ * @property {number} [subchart.axis.x.tick.count] Set the number of x axis ticks.
30
+ * @property {Array|function} [subchart.axis.x.tick.values] Set x axis tick values manually.
31
+ * @property {boolean|object} [subchart.axis.x.tick.culling] Setting for culling x axis ticks.
32
+ * @property {number} [subchart.axis.x.tick.culling.max] The number of x axis tick texts will be adjusted to less than this value.
33
+ * @property {boolean} [subchart.axis.x.tick.culling.lines=true] Control x axis tick line visibility within culling option.
34
+ * @property {boolean} [subchart.axis.x.tick.culling.reverse=false] Control x axis culling start point to be reversed.
35
+ * @property {boolean} [subchart.axis.x.tick.outer] Show or hide x axis outer tick.
22
36
  * @property {function|string} [subchart.axis.x.tick.format] Use custom format for x axis ticks - see [axis.x.tick.format](#.axis․x․tick․format) for details.
23
37
  * @property {boolean} [subchart.axis.x.tick.text.show=true] Show or hide x axis tick text.
38
+ * @property {boolean} [subchart.axis.y.show=false] Show or hide y axis.
39
+ * @property {boolean} [subchart.axis.y.tick.show=true] Show or hide y axis tick line.
40
+ * @property {number} [subchart.axis.y.tick.count] Set the number of y axis ticks.
41
+ * @property {Array|function} [subchart.axis.y.tick.values] Set y axis tick values manually.
42
+ * @property {boolean|object} [subchart.axis.y.tick.culling] Setting for culling y axis ticks.
43
+ * @property {number} [subchart.axis.y.tick.culling.max] The number of y axis tick texts will be adjusted to less than this value.
44
+ * @property {boolean} [subchart.axis.y.tick.culling.lines=true] Control y axis tick line visibility within culling option.
45
+ * @property {boolean} [subchart.axis.y.tick.culling.reverse=false] Control y axis culling start point to be reversed.
46
+ * @property {boolean} [subchart.axis.y.tick.outer] Show or hide y axis outer tick.
47
+ * @property {function|string} [subchart.axis.y.tick.format] Use custom format for y axis ticks - see [axis.y.tick.format](#.axis․y․tick․format) for details.
48
+ * @property {boolean} [subchart.axis.y.tick.text.show=true] Show or hide y axis tick text.
49
+ * @property {boolean} [subchart.axis.y2.show=false] Show or hide y2 axis.
50
+ * @property {boolean} [subchart.axis.y2.tick.show=true] Show or hide y2 axis tick line.
51
+ * @property {number} [subchart.axis.y2.tick.count] Set the number of y2 axis ticks.
52
+ * @property {Array|function} [subchart.axis.y2.tick.values] Set y2 axis tick values manually.
53
+ * @property {boolean|object} [subchart.axis.y2.tick.culling] Setting for culling y2 axis ticks.
54
+ * @property {number} [subchart.axis.y2.tick.culling.max] The number of y2 axis tick texts will be adjusted to less than this value.
55
+ * @property {boolean} [subchart.axis.y2.tick.culling.lines=true] Control y2 axis tick line visibility within culling option.
56
+ * @property {boolean} [subchart.axis.y2.tick.culling.reverse=false] Control y2 axis culling start point to be reversed.
57
+ * @property {boolean} [subchart.axis.y2.tick.outer] Show or hide y2 axis outer tick.
58
+ * @property {function|string} [subchart.axis.y2.tick.format] Use custom format for y2 axis ticks - see [axis.y2.tick.format](#.axis․y2․tick․format) for details.
59
+ * @property {boolean} [subchart.axis.y2.tick.text.show=true] Show or hide y2 axis tick text.
24
60
  * @property {Array} [subchart.init.range] Set initial selection domain range.
25
61
  * @property {number} [subchart.size.height] Change the height of the subchart.
26
62
  * @property {function} [subchart.onbrush] Set callback for brush event.<br>
@@ -30,9 +66,29 @@ export default {
30
66
  * subchart: {
31
67
  * show: true,
32
68
  * showHandle: true,
69
+ *
70
+ * // render the overview with a different chart type than the main chart
71
+ * type: "bar",
72
+ *
73
+ * // override the type per data series
74
+ * types: {
75
+ * data2: "area"
76
+ * },
33
77
  * size: {
34
78
  * height: 20
35
79
  * },
80
+ * brush: {
81
+ * // disable brush(zoom) interaction, rendering the subchart as a static overview
82
+ * enabled: false
83
+ * },
84
+ * grid: {
85
+ * // set false to hide focus grid line in subchart
86
+ * // focus: false,
87
+ * focus: {
88
+ * // NOTE: works only when 'brush.enabled=false'
89
+ * continuous: true
90
+ * }
91
+ * },
36
92
  * init: {
37
93
  * // specify initial range domain selection
38
94
  * range: [1, 2]
@@ -47,6 +103,12 @@ export default {
47
103
  * show: false
48
104
  * }
49
105
  * }
106
+ * },
107
+ * y: {
108
+ * show: true,
109
+ * tick: {
110
+ * count: 3
111
+ * }
50
112
  * }
51
113
  * },
52
114
  * onbrush: function(domain) { ... }
@@ -61,12 +123,47 @@ export default {
61
123
  * }
62
124
  */
63
125
  subchart_show: false,
126
+ subchart_type: <ChartTypes | undefined>undefined,
127
+ subchart_types: <Record<string, ChartTypes>>{},
128
+ subchart_brush_enabled: true,
64
129
  subchart_showHandle: false,
65
130
  subchart_size_height: 60,
131
+ subchart_grid_focus: <boolean | object>true,
132
+ subchart_grid_focus_continuous: false,
66
133
  subchart_axis_x_show: true,
67
134
  subchart_axis_x_tick_show: true,
135
+ subchart_axis_x_tick_count: <number | undefined>undefined,
136
+ subchart_axis_x_tick_values: <(string | Date | number)[] | (() => (string | Date | number)[])
137
+ | undefined>undefined,
138
+ subchart_axis_x_tick_culling: <boolean | object | undefined>undefined,
139
+ subchart_axis_x_tick_culling_max: <number | undefined>undefined,
140
+ subchart_axis_x_tick_culling_lines: <boolean | undefined>undefined,
141
+ subchart_axis_x_tick_culling_reverse: <boolean | undefined>undefined,
142
+ subchart_axis_x_tick_outer: <boolean | undefined>undefined,
68
143
  subchart_axis_x_tick_format: <Function | string | undefined>undefined,
69
144
  subchart_axis_x_tick_text_show: true,
145
+ subchart_axis_y_show: false,
146
+ subchart_axis_y_tick_show: true,
147
+ subchart_axis_y_tick_count: <number | undefined>undefined,
148
+ subchart_axis_y_tick_values: <number[] | (() => number[]) | undefined>undefined,
149
+ subchart_axis_y_tick_culling: <boolean | object | undefined>undefined,
150
+ subchart_axis_y_tick_culling_max: <number | undefined>undefined,
151
+ subchart_axis_y_tick_culling_lines: <boolean | undefined>undefined,
152
+ subchart_axis_y_tick_culling_reverse: <boolean | undefined>undefined,
153
+ subchart_axis_y_tick_outer: <boolean | undefined>undefined,
154
+ subchart_axis_y_tick_format: <Function | string | undefined>undefined,
155
+ subchart_axis_y_tick_text_show: true,
156
+ subchart_axis_y2_show: false,
157
+ subchart_axis_y2_tick_show: true,
158
+ subchart_axis_y2_tick_count: <number | undefined>undefined,
159
+ subchart_axis_y2_tick_values: <number[] | (() => number[]) | undefined>undefined,
160
+ subchart_axis_y2_tick_culling: <boolean | object | undefined>undefined,
161
+ subchart_axis_y2_tick_culling_max: <number | undefined>undefined,
162
+ subchart_axis_y2_tick_culling_lines: <boolean | undefined>undefined,
163
+ subchart_axis_y2_tick_culling_reverse: <boolean | undefined>undefined,
164
+ subchart_axis_y2_tick_outer: <boolean | undefined>undefined,
165
+ subchart_axis_y2_tick_format: <Function | string | undefined>undefined,
166
+ subchart_axis_y2_tick_text_show: true,
70
167
  subchart_init_range: <undefined | [number, number]>undefined,
71
168
  subchart_onbrush: () => {}
72
169
  };
@@ -51,7 +51,7 @@ export default {
51
51
  * @property {number} [gauge.expand.rate=0.98] Set expand rate.
52
52
  * @property {number} [gauge.expand.duration=50] Set the expand transition time in milliseconds.
53
53
  * @property {boolean} [gauge.enforceMinMax=false] Enforce to given min/max value.
54
- * - **Note:** Only works for single data series.
54
+ * - **Note:** Applies only to unstacked/multi-arc gauges; stacked gauge data is not supported.
55
55
  * - When `gauge.min=50` and given value is `30`, gauge will render as empty value.
56
56
  * - When `gauge.max=100` and given value is `120`, gauge will render till 100, not surpassing max value.
57
57
  * @property {number} [gauge.min=0] Set min value of the gauge.
@@ -18,7 +18,7 @@ export default {
18
18
  * - dice ([d3.treemapDice](https://github.com/d3/d3-hierarchy/blob/main/README.md#treemapDice))
19
19
  * - slice ([d3.treemapSlice](https://github.com/d3/d3-hierarchy/blob/main/README.md#treemapSlice))
20
20
  * - sliceDice ([d3.treemapSliceDice](https://github.com/d3/d3-hierarchy/blob/main/README.md#treemapSliceDice))
21
- * - squrify ([d3.treemapSquarify](https://github.com/d3/d3-hierarchy/blob/main/README.md#treemapSquarify))
21
+ * - squarify ([d3.treemapSquarify](https://github.com/d3/d3-hierarchy/blob/main/README.md#treemapSquarify))
22
22
  * - resquarify ([d3.treemapResquarify](https://github.com/d3/d3-hierarchy/blob/main/README.md#treemapResquarify))
23
23
  * @property {function} [treemap.label.format] Set formatter for the label text.<br>
24
24
  * - **Arguments:**
@@ -31,7 +31,7 @@ export default {
31
31
  * @see [Demo: treemap](https://naver.github.io/billboard.js/demo/#Chart.TreemapChart)
32
32
  * @example
33
33
  * treemap: {
34
- * // "binary", "dice", "slice", "sliceDice", "squrify", "resquarify"
34
+ * // "binary", "dice", "slice", "sliceDice", "squarify", "resquarify"
35
35
  * tile: "dice",
36
36
  *
37
37
  * label: {
@@ -22,7 +22,9 @@ export default class Element {
22
22
  x: null,
23
23
  y: null,
24
24
  y2: null,
25
- subX: null
25
+ subX: null,
26
+ subY: null,
27
+ subY2: null
26
28
  },
27
29
  axisTooltip: {
28
30
  x: null,
@@ -62,6 +62,7 @@ export default class State {
62
62
 
63
63
  // Zoom/subchart domain (different from current.domain which is for rendering)
64
64
  domain: <number[] | undefined>undefined,
65
+ subchartSourceTypes: <Record<string, string> | undefined>undefined,
65
66
 
66
67
  current: {
67
68
  // current domain value. Assigned when is zoom is called
@@ -126,6 +126,7 @@ export const $FOCUS = {
126
126
  defocused: "bb-defocused",
127
127
  legendItemFocused: "bb-legend-item-focused",
128
128
  xgridFocus: "bb-xgrid-focus",
129
+ xgridFocusContinuous: "bb-xgrid-focus-continuous",
129
130
  ygridFocus: "bb-ygrid-focus"
130
131
  };
131
132
 
@@ -20,6 +20,7 @@ import {
20
20
  isCanvasTreemapType
21
21
  } from "../../canvas/util";
22
22
  import ChartInternal from "../../ChartInternal/ChartInternal";
23
+ import {getMainCoordFromSubchartCoord} from "../../ChartInternal/internals/subchart.util";
23
24
  import {getRenderDataPoint} from "../../ChartInternal/shape/core/geometry";
24
25
  import {$FOCUS, $LEGEND} from "../../config/classes";
25
26
  import {window} from "../../module/browser";
@@ -697,6 +698,35 @@ function isCanvasSubchartPoint($$, point: number[]): boolean {
697
698
  point[1] <= rect.y + rect.h;
698
699
  }
699
700
 
701
+ /**
702
+ * Convert a canvas subchart point to the equivalent main plot point.
703
+ * @param {object} $$ ChartInternal instance
704
+ * @param {Array} point Canvas-local point
705
+ * @returns {Array|null} Main plot point or null when not applicable
706
+ * @private
707
+ */
708
+ function getCanvasMainPointFromSubchart($$, point: number[]): number[] | null {
709
+ const {config, state} = $$;
710
+ const rect = getCanvasSubchartRect($$);
711
+
712
+ if (config.subchart_brush_enabled !== false || !rect || !isCanvasSubchartPoint($$, point)) {
713
+ return null;
714
+ }
715
+
716
+ const mainCoord = getMainCoordFromSubchartCoord(
717
+ $$,
718
+ config.axis_rotated ? point[1] - rect.y : point[0] - rect.x
719
+ );
720
+
721
+ if (mainCoord === null) {
722
+ return null;
723
+ }
724
+
725
+ return config.axis_rotated ?
726
+ [state.margin.left + (state.width / 2), state.margin.top + mainCoord] :
727
+ [state.margin.left + mainCoord, state.margin.top + (state.height / 2)];
728
+ }
729
+
700
730
  /**
701
731
  * Get the allowed local brush coordinate extent for canvas subchart interactions.
702
732
  * @param {object} $$ ChartInternal instance
@@ -1139,8 +1169,10 @@ function syncCanvasFlowYDomains($$): void {
1139
1169
  scale[key]?.domain($$.getYDomain(targetsToShow, key));
1140
1170
  });
1141
1171
 
1142
- scale.subY?.domain($$.getYDomain(targetsToShow, "y"));
1143
- scale.subY2?.domain($$.getYDomain(targetsToShow, "y2"));
1172
+ $$.withSubchartTypeContext(() => {
1173
+ scale.subY?.domain($$.getYDomain(targetsToShow, "y"));
1174
+ scale.subY2?.domain($$.getYDomain(targetsToShow, "y2"));
1175
+ });
1144
1176
  }
1145
1177
 
1146
1178
  const canvasInternal = {
@@ -2036,13 +2068,34 @@ const canvasInternal = {
2036
2068
  const {config, state} = $$;
2037
2069
  const selected = state.canvasSelection;
2038
2070
  const selectionGrouped = config.data_selection_grouped;
2039
- const targetIds = getCanvasSelectionIds(ids);
2071
+ let targetIds = getCanvasSelectionIds(ids);
2040
2072
  let changed = false;
2073
+ const singleSelection = isSelection && !config.data_selection_multiple;
2074
+ let resetDone = !singleSelection;
2041
2075
 
2042
2076
  if (!config.data_selection_enabled) {
2043
2077
  return;
2044
2078
  }
2045
2079
 
2080
+ // When multiple selection is disabled, only one data point (or one x-index
2081
+ // group when 'grouped' is enabled) can hold the selected state at a time.
2082
+ // Clear any current selection only when the narrowed request can select a point.
2083
+ if (singleSelection) {
2084
+ indices = indices?.length ? [indices[0]] : [0];
2085
+
2086
+ // non-grouped single selection targets exactly one point, so narrow to a
2087
+ // single id (the first requested, or the first shown when none given).
2088
+ if (!selectionGrouped) {
2089
+ if (targetIds) {
2090
+ targetIds = targetIds.slice(0, 1);
2091
+ } else {
2092
+ const [firstTarget] = $$.filterTargetsToShow($$.data.targets);
2093
+
2094
+ targetIds = firstTarget ? [firstTarget.id] : [];
2095
+ }
2096
+ }
2097
+ }
2098
+
2046
2099
  eachCanvasSelectableData($$, d => {
2047
2100
  const key = getCanvasDataKey(d);
2048
2101
  const isTargetId = selectionGrouped || !targetIds || targetIds.indexOf(d.id) >= 0;
@@ -2050,11 +2103,20 @@ const canvasInternal = {
2050
2103
  const isSelected = selected.has(key);
2051
2104
 
2052
2105
  if (isSelection) {
2053
- if (isTargetId && isTargetIndex && !isSelected) {
2106
+ if (isTargetId && isTargetIndex && (!isSelected || singleSelection)) {
2107
+ if (!resetDone) {
2108
+ $$.setCanvasSelection(false);
2109
+ resetDone = true;
2110
+ }
2111
+
2112
+ if (selected.has(key)) {
2113
+ return;
2114
+ }
2115
+
2054
2116
  selected.add(key);
2055
2117
  callFn(config.data_onselected, $$.api, d, $$.canvasEngine.canvas);
2056
2118
  changed = true;
2057
- } else if (resetOther && isSelected) {
2119
+ } else if ((!singleSelection || resetDone) && resetOther && isSelected) {
2058
2120
  selected.delete(key);
2059
2121
  callFn(config.data_onunselected, $$.api, d, $$.canvasEngine.canvas);
2060
2122
  changed = true;
@@ -2354,13 +2416,19 @@ const canvasInternal = {
2354
2416
  */
2355
2417
  updateCanvasSubchartBrush(event: MouseEvent | PointerEvent | TouchEvent): boolean {
2356
2418
  const $$ = this;
2357
- const {state} = $$;
2419
+ const {config, state} = $$;
2358
2420
  const start = state.canvasSubchartBrushStart;
2359
2421
  const origin = state.canvasSubchartBrushOrigin;
2360
2422
  const mode = state.canvasSubchartBrushMode;
2361
2423
  const coord = getCanvasSubchartBrushCoord($$, event, true);
2362
2424
 
2363
- if (!state.canvasSubchartBrushDragging || start === null || coord === null || !mode) {
2425
+ if (
2426
+ config.subchart_brush_enabled === false ||
2427
+ !state.canvasSubchartBrushDragging ||
2428
+ start === null ||
2429
+ coord === null ||
2430
+ !mode
2431
+ ) {
2364
2432
  return false;
2365
2433
  }
2366
2434
 
@@ -2423,6 +2491,12 @@ const canvasInternal = {
2423
2491
  updateCanvasSubchartCursor(event: MouseEvent | PointerEvent | TouchEvent): boolean {
2424
2492
  const $$ = this;
2425
2493
  const canvas = $$.$el.canvas.node();
2494
+
2495
+ if ($$.config.subchart_brush_enabled === false) {
2496
+ canvas.style.cursor = "";
2497
+ return false;
2498
+ }
2499
+
2426
2500
  const coord = getCanvasSubchartBrushCoord($$, event);
2427
2501
 
2428
2502
  if (coord === null) {
@@ -2446,6 +2520,11 @@ const canvasInternal = {
2446
2520
  startCanvasSubchartBrush(event: MouseEvent | PointerEvent | TouchEvent): boolean {
2447
2521
  const $$ = this;
2448
2522
  const {state} = $$;
2523
+
2524
+ if ($$.config.subchart_brush_enabled === false) {
2525
+ return false;
2526
+ }
2527
+
2449
2528
  const coord = getCanvasSubchartBrushCoord($$, event);
2450
2529
 
2451
2530
  if (coord === null) {
@@ -2867,7 +2946,8 @@ const canvasInternal = {
2867
2946
  return;
2868
2947
  }
2869
2948
 
2870
- const point = getCanvasEventPoint($$, event);
2949
+ const rawPoint = getCanvasEventPoint($$, event);
2950
+ const point = rawPoint && (getCanvasMainPointFromSubchart($$, rawPoint) || rawPoint);
2871
2951
  const d = point ? getCanvasHoverDatumFromPoint($$, point) : null;
2872
2952
 
2873
2953
  if (!d) {
@@ -2876,8 +2956,8 @@ const canvasInternal = {
2876
2956
  state.canvasFocusKey = null;
2877
2957
  $$.clearCanvasFocus();
2878
2958
  }
2879
- if (point && config.axis_tooltip && isCanvasAxisTooltipArea($$, point)) {
2880
- $$.renderCanvasAxisTooltip(point);
2959
+ if (rawPoint && config.axis_tooltip && isCanvasAxisTooltipArea($$, rawPoint)) {
2960
+ $$.renderCanvasAxisTooltip(rawPoint);
2881
2961
  $$.hideTooltip?.();
2882
2962
  return;
2883
2963
  }
@@ -3033,6 +3113,7 @@ const canvasInternal = {
3033
3113
  $$.canvasAxisRenderer.drawGridLines($$);
3034
3114
  $$.canvasRenderer.drawSubchart($$, drawShape);
3035
3115
  state.hasAxis && $$.canvasAxisRenderer.drawSubXAxis($$);
3116
+ state.hasAxis && $$.canvasAxisRenderer.drawSubYAxes($$);
3036
3117
  $$.canvasRenderer.drawEmptyLabel($$);
3037
3118
  rebuildHit && $$.hitDetector.rebuild($$, drawShape);
3038
3119
  } finally {
@@ -3069,6 +3150,7 @@ const canvasInternal = {
3069
3150
  $$.canvasAxisRenderer.drawGridLines($$);
3070
3151
  $$.canvasRenderer.drawSubchart($$, drawShape);
3071
3152
  state.hasAxis && $$.canvasAxisRenderer.drawSubXAxis($$);
3153
+ state.hasAxis && $$.canvasAxisRenderer.drawSubYAxes($$);
3072
3154
  $$.canvasRenderer.drawEmptyLabel($$);
3073
3155
  } finally {
3074
3156
  $$.canvasEngine.endFrame();
@@ -18,7 +18,9 @@ const isObjectType = (v: unknown): v is Record<string | number, any> => typeof v
18
18
 
19
19
  const isEmptyObject = (obj: object): boolean => {
20
20
  for (const x in obj) {
21
- return false;
21
+ if (Object.prototype.hasOwnProperty.call(obj, x)) {
22
+ return false;
23
+ }
22
24
  }
23
25
  return true;
24
26
  };
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Copyright (c) 2017 ~ present NAVER Corp.
3
+ * billboard.js project is licensed under the MIT license
4
+ *
5
+ * Bounded Voronoi cells, computed directly by half-plane clipping instead of
6
+ * going through a Delaunay triangulation.
7
+ *
8
+ * A cell is the set of points closer to its site than to any other site, which
9
+ * is exactly the intersection of the half-planes bounded by the perpendicular
10
+ * bisectors between that site and every other one. Starting from the clip
11
+ * rectangle and clipping it against each bisector (Sutherland-Hodgman) yields
12
+ * the same polygons d3-delaunay's `voronoi().cellPolygon()` returns, without
13
+ * the triangulation payload.
14
+ *
15
+ * The trade-off is O(n²) rather than O(n log n). That is the right trade for
16
+ * the label-placement use case, which runs on tens to hundreds of points.
17
+ *
18
+ * Parity with d3-delaunay is asserted by test/module/voronoi-parity-spec.ts.
19
+ */
20
+ type Point = [number, number];
21
+
22
+ // distance below which two sites are treated as coincident
23
+ const EPSILON = 1e-9;
24
+
25
+ /**
26
+ * Clip a convex polygon by the half-plane of points at least as close to `a` as
27
+ * to `b`, i.e. the side of the perpendicular bisector of `ab` that contains `a`.
28
+ * @param {Array} polygon Convex polygon as an open ring of [x, y]
29
+ * @param {Array} a Site kept by the half-plane
30
+ * @param {Array} b Opposing site
31
+ * @returns {Array} Clipped polygon, empty when fully outside
32
+ * @private
33
+ */
34
+ function clipByBisector(polygon: Point[], a: Point, b: Point): Point[] {
35
+ const dx = b[0] - a[0];
36
+ const dy = b[1] - a[1];
37
+
38
+ // bisector as dx*x + dy*y = c, keeping the side where the expression is below c
39
+ const c = (dx * (a[0] + b[0]) + dy * (a[1] + b[1])) / 2;
40
+ const output: Point[] = [];
41
+ const n = polygon.length;
42
+
43
+ let prev = polygon[n - 1];
44
+ let prevDist = dx * prev[0] + dy * prev[1] - c;
45
+
46
+ for (let i = 0; i < n; i++) {
47
+ const curr = polygon[i];
48
+ const currDist = dx * curr[0] + dy * curr[1] - c;
49
+
50
+ // the edge straddles the bisector: emit the crossing point
51
+ if ((prevDist > 0) !== (currDist > 0)) {
52
+ const t = prevDist / (prevDist - currDist);
53
+
54
+ output.push([
55
+ prev[0] + t * (curr[0] - prev[0]),
56
+ prev[1] + t * (curr[1] - prev[1])
57
+ ]);
58
+ }
59
+
60
+ if (currDist <= 0) {
61
+ output.push(curr);
62
+ }
63
+
64
+ prev = curr;
65
+ prevDist = currDist;
66
+ }
67
+
68
+ return output;
69
+ }
70
+
71
+ /**
72
+ * Compute bounded Voronoi cells for the given sites.
73
+ *
74
+ * Cells are returned in site order, closed (first vertex repeated last) as
75
+ * d3-delaunay does. A site yields `null` when it has no cell: it lies outside
76
+ * the bounds, or it coincides with an earlier site.
77
+ * @param {Array} points Sites as [x, y]
78
+ * @param {Array} bounds Clip extent as [xmin, ymin, xmax, ymax]
79
+ * @returns {Array} Cell polygons in site order
80
+ * @private
81
+ */
82
+ export function voronoiCells(points: Point[], bounds: number[]): (Point[] | null)[] {
83
+ const [x0, y0, x1, y1] = [
84
+ Math.min(bounds[0], bounds[2]),
85
+ Math.min(bounds[1], bounds[3]),
86
+ Math.max(bounds[0], bounds[2]),
87
+ Math.max(bounds[1], bounds[3])
88
+ ];
89
+ const rect: Point[] = [[x0, y0], [x1, y0], [x1, y1], [x0, y1]];
90
+ const n = points.length;
91
+
92
+ return points.map((site, i) => {
93
+ let cell = rect;
94
+
95
+ for (let j = 0; j < n && cell.length > 2; j++) {
96
+ if (j === i) {
97
+ continue;
98
+ }
99
+
100
+ const other = points[j];
101
+
102
+ if (
103
+ Math.abs(other[0] - site[0]) < EPSILON &&
104
+ Math.abs(other[1] - site[1]) < EPSILON
105
+ ) {
106
+ // coincident sites: the first one keeps the cell, as in d3-delaunay
107
+ if (j < i) {
108
+ return null;
109
+ }
110
+
111
+ continue;
112
+ }
113
+
114
+ cell = clipByBisector(cell, site, other);
115
+ }
116
+
117
+ return cell.length > 2 ? [...cell, cell[0]] as Point[] : null;
118
+ });
119
+ }
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Copyright (c) 2017 ~ present NAVER Corp.
3
+ * billboard.js project is licensed under the MIT license
4
+ */
5
+ import {columns, json, rows} from "../ChartInternal/data/convert.helper";
6
+
7
+ /**
8
+ * Worker entry point.
9
+ *
10
+ * This module is bundled separately at build time and injected into
11
+ * `src/module/worker.ts` as the `__WORKER_SRC__` string constant. It is never
12
+ * part of the main bundle graph.
13
+ *
14
+ * Offloaded work is addressed by op name, so no function source is ever
15
+ * stringified or evaluated. That keeps the worker immune to whatever transform
16
+ * the host toolchain applies to billboard.js sources - coverage instrumentation,
17
+ * babel helpers or bundler-hoisted module scope references cannot leak in.
18
+ */
19
+ export const ops = {
20
+ columns,
21
+ json,
22
+ rows
23
+ };
24
+
25
+ type TWorkerRequest = {args: unknown[], id: number, op: keyof typeof ops};
26
+
27
+ const ctx = self as unknown as {
28
+ onmessage: ((e: {data: TWorkerRequest}) => void) | null,
29
+ postMessage: (message: unknown) => void
30
+ };
31
+
32
+ /**
33
+ * Run the requested op and post the result back, keyed by the request id.
34
+ * @param {object} e Message event carrying the op name and arguments
35
+ * @param {object} e.data Request payload: `{args, id, op}`
36
+ * @private
37
+ */
38
+ export function handleMessage({data}: {data: TWorkerRequest}): void {
39
+ const {args, id, op} = data;
40
+
41
+ try {
42
+ const fn = ops[op];
43
+
44
+ if (!fn) {
45
+ throw new Error(`Unknown worker op: ${op}`);
46
+ }
47
+
48
+ ctx.postMessage({id, result: (fn as Function)(...args)});
49
+ } catch (error) {
50
+ ctx.postMessage({
51
+ id,
52
+ error: error && ((error as Error).message || (error as Error).name) || String(error)
53
+ });
54
+ }
55
+ }
56
+
57
+ // A dedicated worker has no `window`. The guard keeps this module importable from
58
+ // specs (see test/module/worker-real-spec.ts) without hijacking window.onmessage.
59
+ if (typeof window === "undefined") {
60
+ ctx.onmessage = handleMessage;
61
+ }