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,534 +5,374 @@
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 { selectAll, select } from 'd3-selection';
11
- import { $TEXT, $COMMON } from '../../config/classes.js';
12
- import { KEY } from '../../module/Cache.js';
13
- import { getTextPos, batchGetBBox, setRotatePos, updateTextImagePos, updateTextBorder, updateTextImage, meetsLabelThreshold, getRotateAnchor } from './text.util.js';
14
- import { getTranslation, getBoundingRect, getElementPos, getBBox, setTextValue } from '../../module/util/dom.js';
15
- import { isNumber, isString, isFunction, isObject } from '../../module/util/type-checks.js';
16
- import { capitalize, getRandom } from '../../module/util/object.js';
17
-
10
+ import { isFunction, isNumber, isObject, isString } from "../../module/util/type-checks.js";
11
+ import { capitalize, getRandom } from "../../module/util/object.js";
12
+ import { getBBox, getBoundingRect, getElementPos, getTranslation, setTextValue } from "../../module/util/dom.js";
13
+ import { $COMMON, $TEXT } from "../../config/classes.js";
14
+ import { KEY } from "../../module/Cache.js";
15
+ import { batchGetBBox, getRotateAnchor, getTextPos, meetsLabelThreshold, setRotatePos, updateTextBorder, updateTextImage, updateTextImagePos } from "./text.util.js";
16
+ import { select, selectAll } from "d3-selection";
17
+ //#region src/ChartInternal/internals/text.ts
18
18
  /**
19
- * Copyright (c) 2017 ~ present NAVER Corp.
20
- * billboard.js project is licensed under the MIT license
21
- */
22
- var text = {
23
- opacityForText(d) {
24
- const $$ = this;
25
- return $$.isBarType(d) &&
26
- !meetsLabelThreshold.call($$, Math.abs($$.getRatio("bar", d)), "bar") ?
27
- "0" :
28
- ($$.hasDataLabel() ? null : "0");
29
- },
30
- /**
31
- * Initializes the text
32
- * @private
33
- */
34
- initText() {
35
- const { $el } = this;
36
- $el.main.select(`.${$COMMON.chart}`).append("g")
37
- .attr("class", $TEXT.chartTexts)
38
- .style("pointer-events", $el.funnel || $el.treemap ? "none" : null);
39
- },
40
- /**
41
- * Update chartText
42
- * @param {object} targets $$.data.targets
43
- * @private
44
- */
45
- updateTargetsForText(targets) {
46
- const $$ = this;
47
- const classChartText = $$.getChartClass("Text");
48
- const classTexts = $$.getClass("texts", "id");
49
- const classFocus = $$.classFocus.bind($$);
50
- const mainTextUpdate = $$.$el.main.select(`.${$TEXT.chartTexts}`)
51
- .selectAll(`.${$TEXT.chartText}`)
52
- .data($$.filterNullish(targets))
53
- .attr("class", d => `${classChartText(d)}${classFocus(d)}`.trim());
54
- const mainTextEnter = mainTextUpdate.enter().append("g")
55
- .style("opacity", "0")
56
- .attr("class", classChartText)
57
- .call($$.setCssRule(true, ` .${$TEXT.text}`, ["fill", "pointer-events:none"], $$.updateTextColor));
58
- mainTextEnter.append("g")
59
- .attr("class", classTexts);
60
- },
61
- /**
62
- * Update text
63
- * @private
64
- */
65
- updateText() {
66
- const $$ = this;
67
- const { $el, $T, config, axis } = $$;
68
- const classText = $$.getClass("text", "index");
69
- const labelsCentered = config.data_labels.centered;
70
- const text = $el.main.selectAll(`.${$TEXT.texts}`)
71
- .selectAll(`.${$TEXT.text}`)
72
- .data($$.labelishData.bind($$));
73
- $T(text.exit())
74
- .style("fill-opacity", "0")
75
- .remove();
76
- $el.text = text.enter()
77
- .append("text")
78
- .merge(text)
79
- .attr("class", classText)
80
- .attr("text-anchor", d => {
81
- const isInverted = config[`axis_${axis?.getId(d.id)}_inverted`];
82
- // when value is negative or
83
- let isEndAnchor = isInverted ? d.value > 0 : d.value < 0;
84
- if ($$.isCandlestickType(d)) {
85
- const data = $$.getCandlestickData(d);
86
- isEndAnchor = !data?._isUp;
87
- }
88
- else if ($$.isTreemapType(d)) {
89
- return labelsCentered ? "middle" : "start";
90
- }
91
- return (config.axis_rotated ? (isEndAnchor ? "end" : "start") : "middle");
92
- })
93
- .style("fill", $$.getStylePropValue($$.updateTextColor))
94
- .style("fill-opacity", "0")
95
- .each(function (d, i, texts) {
96
- const node = select(this);
97
- let { value } = d;
98
- if ($$.isBubbleZType(d)) {
99
- value = $$.getBubbleZData(value, "z");
100
- }
101
- else if ($$.isCandlestickType(d)) {
102
- const data = $$.getCandlestickData(d);
103
- if (data) {
104
- value = data.close;
105
- }
106
- }
107
- value = $$.isTreemapType(d) ?
108
- $$.treemapDataLabelFormat(d)(node) :
109
- $$.dataLabelFormat(d.id)(value, d.id, d.index, texts);
110
- if (isNumber(value)) {
111
- this.textContent = value;
112
- }
113
- else {
114
- setTextValue(node, value, undefined, true);
115
- }
116
- });
117
- // Add images if imgUrl is specified
118
- updateTextImage.call($$);
119
- },
120
- updateTextColor(d) {
121
- const $$ = this;
122
- const { config } = $$;
123
- const labelColors = config.data_labels_colors;
124
- const defaultColor = ($$.isArcType(d) && !$$.isRadarType(d)) || $$.isFunnelType(d) || $$.isTreemapType(d) ?
125
- null :
126
- $$.color(d);
127
- let color;
128
- if (isString(labelColors)) {
129
- color = labelColors;
130
- }
131
- else if (isObject(labelColors)) {
132
- const { id } = d.data || d;
133
- color = labelColors[id];
134
- }
135
- else if (isFunction(labelColors)) {
136
- color = labelColors.bind($$.api)(defaultColor, d);
137
- }
138
- if ($$.isCandlestickType(d) && !isFunction(labelColors)) {
139
- const value = $$.getCandlestickData(d);
140
- if (!value?._isUp) {
141
- const downColor = config.candlestick_color_down;
142
- color = isObject(downColor) ? downColor[d.id] : downColor;
143
- }
144
- }
145
- return color || defaultColor;
146
- },
147
- /**
148
- * Update data label text background color
149
- * @param {object} d Data object
150
- * @param {object|string|function} option option object
151
- * @returns {string|null}
152
- * @private
153
- */
154
- updateTextBGColor(d, option) {
155
- const $$ = this;
156
- const { $el: { defs } } = $$;
157
- let color = "";
158
- if (option) {
159
- const id = isString(option) ?
160
- "" :
161
- $$.getTargetSelectorSuffix("id" in d ? d.id : d.data.id);
162
- const filter = defs.select(["filter[id*='labels-bg", "']"].join(id));
163
- if (filter.size()) {
164
- color = `url(#${filter.attr("id")})`;
165
- }
166
- if (isFunction(option)) {
167
- $$.generateTextBGColorFilter(option);
168
- // Get default color and call function
169
- const defaultColor = $$.color(d);
170
- const bgColor = option.bind($$.api)(defaultColor, d);
171
- if (bgColor) {
172
- filter.select("feFlood").attr("flood-color", bgColor);
173
- }
174
- else {
175
- color = "";
176
- }
177
- }
178
- }
179
- return color || null;
180
- },
181
- /**
182
- * Redraw chartText
183
- * @param {function} getX Positioning function for x
184
- * @param {function} getY Positioning function for y
185
- * @param {boolean} forFlow Weather is flow
186
- * @param {boolean} withTransition transition is enabled
187
- * @returns {Array}
188
- * @private
189
- */
190
- redrawText(getX, getY, forFlow, withTransition) {
191
- const $$ = this;
192
- const { $T, axis, config, state: { hasTreemap } } = $$;
193
- const t = getRandom(true);
194
- const isRotated = config.axis_rotated;
195
- const angle = config.data_labels.rotate;
196
- const anchorString = getRotateAnchor(angle);
197
- const rotateString = angle ? `rotate(${angle})` : "";
198
- const text = $$.$el.text
199
- .style("fill", $$.getStylePropValue($$.updateTextColor))
200
- .attr("filter", d => $$.updateTextBGColor.bind($$)(d, config.data_labels_backgroundColors))
201
- .style("fill-opacity", forFlow ? 0 : $$.opacityForText.bind($$));
202
- // Phase 1: collect text dimensions before mutating label positions.
203
- const dimensions = new Map();
204
- const elementsToMeasure = [];
205
- text.each(function (d) {
206
- const element = this;
207
- dimensions.set(element, { rect: getBoundingRect(element) });
208
- if (config.data_labels.centered && ($$.isBarType(d) || $$.isTreemapType(d))) {
209
- elementsToMeasure.push(element);
210
- }
211
- });
212
- if (elementsToMeasure.length > 0) {
213
- batchGetBBox(elementsToMeasure).forEach((bbox, element) => {
214
- const dimension = dimensions.get(element);
215
- dimension && (dimension.bbox = bbox);
216
- });
217
- }
218
- // Phase 2: apply cached dimensions during position calculation.
219
- text.each(function (d, i) {
220
- const labelDimension = dimensions.get(this);
221
- // do not apply transition for newly added text elements
222
- const node = $T(hasTreemap && this.childElementCount ? this.parentNode : this, !!(withTransition &&
223
- (this.getAttribute("x") || this.getAttribute("transform"))), t);
224
- const isInverted = config[`axis_${axis?.getId(d.id)}_inverted`];
225
- let pos = {
226
- x: getX.call(this, d, i, labelDimension),
227
- y: getY.call(this, d, i, labelDimension)
228
- };
229
- if (angle) {
230
- pos = setRotatePos.bind($$)(d, pos, anchorString, isRotated, isInverted);
231
- node.attr("text-anchor", anchorString);
232
- }
233
- updateTextImagePos.call($$, this, pos, labelDimension?.rect);
234
- // when is multiline
235
- if (this.childElementCount || angle) {
236
- node.attr("transform", `translate(${pos.x} ${pos.y}) ${rotateString}`);
237
- }
238
- else {
239
- node.attr("x", pos.x).attr("y", pos.y);
240
- }
241
- config.data_labels.border &&
242
- updateTextBorder.call($$, node.node(), pos, `${$TEXT.textBorderRect}-${i}`);
243
- });
244
- // need to return 'true' as of being pushed to the redraw list
245
- // ref: getRedrawList()
246
- return true;
247
- },
248
- /**
249
- * Gets the getBoundingClientRect value of the element
250
- * @param {HTMLElement|d3.selection|Array} source Target element
251
- * @param {string} className Class name
252
- * @returns {object} value of element.getBoundingClientRect()
253
- * @private
254
- */
255
- getTextRect(source, className) {
256
- const $$ = this;
257
- let cacheKey;
258
- let base;
259
- let text;
260
- if (Array.isArray(source)) {
261
- cacheKey = `${KEY.textRect}-${source.join("_")}`;
262
- }
263
- else {
264
- base = source.node?.() ?? source;
265
- if (!/text/i.test(base.tagName)) {
266
- base = base.querySelector("text");
267
- }
268
- text = base.textContent;
269
- cacheKey = `${KEY.textRect}-${text.replace(/\W/g, "_")}`;
270
- }
271
- const rect = $$.cache.get(cacheKey) || [];
272
- if (rect.length === 0) {
273
- ($$.$el.svg || $$.$el.chart.select("svg"))
274
- .selectAll(`.${$COMMON.dummy}`)
275
- .data(text ? [text] : source)
276
- .enter()
277
- .append("text")
278
- .style("visibility", "hidden")
279
- .style("font", base ? select(base).style("font") : null)
280
- .classed(className || $COMMON.dummy, true)
281
- .text(d => d)
282
- .each(function (v, i) {
283
- rect[i] = getBoundingRect(this);
284
- })
285
- .remove();
286
- $$.cache.add(cacheKey, rect);
287
- }
288
- return rect.length > 1 ? rect : rect[0];
289
- },
290
- /**
291
- * Gets the x or y coordinate of the text
292
- * @param {object} indices Indices values
293
- * @param {boolean} forX whether or not to x
294
- * @returns {function} coordinates
295
- * @private
296
- */
297
- generateXYForText(indices, forX) {
298
- const $$ = this;
299
- const { state: { hasRadar, hasFunnel, hasTreemap } } = $$;
300
- const types = Object.keys(indices);
301
- const points = {};
302
- const getter = forX ? $$.getXForText : $$.getYForText;
303
- hasFunnel && types.push("funnel");
304
- hasRadar && types.push("radar");
305
- hasTreemap && types.push("treemap");
306
- types.forEach(v => {
307
- points[v] = $$[`generateGet${capitalize(v)}Points`](indices[v], false);
308
- });
309
- return function (d, i, labelDimension) {
310
- const type = ($$.isAreaType(d) && "area") ||
311
- ($$.isBarType(d) && "bar") ||
312
- ($$.isCandlestickType(d) && "candlestick") ||
313
- ($$.isFunnelType(d) && "funnel") ||
314
- ($$.isRadarType(d) && "radar") ||
315
- ($$.isTreemapType(d) && "treemap") || "line";
316
- return getter.call($$, points[type](d, i), d, this, labelDimension);
317
- };
318
- },
319
- /**
320
- * Get centerized text position for bar type data.label.text
321
- * @param {object} d Data object
322
- * @param {Array} points Data points position
323
- * @param {HTMLElement} textElement Data label text element
324
- * @param {string} type 'x' or 'y'
325
- * @param {object} labelDimension Optional cached label dimensions
326
- * @returns {number} Position value
327
- * @private
328
- */
329
- getCenteredTextPos(d, points, textElement, type, labelDimension) {
330
- const $$ = this;
331
- const { config } = $$;
332
- const isRotated = config.axis_rotated;
333
- const isBarType = $$.isBarType(d);
334
- const isTreemapType = $$.isTreemapType(d);
335
- if (config.data_labels.centered && (isBarType || isTreemapType)) {
336
- const rect = labelDimension?.bbox || getBBox(textElement);
337
- if (isBarType) {
338
- const isPositive = $$.getRangedData(d, null, "bar") >= 0;
339
- if (isRotated) {
340
- const w = (isPositive ?
341
- points[1][1] - points[0][1] :
342
- points[0][1] - points[1][1]) / 2 + (rect.width / 2);
343
- return isPositive ? -w - 3 : w + 2;
344
- }
345
- else {
346
- const h = (isPositive ?
347
- points[0][1] - points[1][1] :
348
- points[1][1] - points[0][1]) / 2 + (rect.height / 2);
349
- return isPositive ? h : -h - 2;
350
- }
351
- }
352
- else if (isTreemapType) {
353
- return type === "x" ?
354
- (points[1][0] - points[0][0]) / 2 : // X: Move to horizontal center of rect
355
- (points[1][1] - points[0][1]) / 2 - rect.y - rect.height / 2; // Y: Calculate true vertical center
356
- }
357
- }
358
- return 0;
359
- },
360
- /**
361
- * Gets the x coordinate of the text
362
- * @param {object} points Data points position
363
- * @param {object} d Data object
364
- * @param {HTMLElement} textElement Data label text element
365
- * @param {object} labelDimension Optional cached label dimensions
366
- * @returns {number} x coordinate
367
- * @private
368
- */
369
- getXForText(points, d, textElement, labelDimension) {
370
- const $$ = this;
371
- const { config } = $$;
372
- const isRotated = config.axis_rotated;
373
- const isFunnelType = $$.isFunnelType(d);
374
- const isTreemapType = $$.isTreemapType(d);
375
- let xPos = points ? points[0][0] : 0;
376
- if ($$.isCandlestickType(d)) {
377
- if (isRotated) {
378
- xPos = $$.getCandlestickData(d)?._isUp ? points[2][2] + 4 : points[2][1] - 4;
379
- }
380
- else {
381
- xPos += (points[1][0] - xPos) / 2;
382
- }
383
- }
384
- else if (isFunnelType) {
385
- // Use pre-calculated center x from points[2]
386
- // Preserve current position when points unavailable (during hide transition)
387
- if (points) {
388
- xPos = points[2]?.[0] ?? xPos;
389
- }
390
- else {
391
- return getElementPos(textElement, "x");
392
- }
393
- }
394
- else if (isTreemapType) {
395
- xPos += config.data_labels.centered ? 0 : 5;
396
- }
397
- else {
398
- if (isRotated) {
399
- const isInverted = config[`axis_${$$.axis.getId(d.id)}_inverted`];
400
- const padding = $$.isBarType(d) ? 4 : 6;
401
- const value = d.value;
402
- xPos = points[2][1];
403
- xPos += padding * ((isInverted ? value > 0 : value < 0) ? -1 : 1);
404
- }
405
- else {
406
- xPos = $$.hasType("bar") ? (points[2][0] + points[0][0]) / 2 : xPos;
407
- }
408
- }
409
- if (isRotated || isTreemapType || isFunnelType) {
410
- xPos += $$.getCenteredTextPos(d, points, textElement, "x", labelDimension);
411
- }
412
- return xPos + getTextPos.call(this, d, "x");
413
- },
414
- /**
415
- * Gets the y coordinate of the text
416
- * @param {object} points Data points position
417
- * @param {object} d Data object
418
- * @param {HTMLElement} textElement Data label text element
419
- * @param {object} labelDimension Optional cached label dimensions
420
- * @returns {number} y coordinate
421
- * @private
422
- */
423
- getYForText(points, d, textElement, labelDimension) {
424
- const $$ = this;
425
- const { axis, config, state } = $$;
426
- const isRotated = config.axis_rotated;
427
- const isInverted = config[`axis_${axis?.getId(d.id)}_inverted`];
428
- const isBarType = $$.isBarType(d);
429
- const isFunnelType = $$.isFunnelType(d);
430
- const isTreemapType = $$.isTreemapType(d);
431
- const r = config.point_r;
432
- const rect = labelDimension?.rect || getBoundingRect(textElement);
433
- let { value } = d;
434
- let baseY = 3;
435
- let yPos;
436
- if ($$.isCandlestickType(d)) {
437
- value = $$.getCandlestickData(d);
438
- if (isRotated) {
439
- yPos = points[0][0];
440
- yPos += ((points[1][0] - yPos) / 2) + baseY;
441
- }
442
- else {
443
- yPos = value && value._isUp ? points[2][2] - baseY : points[2][1] + (baseY * 4);
444
- if (isInverted) {
445
- yPos += 15 * (value._isUp ? 1 : -1);
446
- }
447
- }
448
- }
449
- else if (isFunnelType) {
450
- // Use pre-calculated center y from points[2]
451
- // Preserve current position when points unavailable (during hide transition)
452
- if (points) {
453
- yPos = (points[2]?.[1] ?? points[0][1]) + rect.height / 2 - 3;
454
- }
455
- else {
456
- return getElementPos(textElement, "y");
457
- }
458
- }
459
- else if (isTreemapType) {
460
- yPos = points[0][1] + (config.data_labels.centered ? 0 : rect.height + 5);
461
- }
462
- else {
463
- if (isRotated) {
464
- yPos = (points[0][0] + points[2][0] + rect.height * 0.6) / 2;
465
- }
466
- else {
467
- yPos = points[2][1];
468
- if (isNumber(r) && r > 5 && ($$.isLineType(d) || $$.isScatterType(d))) {
469
- baseY += config.point_r / 2.3;
470
- }
471
- if (value < 0 || (value === 0 && !state.hasPositiveValue && state.hasNegativeValue)) {
472
- yPos += isInverted ? (isBarType ? -3 : -5) : (rect.height + (isBarType ? -baseY : baseY));
473
- }
474
- else {
475
- let diff = -baseY * 2;
476
- if (isBarType) {
477
- diff = -baseY;
478
- }
479
- else if ($$.isBubbleType(d)) {
480
- diff = baseY;
481
- }
482
- if (isInverted) {
483
- diff = isBarType ? 10 : 15;
484
- }
485
- yPos += diff;
486
- }
487
- }
488
- }
489
- if (!isRotated || isTreemapType) {
490
- yPos += $$.getCenteredTextPos(d, points, textElement, "y", labelDimension);
491
- }
492
- return yPos + getTextPos.call(this, d, "y");
493
- },
494
- /**
495
- * Calculate if two or more text nodes are overlapping
496
- * Mark overlapping text nodes with "text-overlapping" class
497
- * @param {string} id Axis id
498
- * @param {ChartInternal} $$ ChartInternal context
499
- * @param {string} selector Selector string
500
- * @private
501
- */
502
- markOverlapped(id, $$, selector) {
503
- const textNodes = $$.$el.arcs.selectAll(selector);
504
- const filteredTextNodes = textNodes.filter(node => node.data.id !== id);
505
- const textNode = textNodes.filter(node => node.data.id === id);
506
- const translate = getTranslation(textNode.node());
507
- // Calculates the length of the hypotenuse
508
- const calcHypo = (x, y) => Math.sqrt(x * x + y * y);
509
- textNode.node() && filteredTextNodes.each(function () {
510
- const coordinate = getTranslation(this);
511
- const filteredTextNode = select(this);
512
- const nodeForWidth = calcHypo(translate.e, translate.f) > calcHypo(coordinate.e, coordinate.f) ?
513
- textNode :
514
- filteredTextNode;
515
- const overlapsX = Math.ceil(Math.abs(translate.e - coordinate.e)) <
516
- Math.ceil(nodeForWidth.node().getComputedTextLength());
517
- const overlapsY = Math.ceil(Math.abs(translate.f - coordinate.f)) <
518
- parseInt(textNode.style("font-size"), 10);
519
- filteredTextNode.classed($TEXT.TextOverlapping, overlapsX && overlapsY);
520
- });
521
- },
522
- /**
523
- * Calculate if two or more text nodes are overlapping
524
- * Remove "text-overlapping" class on selected text nodes
525
- * @param {ChartInternal} $$ ChartInternal context
526
- * @param {string} selector Selector string
527
- * @private
528
- */
529
- undoMarkOverlapped($$, selector) {
530
- $$.$el.arcs.selectAll(selector)
531
- .each(function () {
532
- selectAll([this, this.previousSibling])
533
- .classed($TEXT.TextOverlapping, false);
534
- });
535
- }
19
+ * Copyright (c) 2017 ~ present NAVER Corp.
20
+ * billboard.js project is licensed under the MIT license
21
+ */
22
+ var text_default = {
23
+ opacityForText(d) {
24
+ const $$ = this;
25
+ return $$.isBarType(d) && !meetsLabelThreshold.call($$, Math.abs($$.getRatio("bar", d)), "bar") ? "0" : $$.hasDataLabel() ? null : "0";
26
+ },
27
+ /**
28
+ * Initializes the text
29
+ * @private
30
+ */
31
+ initText() {
32
+ const { $el } = this;
33
+ $el.main.select(`.${$COMMON.chart}`).append("g").attr("class", $TEXT.chartTexts).style("pointer-events", $el.funnel || $el.treemap ? "none" : null);
34
+ },
35
+ /**
36
+ * Update chartText
37
+ * @param {object} targets $$.data.targets
38
+ * @private
39
+ */
40
+ updateTargetsForText(targets) {
41
+ const $$ = this;
42
+ const classChartText = $$.getChartClass("Text");
43
+ const classTexts = $$.getClass("texts", "id");
44
+ const classFocus = $$.classFocus.bind($$);
45
+ $$.$el.main.select(`.${$TEXT.chartTexts}`).selectAll(`.${$TEXT.chartText}`).data($$.filterNullish(targets)).attr("class", (d) => `${classChartText(d)}${classFocus(d)}`.trim()).enter().append("g").style("opacity", "0").attr("class", classChartText).call($$.setCssRule(true, ` .${$TEXT.text}`, ["fill", "pointer-events:none"], $$.updateTextColor)).append("g").attr("class", classTexts);
46
+ },
47
+ /**
48
+ * Update text
49
+ * @private
50
+ */
51
+ updateText() {
52
+ const $$ = this;
53
+ const { $el, $T, config, axis } = $$;
54
+ const classText = $$.getClass("text", "index");
55
+ const labelsCentered = config.data_labels.centered;
56
+ const text = $el.main.selectAll(`.${$TEXT.texts}`).selectAll(`.${$TEXT.text}`).data($$.labelishData.bind($$));
57
+ $T(text.exit()).style("fill-opacity", "0").remove();
58
+ $el.text = text.enter().append("text").merge(text).attr("class", classText).attr("text-anchor", (d) => {
59
+ let isEndAnchor = config[`axis_${axis?.getId(d.id)}_inverted`] ? d.value > 0 : d.value < 0;
60
+ if ($$.isCandlestickType(d)) isEndAnchor = !$$.getCandlestickData(d)?._isUp;
61
+ else if ($$.isTreemapType(d)) return labelsCentered ? "middle" : "start";
62
+ return config.axis_rotated ? isEndAnchor ? "end" : "start" : "middle";
63
+ }).style("fill", $$.getStylePropValue($$.updateTextColor)).style("fill-opacity", "0").each(function(d, i, texts) {
64
+ const node = select(this);
65
+ let { value } = d;
66
+ if ($$.isBubbleZType(d)) value = $$.getBubbleZData(value, "z");
67
+ else if ($$.isCandlestickType(d)) {
68
+ const data = $$.getCandlestickData(d);
69
+ if (data) value = data.close;
70
+ }
71
+ value = $$.isTreemapType(d) ? $$.treemapDataLabelFormat(d)(node) : $$.dataLabelFormat(d.id)(value, d.id, d.index, texts);
72
+ if (isNumber(value)) this.textContent = value;
73
+ else setTextValue(node, value, void 0, true);
74
+ });
75
+ updateTextImage.call($$);
76
+ },
77
+ updateTextColor(d) {
78
+ const $$ = this;
79
+ const { config } = $$;
80
+ const labelColors = config.data_labels_colors;
81
+ const defaultColor = $$.isArcType(d) && !$$.isRadarType(d) || $$.isFunnelType(d) || $$.isTreemapType(d) ? null : $$.color(d);
82
+ let color;
83
+ if (isString(labelColors)) color = labelColors;
84
+ else if (isObject(labelColors)) {
85
+ const { id } = d.data || d;
86
+ color = labelColors[id];
87
+ } else if (isFunction(labelColors)) color = labelColors.bind($$.api)(defaultColor, d);
88
+ if ($$.isCandlestickType(d) && !isFunction(labelColors)) {
89
+ if (!$$.getCandlestickData(d)?._isUp) {
90
+ const downColor = config.candlestick_color_down;
91
+ color = isObject(downColor) ? downColor[d.id] : downColor;
92
+ }
93
+ }
94
+ return color || defaultColor;
95
+ },
96
+ /**
97
+ * Update data label text background color
98
+ * @param {object} d Data object
99
+ * @param {object|string|function} option option object
100
+ * @returns {string|null}
101
+ * @private
102
+ */
103
+ updateTextBGColor(d, option) {
104
+ const $$ = this;
105
+ const { $el: { defs } } = $$;
106
+ let color = "";
107
+ if (option) {
108
+ const id = isString(option) ? "" : $$.getTargetSelectorSuffix("id" in d ? d.id : d.data.id);
109
+ const filter = defs.select(["filter[id*='labels-bg", "']"].join(id));
110
+ if (filter.size()) color = `url(#${filter.attr("id")})`;
111
+ if (isFunction(option)) {
112
+ $$.generateTextBGColorFilter(option);
113
+ const defaultColor = $$.color(d);
114
+ const bgColor = option.bind($$.api)(defaultColor, d);
115
+ if (bgColor) filter.select("feFlood").attr("flood-color", bgColor);
116
+ else color = "";
117
+ }
118
+ }
119
+ return color || null;
120
+ },
121
+ /**
122
+ * Redraw chartText
123
+ * @param {function} getX Positioning function for x
124
+ * @param {function} getY Positioning function for y
125
+ * @param {boolean} forFlow Weather is flow
126
+ * @param {boolean} withTransition transition is enabled
127
+ * @returns {Array}
128
+ * @private
129
+ */
130
+ redrawText(getX, getY, forFlow, withTransition) {
131
+ const $$ = this;
132
+ const { $T, axis, config, state: { hasTreemap } } = $$;
133
+ const t = getRandom(true);
134
+ const isRotated = config.axis_rotated;
135
+ const angle = config.data_labels.rotate;
136
+ const anchorString = getRotateAnchor(angle);
137
+ const rotateString = angle ? `rotate(${angle})` : "";
138
+ const text = $$.$el.text.style("fill", $$.getStylePropValue($$.updateTextColor)).attr("filter", (d) => $$.updateTextBGColor.bind($$)(d, config.data_labels_backgroundColors)).style("fill-opacity", forFlow ? 0 : $$.opacityForText.bind($$));
139
+ const dimensions = /* @__PURE__ */ new Map();
140
+ const elementsToMeasure = [];
141
+ text.each(function(d) {
142
+ const element = this;
143
+ dimensions.set(element, { rect: getBoundingRect(element) });
144
+ if (config.data_labels.centered && ($$.isBarType(d) || $$.isTreemapType(d))) elementsToMeasure.push(element);
145
+ });
146
+ if (elementsToMeasure.length > 0) batchGetBBox(elementsToMeasure).forEach((bbox, element) => {
147
+ const dimension = dimensions.get(element);
148
+ dimension && (dimension.bbox = bbox);
149
+ });
150
+ text.each(function(d, i) {
151
+ const labelDimension = dimensions.get(this);
152
+ const node = $T(hasTreemap && this.childElementCount ? this.parentNode : this, !!(withTransition && (this.getAttribute("x") || this.getAttribute("transform"))), t);
153
+ const isInverted = config[`axis_${axis?.getId(d.id)}_inverted`];
154
+ let pos = {
155
+ x: getX.call(this, d, i, labelDimension),
156
+ y: getY.call(this, d, i, labelDimension)
157
+ };
158
+ if (angle) {
159
+ pos = setRotatePos.bind($$)(d, pos, anchorString, isRotated, isInverted);
160
+ node.attr("text-anchor", anchorString);
161
+ }
162
+ updateTextImagePos.call($$, this, pos, labelDimension?.rect);
163
+ if (this.childElementCount || angle) node.attr("transform", `translate(${pos.x} ${pos.y}) ${rotateString}`);
164
+ else node.attr("x", pos.x).attr("y", pos.y);
165
+ config.data_labels.border && updateTextBorder.call($$, node.node(), pos, `${$TEXT.textBorderRect}-${i}`);
166
+ });
167
+ return true;
168
+ },
169
+ /**
170
+ * Gets the getBoundingClientRect value of the element
171
+ * @param {HTMLElement|d3.selection|Array} source Target element
172
+ * @param {string} className Class name
173
+ * @returns {object} value of element.getBoundingClientRect()
174
+ * @private
175
+ */
176
+ getTextRect(source, className) {
177
+ const $$ = this;
178
+ let cacheKey;
179
+ let base;
180
+ let text;
181
+ if (Array.isArray(source)) cacheKey = `${KEY.textRect}-${source.join("_")}`;
182
+ else {
183
+ base = source.node?.() ?? source;
184
+ if (!/text/i.test(base.tagName)) base = base.querySelector("text");
185
+ text = base.textContent;
186
+ cacheKey = `${KEY.textRect}-${text.replace(/\W/g, "_")}`;
187
+ }
188
+ const rect = $$.cache.get(cacheKey) || [];
189
+ if (rect.length === 0) {
190
+ ($$.$el.svg || $$.$el.chart.select("svg")).selectAll(`.${$COMMON.dummy}`).data(text ? [text] : source).enter().append("text").style("visibility", "hidden").style("font", base ? select(base).style("font") : null).classed(className || $COMMON.dummy, true).text((d) => d).each(function(v, i) {
191
+ rect[i] = getBoundingRect(this);
192
+ }).remove();
193
+ $$.cache.add(cacheKey, rect);
194
+ }
195
+ return rect.length > 1 ? rect : rect[0];
196
+ },
197
+ /**
198
+ * Gets the x or y coordinate of the text
199
+ * @param {object} indices Indices values
200
+ * @param {boolean} forX whether or not to x
201
+ * @returns {function} coordinates
202
+ * @private
203
+ */
204
+ generateXYForText(indices, forX) {
205
+ const $$ = this;
206
+ const { state: { hasRadar, hasFunnel, hasTreemap } } = $$;
207
+ const types = Object.keys(indices);
208
+ const points = {};
209
+ const getter = forX ? $$.getXForText : $$.getYForText;
210
+ hasFunnel && types.push("funnel");
211
+ hasRadar && types.push("radar");
212
+ hasTreemap && types.push("treemap");
213
+ types.forEach((v) => {
214
+ points[v] = $$[`generateGet${capitalize(v)}Points`](indices[v], false);
215
+ });
216
+ return function(d, i, labelDimension) {
217
+ const type = $$.isAreaType(d) && "area" || $$.isBarType(d) && "bar" || $$.isCandlestickType(d) && "candlestick" || $$.isFunnelType(d) && "funnel" || $$.isRadarType(d) && "radar" || $$.isTreemapType(d) && "treemap" || "line";
218
+ return getter.call($$, points[type](d, i), d, this, labelDimension);
219
+ };
220
+ },
221
+ /**
222
+ * Get centerized text position for bar type data.label.text
223
+ * @param {object} d Data object
224
+ * @param {Array} points Data points position
225
+ * @param {HTMLElement} textElement Data label text element
226
+ * @param {string} type 'x' or 'y'
227
+ * @param {object} labelDimension Optional cached label dimensions
228
+ * @returns {number} Position value
229
+ * @private
230
+ */
231
+ getCenteredTextPos(d, points, textElement, type, labelDimension) {
232
+ const $$ = this;
233
+ const { config } = $$;
234
+ const isRotated = config.axis_rotated;
235
+ const isBarType = $$.isBarType(d);
236
+ const isTreemapType = $$.isTreemapType(d);
237
+ if (config.data_labels.centered && (isBarType || isTreemapType)) {
238
+ const rect = labelDimension?.bbox || getBBox(textElement);
239
+ if (isBarType) {
240
+ const isPositive = $$.getRangedData(d, null, "bar") >= 0;
241
+ if (isRotated) {
242
+ const w = (isPositive ? points[1][1] - points[0][1] : points[0][1] - points[1][1]) / 2 + rect.width / 2;
243
+ return isPositive ? -w - 3 : w + 2;
244
+ } else {
245
+ const h = (isPositive ? points[0][1] - points[1][1] : points[1][1] - points[0][1]) / 2 + rect.height / 2;
246
+ return isPositive ? h : -h - 2;
247
+ }
248
+ } else if (isTreemapType) return type === "x" ? (points[1][0] - points[0][0]) / 2 : (points[1][1] - points[0][1]) / 2 - rect.y - rect.height / 2;
249
+ }
250
+ return 0;
251
+ },
252
+ /**
253
+ * Gets the x coordinate of the text
254
+ * @param {object} points Data points position
255
+ * @param {object} d Data object
256
+ * @param {HTMLElement} textElement Data label text element
257
+ * @param {object} labelDimension Optional cached label dimensions
258
+ * @returns {number} x coordinate
259
+ * @private
260
+ */
261
+ getXForText(points, d, textElement, labelDimension) {
262
+ const $$ = this;
263
+ const { config } = $$;
264
+ const isRotated = config.axis_rotated;
265
+ const isFunnelType = $$.isFunnelType(d);
266
+ const isTreemapType = $$.isTreemapType(d);
267
+ let xPos = points ? points[0][0] : 0;
268
+ if ($$.isCandlestickType(d)) if (isRotated) xPos = $$.getCandlestickData(d)?._isUp ? points[2][2] + 4 : points[2][1] - 4;
269
+ else xPos += (points[1][0] - xPos) / 2;
270
+ else if (isFunnelType) if (points) xPos = points[2]?.[0] ?? xPos;
271
+ else return getElementPos(textElement, "x");
272
+ else if (isTreemapType) xPos += config.data_labels.centered ? 0 : 5;
273
+ else if (isRotated) {
274
+ const isInverted = config[`axis_${$$.axis.getId(d.id)}_inverted`];
275
+ const padding = $$.isBarType(d) ? 4 : 6;
276
+ const value = d.value;
277
+ xPos = points[2][1];
278
+ xPos += padding * ((isInverted ? value > 0 : value < 0) ? -1 : 1);
279
+ } else xPos = $$.hasType("bar") ? (points[2][0] + points[0][0]) / 2 : xPos;
280
+ if (isRotated || isTreemapType || isFunnelType) xPos += $$.getCenteredTextPos(d, points, textElement, "x", labelDimension);
281
+ return xPos + getTextPos.call(this, d, "x");
282
+ },
283
+ /**
284
+ * Gets the y coordinate of the text
285
+ * @param {object} points Data points position
286
+ * @param {object} d Data object
287
+ * @param {HTMLElement} textElement Data label text element
288
+ * @param {object} labelDimension Optional cached label dimensions
289
+ * @returns {number} y coordinate
290
+ * @private
291
+ */
292
+ getYForText(points, d, textElement, labelDimension) {
293
+ const $$ = this;
294
+ const { axis, config, state } = $$;
295
+ const isRotated = config.axis_rotated;
296
+ const isInverted = config[`axis_${axis?.getId(d.id)}_inverted`];
297
+ const isBarType = $$.isBarType(d);
298
+ const isFunnelType = $$.isFunnelType(d);
299
+ const isTreemapType = $$.isTreemapType(d);
300
+ const r = config.point_r;
301
+ const rect = labelDimension?.rect || getBoundingRect(textElement);
302
+ let { value } = d;
303
+ let baseY = 3;
304
+ let yPos;
305
+ if ($$.isCandlestickType(d)) {
306
+ value = $$.getCandlestickData(d);
307
+ if (isRotated) {
308
+ yPos = points[0][0];
309
+ yPos += (points[1][0] - yPos) / 2 + baseY;
310
+ } else {
311
+ yPos = value && value._isUp ? points[2][2] - baseY : points[2][1] + baseY * 4;
312
+ if (isInverted) yPos += 15 * (value._isUp ? 1 : -1);
313
+ }
314
+ } else if (isFunnelType) if (points) yPos = (points[2]?.[1] ?? points[0][1]) + rect.height / 2 - 3;
315
+ else return getElementPos(textElement, "y");
316
+ else if (isTreemapType) yPos = points[0][1] + (config.data_labels.centered ? 0 : rect.height + 5);
317
+ else if (isRotated) yPos = (points[0][0] + points[2][0] + rect.height * .6) / 2;
318
+ else {
319
+ yPos = points[2][1];
320
+ if (isNumber(r) && r > 5 && ($$.isLineType(d) || $$.isScatterType(d))) baseY += config.point_r / 2.3;
321
+ if (value < 0 || value === 0 && !state.hasPositiveValue && state.hasNegativeValue) yPos += isInverted ? isBarType ? -3 : -5 : rect.height + (isBarType ? -baseY : baseY);
322
+ else {
323
+ let diff = -baseY * 2;
324
+ if (isBarType) diff = -baseY;
325
+ else if ($$.isBubbleType(d)) diff = baseY;
326
+ if (isInverted) diff = isBarType ? 10 : 15;
327
+ yPos += diff;
328
+ }
329
+ }
330
+ if (!isRotated || isTreemapType) yPos += $$.getCenteredTextPos(d, points, textElement, "y", labelDimension);
331
+ return yPos + getTextPos.call(this, d, "y");
332
+ },
333
+ /**
334
+ * Calculate if two or more text nodes are overlapping
335
+ * Mark overlapping text nodes with "text-overlapping" class
336
+ * @param {string} id Axis id
337
+ * @param {ChartInternal} $$ ChartInternal context
338
+ * @param {string} selector Selector string
339
+ * @private
340
+ */
341
+ markOverlapped(id, $$, selector) {
342
+ const textNodes = $$.$el.arcs.selectAll(selector);
343
+ const filteredTextNodes = textNodes.filter((node) => node.data.id !== id);
344
+ const textNode = textNodes.filter((node) => node.data.id === id);
345
+ const translate = getTranslation(textNode.node());
346
+ const calcHypo = (x, y) => Math.sqrt(x * x + y * y);
347
+ if (!textNode.node()) return;
348
+ const fontSize = parseInt(textNode.style("font-size"), 10);
349
+ const overlapStates = [];
350
+ filteredTextNodes.each(function() {
351
+ const coordinate = getTranslation(this);
352
+ const nodeForWidth = calcHypo(translate.e, translate.f) > calcHypo(coordinate.e, coordinate.f) ? textNode : select(this);
353
+ const overlapsX = Math.ceil(Math.abs(translate.e - coordinate.e)) < Math.ceil(nodeForWidth.node().getComputedTextLength());
354
+ const overlapsY = Math.ceil(Math.abs(translate.f - coordinate.f)) < fontSize;
355
+ overlapStates.push({
356
+ node: this,
357
+ overlaps: overlapsX && overlapsY
358
+ });
359
+ });
360
+ overlapStates.forEach(({ node, overlaps }) => {
361
+ select(node).classed($TEXT.TextOverlapping, overlaps);
362
+ });
363
+ },
364
+ /**
365
+ * Calculate if two or more text nodes are overlapping
366
+ * Remove "text-overlapping" class on selected text nodes
367
+ * @param {ChartInternal} $$ ChartInternal context
368
+ * @param {string} selector Selector string
369
+ * @private
370
+ */
371
+ undoMarkOverlapped($$, selector) {
372
+ $$.$el.arcs.selectAll(selector).each(function() {
373
+ selectAll([this, this.previousSibling]).classed($TEXT.TextOverlapping, false);
374
+ });
375
+ }
536
376
  };
537
-
538
- export { text as default };
377
+ //#endregion
378
+ export { text_default as default };