billboard.js 4.0.2 → 4.1.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 (272) hide show
  1. package/README.md +82 -7
  2. package/dist/billboard.css +1 -1
  3. package/dist/billboard.js +1938 -557
  4. package/dist/billboard.min.css +1 -1
  5. package/dist/billboard.min.js +19 -25
  6. package/dist/billboard.pkgd.js +1934 -742
  7. package/dist/billboard.pkgd.min.js +24 -30
  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 +2 -2
  12. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  13. package/dist/plugin/billboardjs-plugin-sparkline.js +3 -2
  14. package/dist/plugin/billboardjs-plugin-sparkline.min.js +3 -3
  15. package/dist/plugin/billboardjs-plugin-stanford.js +3 -2
  16. package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
  17. package/dist/plugin/billboardjs-plugin-tableview.js +57 -27
  18. package/dist/plugin/billboardjs-plugin-tableview.min.js +5 -5
  19. package/dist/plugin/billboardjs-plugin-textoverlap.js +72 -54
  20. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  21. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +2 -2
  22. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +2 -2
  23. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +3 -2
  24. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +3 -3
  25. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +3 -2
  26. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +2 -2
  27. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +57 -27
  28. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +11 -11
  29. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +65 -3556
  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 -147
  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 +970 -1147
  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 +286 -245
  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 -272
  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 -413
  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 -828
  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/focus.ts +8 -12
  222. package/src/Chart/api/selection.ts +130 -5
  223. package/src/ChartInternal/Axis/Axis.ts +164 -65
  224. package/src/ChartInternal/Axis/AxisRenderer.ts +41 -8
  225. package/src/ChartInternal/Axis/AxisRendererHelper.ts +1 -1
  226. package/src/ChartInternal/ChartInternal.ts +1 -1
  227. package/src/ChartInternal/data/convert.ts +54 -4
  228. package/src/ChartInternal/data/data.ts +19 -6
  229. package/src/ChartInternal/interactions/eventrect.ts +6 -0
  230. package/src/ChartInternal/interactions/subchart.ts +437 -66
  231. package/src/ChartInternal/internals/color.ts +7 -6
  232. package/src/ChartInternal/internals/domain.ts +15 -3
  233. package/src/ChartInternal/internals/grid.ts +21 -1
  234. package/src/ChartInternal/internals/scale.ts +9 -2
  235. package/src/ChartInternal/internals/selection.ts +1 -1
  236. package/src/ChartInternal/internals/subchart.util.ts +55 -0
  237. package/src/ChartInternal/internals/text.arc.ts +3 -1
  238. package/src/ChartInternal/internals/text.ts +19 -6
  239. package/src/ChartInternal/internals/transform.ts +8 -2
  240. package/src/ChartInternal/internals/type.ts +131 -33
  241. package/src/ChartInternal/shape/IShape.ts +6 -3
  242. package/src/ChartInternal/shape/bar.ts +87 -37
  243. package/src/ChartInternal/shape/core/barRadius.ts +129 -0
  244. package/src/ChartInternal/shape/core/candlestick.ts +1 -1
  245. package/src/ChartInternal/shape/core/path.ts +76 -9
  246. package/src/ChartInternal/shape/funnel.ts +2 -3
  247. package/src/ChartInternal/shape/line.ts +1 -1
  248. package/src/ChartInternal/shape/point.ts +27 -13
  249. package/src/ChartInternal/shape/shape.ts +172 -18
  250. package/src/Plugin/stanford/index.ts +0 -4
  251. package/src/Plugin/tableview/index.ts +85 -3
  252. package/src/Plugin/textoverlap/index.ts +9 -15
  253. package/src/canvas/CanvasAxisRenderer.ts +184 -36
  254. package/src/canvas/CanvasRenderer.ts +247 -160
  255. package/src/canvas/CanvasTheme.ts +212 -0
  256. package/src/canvas/axisTicks.ts +122 -40
  257. package/src/config/Options/axis/y2.ts +13 -0
  258. package/src/config/Options/common/boost.ts +64 -4
  259. package/src/config/Options/common/color.ts +2 -2
  260. package/src/config/Options/interaction/subchart.ts +98 -1
  261. package/src/config/Options/shape/gauge.ts +1 -1
  262. package/src/config/Options/shape/treemap.ts +2 -2
  263. package/src/config/Store/Element.ts +3 -1
  264. package/src/config/Store/State.ts +1 -0
  265. package/src/config/classes.ts +1 -0
  266. package/src/config/resolver/canvas.ts +92 -10
  267. package/src/module/voronoi.ts +119 -0
  268. package/src/module/worker.entry.ts +61 -0
  269. package/src/module/worker.ts +346 -63
  270. package/src/react/index.ts +193 -0
  271. package/types/options.d.ts +206 -3
  272. package/types/react/index.d.ts +27 -0
@@ -5,764 +5,588 @@
5
5
  * billboard.js, JavaScript chart library
6
6
  * https://naver.github.io/billboard.js/
7
7
  *
8
- * @version 4.0.2
8
+ * @version 4.1.0-next.1
9
9
  */
10
- import { select } from 'd3-selection';
11
- import { timeParse, utcParse, timeFormat, utcFormat } from 'd3-time-format';
12
- import { $COMMON, $TEXT, $CIRCLE } from '../config/classes.js';
13
- import Options from '../config/Options/Options.js';
14
- import Store from '../config/Store/Store.js';
15
- import { document as doc, window as win } from '../module/browser.js';
16
- import Cache from '../module/Cache.js';
17
- import { checkModuleImport } from '../module/error.js';
18
- import { generateResize } from '../module/generator.js';
19
- import dataConvert from './data/convert.js';
20
- import data from './data/data.js';
21
- import dataLoad from './data/load.js';
22
- import interaction from './interactions/interaction.js';
23
- import category from './internals/category.js';
24
- import classModule from './internals/class.js';
25
- import color from './internals/color.js';
26
- import domain from './internals/domain.js';
27
- import format from './internals/format.js';
28
- import legend from './internals/legend.js';
29
- import redraw from './internals/redraw.js';
30
- import scale from './internals/scale.js';
31
- import size from './internals/size.js';
32
- import style from './internals/style.js';
33
- import text from './internals/text.js';
34
- import title from './internals/title.js';
35
- import tooltip from './internals/tooltip.js';
36
- import transform from './internals/transform.js';
37
- import typeInternals from './internals/type.js';
38
- import shape from './shape/shape.js';
39
- import { callFn, getRandom, sortValue, capitalize, getOption, extend } from '../module/util/object.js';
40
- import { isFunction, notEmpty, isObject, isBoolean, isString } from '../module/util/type-checks.js';
41
- import { convertInputType, hasStyle } from '../module/util/dom.js';
42
-
10
+ import { document as doc, window as win } from "../module/browser.js";
11
+ import { isBoolean, isFunction, isObject, isString, notEmpty } from "../module/util/type-checks.js";
12
+ import { callFn, capitalize, extend, getOption, getRandom, sortValue } from "../module/util/object.js";
13
+ import { convertInputType, hasStyle } from "../module/util/dom.js";
14
+ import { checkModuleImport } from "../module/error.js";
15
+ import { $CIRCLE, $COMMON, $TEXT } from "../config/classes.js";
16
+ import Options from "../config/Options/Options.js";
17
+ import Store from "../config/Store/Store.js";
18
+ import Cache from "../module/Cache.js";
19
+ import { generateResize } from "../module/generator.js";
20
+ import convert_default from "./data/convert.js";
21
+ import data_default from "./data/data.js";
22
+ import load_default from "./data/load.js";
23
+ import interaction_default from "./interactions/interaction.js";
24
+ import category_default from "./internals/category.js";
25
+ import class_default from "./internals/class.js";
26
+ import color_default from "./internals/color.js";
27
+ import domain_default from "./internals/domain.js";
28
+ import format_default from "./internals/format.js";
29
+ import legend_default from "./internals/legend.js";
30
+ import redraw_default from "./internals/redraw.js";
31
+ import scale_default from "./internals/scale.js";
32
+ import size_default from "./internals/size.js";
33
+ import style_default from "./internals/style.js";
34
+ import text_default from "./internals/text.js";
35
+ import title_default from "./internals/title.js";
36
+ import tooltip_default from "./internals/tooltip.js";
37
+ import transform_default from "./internals/transform.js";
38
+ import type_default from "./internals/type.js";
39
+ import shape_default from "./shape/shape.js";
40
+ import { select } from "d3-selection";
41
+ import { timeFormat, timeParse, utcFormat, utcParse } from "d3-time-format";
42
+ //#region src/ChartInternal/ChartInternal.ts
43
43
  /**
44
- * Copyright (c) 2017 ~ present NAVER Corp.
45
- * billboard.js project is licensed under the MIT license
46
- * @ignore
47
- */
44
+ * Copyright (c) 2017 ~ present NAVER Corp.
45
+ * billboard.js project is licensed under the MIT license
46
+ * @ignore
47
+ */
48
48
  /**
49
- * Get SVG-only chart type reason for canvas render fallback.
50
- * @param {object} $$ ChartInternal instance
51
- * @returns {string|null} Unsupported chart type reason
52
- * @private
53
- */
49
+ * Get SVG-only chart type reason for canvas render fallback.
50
+ * @param {object} $$ ChartInternal instance
51
+ * @returns {string|null} Unsupported chart type reason
52
+ * @private
53
+ */
54
54
  function getUnsupportedCanvasRenderType($$) {
55
- if ($$.hasArcType()) {
56
- return "arc charts";
57
- }
58
- if ($$.hasType("funnel")) {
59
- return "funnel chart";
60
- }
61
- return null;
55
+ if ($$.hasArcType()) return "arc charts";
56
+ if ($$.hasType("funnel")) return "funnel chart";
57
+ return null;
62
58
  }
63
59
  /**
64
- * Fall back to SVG when canvas mode is requested for unsupported chart types.
65
- * @param {object} $$ ChartInternal instance
66
- * @private
67
- */
60
+ * Fall back to SVG when canvas mode is requested for unsupported chart types.
61
+ * @param {object} $$ ChartInternal instance
62
+ * @private
63
+ */
68
64
  function fallbackUnsupportedCanvasRenderMode($$) {
69
- const { config } = $$;
70
- const unsupportedType = config.render_mode === "canvas" ?
71
- getUnsupportedCanvasRenderType($$) :
72
- null;
73
- if (!unsupportedType) {
74
- return;
75
- }
76
- win.console?.warn?.(`[billboard.js] render.mode='canvas' is ignored for ${unsupportedType}; falling back to SVG.`);
77
- config.render_mode = "svg";
65
+ const { config } = $$;
66
+ const unsupportedType = config.render_mode === "canvas" ? getUnsupportedCanvasRenderType($$) : null;
67
+ if (!unsupportedType) return;
68
+ win.console?.warn?.(`[billboard.js] render.mode='canvas' is ignored for ${unsupportedType}; falling back to SVG.`);
69
+ config.render_mode = "svg";
78
70
  }
79
71
  /**
80
- * Internal chart class.
81
- * - Note: Instantiated internally, not exposed for public.
82
- * @class ChartInternal
83
- * @ignore
84
- * @private
85
- */
86
- class ChartInternal {
87
- api; // API interface
88
- config; // config object
89
- cache; // cache instance
90
- $el; // elements
91
- state; // state variables
92
- charts; // all Chart instances array within page (equivalent of 'bb.instances')
93
- // data object
94
- data = {
95
- xs: {},
96
- targets: []
97
- };
98
- // Axis
99
- axis; // Axis
100
- // scales
101
- scale = {
102
- x: null,
103
- y: null,
104
- y2: null,
105
- subX: null,
106
- subY: null,
107
- subY2: null,
108
- zoom: null
109
- };
110
- // original values
111
- org = {
112
- xScale: null,
113
- xDomain: null
114
- };
115
- // formatter function
116
- color;
117
- patterns;
118
- levelColor;
119
- point;
120
- brush;
121
- // format function
122
- format = {
123
- extraLineClasses: null,
124
- xAxisTick: null,
125
- dataTime: null, // dataTimeFormat
126
- defaultAxisTime: null, // defaultAxisTimeFormat
127
- axisTime: null // axisTimeFormat
128
- };
129
- constructor(api) {
130
- const $$ = this;
131
- $$.api = api; // Chart class instance alias
132
- $$.config = new Options();
133
- $$.cache = new Cache();
134
- const store = new Store();
135
- $$.$el = store.getStore("element");
136
- $$.state = store.getStore("state");
137
- $$.$T = $$.$T.bind($$);
138
- }
139
- /**
140
- * Get the selection based on transition config
141
- * @param {SVGElement|d3Selection} selection Target selection
142
- * @param {boolean} force Force transition
143
- * @param {string} name Transition name
144
- * @returns {d3Selection}
145
- * @private
146
- */
147
- $T(selection, force, name) {
148
- const { config, state } = this;
149
- const duration = config.transition_duration;
150
- const subchart = config.subchart_show;
151
- let t = selection;
152
- if (t) {
153
- // in case of non d3 selection, wrap with d3 selection
154
- if ("tagName" in t) {
155
- t = select(t);
156
- }
157
- // do not transit on:
158
- // - wheel zoom (state.zooming = true)
159
- // - when has no subchart
160
- // - initialization
161
- // - resizing
162
- const transit = ((force !== false && duration) || force) &&
163
- (!state.zooming || state.dragging) &&
164
- !state.resizing &&
165
- state.rendered &&
166
- !subchart;
167
- // @ts-ignore
168
- t = (transit ? t.transition(name).duration(duration) : t);
169
- }
170
- return t;
171
- }
172
- beforeInit() {
173
- const $$ = this;
174
- $$.callPluginHook("$beforeInit");
175
- // can do something
176
- callFn($$.config.onbeforeinit, $$.api);
177
- }
178
- afterInit() {
179
- const $$ = this;
180
- $$.callPluginHook("$afterInit");
181
- // can do something
182
- callFn($$.config.onafterinit, $$.api);
183
- }
184
- init() {
185
- const $$ = this;
186
- const { config, state, $el } = $$;
187
- const { boost_useCssRule, bindto } = config;
188
- checkModuleImport($$);
189
- fallbackUnsupportedCanvasRenderMode($$);
190
- const hasArcType = $$.hasArcType();
191
- state.hasRadar = !state.hasAxis && $$.hasType("radar");
192
- state.hasFunnel = !state.hasAxis && $$.hasType("funnel");
193
- state.hasTreemap = !state.hasAxis && $$.hasType("treemap");
194
- state.hasAxis = !hasArcType && !state.hasFunnel && !state.hasTreemap;
195
- // datetime to be used for uniqueness
196
- state.datetimeId = `bb-${+new Date() * getRandom()}`;
197
- if (boost_useCssRule) {
198
- // append style element
199
- const styleEl = doc.createElement("style");
200
- // styleEl.id = styleId;
201
- styleEl.type = "text/css";
202
- doc.head.appendChild(styleEl);
203
- state.style = {
204
- rootSelector: `.${state.datetimeId}`,
205
- sheet: styleEl.sheet
206
- };
207
- // used on .destroy()
208
- $el.style = styleEl;
209
- }
210
- const bindConfig = {
211
- element: bindto,
212
- classname: "bb"
213
- };
214
- if (isObject(bindto)) {
215
- bindConfig.element = bindto.element || "#chart";
216
- bindConfig.classname = bindto.classname || bindConfig.classname;
217
- }
218
- // select bind element
219
- $el.chart = isFunction(bindConfig.element.node) ?
220
- bindto.element :
221
- select(bindConfig.element || []);
222
- if ($el.chart.empty()) {
223
- $el.chart = select(doc.body.appendChild(doc.createElement("div")));
224
- }
225
- $el.chart.html("")
226
- .classed(bindConfig.classname, true)
227
- .classed(state.datetimeId, boost_useCssRule)
228
- .style("position", "relative");
229
- $$.initParams();
230
- $$.initToRender();
231
- }
232
- /**
233
- * Initialize the rendering process
234
- * @param {boolean} forced Force to render process
235
- * @private
236
- */
237
- initToRender(forced) {
238
- const $$ = this;
239
- const { config, state, $el: { chart } } = $$;
240
- const isHidden = () => hasStyle(chart, { display: "none", visibility: "hidden" });
241
- const isLazy = config.render.lazy === false ? false : config.render.lazy || isHidden();
242
- const MutationObserver = win.MutationObserver;
243
- if (isLazy && MutationObserver && config.render.observe !== false && !forced) {
244
- new MutationObserver((mutation, observer) => {
245
- if (!isHidden()) {
246
- observer.disconnect();
247
- !state.rendered && $$.initToRender(true);
248
- }
249
- }).observe(chart.node(), {
250
- attributes: true,
251
- attributeFilter: ["class", "style"]
252
- });
253
- }
254
- if (!isLazy || forced) {
255
- $$.convertData(config, res => {
256
- $$.initWithData(res);
257
- $$.afterInit();
258
- });
259
- }
260
- }
261
- initParams() {
262
- const $$ = this;
263
- const { config, format, state } = $$;
264
- if (config.render_mode === "canvas") {
265
- $$.prepareCanvasConfig?.();
266
- }
267
- // color settings
268
- $$.color = $$.generateColor();
269
- $$.levelColor = $$.generateLevelColor();
270
- // when 'padding=false' is set, disable axes and subchart. Because they are useless.
271
- if (config.padding === false) {
272
- config.axis_x_show = false;
273
- config.axis_y_show = false;
274
- config.axis_y2_show = false;
275
- config.subchart_show = false;
276
- }
277
- if (config.render_mode !== "canvas" && ($$.hasPointType() || $$.hasLegendDefsPoint?.())) {
278
- $$.point = $$.generatePoint();
279
- }
280
- if (state.hasAxis) {
281
- $$.initClip();
282
- format.extraLineClasses = $$.generateExtraLineClass();
283
- format.dataTime = config.data_xLocaltime ? timeParse : utcParse;
284
- format.axisTime = config.axis_x_localtime ? timeFormat : utcFormat;
285
- const isDragZoom = config.zoom_enabled && config.zoom_type === "drag";
286
- format.defaultAxisTime = d => {
287
- const { x, zoom } = $$.scale;
288
- const isZoomed = isDragZoom ?
289
- zoom :
290
- zoom && x.orgDomain().toString() !== zoom.domain().toString();
291
- const specifier = (d.getMilliseconds() && ".%L") ||
292
- (d.getSeconds() && ".:%S") ||
293
- (d.getMinutes() && "%I:%M") ||
294
- (d.getHours() && "%I %p") ||
295
- (d.getDate() !== 1 && "%b %d") ||
296
- (isZoomed && d.getDate() === 1 && "%b'%y") ||
297
- (d.getMonth() && "%-m/%-d") || "%Y";
298
- return format.axisTime(specifier)(d);
299
- };
300
- }
301
- const { legend_position, legend_inset_anchor, axis_rotated } = config;
302
- state.isLegendRight = legend_position === "right";
303
- state.isLegendInset = legend_position === "inset";
304
- state.isLegendTop = legend_inset_anchor === "top-left" ||
305
- legend_inset_anchor === "top-right";
306
- state.isLegendLeft = legend_inset_anchor === "top-left" ||
307
- legend_inset_anchor === "bottom-left";
308
- state.rotatedPadding.top = $$.getResettedPadding(state.rotatedPadding.top);
309
- state.rotatedPadding.right = axis_rotated && !config.axis_x_show ? 0 : 30;
310
- state.inputType = convertInputType(config.interaction_inputType_mouse, config.interaction_inputType_touch);
311
- }
312
- initWithData(data) {
313
- const $$ = this;
314
- const { config, scale, state, $el, org } = $$;
315
- const { hasAxis, hasFunnel, hasTreemap } = state;
316
- const hasInteraction = config.interaction_enabled;
317
- const hasPolar = $$.hasType("polar");
318
- const labelsBGColor = config.data_labels_backgroundColors;
319
- // for arc type, set axes to not be shown
320
- // $$.hasArcType() && ["x", "y", "y2"].forEach(id => (config[`axis_${id}_show`] = false));
321
- if (hasAxis) {
322
- $$.axis = $$.getAxisInstance();
323
- config.zoom_enabled && $$.initZoom();
324
- }
325
- // Init data as targets
326
- $$.data.xs = {};
327
- $$.data.targets = $$.convertDataToTargets(data);
328
- if (config.data_filter) {
329
- $$.data.targets = $$.data.targets.filter(config.data_filter.bind($$.api));
330
- }
331
- // Set targets to hide if needed
332
- if (config.data_hide) {
333
- $$.addHiddenTargetIds(config.data_hide === true ? $$.mapToIds($$.data.targets) : config.data_hide);
334
- }
335
- if (config.legend_hide) {
336
- $$.addHiddenLegendIds(config.legend_hide === true ? $$.mapToIds($$.data.targets) : config.legend_hide);
337
- }
338
- // Init sizes and scales
339
- $$.updateSizes();
340
- $$.updateScales(true);
341
- // retrieve scale after the 'updateScales()' is called
342
- if (hasAxis) {
343
- const { x, y, y2, subX, subY, subY2 } = scale;
344
- // Set domains for each scale
345
- if (x) {
346
- x.domain(sortValue($$.getXDomain($$.data.targets), !config.axis_x_inverted));
347
- subX.domain(x.domain());
348
- // Save original x domain for zoom update
349
- org.xDomain = x.domain();
350
- }
351
- if (y) {
352
- y.domain($$.getYDomain($$.data.targets, "y"));
353
- subY.domain(y.domain());
354
- }
355
- if (y2) {
356
- y2.domain($$.getYDomain($$.data.targets, "y2"));
357
- subY2 && subY2.domain(y2.domain());
358
- }
359
- }
360
- if (config.render_mode === "canvas") {
361
- if (!$$.initCanvas) {
362
- throw Error("[billboard.js] Please import and call canvas() to use render.mode='canvas'.");
363
- }
364
- // Bind resize event before tooltip init because tooltip position registers resize hooks.
365
- $$.bindResize();
366
- $$.initCanvas();
367
- config.tooltip_show && $$.initTooltip();
368
- $$.callPluginHook("$init");
369
- // oninit callback
370
- callFn(config.oninit, $$.api);
371
- $$.redraw({
372
- withTransition: false,
373
- withTransform: true,
374
- withUpdateXDomain: true,
375
- withUpdateOrgXDomain: true,
376
- withTransitionForAxis: false,
377
- initializing: true
378
- });
379
- // data.onmin/max callback
380
- if (config.data_onmin || config.data_onmax) {
381
- const minMax = $$.getMinMaxData();
382
- callFn(config.data_onmin, $$.api, minMax.min);
383
- callFn(config.data_onmax, $$.api, minMax.max);
384
- }
385
- state.rendered = true;
386
- return;
387
- }
388
- // -- Basic Elements --
389
- $el.svg = $el.chart.append("svg")
390
- .style("overflow", "hidden")
391
- .style("display", "block");
392
- if (hasInteraction && state.inputType) {
393
- const isTouch = state.inputType === "touch";
394
- const { onclick, onover, onout } = config;
395
- const preventDefault = config.interaction_inputType_touch?.preventDefault;
396
- const isPrevented = (isBoolean(preventDefault) && preventDefault) || false;
397
- const preventThreshold = (!isNaN(preventDefault) && preventDefault) || null;
398
- const touchOption = isTouch ?
399
- {
400
- passive: !isPrevented && preventThreshold === null
401
- } :
402
- undefined;
403
- $el.svg
404
- .on("click", onclick?.bind($$.api) || null)
405
- .on(isTouch ? "touchstart" : "mouseenter", onover?.bind($$.api) || null, touchOption)
406
- .on(isTouch ? "touchend" : "mouseleave", onout?.bind($$.api) || null);
407
- }
408
- config.svg_classname && $el.svg.attr("class", config.svg_classname);
409
- // Define defs
410
- const hasColorPatterns = isFunction(config.color_tiles) && $$.patterns;
411
- if (hasAxis || hasColorPatterns || hasPolar || hasTreemap ||
412
- labelsBGColor || $$.hasLegendDefsPoint?.()) {
413
- $el.defs = $el.svg.append("defs");
414
- if (hasAxis) {
415
- ["id", "idXAxis", "idYAxis", "idGrid"].forEach(v => {
416
- $$.appendClip($el.defs, state.clip[v]);
417
- });
418
- }
419
- // Append data background color filter definition
420
- $$.generateTextBGColorFilter(labelsBGColor);
421
- // set color patterns
422
- if (hasColorPatterns) {
423
- $$.patterns.forEach(p => $el.defs.append(() => p.node));
424
- }
425
- }
426
- $$.updateSvgSize();
427
- // Bind resize event
428
- $$.bindResize();
429
- // Define regions
430
- const main = $el.svg.append("g")
431
- .classed($COMMON.main, true)
432
- .attr("transform", hasFunnel || hasTreemap ? null : $$.getTranslate("main"));
433
- $el.main = main;
434
- // initialize subchart when subchart show option is set
435
- config.subchart_show && $$.initSubchart();
436
- config.tooltip_show && $$.initTooltip();
437
- config.title_text && $$.initTitle();
438
- !hasTreemap && config.legend_show && $$.initLegend();
439
- // -- Main Region --
440
- // text when empty
441
- if (config.data_empty_label_text) {
442
- main.append("text")
443
- .attr("class", `${$TEXT.text} ${$COMMON.empty}`)
444
- .attr("text-anchor", "middle") // horizontal centering of text at x position in all browsers.
445
- .attr("dominant-baseline", "middle"); // vertical centering of text at y position in all browsers, except IE.
446
- }
447
- if (hasAxis) {
448
- // Regions (optional module — initRegion installed by regions resolver)
449
- config.regions.length && $$.initRegion?.();
450
- // Add Axis here, when clipPath is 'false'
451
- !config.clipPath && $$.axis.init();
452
- }
453
- // Define g for chart area
454
- main.append("g")
455
- .classed($COMMON.chart, true)
456
- .attr("clip-path", hasAxis ? state.clip.path : null);
457
- $$.callPluginHook("$init");
458
- $$.initChartElements();
459
- if (hasAxis) {
460
- // Cover whole with rects for events
461
- hasInteraction && $$.initEventRect?.();
462
- // Grids (optional module — initGrid installed by grid resolver)
463
- $$.initGrid?.();
464
- // Add Axis here, when clipPath is 'true'
465
- config.clipPath && $$.axis?.init();
466
- }
467
- // Set targets
468
- $$.updateTargets($$.data.targets);
469
- // Draw with targets
470
- $$.updateDimension();
471
- // oninit callback
472
- callFn(config.oninit, $$.api);
473
- // Set background
474
- $$.setBackground();
475
- $$.redraw({
476
- withTransition: false,
477
- withTransform: true,
478
- withUpdateXDomain: true,
479
- withUpdateOrgXDomain: true,
480
- withTransitionForAxis: false,
481
- initializing: true
482
- });
483
- // data.onmin/max callback
484
- if (config.data_onmin || config.data_onmax) {
485
- const minMax = $$.getMinMaxData();
486
- callFn(config.data_onmin, $$.api, minMax.min);
487
- callFn(config.data_onmax, $$.api, minMax.max);
488
- }
489
- config.tooltip_show && $$.initShowTooltip();
490
- state.rendered = true;
491
- }
492
- /**
493
- * Initialize chart elements
494
- * @private
495
- */
496
- initChartElements() {
497
- const $$ = this;
498
- const { hasAxis, hasRadar, hasTreemap } = $$.state;
499
- const types = [];
500
- if (hasAxis) {
501
- const shapes = ["bar", "bubble", "candlestick", "line"];
502
- if ($$.config.bar_front) {
503
- shapes.push(shapes.shift());
504
- }
505
- for (const shape of shapes) {
506
- const name = capitalize(shape);
507
- if ((shape === "line" && $$.hasTypeOf(name)) || $$.hasType(shape)) {
508
- types.push(name);
509
- }
510
- }
511
- }
512
- else if (hasTreemap) {
513
- types.push("Treemap");
514
- }
515
- else if ($$.hasType("funnel")) {
516
- types.push("Funnel");
517
- }
518
- else {
519
- const hasPolar = $$.hasType("polar");
520
- const hasGauge = $$.hasType("gauge");
521
- if (!hasRadar) {
522
- types.push("Arc", "Pie");
523
- }
524
- if (hasGauge) {
525
- types.push("Gauge");
526
- }
527
- else if (hasRadar) {
528
- types.push("Radar");
529
- }
530
- else if (hasPolar) {
531
- types.push("Polar");
532
- }
533
- }
534
- for (const type of types) {
535
- $$[`init${type}`]();
536
- }
537
- if (notEmpty($$.config.data_labels) && !$$.hasArcType(null, ["radar"])) {
538
- $$.initText();
539
- }
540
- }
541
- /**
542
- * Set chart elements
543
- * @private
544
- */
545
- setChartElements() {
546
- const $$ = this;
547
- const { $el: { chart, svg, defs, main, tooltip, legend, title, canvas, eventOverlay, grid, needle, arcs: arc, circle: circles, bar: bars, candlestick, line: lines, area: areas, text: texts } } = $$;
548
- // public
549
- $$.api.$ = {
550
- chart,
551
- svg,
552
- canvas,
553
- eventOverlay,
554
- defs,
555
- main,
556
- tooltip,
557
- legend,
558
- title,
559
- grid,
560
- arc,
561
- circles,
562
- bar: { bars },
563
- candlestick,
564
- line: { lines, areas },
565
- needle,
566
- text: { texts }
567
- };
568
- }
569
- /**
570
- * Set background element/image
571
- * @private
572
- */
573
- setBackground() {
574
- const $$ = this;
575
- const { config: { background: bg }, state, $el: { svg } } = $$;
576
- if (notEmpty(bg)) {
577
- const element = svg.select("g")
578
- .insert(bg.imgUrl ? "image" : "rect", ":first-child");
579
- if (bg.imgUrl) {
580
- element.attr("href", bg.imgUrl);
581
- }
582
- else if (bg.color) {
583
- element
584
- .style("fill", bg.color)
585
- .attr("clip-path", state.clip.path);
586
- }
587
- element
588
- .attr("class", bg.class || null)
589
- .attr("width", "100%")
590
- .attr("height", "100%");
591
- }
592
- }
593
- /**
594
- * Update targeted element with given data
595
- * @param {object} targets Data object formatted as 'target'
596
- * @private
597
- */
598
- updateTargets(targets) {
599
- const $$ = this;
600
- const { hasAxis, hasFunnel, hasRadar, hasTreemap } = $$.state;
601
- const helper = type => $$[`updateTargetsFor${type}`](targets.filter($$[`is${type}Type`].bind($$)));
602
- // Text
603
- $$.updateTargetsForText(targets);
604
- if (hasAxis) {
605
- const shapes = ["bar", "candlestick", "line"];
606
- for (const shape of shapes) {
607
- const name = capitalize(shape);
608
- if ((shape === "line" && $$.hasTypeOf(name)) || $$.hasType(shape)) {
609
- helper(name);
610
- }
611
- }
612
- // Sub Chart
613
- $$.updateTargetsForSubchart?.(targets);
614
- // Arc, Polar, Radar
615
- }
616
- else if ($$.hasArcType(targets)) {
617
- let type = "Arc";
618
- if (hasRadar) {
619
- type = "Radar";
620
- }
621
- else if ($$.hasType("polar")) {
622
- type = "Polar";
623
- }
624
- helper(type);
625
- }
626
- else if (hasFunnel) {
627
- helper("Funnel");
628
- }
629
- else if (hasTreemap) {
630
- helper("Treemap");
631
- }
632
- // Point types
633
- const hasPointType = $$.hasType("bubble") || $$.hasType("scatter");
634
- if (hasPointType) {
635
- $$.updateTargetForCircle?.();
636
- }
637
- // Fade-in each chart
638
- $$.filterTargetsToShowAtInit(hasPointType);
639
- }
640
- /**
641
- * Display targeted elements at initialization
642
- * @param {boolean} hasPointType whether has point type(bubble, scatter) or not
643
- * @private
644
- */
645
- filterTargetsToShowAtInit(hasPointType = false) {
646
- const $$ = this;
647
- const { $el: { svg }, $T } = $$;
648
- let selector = `.${$COMMON.target}`;
649
- if (hasPointType) {
650
- selector += `, .${$CIRCLE.chartCircles} > .${$CIRCLE.circles}`;
651
- }
652
- $T(svg.selectAll(selector)
653
- .filter(d => $$.isTargetToShow(d.id))).style("opacity", null);
654
- }
655
- getWithOption(options) {
656
- const withOptions = {
657
- Dimension: true,
658
- EventRect: true,
659
- Legend: false,
660
- Subchart: true,
661
- Transform: false,
662
- Transition: true,
663
- TrimXDomain: true,
664
- UpdateXAxis: "UpdateXDomain",
665
- UpdateXDomain: false,
666
- UpdateOrgXDomain: false,
667
- TransitionForExit: "Transition",
668
- TransitionForAxis: "Transition",
669
- Y: true
670
- };
671
- for (const [key, defVal] of Object.entries(withOptions)) {
672
- const value = isString(defVal) ? withOptions[defVal] : defVal;
673
- withOptions[key] = getOption(options, `with${key}`, value);
674
- }
675
- return withOptions;
676
- }
677
- initialOpacity(d) {
678
- const $$ = this;
679
- const { withoutFadeIn } = $$.state;
680
- return $$.getBaseValue(d) !== null && withoutFadeIn[d.id] ? null : "0";
681
- }
682
- bindResize() {
683
- const $$ = this;
684
- const { $el, config, state } = $$;
685
- const resizeFunction = generateResize(config.resize_timer);
686
- const { resize_auto } = config;
687
- const list = [];
688
- list.push(() => callFn(config.onresize, $$.api));
689
- if (/^(true|parent)$/.test(resize_auto)) {
690
- list.push(() => {
691
- // Skip resize if dimensions haven't changed
692
- const prevWidth = state.current.width;
693
- const prevHeight = state.current.height;
694
- $$.setContainerSize();
695
- if (prevWidth === state.current.width &&
696
- prevHeight === state.current.height) {
697
- return;
698
- }
699
- state.resizing = true;
700
- // https://github.com/naver/billboard.js/issues/2650
701
- if (config.legend_show) {
702
- $$.updateSizes();
703
- state.isCanvasMode ? $$.updateHtmlLegend?.() : $$.updateLegend();
704
- }
705
- $$.api.flush(false);
706
- });
707
- }
708
- list.push(() => {
709
- callFn(config.onresized, $$.api);
710
- state.resizing = false;
711
- });
712
- // add resize functions
713
- list.forEach(v => resizeFunction.add(v));
714
- $$.resizeFunction = resizeFunction;
715
- // attach resize event
716
- if (resize_auto === "parent" && win.ResizeObserver) {
717
- ($$.resizeFunction.resizeObserver = new win.ResizeObserver($$.resizeFunction.bind($$)))
718
- .observe($el.chart.node().parentNode);
719
- }
720
- else {
721
- if (resize_auto === "parent") {
722
- // ResizeObserver unavailable: parent-specific resize won't be detected
723
- win.console?.warn?.("[billboard.js] resize.auto='parent' requires ResizeObserver; falling back to window resize.");
724
- }
725
- win.addEventListener("resize", $$.resizeFunction);
726
- }
727
- }
728
- /**
729
- * Call plugin hook
730
- * @param {string} phase The lifecycle phase
731
- * @param {Array} args Arguments
732
- * @private
733
- */
734
- callPluginHook(phase, ...args) {
735
- this.config.plugins.forEach(v => {
736
- if (phase === "$beforeInit") {
737
- v.$$ = this;
738
- this.api.plugins.push(v);
739
- }
740
- v[phase](...args);
741
- });
742
- }
743
- }
72
+ * Internal chart class.
73
+ * - Note: Instantiated internally, not exposed for public.
74
+ * @class ChartInternal
75
+ * @ignore
76
+ * @private
77
+ */
78
+ var ChartInternal = class {
79
+ api;
80
+ config;
81
+ cache;
82
+ $el;
83
+ state;
84
+ charts;
85
+ data = {
86
+ xs: {},
87
+ targets: []
88
+ };
89
+ axis;
90
+ scale = {
91
+ x: null,
92
+ y: null,
93
+ y2: null,
94
+ subX: null,
95
+ subY: null,
96
+ subY2: null,
97
+ zoom: null
98
+ };
99
+ org = {
100
+ xScale: null,
101
+ xDomain: null
102
+ };
103
+ color;
104
+ patterns;
105
+ levelColor;
106
+ point;
107
+ brush;
108
+ format = {
109
+ extraLineClasses: null,
110
+ xAxisTick: null,
111
+ dataTime: null,
112
+ defaultAxisTime: null,
113
+ axisTime: null
114
+ };
115
+ constructor(api) {
116
+ const $$ = this;
117
+ $$.api = api;
118
+ $$.config = new Options();
119
+ $$.cache = new Cache();
120
+ const store = new Store();
121
+ $$.$el = store.getStore("element");
122
+ $$.state = store.getStore("state");
123
+ $$.$T = $$.$T.bind($$);
124
+ }
125
+ /**
126
+ * Get the selection based on transition config
127
+ * @param {SVGElement|d3Selection} selection Target selection
128
+ * @param {boolean} force Force transition
129
+ * @param {string} name Transition name
130
+ * @returns {d3Selection}
131
+ * @private
132
+ */
133
+ $T(selection, force, name) {
134
+ const { config, state } = this;
135
+ const duration = config.transition_duration;
136
+ const subchart = config.subchart_show;
137
+ let t = selection;
138
+ if (t) {
139
+ if ("tagName" in t) t = select(t);
140
+ t = (force !== false && duration || force) && (!state.zooming || state.dragging) && !state.resizing && state.rendered && !subchart ? t.transition(name).duration(duration) : t;
141
+ }
142
+ return t;
143
+ }
144
+ beforeInit() {
145
+ const $$ = this;
146
+ $$.callPluginHook("$beforeInit");
147
+ callFn($$.config.onbeforeinit, $$.api);
148
+ }
149
+ afterInit() {
150
+ const $$ = this;
151
+ $$.callPluginHook("$afterInit");
152
+ callFn($$.config.onafterinit, $$.api);
153
+ }
154
+ init() {
155
+ const $$ = this;
156
+ const { config, state, $el } = $$;
157
+ const { boost_useCssRule, bindto } = config;
158
+ checkModuleImport($$);
159
+ fallbackUnsupportedCanvasRenderMode($$);
160
+ const hasArcType = $$.hasArcType();
161
+ state.hasRadar = !state.hasAxis && $$.hasType("radar");
162
+ state.hasFunnel = !state.hasAxis && $$.hasType("funnel");
163
+ state.hasTreemap = !state.hasAxis && $$.hasType("treemap");
164
+ state.hasAxis = !hasArcType && !state.hasFunnel && !state.hasTreemap;
165
+ state.datetimeId = `bb-${+/* @__PURE__ */ new Date() * getRandom()}`;
166
+ if (boost_useCssRule) {
167
+ const styleEl = doc.createElement("style");
168
+ styleEl.type = "text/css";
169
+ doc.head.appendChild(styleEl);
170
+ state.style = {
171
+ rootSelector: `.${state.datetimeId}`,
172
+ sheet: styleEl.sheet
173
+ };
174
+ $el.style = styleEl;
175
+ }
176
+ const bindConfig = {
177
+ element: bindto,
178
+ classname: "bb"
179
+ };
180
+ if (isObject(bindto)) {
181
+ bindConfig.element = bindto.element || "#chart";
182
+ bindConfig.classname = bindto.classname || bindConfig.classname;
183
+ }
184
+ $el.chart = isFunction(bindConfig.element.node) ? bindto.element : select(bindConfig.element || []);
185
+ if ($el.chart.empty()) $el.chart = select(doc.body.appendChild(doc.createElement("div")));
186
+ $el.chart.html("").classed(bindConfig.classname, true).classed(state.datetimeId, boost_useCssRule).style("position", "relative");
187
+ $$.initParams();
188
+ $$.initToRender();
189
+ }
190
+ /**
191
+ * Initialize the rendering process
192
+ * @param {boolean} forced Force to render process
193
+ * @private
194
+ */
195
+ initToRender(forced) {
196
+ const $$ = this;
197
+ const { config, state, $el: { chart } } = $$;
198
+ const isHidden = () => hasStyle(chart, {
199
+ display: "none",
200
+ visibility: "hidden"
201
+ });
202
+ const isLazy = config.render.lazy === false ? false : config.render.lazy || isHidden();
203
+ const MutationObserver = win.MutationObserver;
204
+ if (isLazy && MutationObserver && config.render.observe !== false && !forced) new MutationObserver((mutation, observer) => {
205
+ if (!isHidden()) {
206
+ observer.disconnect();
207
+ !state.rendered && $$.initToRender(true);
208
+ }
209
+ }).observe(chart.node(), {
210
+ attributes: true,
211
+ attributeFilter: ["class", "style"]
212
+ });
213
+ if (!isLazy || forced) $$.convertData(config, (res) => {
214
+ $$.initWithData(res);
215
+ $$.afterInit();
216
+ });
217
+ }
218
+ initParams() {
219
+ const $$ = this;
220
+ const { config, format, state } = $$;
221
+ if (config.render_mode === "canvas") $$.prepareCanvasConfig?.();
222
+ $$.color = $$.generateColor();
223
+ $$.levelColor = $$.generateLevelColor();
224
+ if (config.padding === false) {
225
+ config.axis_x_show = false;
226
+ config.axis_y_show = false;
227
+ config.axis_y2_show = false;
228
+ config.subchart_show = false;
229
+ }
230
+ if (config.render_mode !== "canvas" && ($$.hasPointType() || $$.hasLegendDefsPoint?.())) $$.point = $$.generatePoint();
231
+ if (state.hasAxis) {
232
+ $$.initClip();
233
+ format.extraLineClasses = $$.generateExtraLineClass();
234
+ format.dataTime = config.data_xLocaltime ? timeParse : utcParse;
235
+ format.axisTime = config.axis_x_localtime ? timeFormat : utcFormat;
236
+ const isDragZoom = config.zoom_enabled && config.zoom_type === "drag";
237
+ format.defaultAxisTime = (d) => {
238
+ const { x, zoom } = $$.scale;
239
+ const isZoomed = isDragZoom ? zoom : zoom && x.orgDomain().toString() !== zoom.domain().toString();
240
+ const specifier = d.getMilliseconds() && ".%L" || d.getSeconds() && ".:%S" || d.getMinutes() && "%I:%M" || d.getHours() && "%I %p" || d.getDate() !== 1 && "%b %d" || isZoomed && d.getDate() === 1 && "%b'%y" || d.getMonth() && "%-m/%-d" || "%Y";
241
+ return format.axisTime(specifier)(d);
242
+ };
243
+ }
244
+ const { legend_position, legend_inset_anchor, axis_rotated } = config;
245
+ state.isLegendRight = legend_position === "right";
246
+ state.isLegendInset = legend_position === "inset";
247
+ state.isLegendTop = legend_inset_anchor === "top-left" || legend_inset_anchor === "top-right";
248
+ state.isLegendLeft = legend_inset_anchor === "top-left" || legend_inset_anchor === "bottom-left";
249
+ state.rotatedPadding.top = $$.getResettedPadding(state.rotatedPadding.top);
250
+ state.rotatedPadding.right = axis_rotated && !config.axis_x_show ? 0 : 30;
251
+ state.inputType = convertInputType(config.interaction_inputType_mouse, config.interaction_inputType_touch);
252
+ }
253
+ initWithData(data) {
254
+ const $$ = this;
255
+ const { config, scale, state, $el, org } = $$;
256
+ const { hasAxis, hasFunnel, hasTreemap } = state;
257
+ const hasInteraction = config.interaction_enabled;
258
+ const hasPolar = $$.hasType("polar");
259
+ const labelsBGColor = config.data_labels_backgroundColors;
260
+ if (hasAxis) {
261
+ $$.axis = $$.getAxisInstance();
262
+ config.zoom_enabled && $$.initZoom();
263
+ }
264
+ $$.data.xs = {};
265
+ $$.data.targets = $$.convertDataToTargets(data);
266
+ if (config.data_filter) $$.data.targets = $$.data.targets.filter(config.data_filter.bind($$.api));
267
+ if (config.data_hide) $$.addHiddenTargetIds(config.data_hide === true ? $$.mapToIds($$.data.targets) : config.data_hide);
268
+ if (config.legend_hide) $$.addHiddenLegendIds(config.legend_hide === true ? $$.mapToIds($$.data.targets) : config.legend_hide);
269
+ $$.updateSizes();
270
+ $$.updateScales(true);
271
+ if (hasAxis) {
272
+ const { x, y, y2, subX, subY, subY2 } = scale;
273
+ if (x) {
274
+ x.domain(sortValue($$.getXDomain($$.data.targets), !config.axis_x_inverted));
275
+ subX.domain(x.domain());
276
+ org.xDomain = x.domain();
277
+ }
278
+ if (y) {
279
+ y.domain($$.getYDomain($$.data.targets, "y"));
280
+ subY.domain(y.domain());
281
+ }
282
+ if (y2) {
283
+ y2.domain($$.getYDomain($$.data.targets, "y2"));
284
+ subY2 && subY2.domain(y2.domain());
285
+ }
286
+ }
287
+ if (config.render_mode === "canvas") {
288
+ if (!$$.initCanvas) throw Error("[billboard.js] Please import and call canvas() to use render.mode='canvas'.");
289
+ $$.bindResize();
290
+ $$.initCanvas();
291
+ config.tooltip_show && $$.initTooltip();
292
+ $$.callPluginHook("$init");
293
+ callFn(config.oninit, $$.api);
294
+ $$.redraw({
295
+ withTransition: false,
296
+ withTransform: true,
297
+ withUpdateXDomain: true,
298
+ withUpdateOrgXDomain: true,
299
+ withTransitionForAxis: false,
300
+ initializing: true
301
+ });
302
+ if (config.data_onmin || config.data_onmax) {
303
+ const minMax = $$.getMinMaxData();
304
+ callFn(config.data_onmin, $$.api, minMax.min);
305
+ callFn(config.data_onmax, $$.api, minMax.max);
306
+ }
307
+ state.rendered = true;
308
+ return;
309
+ }
310
+ $el.svg = $el.chart.append("svg").style("overflow", "hidden").style("display", "block");
311
+ if (hasInteraction && state.inputType) {
312
+ const isTouch = state.inputType === "touch";
313
+ const { onclick, onover, onout } = config;
314
+ const preventDefault = config.interaction_inputType_touch?.preventDefault;
315
+ const isPrevented = isBoolean(preventDefault) && preventDefault || false;
316
+ const touchOption = isTouch ? { passive: !isPrevented && (!isNaN(preventDefault) && preventDefault || null) === null } : void 0;
317
+ $el.svg.on("click", onclick?.bind($$.api) || null).on(isTouch ? "touchstart" : "mouseenter", onover?.bind($$.api) || null, touchOption).on(isTouch ? "touchend" : "mouseleave", onout?.bind($$.api) || null);
318
+ }
319
+ config.svg_classname && $el.svg.attr("class", config.svg_classname);
320
+ const hasColorPatterns = isFunction(config.color_tiles) && $$.patterns;
321
+ if (hasAxis || hasColorPatterns || hasPolar || hasTreemap || labelsBGColor || $$.hasLegendDefsPoint?.()) {
322
+ $el.defs = $el.svg.append("defs");
323
+ if (hasAxis) [
324
+ "id",
325
+ "idXAxis",
326
+ "idYAxis",
327
+ "idY2Axis",
328
+ "idGrid"
329
+ ].forEach((v) => {
330
+ $$.appendClip($el.defs, state.clip[v]);
331
+ });
332
+ $$.generateTextBGColorFilter(labelsBGColor);
333
+ if (hasColorPatterns) $$.patterns.forEach((p) => $el.defs.append(() => p.node));
334
+ }
335
+ $$.updateSvgSize();
336
+ $$.bindResize();
337
+ const main = $el.svg.append("g").classed($COMMON.main, true).attr("transform", hasFunnel || hasTreemap ? null : $$.getTranslate("main"));
338
+ $el.main = main;
339
+ config.subchart_show && $$.initSubchart();
340
+ config.tooltip_show && $$.initTooltip();
341
+ config.title_text && $$.initTitle();
342
+ !hasTreemap && config.legend_show && $$.initLegend();
343
+ if (config.data_empty_label_text) main.append("text").attr("class", `${$TEXT.text} ${$COMMON.empty}`).attr("text-anchor", "middle").attr("dominant-baseline", "middle");
344
+ if (hasAxis) {
345
+ config.regions.length && $$.initRegion?.();
346
+ !config.clipPath && $$.axis.init();
347
+ }
348
+ main.append("g").classed($COMMON.chart, true).attr("clip-path", hasAxis ? state.clip.path : null);
349
+ $$.callPluginHook("$init");
350
+ $$.initChartElements();
351
+ if (hasAxis) {
352
+ hasInteraction && $$.initEventRect?.();
353
+ $$.initGrid?.();
354
+ config.clipPath && $$.axis?.init();
355
+ }
356
+ $$.updateTargets($$.data.targets);
357
+ $$.updateDimension();
358
+ callFn(config.oninit, $$.api);
359
+ $$.setBackground();
360
+ $$.redraw({
361
+ withTransition: false,
362
+ withTransform: true,
363
+ withUpdateXDomain: true,
364
+ withUpdateOrgXDomain: true,
365
+ withTransitionForAxis: false,
366
+ initializing: true
367
+ });
368
+ if (config.data_onmin || config.data_onmax) {
369
+ const minMax = $$.getMinMaxData();
370
+ callFn(config.data_onmin, $$.api, minMax.min);
371
+ callFn(config.data_onmax, $$.api, minMax.max);
372
+ }
373
+ config.tooltip_show && $$.initShowTooltip();
374
+ state.rendered = true;
375
+ }
376
+ /**
377
+ * Initialize chart elements
378
+ * @private
379
+ */
380
+ initChartElements() {
381
+ const $$ = this;
382
+ const { hasAxis, hasRadar, hasTreemap } = $$.state;
383
+ const types = [];
384
+ if (hasAxis) {
385
+ const shapes = [
386
+ "bar",
387
+ "bubble",
388
+ "candlestick",
389
+ "line"
390
+ ];
391
+ if ($$.config.bar_front) shapes.push(shapes.shift());
392
+ for (const shape of shapes) {
393
+ const name = capitalize(shape);
394
+ if (shape === "line" && $$.hasTypeOf(name) || $$.hasType(shape)) types.push(name);
395
+ }
396
+ } else if (hasTreemap) types.push("Treemap");
397
+ else if ($$.hasType("funnel")) types.push("Funnel");
398
+ else {
399
+ const hasPolar = $$.hasType("polar");
400
+ const hasGauge = $$.hasType("gauge");
401
+ if (!hasRadar) types.push("Arc", "Pie");
402
+ if (hasGauge) types.push("Gauge");
403
+ else if (hasRadar) types.push("Radar");
404
+ else if (hasPolar) types.push("Polar");
405
+ }
406
+ for (const type of types) $$[`init${type}`]();
407
+ if (notEmpty($$.config.data_labels) && !$$.hasArcType(null, ["radar"])) $$.initText();
408
+ }
409
+ /**
410
+ * Set chart elements
411
+ * @private
412
+ */
413
+ setChartElements() {
414
+ const $$ = this;
415
+ const { $el: { chart, svg, defs, main, tooltip, legend, title, canvas, eventOverlay, grid, needle, arcs: arc, circle: circles, bar: bars, candlestick, line: lines, area: areas, text: texts } } = $$;
416
+ $$.api.$ = {
417
+ chart,
418
+ svg,
419
+ canvas,
420
+ eventOverlay,
421
+ defs,
422
+ main,
423
+ tooltip,
424
+ legend,
425
+ title,
426
+ grid,
427
+ arc,
428
+ circles,
429
+ bar: { bars },
430
+ candlestick,
431
+ line: {
432
+ lines,
433
+ areas
434
+ },
435
+ needle,
436
+ text: { texts }
437
+ };
438
+ }
439
+ /**
440
+ * Set background element/image
441
+ * @private
442
+ */
443
+ setBackground() {
444
+ const { config: { background: bg }, state, $el: { svg } } = this;
445
+ if (notEmpty(bg)) {
446
+ const element = svg.select("g").insert(bg.imgUrl ? "image" : "rect", ":first-child");
447
+ if (bg.imgUrl) element.attr("href", bg.imgUrl);
448
+ else if (bg.color) element.style("fill", bg.color).attr("clip-path", state.clip.path);
449
+ element.attr("class", bg.class || null).attr("width", "100%").attr("height", "100%");
450
+ }
451
+ }
452
+ /**
453
+ * Update targeted element with given data
454
+ * @param {object} targets Data object formatted as 'target'
455
+ * @private
456
+ */
457
+ updateTargets(targets) {
458
+ const $$ = this;
459
+ const { hasAxis, hasFunnel, hasRadar, hasTreemap } = $$.state;
460
+ const helper = (type) => $$[`updateTargetsFor${type}`](targets.filter($$[`is${type}Type`].bind($$)));
461
+ $$.updateTargetsForText(targets);
462
+ if (hasAxis) {
463
+ for (const shape of [
464
+ "bar",
465
+ "candlestick",
466
+ "line"
467
+ ]) {
468
+ const name = capitalize(shape);
469
+ if (shape === "line" && $$.hasTypeOf(name) || $$.hasType(shape)) helper(name);
470
+ }
471
+ $$.updateTargetsForSubchart?.(targets);
472
+ } else if ($$.hasArcType(targets)) {
473
+ let type = "Arc";
474
+ if (hasRadar) type = "Radar";
475
+ else if ($$.hasType("polar")) type = "Polar";
476
+ helper(type);
477
+ } else if (hasFunnel) helper("Funnel");
478
+ else if (hasTreemap) helper("Treemap");
479
+ const hasPointType = $$.hasType("bubble") || $$.hasType("scatter");
480
+ if (hasPointType) $$.updateTargetForCircle?.();
481
+ $$.filterTargetsToShowAtInit(hasPointType);
482
+ }
483
+ /**
484
+ * Display targeted elements at initialization
485
+ * @param {boolean} hasPointType whether has point type(bubble, scatter) or not
486
+ * @private
487
+ */
488
+ filterTargetsToShowAtInit(hasPointType = false) {
489
+ const $$ = this;
490
+ const { $el: { svg }, $T } = $$;
491
+ let selector = `.${$COMMON.target}`;
492
+ if (hasPointType) selector += `, .${$CIRCLE.chartCircles} > .${$CIRCLE.circles}`;
493
+ $T(svg.selectAll(selector).filter((d) => $$.isTargetToShow(d.id))).style("opacity", null);
494
+ }
495
+ getWithOption(options) {
496
+ const withOptions = {
497
+ Dimension: true,
498
+ EventRect: true,
499
+ Legend: false,
500
+ Subchart: true,
501
+ Transform: false,
502
+ Transition: true,
503
+ TrimXDomain: true,
504
+ UpdateXAxis: "UpdateXDomain",
505
+ UpdateXDomain: false,
506
+ UpdateOrgXDomain: false,
507
+ TransitionForExit: "Transition",
508
+ TransitionForAxis: "Transition",
509
+ Y: true
510
+ };
511
+ for (const [key, defVal] of Object.entries(withOptions)) {
512
+ const value = isString(defVal) ? withOptions[defVal] : defVal;
513
+ withOptions[key] = getOption(options, `with${key}`, value);
514
+ }
515
+ return withOptions;
516
+ }
517
+ initialOpacity(d) {
518
+ const $$ = this;
519
+ const { withoutFadeIn } = $$.state;
520
+ return $$.getBaseValue(d) !== null && withoutFadeIn[d.id] ? null : "0";
521
+ }
522
+ bindResize() {
523
+ const $$ = this;
524
+ const { $el, config, state } = $$;
525
+ const resizeFunction = generateResize(config.resize_timer);
526
+ const { resize_auto } = config;
527
+ const list = [];
528
+ list.push(() => callFn(config.onresize, $$.api));
529
+ if (/^(true|parent)$/.test(resize_auto)) list.push(() => {
530
+ const prevWidth = state.current.width;
531
+ const prevHeight = state.current.height;
532
+ $$.setContainerSize();
533
+ if (prevWidth === state.current.width && prevHeight === state.current.height) return;
534
+ state.resizing = true;
535
+ if (config.legend_show) {
536
+ $$.updateSizes();
537
+ state.isCanvasMode ? $$.updateHtmlLegend?.() : $$.updateLegend();
538
+ }
539
+ $$.api.flush(false);
540
+ });
541
+ list.push(() => {
542
+ callFn(config.onresized, $$.api);
543
+ state.resizing = false;
544
+ });
545
+ list.forEach((v) => resizeFunction.add(v));
546
+ $$.resizeFunction = resizeFunction;
547
+ if (resize_auto === "parent" && win.ResizeObserver) ($$.resizeFunction.resizeObserver = new win.ResizeObserver($$.resizeFunction.bind($$))).observe($el.chart.node().parentNode);
548
+ else {
549
+ if (resize_auto === "parent") win.console?.warn?.("[billboard.js] resize.auto='parent' requires ResizeObserver; falling back to window resize.");
550
+ win.addEventListener("resize", $$.resizeFunction);
551
+ }
552
+ }
553
+ /**
554
+ * Call plugin hook
555
+ * @param {string} phase The lifecycle phase
556
+ * @param {Array} args Arguments
557
+ * @private
558
+ */
559
+ callPluginHook(phase, ...args) {
560
+ this.config.plugins.forEach((v) => {
561
+ if (phase === "$beforeInit") {
562
+ v.$$ = this;
563
+ this.api.plugins.push(v);
564
+ }
565
+ v[phase](...args);
566
+ });
567
+ }
568
+ };
744
569
  extend(ChartInternal.prototype, [
745
- // common
746
- dataConvert,
747
- data,
748
- dataLoad,
749
- category,
750
- classModule,
751
- color,
752
- domain,
753
- interaction,
754
- format,
755
- legend,
756
- redraw,
757
- scale,
758
- shape,
759
- size,
760
- style,
761
- text,
762
- title,
763
- tooltip,
764
- transform,
765
- typeInternals
570
+ convert_default,
571
+ data_default,
572
+ load_default,
573
+ category_default,
574
+ class_default,
575
+ color_default,
576
+ domain_default,
577
+ interaction_default,
578
+ format_default,
579
+ legend_default,
580
+ redraw_default,
581
+ scale_default,
582
+ shape_default,
583
+ size_default,
584
+ style_default,
585
+ text_default,
586
+ title_default,
587
+ tooltip_default,
588
+ transform_default,
589
+ type_default
766
590
  ]);
767
-
591
+ //#endregion
768
592
  export { ChartInternal as default };