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
@@ -5,415 +5,355 @@
5
5
  * billboard.js, JavaScript chart library
6
6
  * https://naver.github.io/billboard.js/
7
7
  *
8
- * @version 4.0.3
8
+ * @version 4.1.0-next.2
9
9
  */
10
- import { pointer } from 'd3-selection';
11
- import { window as win, document as doc } from '../browser.js';
12
- import { toArray, mergeObj } from './object.js';
13
- import { isString } from './type-checks.js';
14
-
10
+ import { document as doc, window as win } from "../browser.js";
11
+ import { isString } from "./type-checks.js";
12
+ import { mergeObj, toArray } from "./object.js";
13
+ import { pointer } from "d3-selection";
14
+ //#region src/module/util/dom.ts
15
15
  /**
16
- * Copyright (c) 2017 ~ present NAVER Corp.
17
- * billboard.js project is licensed under the MIT license
18
- * @ignore
19
- */
20
- // Hoisted to module level to avoid recompilation on every addCssRules() call
16
+ * Copyright (c) 2017 ~ present NAVER Corp.
17
+ * billboard.js project is licensed under the MIT license
18
+ * @ignore
19
+ */
21
20
  const RE_CSS_BB = /\s?(bb-)/g;
22
21
  const RE_CSS_DOTS = /\.+/g;
23
22
  /**
24
- * Convert a CSS selector string to dot-notation class selector
25
- * @param {string} s Selector string
26
- * @returns {string}
27
- * @private
28
- */
23
+ * Convert a CSS selector string to dot-notation class selector
24
+ * @param {string} s Selector string
25
+ * @returns {string}
26
+ * @private
27
+ */
29
28
  function getCssSelector(s) {
30
- return s.replace(RE_CSS_BB, ".$1").replace(RE_CSS_DOTS, ".");
29
+ return s.replace(RE_CSS_BB, ".$1").replace(RE_CSS_DOTS, ".");
31
30
  }
32
- // ====================================
33
- // Internal Helper (Not Exported)
34
- // ====================================
35
31
  /**
36
- * Get boundingClientRect or BBox with caching.
37
- * Internal helper for getBoundingRect() and getBBox()
38
- * @param {boolean} relativeViewport Relative to viewport - true: will use .getBoundingClientRect(), false: will use .getBBox()
39
- * @param {SVGElement} node Target element
40
- * @param {boolean} forceEval Force evaluation
41
- * @returns {object}
42
- * @private
43
- */
32
+ * Get boundingClientRect or BBox with caching.
33
+ * Internal helper for getBoundingRect() and getBBox()
34
+ * @param {boolean} relativeViewport Relative to viewport - true: will use .getBoundingClientRect(), false: will use .getBBox()
35
+ * @param {SVGElement} node Target element
36
+ * @param {boolean} forceEval Force evaluation
37
+ * @returns {object}
38
+ * @private
39
+ */
44
40
  function _getRect(relativeViewport, node, forceEval = false) {
45
- const _ = n => n[relativeViewport ? "getBoundingClientRect" : "getBBox"]();
46
- // cache per API: getBoundingClientRect(viewport coords) and getBBox(local coords)
47
- // return different values for the same node and must not share one slot
48
- const cacheKey = relativeViewport ? "rectClient" : "rectBBox";
49
- if (forceEval) {
50
- return _(node);
51
- }
52
- else {
53
- // will cache the value if the element is not a SVGElement or the width is not set
54
- const needEvaluate = !(cacheKey in node) || (node.hasAttribute("width") &&
55
- node[cacheKey].width !== +(node.getAttribute("width") || 0));
56
- return needEvaluate ? (node[cacheKey] = _(node)) : node[cacheKey];
57
- }
41
+ const _ = (n) => n[relativeViewport ? "getBoundingClientRect" : "getBBox"]();
42
+ const cacheKey = relativeViewport ? "rectClient" : "rectBBox";
43
+ if (forceEval) return _(node);
44
+ else return !(cacheKey in node) || node.hasAttribute("width") && node[cacheKey].width !== +(node.getAttribute("width") || 0) ? node[cacheKey] = _(node) : node[cacheKey];
58
45
  }
59
- // ====================================
60
- // Exported
61
- // ====================================
62
46
  /**
63
- * Set text value. If there're multiline add nodes.
64
- * @param {d3Selection} node Text node
65
- * @param {string} text Text value string
66
- * @param {Array} dy dy value for multilined text
67
- * @param {boolean} toMiddle To be alingned vertically middle
68
- * @private
69
- */
47
+ * Set text value. If there're multiline add nodes.
48
+ * @param {d3Selection} node Text node
49
+ * @param {string} text Text value string
50
+ * @param {Array} dy dy value for multilined text
51
+ * @param {boolean} toMiddle To be alingned vertically middle
52
+ * @private
53
+ */
70
54
  function setTextValue(node, text, dy = [-1, 1], toMiddle = false) {
71
- if (!node || !isString(text)) {
72
- return;
73
- }
74
- if (text.indexOf("\n") === -1) {
75
- node.text(text);
76
- }
77
- else {
78
- const diff = [node.text(), text].map(v => v.replace(/[\s\n]/g, ""));
79
- if (diff[0] !== diff[1]) {
80
- const multiline = text.split("\n");
81
- const len = toMiddle ? multiline.length - 1 : 1;
82
- // reset possible text
83
- node.html("");
84
- multiline.forEach((v, i) => {
85
- node.append("tspan")
86
- .attr("x", 0)
87
- .attr("dy", `${i === 0 ? dy[0] * len : dy[1]}em`)
88
- .text(v);
89
- });
90
- }
91
- }
55
+ if (!node || !isString(text)) return;
56
+ if (text.indexOf("\n") === -1) node.text(text);
57
+ else {
58
+ const diff = [node.text(), text].map((v) => v.replace(/[\s\n]/g, ""));
59
+ if (diff[0] !== diff[1]) {
60
+ const multiline = text.split("\n");
61
+ const len = toMiddle ? multiline.length - 1 : 1;
62
+ node.html("");
63
+ multiline.forEach((v, i) => {
64
+ node.append("tspan").attr("x", 0).attr("dy", `${i === 0 ? dy[0] * len : dy[1]}em`).text(v);
65
+ });
66
+ }
67
+ }
92
68
  }
93
69
  /**
94
- * Substitution of SVGPathSeg API polyfill
95
- * @param {SVGGraphicsElement} path Target svg element
96
- * @returns {Array}
97
- * @private
98
- */
70
+ * Substitution of SVGPathSeg API polyfill
71
+ * @param {SVGGraphicsElement} path Target svg element
72
+ * @returns {Array}
73
+ * @private
74
+ */
99
75
  function getRectSegList(path) {
100
- /*
101
- * seg1 ---------- seg2
102
- * | |
103
- * | |
104
- * | |
105
- * seg0 ---------- seg3
106
- */
107
- const { x, y, width, height } = getBBox(path, true);
108
- return [
109
- { x, y: y + height }, // seg0
110
- { x, y }, // seg1
111
- { x: x + width, y }, // seg2
112
- { x: x + width, y: y + height } // seg3
113
- ];
76
+ const { x, y, width, height } = getBBox(path, true);
77
+ return [
78
+ {
79
+ x,
80
+ y: y + height
81
+ },
82
+ {
83
+ x,
84
+ y
85
+ },
86
+ {
87
+ x: x + width,
88
+ y
89
+ },
90
+ {
91
+ x: x + width,
92
+ y: y + height
93
+ }
94
+ ];
114
95
  }
115
96
  /**
116
- * Get svg bounding path box dimension
117
- * @param {SVGGraphicsElement} path Target svg element
118
- * @returns {object}
119
- * @private
120
- */
97
+ * Get svg bounding path box dimension
98
+ * @param {SVGGraphicsElement} path Target svg element
99
+ * @returns {object}
100
+ * @private
101
+ */
121
102
  function getPathBox(path) {
122
- const { width, height } = getBoundingRect(path);
123
- const items = getRectSegList(path);
124
- const x = items[0].x;
125
- const y = Math.min(items[0].y, items[1].y);
126
- return {
127
- x,
128
- y,
129
- width,
130
- height
131
- };
103
+ const { width, height } = getBoundingRect(path);
104
+ const items = getRectSegList(path);
105
+ return {
106
+ x: items[0].x,
107
+ y: Math.min(items[0].y, items[1].y),
108
+ width,
109
+ height
110
+ };
132
111
  }
133
112
  /**
134
- * Get event's current position coordinates
135
- * @param {object} event Event object
136
- * @param {SVGElement|HTMLElement} element Target element
137
- * @returns {Array} [x, y] Coordinates x, y array
138
- * @private
139
- */
113
+ * Get event's current position coordinates
114
+ * @param {object} event Event object
115
+ * @param {SVGElement|HTMLElement} element Target element
116
+ * @returns {Array} [x, y] Coordinates x, y array
117
+ * @private
118
+ */
140
119
  function getPointer(event, element) {
141
- const touches = event &&
142
- (event.touches || (event.sourceEvent && event.sourceEvent.touches))?.[0];
143
- let pointer$1 = [0, 0];
144
- try {
145
- pointer$1 = pointer(touches || event, element);
146
- }
147
- catch { }
148
- return pointer$1.map(v => (isNaN(v) ? 0 : v));
120
+ const touches = event && (event.touches || event.sourceEvent && event.sourceEvent.touches)?.[0];
121
+ let pointer$1 = [0, 0];
122
+ try {
123
+ pointer$1 = pointer(touches || event, element);
124
+ } catch {}
125
+ return pointer$1.map((v) => isNaN(v) ? 0 : v);
149
126
  }
150
127
  /**
151
- * Get boundingClientRect.
152
- * @param {SVGElement} node Target element
153
- * @param {boolean} forceEval Force evaluation
154
- * @returns {object}
155
- * @private
156
- */
128
+ * Get boundingClientRect.
129
+ * @param {SVGElement} node Target element
130
+ * @param {boolean} forceEval Force evaluation
131
+ * @returns {object}
132
+ * @private
133
+ */
157
134
  function getBoundingRect(node, forceEval = false) {
158
- return _getRect(true, node, forceEval);
135
+ return _getRect(true, node, forceEval);
159
136
  }
160
137
  /**
161
- * Get BBox.
162
- * @param {SVGElement} node Target element
163
- * @param {boolean} forceEval Force evaluation
164
- * @returns {object}
165
- * @private
166
- */
138
+ * Get BBox.
139
+ * @param {SVGElement} node Target element
140
+ * @param {boolean} forceEval Force evaluation
141
+ * @returns {object}
142
+ * @private
143
+ */
167
144
  function getBBox(node, forceEval = false) {
168
- return _getRect(false, node, forceEval);
145
+ return _getRect(false, node, forceEval);
169
146
  }
170
147
  /**
171
- * Add CSS rules
172
- * @param {object} style Style object
173
- * @param {string} selector Selector string
174
- * @param {Array} prop Prps arrary
175
- * @returns {number} Newely added rule index
176
- * @private
177
- */
148
+ * Add CSS rules
149
+ * @param {object} style Style object
150
+ * @param {string} selector Selector string
151
+ * @param {Array} prop Prps arrary
152
+ * @returns {number} Newely added rule index
153
+ * @private
154
+ */
178
155
  function addCssRules(style, selector, prop) {
179
- const { rootSelector = "", sheet } = style;
180
- const rule = `${rootSelector} ${getCssSelector(selector)} {${prop.join(";")}}`;
181
- return sheet[sheet.insertRule ? "insertRule" : "addRule"](rule, sheet.cssRules.length);
156
+ const { rootSelector = "", sheet } = style;
157
+ const rule = `${rootSelector} ${getCssSelector(selector)} {${prop.join(";")}}`;
158
+ return sheet[sheet.insertRule ? "insertRule" : "addRule"](rule, sheet.cssRules.length);
182
159
  }
183
160
  /**
184
- * Get css rules for specified stylesheets
185
- * @param {Array} styleSheets The stylesheets to get the rules from
186
- * @returns {Array}
187
- * @private
188
- */
161
+ * Get css rules for specified stylesheets
162
+ * @param {Array} styleSheets The stylesheets to get the rules from
163
+ * @returns {Array}
164
+ * @private
165
+ */
189
166
  function getCssRules(styleSheets) {
190
- let rules = [];
191
- styleSheets.forEach(sheet => {
192
- try {
193
- if (sheet.cssRules && sheet.cssRules.length) {
194
- rules = rules.concat(toArray(sheet.cssRules));
195
- }
196
- }
197
- catch (e) {
198
- win.console?.warn(`Error while reading rules from ${sheet.href}: ${String(e)}`);
199
- }
200
- });
201
- return rules;
167
+ let rules = [];
168
+ styleSheets.forEach((sheet) => {
169
+ try {
170
+ if (sheet.cssRules && sheet.cssRules.length) rules = rules.concat(toArray(sheet.cssRules));
171
+ } catch (e) {
172
+ win.console?.warn(`Error while reading rules from ${sheet.href}: ${String(e)}`);
173
+ }
174
+ });
175
+ return rules;
202
176
  }
203
177
  /**
204
- * Get current window and container scroll position
205
- * @param {HTMLElement} node Target element
206
- * @returns {object} window scroll position
207
- * @private
208
- */
178
+ * Get current window and container scroll position
179
+ * @param {HTMLElement} node Target element
180
+ * @returns {object} window scroll position
181
+ * @private
182
+ */
209
183
  function getScrollPosition(node) {
210
- return {
211
- x: (win.pageXOffset ?? win.scrollX ?? 0) + (node.scrollLeft ?? 0),
212
- y: (win.pageYOffset ?? win.scrollY ?? 0) + (node.scrollTop ?? 0)
213
- };
184
+ return {
185
+ x: (win.pageXOffset ?? win.scrollX ?? 0) + (node.scrollLeft ?? 0),
186
+ y: (win.pageYOffset ?? win.scrollY ?? 0) + (node.scrollTop ?? 0)
187
+ };
214
188
  }
215
189
  /**
216
- * Get translation string from screen <--> svg point
217
- * @param {SVGGraphicsElement} node graphics element
218
- * @param {number} x target x point
219
- * @param {number} y target y point
220
- * @param {boolean} inverse inverse flag
221
- * @returns {object}
222
- */
190
+ * Get translation string from screen <--> svg point
191
+ * @param {SVGGraphicsElement} node graphics element
192
+ * @param {number} x target x point
193
+ * @param {number} y target y point
194
+ * @param {boolean} inverse inverse flag
195
+ * @returns {object}
196
+ */
223
197
  function getTransformCTM(node, x = 0, y = 0, inverse = true) {
224
- const point = new DOMPoint(x, y);
225
- const screen = node.getScreenCTM();
226
- const res = point.matrixTransform(inverse ? screen?.inverse() : screen);
227
- if (inverse === false) {
228
- const rect = getBoundingRect(node);
229
- res.x -= rect.x;
230
- res.y -= rect.y;
231
- }
232
- return res;
198
+ const point = new DOMPoint(x, y);
199
+ const screen = node.getScreenCTM();
200
+ const res = point.matrixTransform(inverse ? screen?.inverse() : screen);
201
+ if (inverse === false) {
202
+ const rect = getBoundingRect(node);
203
+ res.x -= rect.x;
204
+ res.y -= rect.y;
205
+ }
206
+ return res;
233
207
  }
234
208
  /**
235
- * Gets the SVGMatrix of an SVGGElement
236
- * @param {SVGElement} node Node element
237
- * @returns {SVGMatrix} matrix
238
- * @private
239
- */
209
+ * Gets the SVGMatrix of an SVGGElement
210
+ * @param {SVGElement} node Node element
211
+ * @returns {SVGMatrix} matrix
212
+ * @private
213
+ */
240
214
  function getTranslation(node) {
241
- const transform = node ? node.transform : null;
242
- const baseVal = transform && transform.baseVal;
243
- return baseVal && baseVal.numberOfItems ?
244
- baseVal.getItem(0).matrix :
245
- { a: 0, b: 0, c: 0, d: 0, e: 0, f: 0 };
215
+ const transform = node ? node.transform : null;
216
+ const baseVal = transform && transform.baseVal;
217
+ return baseVal && baseVal.numberOfItems ? baseVal.getItem(0).matrix : {
218
+ a: 0,
219
+ b: 0,
220
+ c: 0,
221
+ d: 0,
222
+ e: 0,
223
+ f: 0
224
+ };
246
225
  }
247
226
  /**
248
- * Get position value from element's attribute or transform
249
- * @param {SVGElement} element SVG element
250
- * @param {string} type Coordinate type ("x" or "y")
251
- * @returns {number} Position value
252
- * @private
253
- */
227
+ * Get position value from element's attribute or transform
228
+ * @param {SVGElement} element SVG element
229
+ * @param {string} type Coordinate type ("x" or "y")
230
+ * @returns {number} Position value
231
+ * @private
232
+ */
254
233
  function getElementPos(element, type) {
255
- const attr = element?.getAttribute?.(type);
256
- if (attr) {
257
- return parseFloat(attr);
258
- }
259
- const matrix = getTranslation(element);
260
- return type === "x" ? matrix.e : matrix.f;
234
+ const attr = element?.getAttribute?.(type);
235
+ if (attr) return parseFloat(attr);
236
+ const matrix = getTranslation(element);
237
+ return type === "x" ? matrix.e : matrix.f;
261
238
  }
262
239
  /**
263
- * Check if svg element has viewBox attribute
264
- * @param {d3Selection} svg Target svg selection
265
- * @returns {boolean}
266
- */
240
+ * Check if svg element has viewBox attribute
241
+ * @param {d3Selection} svg Target svg selection
242
+ * @returns {boolean}
243
+ */
267
244
  function hasViewBox(svg) {
268
- const attr = svg.attr("viewBox");
269
- // a valid viewBox has 4 numeric tokens: "min-x min-y width height"
270
- return attr ? attr.trim().split(/[\s,]+/).length === 4 : false;
245
+ const attr = svg.attr("viewBox");
246
+ return attr ? attr.trim().split(/[\s,]+/).length === 4 : false;
271
247
  }
272
248
  /**
273
- * Determine if given node has the specified style
274
- * @param {d3Selection|SVGElement} node Target node
275
- * @param {object} condition Conditional style props object
276
- * @param {boolean} all If true, all condition should be matched
277
- * @returns {boolean}
278
- */
249
+ * Determine if given node has the specified style
250
+ * @param {d3Selection|SVGElement} node Target node
251
+ * @param {object} condition Conditional style props object
252
+ * @param {boolean} all If true, all condition should be matched
253
+ * @returns {boolean}
254
+ */
279
255
  function hasStyle(node, condition, all = false) {
280
- const isD3Node = !!node.node;
281
- let has = false;
282
- for (const [key, value] of Object.entries(condition)) {
283
- has = isD3Node ? node.style(key) === value : node.style[key] === value;
284
- // any-mode: stop on first match / all-mode: stop on first mismatch
285
- if (all ? !has : has) {
286
- break;
287
- }
288
- }
289
- return has;
256
+ const isD3Node = !!node.node;
257
+ let has = false;
258
+ for (const [key, value] of Object.entries(condition)) {
259
+ has = isD3Node ? node.style(key) === value : node.style[key] === value;
260
+ if (all ? !has : has) break;
261
+ }
262
+ return has;
290
263
  }
291
264
  /**
292
- * Return if the current doc is visible or not
293
- * @returns {boolean}
294
- * @private
295
- */
265
+ * Return if the current doc is visible or not
266
+ * @returns {boolean}
267
+ * @private
268
+ */
296
269
  function isTabVisible() {
297
- return doc?.hidden === false || doc?.visibilityState === "visible";
270
+ return doc?.hidden === false || doc?.visibilityState === "visible";
298
271
  }
299
272
  /**
300
- * Get the current input type
301
- * @param {boolean} mouse Config value: interaction.inputType.mouse
302
- * @param {boolean} touch Config value: interaction.inputType.touch
303
- * @returns {string} "mouse" | "touch" | null
304
- * @private
305
- */
273
+ * Get the current input type
274
+ * @param {boolean} mouse Config value: interaction.inputType.mouse
275
+ * @param {boolean} touch Config value: interaction.inputType.touch
276
+ * @returns {string} "mouse" | "touch" | null
277
+ * @private
278
+ */
306
279
  function convertInputType(mouse, touch) {
307
- const { DocumentTouch, matchMedia, navigator } = win;
308
- // https://developer.mozilla.org/en-US/docs/Web/CSS/@media/pointer#coarse
309
- const hasPointerCoarse = matchMedia?.("(pointer:coarse)").matches;
310
- let hasTouch = false;
311
- if (touch) {
312
- // Some Edge desktop return true: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/20417074/
313
- if (navigator && "maxTouchPoints" in navigator) {
314
- hasTouch = navigator.maxTouchPoints > 0;
315
- // Ref: https://github.com/Modernizr/Modernizr/blob/master/feature-detects/touchevents.js
316
- // On IE11 with IE9 emulation mode, ('ontouchstart' in window) is returning true
317
- }
318
- else if ("ontouchmove" in win || (DocumentTouch && doc instanceof DocumentTouch)) {
319
- hasTouch = true;
320
- }
321
- else {
322
- // https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent#avoiding_user_agent_detection
323
- if (hasPointerCoarse) {
324
- hasTouch = true;
325
- }
326
- else {
327
- // Only as a last resort, fall back to user agent sniffing
328
- const UA = navigator.userAgent;
329
- hasTouch = /\b(BlackBerry|webOS|iPhone|IEMobile)\b/i.test(UA) ||
330
- /\b(Android|Windows Phone|iPad|iPod)\b/i.test(UA);
331
- }
332
- }
333
- }
334
- // For non-touch device, media feature condition is: '(pointer:coarse) = false' and '(pointer:fine) = true'
335
- // https://github.com/naver/billboard.js/issues/3854#issuecomment-2404183158
336
- const hasMouse = mouse && !hasPointerCoarse && matchMedia?.("(pointer:fine)").matches;
337
- // fallback to 'mouse' if no input type is detected.
338
- return (hasMouse && "mouse") || (hasTouch && "touch") || "mouse";
280
+ const { DocumentTouch, matchMedia, navigator } = win;
281
+ const hasPointerCoarse = matchMedia?.("(pointer:coarse)").matches;
282
+ let hasTouch = false;
283
+ if (touch) if (navigator && "maxTouchPoints" in navigator) hasTouch = navigator.maxTouchPoints > 0;
284
+ else if ("ontouchmove" in win || DocumentTouch && doc instanceof DocumentTouch) hasTouch = true;
285
+ else if (hasPointerCoarse) hasTouch = true;
286
+ else {
287
+ const UA = navigator.userAgent;
288
+ hasTouch = /\b(BlackBerry|webOS|iPhone|IEMobile)\b/i.test(UA) || /\b(Android|Windows Phone|iPad|iPod)\b/i.test(UA);
289
+ }
290
+ return mouse && !hasPointerCoarse && matchMedia?.("(pointer:fine)").matches && "mouse" || hasTouch && "touch" || "mouse";
339
291
  }
340
292
  /**
341
- * Schedule a RAF update to batch multiple redraw requests
342
- * Manages a RAF state object to intelligently batch rapid updates while ensuring
343
- * immediate execution for the first call (for test compatibility)
344
- * @param {object} rafState RAF state object with pendingRaf property
345
- * @param {number|null} rafState.pendingRaf ID of pending RAF or null
346
- * @param {function} callback Function to execute in RAF
347
- * @returns {void}
348
- * @private
349
- */
293
+ * Schedule a RAF update to batch multiple redraw requests
294
+ * Manages a RAF state object to intelligently batch rapid updates while ensuring
295
+ * immediate execution for the first call (for test compatibility)
296
+ * @param {object} rafState RAF state object with pendingRaf property
297
+ * @param {number|null} rafState.pendingRaf ID of pending RAF or null
298
+ * @param {function} callback Function to execute in RAF
299
+ * @returns {void}
300
+ * @private
301
+ */
350
302
  function scheduleRAFUpdate(rafState, callback) {
351
- // If there's already a pending RAF, we're in a rapid update scenario
352
- // Cancel it and schedule a new one to batch the updates
353
- if (rafState.pendingRaf !== null) {
354
- win.cancelAnimationFrame(rafState.pendingRaf);
355
- // Schedule new RAF
356
- rafState.pendingRaf = win.requestAnimationFrame(() => {
357
- rafState.pendingRaf = null;
358
- callback();
359
- });
360
- }
361
- else {
362
- // First call - execute immediately for test compatibility
363
- // But set pending RAF to detect rapid consecutive calls
364
- rafState.pendingRaf = win.requestAnimationFrame(() => {
365
- rafState.pendingRaf = null;
366
- });
367
- callback();
368
- }
303
+ if (rafState.pendingRaf !== null) {
304
+ win.cancelAnimationFrame(rafState.pendingRaf);
305
+ rafState.pendingRaf = win.requestAnimationFrame(() => {
306
+ rafState.pendingRaf = null;
307
+ callback();
308
+ });
309
+ } else {
310
+ rafState.pendingRaf = win.requestAnimationFrame(() => {
311
+ rafState.pendingRaf = null;
312
+ });
313
+ callback();
314
+ }
369
315
  }
370
- // emulate event
371
316
  const emulateEvent = {
372
- mouse: (() => {
373
- const getParams = () => ({
374
- bubbles: false,
375
- cancelable: false,
376
- screenX: 0,
377
- screenY: 0,
378
- clientX: 0,
379
- clientY: 0
380
- });
381
- try {
382
- // eslint-disable-next-line no-new
383
- new MouseEvent("t");
384
- return (el, eventType, params = getParams()) => {
385
- el.dispatchEvent(new MouseEvent(eventType, params));
386
- };
387
- }
388
- catch {
389
- // Polyfills DOM4 MouseEvent
390
- return (el, eventType, params = getParams()) => {
391
- const mouseEvent = doc.createEvent("MouseEvent");
392
- // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/initMouseEvent
393
- mouseEvent.initMouseEvent(eventType, params.bubbles, params.cancelable, win, 0, // the event's mouse click count
394
- params.screenX, params.screenY, params.clientX, params.clientY, false, false, false, false, 0, null);
395
- el.dispatchEvent(mouseEvent);
396
- };
397
- }
398
- })(),
399
- touch: (el, eventType, params) => {
400
- const touchObj = new Touch(mergeObj({
401
- identifier: Date.now(),
402
- target: el,
403
- radiusX: 2.5,
404
- radiusY: 2.5,
405
- rotationAngle: 10,
406
- force: 0.5
407
- }, params));
408
- el.dispatchEvent(new TouchEvent(eventType, {
409
- cancelable: true,
410
- bubbles: true,
411
- shiftKey: true,
412
- touches: [touchObj],
413
- targetTouches: [],
414
- changedTouches: [touchObj]
415
- }));
416
- }
317
+ mouse: (() => {
318
+ const getParams = () => ({
319
+ bubbles: false,
320
+ cancelable: false,
321
+ screenX: 0,
322
+ screenY: 0,
323
+ clientX: 0,
324
+ clientY: 0
325
+ });
326
+ try {
327
+ new MouseEvent("t");
328
+ return (el, eventType, params = getParams()) => {
329
+ el.dispatchEvent(new MouseEvent(eventType, params));
330
+ };
331
+ } catch {
332
+ return (el, eventType, params = getParams()) => {
333
+ const mouseEvent = doc.createEvent("MouseEvent");
334
+ mouseEvent.initMouseEvent(eventType, params.bubbles, params.cancelable, win, 0, params.screenX, params.screenY, params.clientX, params.clientY, false, false, false, false, 0, null);
335
+ el.dispatchEvent(mouseEvent);
336
+ };
337
+ }
338
+ })(),
339
+ touch: (el, eventType, params) => {
340
+ const touchObj = new Touch(mergeObj({
341
+ identifier: Date.now(),
342
+ target: el,
343
+ radiusX: 2.5,
344
+ radiusY: 2.5,
345
+ rotationAngle: 10,
346
+ force: .5
347
+ }, params));
348
+ el.dispatchEvent(new TouchEvent(eventType, {
349
+ cancelable: true,
350
+ bubbles: true,
351
+ shiftKey: true,
352
+ touches: [touchObj],
353
+ targetTouches: [],
354
+ changedTouches: [touchObj]
355
+ }));
356
+ }
417
357
  };
418
-
358
+ //#endregion
419
359
  export { addCssRules, convertInputType, emulateEvent, getBBox, getBoundingRect, getCssRules, getElementPos, getPathBox, getPointer, getRectSegList, getScrollPosition, getTransformCTM, getTranslation, hasStyle, hasViewBox, isTabVisible, scheduleRAFUpdate, setTextValue };