billboard.js 4.0.2 → 4.1.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (272) hide show
  1. package/README.md +82 -7
  2. package/dist/billboard.css +1 -1
  3. package/dist/billboard.js +1938 -557
  4. package/dist/billboard.min.css +1 -1
  5. package/dist/billboard.min.js +19 -25
  6. package/dist/billboard.pkgd.js +1934 -742
  7. package/dist/billboard.pkgd.min.js +24 -30
  8. package/dist/billboard.react.js +205 -0
  9. package/dist/billboard.react.min.js +9 -0
  10. package/dist/billboard.worker.js +10 -0
  11. package/dist/plugin/billboardjs-plugin-bubblecompare.js +2 -2
  12. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  13. package/dist/plugin/billboardjs-plugin-sparkline.js +3 -2
  14. package/dist/plugin/billboardjs-plugin-sparkline.min.js +3 -3
  15. package/dist/plugin/billboardjs-plugin-stanford.js +3 -2
  16. package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
  17. package/dist/plugin/billboardjs-plugin-tableview.js +57 -27
  18. package/dist/plugin/billboardjs-plugin-tableview.min.js +5 -5
  19. package/dist/plugin/billboardjs-plugin-textoverlap.js +72 -54
  20. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  21. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +2 -2
  22. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +2 -2
  23. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +3 -2
  24. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +3 -3
  25. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +3 -2
  26. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +2 -2
  27. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +57 -27
  28. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +11 -11
  29. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +65 -3556
  30. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +8 -8
  31. package/dist/theme/dark.css +1 -1
  32. package/dist/theme/dark.min.css +1 -1
  33. package/dist/theme/datalab.css +1 -1
  34. package/dist/theme/datalab.min.css +1 -1
  35. package/dist/theme/graph.css +1 -1
  36. package/dist/theme/graph.min.css +1 -1
  37. package/dist/theme/insight.css +1 -1
  38. package/dist/theme/insight.min.css +1 -1
  39. package/dist/theme/modern.css +1 -1
  40. package/dist/theme/modern.min.css +1 -1
  41. package/dist-esm/Chart/Chart.js +134 -152
  42. package/dist-esm/Chart/api/axis.js +217 -237
  43. package/dist-esm/Chart/api/category.js +54 -54
  44. package/dist-esm/Chart/api/chart.js +172 -215
  45. package/dist-esm/Chart/api/color.js +21 -21
  46. package/dist-esm/Chart/api/data.js +172 -173
  47. package/dist-esm/Chart/api/export.js +242 -262
  48. package/dist-esm/Chart/api/flow.js +198 -254
  49. package/dist-esm/Chart/api/focus.js +136 -147
  50. package/dist-esm/Chart/api/grid.js +191 -190
  51. package/dist-esm/Chart/api/group.js +31 -34
  52. package/dist-esm/Chart/api/legend.js +54 -63
  53. package/dist-esm/Chart/api/load.js +237 -257
  54. package/dist-esm/Chart/api/regions.js +148 -168
  55. package/dist-esm/Chart/api/selection.js +181 -139
  56. package/dist-esm/Chart/api/show.js +133 -147
  57. package/dist-esm/Chart/api/stubs.js +43 -42
  58. package/dist-esm/Chart/api/subchart.js +155 -172
  59. package/dist-esm/Chart/api/tooltip.js +132 -177
  60. package/dist-esm/Chart/api/x.js +67 -71
  61. package/dist-esm/Chart/api/zoom.js +183 -220
  62. package/dist-esm/ChartInternal/Axis/Axis.js +1059 -1266
  63. package/dist-esm/ChartInternal/Axis/AxisRenderer.js +408 -540
  64. package/dist-esm/ChartInternal/Axis/AxisRendererHelper.js +113 -149
  65. package/dist-esm/ChartInternal/ChartInternal.js +573 -749
  66. package/dist-esm/ChartInternal/data/convert.helper.js +133 -159
  67. package/dist-esm/ChartInternal/data/convert.js +200 -229
  68. package/dist-esm/ChartInternal/data/data.js +970 -1147
  69. package/dist-esm/ChartInternal/data/load.js +145 -197
  70. package/dist-esm/ChartInternal/interactions/drag.js +86 -122
  71. package/dist-esm/ChartInternal/interactions/eventrect.js +455 -621
  72. package/dist-esm/ChartInternal/interactions/flow.js +151 -215
  73. package/dist-esm/ChartInternal/interactions/interaction.js +214 -252
  74. package/dist-esm/ChartInternal/interactions/subchart.js +425 -300
  75. package/dist-esm/ChartInternal/interactions/zoom.js +321 -440
  76. package/dist-esm/ChartInternal/internals/category.js +18 -18
  77. package/dist-esm/ChartInternal/internals/class.js +89 -99
  78. package/dist-esm/ChartInternal/internals/clip.js +88 -119
  79. package/dist-esm/ChartInternal/internals/color.js +233 -288
  80. package/dist-esm/ChartInternal/internals/domain.js +452 -588
  81. package/dist-esm/ChartInternal/internals/format.js +64 -77
  82. package/dist-esm/ChartInternal/internals/grid.js +333 -457
  83. package/dist-esm/ChartInternal/internals/legend.js +675 -927
  84. package/dist-esm/ChartInternal/internals/redraw.js +200 -289
  85. package/dist-esm/ChartInternal/internals/region.js +106 -159
  86. package/dist-esm/ChartInternal/internals/scale.js +186 -215
  87. package/dist-esm/ChartInternal/internals/selection.js +132 -159
  88. package/dist-esm/ChartInternal/internals/size.axis.js +92 -139
  89. package/dist-esm/ChartInternal/internals/size.js +286 -394
  90. package/dist-esm/ChartInternal/internals/style.js +39 -41
  91. package/dist-esm/ChartInternal/internals/subchart.util.js +49 -0
  92. package/dist-esm/ChartInternal/internals/text.arc.js +155 -219
  93. package/dist-esm/ChartInternal/internals/text.js +368 -528
  94. package/dist-esm/ChartInternal/internals/text.util.js +179 -239
  95. package/dist-esm/ChartInternal/internals/title.js +96 -121
  96. package/dist-esm/ChartInternal/internals/tooltip.js +450 -586
  97. package/dist-esm/ChartInternal/internals/transform.js +79 -97
  98. package/dist-esm/ChartInternal/internals/type.js +286 -245
  99. package/dist-esm/ChartInternal/shape/arc.js +825 -1112
  100. package/dist-esm/ChartInternal/shape/area.js +73 -94
  101. package/dist-esm/ChartInternal/shape/bar.js +227 -272
  102. package/dist-esm/ChartInternal/shape/bubble.js +9 -8
  103. package/dist-esm/ChartInternal/shape/candlestick.js +110 -138
  104. package/dist-esm/ChartInternal/shape/core/barRadius.js +197 -133
  105. package/dist-esm/ChartInternal/shape/core/bubble.js +64 -73
  106. package/dist-esm/ChartInternal/shape/core/candlestick.js +93 -86
  107. package/dist-esm/ChartInternal/shape/core/dataRegion.js +68 -75
  108. package/dist-esm/ChartInternal/shape/core/geometry.js +112 -112
  109. package/dist-esm/ChartInternal/shape/core/path.js +142 -115
  110. package/dist-esm/ChartInternal/shape/core/point.js +105 -125
  111. package/dist-esm/ChartInternal/shape/core/treemap.js +83 -88
  112. package/dist-esm/ChartInternal/shape/funnel.js +310 -338
  113. package/dist-esm/ChartInternal/shape/gauge.js +71 -103
  114. package/dist-esm/ChartInternal/shape/line.js +208 -278
  115. package/dist-esm/ChartInternal/shape/point.js +310 -413
  116. package/dist-esm/ChartInternal/shape/polar.js +84 -109
  117. package/dist-esm/ChartInternal/shape/radar.js +228 -318
  118. package/dist-esm/ChartInternal/shape/shape.js +782 -828
  119. package/dist-esm/ChartInternal/shape/treemap.js +152 -190
  120. package/dist-esm/canvas/CanvasAxisRenderer.js +1180 -1328
  121. package/dist-esm/canvas/CanvasEngine.js +148 -166
  122. package/dist-esm/canvas/CanvasPainter.js +395 -411
  123. package/dist-esm/canvas/CanvasRenderer.js +1584 -1834
  124. package/dist-esm/canvas/CanvasTheme.js +899 -802
  125. package/dist-esm/canvas/HitDetector.js +394 -463
  126. package/dist-esm/canvas/axisTicks.js +672 -786
  127. package/dist-esm/canvas/classes.js +19 -17
  128. package/dist-esm/canvas/color.js +40 -59
  129. package/dist-esm/canvas/geometry.js +38 -38
  130. package/dist-esm/canvas/labels.js +318 -371
  131. package/dist-esm/canvas/pointPattern.js +578 -580
  132. package/dist-esm/canvas/util.js +242 -262
  133. package/dist-esm/config/Options/Options.js +29 -32
  134. package/dist-esm/config/Options/axis/axis.js +101 -101
  135. package/dist-esm/config/Options/axis/x.js +759 -755
  136. package/dist-esm/config/Options/axis/y.js +525 -522
  137. package/dist-esm/config/Options/axis/y2.js +501 -485
  138. package/dist-esm/config/Options/common/boost.js +93 -32
  139. package/dist-esm/config/Options/common/color.js +88 -87
  140. package/dist-esm/config/Options/common/grid.js +74 -73
  141. package/dist-esm/config/Options/common/legend.js +180 -179
  142. package/dist-esm/config/Options/common/main.js +474 -473
  143. package/dist-esm/config/Options/common/point.js +160 -159
  144. package/dist-esm/config/Options/common/title.js +47 -46
  145. package/dist-esm/config/Options/common/tooltip.js +253 -252
  146. package/dist-esm/config/Options/data/axis.js +173 -172
  147. package/dist-esm/config/Options/data/data.js +958 -957
  148. package/dist-esm/config/Options/data/selection.js +131 -130
  149. package/dist-esm/config/Options/interaction/interaction.js +53 -52
  150. package/dist-esm/config/Options/interaction/subchart.js +164 -73
  151. package/dist-esm/config/Options/interaction/zoom.js +86 -85
  152. package/dist-esm/config/Options/shape/arc.js +150 -149
  153. package/dist-esm/config/Options/shape/area.js +69 -68
  154. package/dist-esm/config/Options/shape/bar.js +147 -146
  155. package/dist-esm/config/Options/shape/bubble.js +35 -34
  156. package/dist-esm/config/Options/shape/candlestick.js +61 -60
  157. package/dist-esm/config/Options/shape/donut.js +181 -180
  158. package/dist-esm/config/Options/shape/funnel.js +49 -48
  159. package/dist-esm/config/Options/shape/gauge.js +237 -236
  160. package/dist-esm/config/Options/shape/line.js +58 -57
  161. package/dist-esm/config/Options/shape/pie.js +185 -184
  162. package/dist-esm/config/Options/shape/polar.js +167 -166
  163. package/dist-esm/config/Options/shape/radar.js +76 -75
  164. package/dist-esm/config/Options/shape/scatter.js +36 -36
  165. package/dist-esm/config/Options/shape/spline.js +46 -46
  166. package/dist-esm/config/Options/shape/treemap.js +80 -79
  167. package/dist-esm/config/Store/Element.js +64 -62
  168. package/dist-esm/config/Store/State.js +189 -200
  169. package/dist-esm/config/Store/Store.js +25 -26
  170. package/dist-esm/config/classes.js +157 -155
  171. package/dist-esm/config/config.js +26 -35
  172. package/dist-esm/config/const.js +120 -128
  173. package/dist-esm/config/resolver/axis.core.js +25 -25
  174. package/dist-esm/config/resolver/axis.js +26 -27
  175. package/dist-esm/config/resolver/canvas.js +2071 -2472
  176. package/dist-esm/config/resolver/canvasShape.js +201 -177
  177. package/dist-esm/config/resolver/category.js +26 -27
  178. package/dist-esm/config/resolver/export.js +24 -26
  179. package/dist-esm/config/resolver/flow.js +29 -31
  180. package/dist-esm/config/resolver/grid.js +34 -35
  181. package/dist-esm/config/resolver/interaction/selection.js +17 -17
  182. package/dist-esm/config/resolver/interaction/subchart.js +17 -17
  183. package/dist-esm/config/resolver/interaction/zoom.js +17 -17
  184. package/dist-esm/config/resolver/regions.js +30 -31
  185. package/dist-esm/config/resolver/shape/arc.helpers.js +19 -19
  186. package/dist-esm/config/resolver/shape/area.js +17 -17
  187. package/dist-esm/config/resolver/shape/axis.helpers.js +28 -25
  188. package/dist-esm/config/resolver/shape/bar.js +13 -13
  189. package/dist-esm/config/resolver/shape/bubble.js +18 -14
  190. package/dist-esm/config/resolver/shape/candlestick.js +13 -13
  191. package/dist-esm/config/resolver/shape/donut.js +11 -11
  192. package/dist-esm/config/resolver/shape/funnel.js +11 -11
  193. package/dist-esm/config/resolver/shape/gauge.js +12 -12
  194. package/dist-esm/config/resolver/shape/line.js +10 -10
  195. package/dist-esm/config/resolver/shape/pie.js +11 -11
  196. package/dist-esm/config/resolver/shape/polar.js +12 -12
  197. package/dist-esm/config/resolver/shape/radar.js +22 -14
  198. package/dist-esm/config/resolver/shape/scatter.js +13 -13
  199. package/dist-esm/config/resolver/shape/treemap.js +11 -11
  200. package/dist-esm/core.js +208 -211
  201. package/dist-esm/index.canvas.js +14 -13
  202. package/dist-esm/index.esm.js +25 -24
  203. package/dist-esm/module/Cache.js +117 -129
  204. package/dist-esm/module/browser.js +30 -35
  205. package/dist-esm/module/dsv.js +107 -127
  206. package/dist-esm/module/error.js +45 -52
  207. package/dist-esm/module/generator.js +75 -83
  208. package/dist-esm/module/sanitize.js +302 -399
  209. package/dist-esm/module/util/brush.js +27 -38
  210. package/dist-esm/module/util/dom.js +288 -348
  211. package/dist-esm/module/util/object.js +277 -341
  212. package/dist-esm/module/util/type-checks.js +21 -25
  213. package/dist-esm/module/worker.js +312 -130
  214. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +185 -198
  215. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +442 -450
  216. package/dist-esm/plugin/billboardjs-plugin-stanford.js +813 -950
  217. package/dist-esm/plugin/billboardjs-plugin-tableview.js +708 -788
  218. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +344 -301
  219. package/dist-esm/react/index.js +157 -0
  220. package/package.json +28 -8
  221. package/src/Chart/api/focus.ts +8 -12
  222. package/src/Chart/api/selection.ts +130 -5
  223. package/src/ChartInternal/Axis/Axis.ts +164 -65
  224. package/src/ChartInternal/Axis/AxisRenderer.ts +41 -8
  225. package/src/ChartInternal/Axis/AxisRendererHelper.ts +1 -1
  226. package/src/ChartInternal/ChartInternal.ts +1 -1
  227. package/src/ChartInternal/data/convert.ts +54 -4
  228. package/src/ChartInternal/data/data.ts +19 -6
  229. package/src/ChartInternal/interactions/eventrect.ts +6 -0
  230. package/src/ChartInternal/interactions/subchart.ts +437 -66
  231. package/src/ChartInternal/internals/color.ts +7 -6
  232. package/src/ChartInternal/internals/domain.ts +15 -3
  233. package/src/ChartInternal/internals/grid.ts +21 -1
  234. package/src/ChartInternal/internals/scale.ts +9 -2
  235. package/src/ChartInternal/internals/selection.ts +1 -1
  236. package/src/ChartInternal/internals/subchart.util.ts +55 -0
  237. package/src/ChartInternal/internals/text.arc.ts +3 -1
  238. package/src/ChartInternal/internals/text.ts +19 -6
  239. package/src/ChartInternal/internals/transform.ts +8 -2
  240. package/src/ChartInternal/internals/type.ts +131 -33
  241. package/src/ChartInternal/shape/IShape.ts +6 -3
  242. package/src/ChartInternal/shape/bar.ts +87 -37
  243. package/src/ChartInternal/shape/core/barRadius.ts +129 -0
  244. package/src/ChartInternal/shape/core/candlestick.ts +1 -1
  245. package/src/ChartInternal/shape/core/path.ts +76 -9
  246. package/src/ChartInternal/shape/funnel.ts +2 -3
  247. package/src/ChartInternal/shape/line.ts +1 -1
  248. package/src/ChartInternal/shape/point.ts +27 -13
  249. package/src/ChartInternal/shape/shape.ts +172 -18
  250. package/src/Plugin/stanford/index.ts +0 -4
  251. package/src/Plugin/tableview/index.ts +85 -3
  252. package/src/Plugin/textoverlap/index.ts +9 -15
  253. package/src/canvas/CanvasAxisRenderer.ts +184 -36
  254. package/src/canvas/CanvasRenderer.ts +247 -160
  255. package/src/canvas/CanvasTheme.ts +212 -0
  256. package/src/canvas/axisTicks.ts +122 -40
  257. package/src/config/Options/axis/y2.ts +13 -0
  258. package/src/config/Options/common/boost.ts +64 -4
  259. package/src/config/Options/common/color.ts +2 -2
  260. package/src/config/Options/interaction/subchart.ts +98 -1
  261. package/src/config/Options/shape/gauge.ts +1 -1
  262. package/src/config/Options/shape/treemap.ts +2 -2
  263. package/src/config/Store/Element.ts +3 -1
  264. package/src/config/Store/State.ts +1 -0
  265. package/src/config/classes.ts +1 -0
  266. package/src/config/resolver/canvas.ts +92 -10
  267. package/src/module/voronoi.ts +119 -0
  268. package/src/module/worker.entry.ts +61 -0
  269. package/src/module/worker.ts +346 -63
  270. package/src/react/index.ts +193 -0
  271. package/types/options.d.ts +206 -3
  272. package/types/react/index.d.ts +27 -0
@@ -5,1136 +5,849 @@
5
5
  * billboard.js, JavaScript chart library
6
6
  * https://naver.github.io/billboard.js/
7
7
  *
8
- * @version 4.0.2
8
+ * @version 4.1.0-next.1
9
9
  */
10
- import { interpolate } from 'd3-interpolate';
11
- import { select } from 'd3-selection';
12
- import { arc, pie } from 'd3-shape';
13
- import { $COMMON, $ARC, $GAUGE, $FOCUS } from '../../config/classes.js';
14
- import { document as doc } from '../../module/browser.js';
15
- import { isLabelWithLine, redrawArcLabelLines } from '../internals/text.arc.js';
16
- import { updateTextImage, meetsLabelThreshold, updateTextImagePos } from '../internals/text.util.js';
17
- import { isUndefined, isFunction, isNumber, isDefined, isObject } from '../../module/util/type-checks.js';
18
- import { endall, callFn, tplProcess } from '../../module/util/object.js';
19
- import { setTextValue } from '../../module/util/dom.js';
20
-
10
+ import { document as doc } from "../../module/browser.js";
11
+ import { isDefined, isFunction, isNumber, isObject, isUndefined } from "../../module/util/type-checks.js";
12
+ import { callFn, endall, tplProcess } from "../../module/util/object.js";
13
+ import { setTextValue } from "../../module/util/dom.js";
14
+ import { $ARC, $COMMON, $FOCUS, $GAUGE } from "../../config/classes.js";
15
+ import { meetsLabelThreshold, updateTextImage, updateTextImagePos } from "../internals/text.util.js";
16
+ import { isLabelWithLine, redrawArcLabelLines } from "../internals/text.arc.js";
17
+ import { select } from "d3-selection";
18
+ import { arc, pie } from "d3-shape";
19
+ import { interpolate } from "d3-interpolate";
20
+ //#region src/ChartInternal/shape/arc.ts
21
21
  /**
22
- * Copyright (c) 2017 ~ present NAVER Corp.
23
- * billboard.js project is licensed under the MIT license
24
- */
25
- const ARC_TYPES = ["donut", "gauge", "pie", "polar"];
22
+ * Copyright (c) 2017 ~ present NAVER Corp.
23
+ * billboard.js project is licensed under the MIT license
24
+ */
25
+ const ARC_TYPES = [
26
+ "donut",
27
+ "gauge",
28
+ "pie",
29
+ "polar"
30
+ ];
26
31
  /**
27
- * Get the first matching arc chart type
28
- * @param {ChartInternalThis} $$ ChartInternal context
29
- * @returns {string|undefined} Chart type or undefined
30
- * @private
31
- */
32
+ * Get the first matching arc chart type
33
+ * @param {ChartInternalThis} $$ ChartInternal context
34
+ * @returns {string|undefined} Chart type or undefined
35
+ * @private
36
+ */
32
37
  function _getArcType($$) {
33
- return ["donut", "pie", "polar", "gauge"].find(type => $$.hasType(type));
38
+ return [
39
+ "donut",
40
+ "pie",
41
+ "polar",
42
+ "gauge"
43
+ ].find((type) => $$.hasType(type));
34
44
  }
35
45
  /**
36
- * Calculate position for range text or multi-arc gauge labels
37
- * @param {ChartInternalThis} $$ ChartInternal context
38
- * @param {IArcData} d Data object
39
- * @param {IArcData} updated Updated angle data
40
- * @param {boolean} forRange Whether is for ranged text option
41
- * @returns {object} Position object {x, y}
42
- * @private
43
- */
46
+ * Calculate position for range text or multi-arc gauge labels
47
+ * @param {ChartInternalThis} $$ ChartInternal context
48
+ * @param {IArcData} d Data object
49
+ * @param {IArcData} updated Updated angle data
50
+ * @param {boolean} forRange Whether is for ranged text option
51
+ * @returns {object} Position object {x, y}
52
+ * @private
53
+ */
44
54
  function _calculateRangeOrGaugePosition($$, d, updated, forRange) {
45
- const { config, state: { radiusExpanded } } = $$;
46
- const angle = updated.endAngle - Math.PI / 2;
47
- const sinAngle = Math.sin(angle);
48
- const pos = {
49
- x: Math.cos(angle) * (radiusExpanded + (forRange ? 5 : 25)), // 5: range offset, 25: gauge offset
50
- y: sinAngle * (radiusExpanded + 15 - Math.abs(sinAngle * 10)) + 3 // 10: y factor, 3: y offset
51
- };
52
- if (forRange) {
53
- const rangeTextPosition = config.arc_rangeText_position;
54
- if (rangeTextPosition) {
55
- const rangeValues = config.arc_rangeText_values;
56
- const position = isFunction(rangeTextPosition) ?
57
- rangeTextPosition(rangeValues[d.index]) :
58
- rangeTextPosition;
59
- pos.x += position?.x ?? 0;
60
- pos.y += position?.y ?? 0;
61
- }
62
- }
63
- return pos;
55
+ const { config, state: { radiusExpanded } } = $$;
56
+ const angle = updated.endAngle - Math.PI / 2;
57
+ const sinAngle = Math.sin(angle);
58
+ const pos = {
59
+ x: Math.cos(angle) * (radiusExpanded + (forRange ? 5 : 25)),
60
+ y: sinAngle * (radiusExpanded + 15 - Math.abs(sinAngle * 10)) + 3
61
+ };
62
+ if (forRange) {
63
+ const rangeTextPosition = config.arc_rangeText_position;
64
+ if (rangeTextPosition) {
65
+ const rangeValues = config.arc_rangeText_values;
66
+ const position = isFunction(rangeTextPosition) ? rangeTextPosition(rangeValues[d.index]) : rangeTextPosition;
67
+ pos.x += position?.x ?? 0;
68
+ pos.y += position?.y ?? 0;
69
+ }
70
+ }
71
+ return pos;
64
72
  }
65
73
  /**
66
- * Calculate label ratio for standard arc types
67
- * @param {ChartInternalThis} $$ ChartInternal context
68
- * @param {IArcData} d Data object
69
- * @param {number} outerRadius Outer radius value
70
- * @param {number} distance Distance from center
71
- * @returns {number} Calculated ratio
72
- * @private
73
- */
74
+ * Calculate label ratio for standard arc types
75
+ * @param {ChartInternalThis} $$ ChartInternal context
76
+ * @param {IArcData} d Data object
77
+ * @param {number} outerRadius Outer radius value
78
+ * @param {number} distance Distance from center
79
+ * @returns {number} Calculated ratio
80
+ * @private
81
+ */
74
82
  function _calculateLabelRatio($$, d, outerRadius, distance) {
75
- const { config } = $$;
76
- const chartType = _getArcType($$);
77
- let ratio = chartType ? config[`${chartType}_label_ratio`] : undefined;
78
- if (ratio) {
79
- ratio = isFunction(ratio) ? ratio.bind($$.api)(d, outerRadius, distance) : ratio;
80
- }
81
- else {
82
- // Label positioning constants
83
- const LABEL_MIN_SIZE = 36; // Minimum space needed for label text (pixels)
84
- const LABEL_RATIO_THRESHOLD = 0.375; // Threshold ratio (3/8) to determine "small chart"
85
- const LABEL_RATIO_BASE = 1.175; // Base ratio for dynamic positioning on small charts
86
- const LABEL_RATIO_LARGE = 0.8; // Fixed ratio for large charts (80% position)
87
- // Calculate ratio based on chart size
88
- // For small charts (label space > 37.5% of radius), position labels closer to center
89
- // For large charts, use fixed 80% position
90
- const labelSpaceRatio = LABEL_MIN_SIZE / outerRadius;
91
- const isSmallChart = labelSpaceRatio > LABEL_RATIO_THRESHOLD;
92
- ratio = outerRadius && distance ?
93
- (isSmallChart ? LABEL_RATIO_BASE - labelSpaceRatio : LABEL_RATIO_LARGE) * outerRadius /
94
- distance :
95
- 0;
96
- }
97
- return ratio;
83
+ const { config } = $$;
84
+ const chartType = _getArcType($$);
85
+ let ratio = chartType ? config[`${chartType}_label_ratio`] : void 0;
86
+ if (ratio) ratio = isFunction(ratio) ? ratio.bind($$.api)(d, outerRadius, distance) : ratio;
87
+ else {
88
+ const LABEL_MIN_SIZE = 36;
89
+ const LABEL_RATIO_THRESHOLD = .375;
90
+ const LABEL_RATIO_BASE = 1.175;
91
+ const LABEL_RATIO_LARGE = .8;
92
+ const labelSpaceRatio = LABEL_MIN_SIZE / outerRadius;
93
+ ratio = outerRadius && distance ? (labelSpaceRatio > LABEL_RATIO_THRESHOLD ? LABEL_RATIO_BASE - labelSpaceRatio : LABEL_RATIO_LARGE) * outerRadius / distance : 0;
94
+ }
95
+ return ratio;
98
96
  }
99
97
  /**
100
- * Calculate position for standard arc label (donut, pie, polar)
101
- * @param {ChartInternalThis} $$ ChartInternal context
102
- * @param {IArcData} d Data object
103
- * @param {IArcData} updated Updated angle data
104
- * @returns {object} Object with pos {x, y} and ratio
105
- * @private
106
- */
98
+ * Calculate position for standard arc label (donut, pie, polar)
99
+ * @param {ChartInternalThis} $$ ChartInternal context
100
+ * @param {IArcData} d Data object
101
+ * @param {IArcData} updated Updated angle data
102
+ * @returns {object} Object with pos {x, y} and ratio
103
+ * @private
104
+ */
107
105
  function _calculateStandardArcPosition($$, d, updated) {
108
- let { outerRadius } = $$.getRadius(d);
109
- if ($$.hasType("polar")) {
110
- outerRadius = $$.getPolarOuterRadius(d, outerRadius);
111
- }
112
- const [x, y] = $$.svgArc.centroid(updated).map((v) => (isNaN(v) ? 0 : v));
113
- const distance = Math.sqrt(x * x + y * y);
114
- const ratio = _calculateLabelRatio($$, d, outerRadius, distance);
115
- return {
116
- pos: { x, y },
117
- ratio
118
- };
106
+ let { outerRadius } = $$.getRadius(d);
107
+ if ($$.hasType("polar")) outerRadius = $$.getPolarOuterRadius(d, outerRadius);
108
+ const [x, y] = $$.svgArc.centroid(updated).map((v) => isNaN(v) ? 0 : v);
109
+ const distance = Math.sqrt(x * x + y * y);
110
+ const ratio = _calculateLabelRatio($$, d, outerRadius, distance);
111
+ return {
112
+ pos: {
113
+ x,
114
+ y
115
+ },
116
+ ratio
117
+ };
119
118
  }
120
119
  /**
121
- * Get radius functions
122
- * @param {number} expandRate Expand rate number.
123
- * - If 0, means for "normal" radius.
124
- * - If > 0, means for "expanded" radius.
125
- * @returns {object} radius functions
126
- * @private
127
- */
120
+ * Get radius functions
121
+ * @param {number} expandRate Expand rate number.
122
+ * - If 0, means for "normal" radius.
123
+ * - If > 0, means for "expanded" radius.
124
+ * @returns {object} radius functions
125
+ * @private
126
+ */
128
127
  function _getRadiusFn(expandRate = 0) {
129
- const $$ = this;
130
- const { config, state } = $$;
131
- const hasMultiArcGauge = $$.hasMultiArcGauge();
132
- const singleArcWidth = state.gaugeArcWidth / $$.getTargetsToShow().length;
133
- const expandWidth = expandRate ?
134
- (Math.min(state.radiusExpanded * expandRate - state.radius, singleArcWidth * 0.8 - (1 - expandRate) * 100)) :
135
- 0;
136
- return {
137
- /**
138
- * Getter of arc innerRadius value
139
- * @param {IArcData} d Data object
140
- * @returns {number} innerRadius value
141
- * @private
142
- */
143
- inner(d) {
144
- const { innerRadius } = $$.getRadius(d);
145
- return hasMultiArcGauge ?
146
- state.radius - singleArcWidth * (d.index + 1) :
147
- (isNumber(innerRadius) ? innerRadius : 0);
148
- },
149
- /**
150
- * Getter of arc outerRadius value
151
- * @param {IArcData} d Data object
152
- * @returns {number} outerRadius value
153
- * @private
154
- */
155
- outer(d) {
156
- const { outerRadius } = $$.getRadius(d);
157
- let radius;
158
- if (hasMultiArcGauge) {
159
- radius = state.radius - singleArcWidth * d.index + expandWidth;
160
- }
161
- else if ($$.hasType("polar") && !expandRate) {
162
- radius = $$.getPolarOuterRadius(d, outerRadius);
163
- }
164
- else {
165
- radius = outerRadius;
166
- if (expandRate) {
167
- let { radiusExpanded } = state;
168
- if (state.radius !== outerRadius) {
169
- radiusExpanded -= Math.abs(state.radius - outerRadius);
170
- }
171
- radius = radiusExpanded * expandRate;
172
- }
173
- }
174
- return radius;
175
- },
176
- /**
177
- * Getter of arc cornerRadius value
178
- * @param {IArcData} d Data object
179
- * @param {number} outerRadius outer radius value
180
- * @returns {number} cornerRadius value
181
- * @private
182
- */
183
- corner(d, outerRadius) {
184
- const { arc_cornerRadius_ratio: ratio = 0, arc_cornerRadius: cornerRadius = 0 } = config;
185
- const { data: { id }, value } = d;
186
- let corner;
187
- if (ratio) {
188
- corner = ratio * outerRadius;
189
- }
190
- else {
191
- corner = isNumber(cornerRadius) ?
192
- cornerRadius :
193
- cornerRadius.call($$.api, id, value, outerRadius);
194
- }
195
- return corner;
196
- }
197
- };
128
+ const $$ = this;
129
+ const { config, state } = $$;
130
+ const hasMultiArcGauge = $$.hasMultiArcGauge();
131
+ const singleArcWidth = state.gaugeArcWidth / $$.getTargetsToShow().length;
132
+ const expandWidth = expandRate ? Math.min(state.radiusExpanded * expandRate - state.radius, singleArcWidth * .8 - (1 - expandRate) * 100) : 0;
133
+ return {
134
+ /**
135
+ * Getter of arc innerRadius value
136
+ * @param {IArcData} d Data object
137
+ * @returns {number} innerRadius value
138
+ * @private
139
+ */
140
+ inner(d) {
141
+ const { innerRadius } = $$.getRadius(d);
142
+ return hasMultiArcGauge ? state.radius - singleArcWidth * (d.index + 1) : isNumber(innerRadius) ? innerRadius : 0;
143
+ },
144
+ /**
145
+ * Getter of arc outerRadius value
146
+ * @param {IArcData} d Data object
147
+ * @returns {number} outerRadius value
148
+ * @private
149
+ */
150
+ outer(d) {
151
+ const { outerRadius } = $$.getRadius(d);
152
+ let radius;
153
+ if (hasMultiArcGauge) radius = state.radius - singleArcWidth * d.index + expandWidth;
154
+ else if ($$.hasType("polar") && !expandRate) radius = $$.getPolarOuterRadius(d, outerRadius);
155
+ else {
156
+ radius = outerRadius;
157
+ if (expandRate) {
158
+ let { radiusExpanded } = state;
159
+ if (state.radius !== outerRadius) radiusExpanded -= Math.abs(state.radius - outerRadius);
160
+ radius = radiusExpanded * expandRate;
161
+ }
162
+ }
163
+ return radius;
164
+ },
165
+ /**
166
+ * Getter of arc cornerRadius value
167
+ * @param {IArcData} d Data object
168
+ * @param {number} outerRadius outer radius value
169
+ * @returns {number} cornerRadius value
170
+ * @private
171
+ */
172
+ corner(d, outerRadius) {
173
+ const { arc_cornerRadius_ratio: ratio = 0, arc_cornerRadius: cornerRadius = 0 } = config;
174
+ const { data: { id }, value } = d;
175
+ let corner;
176
+ if (ratio) corner = ratio * outerRadius;
177
+ else corner = isNumber(cornerRadius) ? cornerRadius : cornerRadius.call($$.api, id, value, outerRadius);
178
+ return corner;
179
+ }
180
+ };
198
181
  }
199
182
  /**
200
- * Get attrTween function to get interpolated value on transition
201
- * @param {function} fn Arc function to execute
202
- * @returns {function} attrTween function
203
- * @private
204
- */
183
+ * Get attrTween function to get interpolated value on transition
184
+ * @param {function} fn Arc function to execute
185
+ * @returns {function} attrTween function
186
+ * @private
187
+ */
205
188
  function _getAttrTweenFn(fn) {
206
- return function (d) {
207
- const getAngleKeyValue = ({ startAngle = 0, endAngle = 0, padAngle = 0 }) => ({
208
- startAngle,
209
- endAngle,
210
- padAngle
211
- });
212
- // d3.interpolate interpolates id value, if id is given as color string(ex. gold, silver, etc)
213
- // to avoid unexpected behavior, interpolate only angle values
214
- // https://github.com/naver/billboard.js/issues/3321
215
- const interpolate$1 = interpolate(getAngleKeyValue(this._current), getAngleKeyValue(d));
216
- this._current = d;
217
- return function (t) {
218
- const interpolated = interpolate$1(t);
219
- const { data, index, value } = d;
220
- return fn({ ...interpolated, data, index, value });
221
- };
222
- };
189
+ return function(d) {
190
+ const getAngleKeyValue = ({ startAngle = 0, endAngle = 0, padAngle = 0 }) => ({
191
+ startAngle,
192
+ endAngle,
193
+ padAngle
194
+ });
195
+ const interpolate$1 = interpolate(getAngleKeyValue(this._current), getAngleKeyValue(d));
196
+ this._current = d;
197
+ return function(t) {
198
+ const interpolated = interpolate$1(t);
199
+ const { data, index, value } = d;
200
+ return fn({
201
+ ...interpolated,
202
+ data,
203
+ index,
204
+ value
205
+ });
206
+ };
207
+ };
223
208
  }
224
- var shapeArc = {
225
- initPie() {
226
- const $$ = this;
227
- const { config } = $$;
228
- const dataType = config.data_type;
229
- const padding = config[`${dataType}_padding`];
230
- const startingAngle = config[`${dataType}_startingAngle`] || 0;
231
- const padAngle = (padding ? padding * 0.01 : config[`${dataType}_padAngle`]) || 0;
232
- $$.pie = pie()
233
- .startAngle(startingAngle)
234
- .endAngle(startingAngle + (2 * Math.PI))
235
- .padAngle(padAngle)
236
- .value((d) => d.values?.reduce((a, b) => a + b.value, 0) ?? d)
237
- .sort($$.getSortCompareFn.bind($$)(true));
238
- },
239
- updateRadius() {
240
- const $$ = this;
241
- const { config, state } = $$;
242
- const dataType = config.data_type;
243
- const padding = config[`${dataType}_padding`];
244
- const w = config.gauge_width || config.donut_width;
245
- const gaugeArcWidth = $$.getTargetsToShow().length *
246
- config.gauge_arcs_minWidth;
247
- // Radius reduction ratio when labels are present
248
- const LABEL_RADIUS_RATIO = 0.85;
249
- // Reduce radius for label with lines to make room for external labels
250
- const labelWithLineRatio = isLabelWithLine.call($$) ? LABEL_RADIUS_RATIO : 1;
251
- // determine radius
252
- state.radiusExpanded = Math.min(state.arcWidth, state.arcHeight) / 2 * ($$.hasMultiArcGauge() && config.gauge_label_show ?
253
- LABEL_RADIUS_RATIO :
254
- labelWithLineRatio);
255
- state.radius = state.radiusExpanded * 0.95;
256
- state.innerRadiusRatio = w ? (state.radius - w) / state.radius : 0.6;
257
- state.gaugeArcWidth = w || (gaugeArcWidth <= state.radius - state.innerRadius ?
258
- state.radius - state.innerRadius :
259
- (gaugeArcWidth <= state.radius ? gaugeArcWidth : state.radius));
260
- const innerRadius = config.pie_innerRadius || (padding ? padding * (state.innerRadiusRatio + 0.1) : 0);
261
- // NOTE: inner/outerRadius can be an object by user setting, only for 'pie' type
262
- state.outerRadius = config.pie_outerRadius;
263
- state.innerRadius = $$.hasType("donut") || $$.hasType("gauge") ?
264
- state.radius * state.innerRadiusRatio :
265
- innerRadius;
266
- },
267
- /**
268
- * Get pie's inner & outer radius value
269
- * @param {object|undefined} d Data object
270
- * @returns {object}
271
- * @private
272
- */
273
- getRadius(d) {
274
- const $$ = this;
275
- const data = d?.data;
276
- let { innerRadius, outerRadius } = $$.state;
277
- if (!isNumber(innerRadius) && data) {
278
- innerRadius = innerRadius[data.id] || 0;
279
- }
280
- if (isObject(outerRadius) && data && data.id in outerRadius) {
281
- outerRadius = outerRadius[data.id];
282
- }
283
- else if (!isNumber(outerRadius)) {
284
- outerRadius = $$.state.radius;
285
- }
286
- return { innerRadius, outerRadius };
287
- },
288
- updateArc() {
289
- const $$ = this;
290
- $$.updateRadius();
291
- $$.svgArc = $$.getSvgArc();
292
- $$.svgArcExpanded = $$.getSvgArcExpanded();
293
- },
294
- getArcLength() {
295
- const $$ = this;
296
- const { config } = $$;
297
- const arcLengthInPercent = config.gauge_arcLength * 3.6;
298
- let len = 2 * (arcLengthInPercent / 360);
299
- if (arcLengthInPercent < -360) {
300
- len = -2;
301
- }
302
- else if (arcLengthInPercent > 360) {
303
- len = 2;
304
- }
305
- return len * Math.PI;
306
- },
307
- getStartingAngle() {
308
- const $$ = this;
309
- const { config } = $$;
310
- const dataType = config.data_type;
311
- const isFullCircle = $$.hasType("gauge") ? config.gauge_fullCircle : false;
312
- const defaultStartAngle = -1 * Math.PI / 2;
313
- const defaultEndAngle = Math.PI / 2;
314
- let startAngle = config[`${dataType}_startingAngle`] || 0;
315
- if (!isFullCircle && startAngle <= defaultStartAngle) {
316
- startAngle = defaultStartAngle;
317
- }
318
- else if (!isFullCircle && startAngle >= defaultEndAngle) {
319
- startAngle = defaultEndAngle;
320
- }
321
- else if (startAngle > Math.PI || startAngle < -1 * Math.PI) {
322
- startAngle = Math.PI;
323
- }
324
- return startAngle;
325
- },
326
- /**
327
- * Update angle data
328
- * @param {object} dValue Data object
329
- * @param {boolean} forRange Weather is for ranged text option(arc.rangeText.values)
330
- * @returns {object|null} Updated angle data
331
- * @private
332
- */
333
- updateAngle(dValue, forRange = false) {
334
- const $$ = this;
335
- const { config, state } = $$;
336
- const hasGauge = forRange && $$.hasType("gauge");
337
- // to prevent excluding total data sum during the init(when data.hide option is used), use $$.rendered state value
338
- // const totalSum = $$.getTotalDataSum(state.rendered);
339
- let { pie } = $$;
340
- let d = dValue;
341
- let found = false;
342
- if (!config) {
343
- return null;
344
- }
345
- const gStart = $$.getStartingAngle();
346
- const radius = config.gauge_fullCircle || (forRange && !hasGauge) ?
347
- $$.getArcLength() :
348
- gStart * -2;
349
- const isSingleArcGauge = d.data && $$.isGaugeType(d.data) && !$$.hasMultiArcGauge();
350
- if (isSingleArcGauge) {
351
- const { gauge_min: gMin, gauge_max: gMax } = config;
352
- // to prevent excluding total data sum during the init(when data.hide option is used), use $$.rendered state value
353
- const totalSum = $$.getTotalDataSum(state.rendered);
354
- // https://github.com/naver/billboard.js/issues/2123
355
- const gEnd = radius * ((totalSum - gMin) / (gMax - gMin));
356
- pie = pie
357
- .startAngle(gStart)
358
- .endAngle(gEnd + gStart);
359
- }
360
- if (forRange === false) {
361
- // cache the pie layout per redraw: updateAngle() is called per arc/label,
362
- // recomputing the full layout each time makes redraw O(n²) for many slices.
363
- // The single arc gauge layout isn't cacheable: its angles depend on
364
- // state.rendered, which can flip within the same redraw generation.
365
- let layout;
366
- if (isSingleArcGauge) {
367
- layout = pie($$.filterTargetsToShow());
368
- }
369
- else {
370
- const cacheKey = "$arcPieLayout";
371
- let cached = $$.cache.get(cacheKey);
372
- if (!cached || cached.generation !== state.redrawGeneration) {
373
- cached = {
374
- generation: state.redrawGeneration,
375
- layout: pie($$.filterTargetsToShow())
376
- };
377
- $$.cache.add(cacheKey, cached);
378
- }
379
- layout = cached.layout;
380
- }
381
- layout.forEach((t, i) => {
382
- if (!found && t.data.id === d.data?.id) {
383
- found = true;
384
- d = t;
385
- d.index = i;
386
- }
387
- });
388
- }
389
- if (isNaN(d.startAngle)) {
390
- d.startAngle = 0;
391
- }
392
- if (isNaN(d.endAngle)) {
393
- d.endAngle = d.startAngle;
394
- }
395
- if (forRange || (d.data && (config.gauge_enforceMinMax || $$.hasMultiArcGauge()))) {
396
- const { gauge_min: gMin, gauge_max: gMax } = config;
397
- const max = forRange && !hasGauge ? $$.getTotalDataSum(state.rendered) : gMax;
398
- const gTic = radius / (max - gMin);
399
- const value = d.value ?? 0;
400
- const gValue = value < gMin ? 0 : value < max ? value - gMin : (max - gMin);
401
- d.startAngle = gStart;
402
- d.endAngle = gStart + gTic * gValue;
403
- }
404
- return found || forRange ? d : null;
405
- },
406
- getSvgArc() {
407
- const $$ = this;
408
- const { inner, outer, corner } = _getRadiusFn.call($$);
409
- const arc$1 = arc()
410
- .innerRadius(inner)
411
- .outerRadius(outer);
412
- const newArc = function (d, withoutUpdate) {
413
- let path = "M 0 0";
414
- if (d.value || d.data) {
415
- const data = withoutUpdate ? d : $$.updateAngle(d) ?? null;
416
- if (data) {
417
- path = arc$1.cornerRadius(corner(data, outer(data)))(data);
418
- }
419
- }
420
- return path;
421
- };
422
- // TODO: extends all function
423
- newArc.centroid = arc$1.centroid;
424
- return newArc;
425
- },
426
- /**
427
- * Get expanded arc path function
428
- * @param {number} rate Expand rate
429
- * @returns {function} Expanded arc path getter function
430
- * @private
431
- */
432
- getSvgArcExpanded(rate = 1) {
433
- const $$ = this;
434
- const { inner, outer, corner } = _getRadiusFn.call($$, rate);
435
- const arc$1 = arc()
436
- .innerRadius(inner)
437
- .outerRadius(outer);
438
- return (d) => {
439
- const updated = $$.updateAngle(d);
440
- const outerR = outer(updated);
441
- let cornerR = 0;
442
- if (updated) {
443
- cornerR = corner(updated, outerR);
444
- }
445
- return updated ? arc$1.cornerRadius(cornerR)(updated) || "M 0 0" : "M 0 0";
446
- };
447
- },
448
- getArc(d, withoutUpdate, force) {
449
- return force || this.isArcType(d.data) ? this.svgArc(d, withoutUpdate) : "M 0 0";
450
- },
451
- /**
452
- * Render range value text
453
- * @private
454
- */
455
- redrawArcRangeText() {
456
- const $$ = this;
457
- const { config, $el: { arcs }, state, $T } = $$;
458
- const format = config.arc_rangeText_format;
459
- const fixed = $$.hasType("gauge") && config.arc_rangeText_fixed;
460
- let values = config.arc_rangeText_values;
461
- if (values?.length) {
462
- const isPercent = config.arc_rangeText_unit === "%";
463
- const totalSum = $$.getTotalDataSum(state.rendered);
464
- if (isPercent) {
465
- values = values.map(v => totalSum / 100 * v);
466
- }
467
- const pieData = $$.pie(values).map((d, i) => ((d.index = i), d));
468
- let rangeText = arcs.selectAll(`.${$ARC.arcRange}`)
469
- .data(values);
470
- rangeText.exit().remove();
471
- rangeText = $T(rangeText.enter()
472
- .append("text")
473
- .attr("class", $ARC.arcRange)
474
- .style("text-anchor", "middle")
475
- .style("pointer-events", "none")
476
- .style("opacity", "0")
477
- .text(v => {
478
- const range = isPercent ? (v / totalSum * 100) : v;
479
- return isFunction(format) ? format(range) : (`${range}${isPercent ? "%" : ""}`);
480
- })
481
- .merge(rangeText));
482
- if ((!state.rendered || (state.rendered && !fixed)) && totalSum > 0) {
483
- rangeText.attr("transform", function (d, i) {
484
- return $$.transformForArcLabel(this, pieData[i], true);
485
- });
486
- }
487
- rangeText.style("opacity", d => (!fixed && (d > totalSum || totalSum === 0) ? "0" : null));
488
- }
489
- },
490
- /**
491
- * Set transform attributes to arc label text
492
- * @param {SVGTextElement} textNode Text node element
493
- * @param {object} d Data object
494
- * @param {boolean} forRange Weather is for ranged text option(arc.rangeText.values)
495
- * @returns {string} Translate attribute string
496
- * @private
497
- */
498
- transformForArcLabel(textNode, d, forRange = false) {
499
- const $$ = this;
500
- const updated = $$.updateAngle(d, forRange);
501
- if (!updated) {
502
- return "";
503
- }
504
- let pos;
505
- let ratio = 1;
506
- // Handle range text or multi-arc gauge labels
507
- if (forRange || $$.hasMultiArcGauge()) {
508
- pos = _calculateRangeOrGaugePosition($$, d, updated, forRange);
509
- } // Handle standard arc types (donut, pie, polar)
510
- else if (!$$.hasType("gauge") || $$.data.targets.length > 1) {
511
- const result = _calculateStandardArcPosition($$, d, updated);
512
- pos = result.pos;
513
- ratio = result.ratio;
514
- }
515
- else {
516
- return "";
517
- }
518
- updateTextImagePos.call($$, textNode, pos);
519
- return `translate(${pos.x * ratio},${pos.y * ratio})`;
520
- },
521
- convertToArcData(d) {
522
- return this.addName({
523
- id: "data" in d ? d.data.id : d.id,
524
- value: d.value,
525
- ratio: this.getRatio("arc", d),
526
- index: d.index
527
- });
528
- },
529
- textForArcLabel(selection) {
530
- const $$ = this;
531
- const hasGauge = $$.hasType("gauge");
532
- const chartType = ARC_TYPES.filter($$.hasType.bind($$))?.[0];
533
- if ($$.shouldShowArcLabel()) {
534
- selection
535
- .style("fill", $$.updateTextColor.bind($$))
536
- .attr("filter", d => $$.updateTextBGColor.bind($$)(d, $$.config.data_labels_backgroundColors))
537
- .each(function (d) {
538
- const node = select(this);
539
- const updated = $$.updateAngle(d);
540
- const ratio = $$.getRatio("arc", updated);
541
- const meetsThreshold = meetsLabelThreshold.call($$, ratio, chartType);
542
- // Cache calculated values for reuse in redrawArcLabelLines
543
- d._cache = { updated, ratio, meetsThreshold };
544
- if (meetsThreshold) {
545
- const { value } = updated || d;
546
- const text = ($$.getArcLabelConfig("format") || $$.defaultArcValueFormat)(value, ratio, d.data.id).toString();
547
- setTextValue(node, text, [-1, 1], hasGauge);
548
- }
549
- else {
550
- node.text("");
551
- }
552
- });
553
- }
554
- },
555
- expandArc(targetIds) {
556
- const $$ = this;
557
- const { state: { transiting }, $el } = $$;
558
- // MEMO: avoid to cancel transition
559
- if (transiting) {
560
- const interval = setInterval(() => {
561
- // check the live state value: the destructured one is stale within this closure
562
- if (!$$.state.transiting) {
563
- clearInterval(interval);
564
- $el.legend.selectAll(`.${$FOCUS.legendItemFocused}`).size() > 0 &&
565
- $$.expandArc(targetIds);
566
- }
567
- }, 10);
568
- return;
569
- }
570
- const newTargetIds = $$.mapToTargetIds(targetIds);
571
- $el.svg.selectAll($$.selectorTargets(newTargetIds, `.${$ARC.chartArc}`))
572
- .each(function (d) {
573
- if (!$$.shouldExpand(d.data.id)) {
574
- return;
575
- }
576
- const expandDuration = $$.getExpandConfig(d.data.id, "duration");
577
- const svgArcExpandedSub = $$.getSvgArcExpanded($$.getExpandConfig(d.data.id, "rate"));
578
- select(this).selectAll("path")
579
- // @ts-ignore
580
- .transition()
581
- .duration(expandDuration)
582
- .attrTween("d", _getAttrTweenFn($$.svgArcExpanded.bind($$)))
583
- .transition()
584
- .duration(expandDuration * 2)
585
- .attrTween("d", _getAttrTweenFn(svgArcExpandedSub.bind($$)));
586
- });
587
- },
588
- unexpandArc(targetIds) {
589
- const $$ = this;
590
- const { state: { transiting }, $el: { svg } } = $$;
591
- if (transiting) {
592
- return;
593
- }
594
- const newTargetIds = $$.mapToTargetIds(targetIds);
595
- svg.selectAll($$.selectorTargets(newTargetIds, `.${$ARC.chartArc}`))
596
- .selectAll("path")
597
- .transition()
598
- .duration(d => $$.getExpandConfig(d.data.id, "duration"))
599
- .attrTween("d", _getAttrTweenFn($$.svgArc.bind($$)));
600
- svg.selectAll(`${$ARC.arc}`)
601
- .style("opacity", null);
602
- },
603
- /**
604
- * Get expand config value
605
- * @param {string} id data ID
606
- * @param {string} key config key: 'duration | rate'
607
- * @returns {number}
608
- * @private
609
- */
610
- getExpandConfig(id, key) {
611
- const $$ = this;
612
- const { config } = $$;
613
- const def = {
614
- duration: 50,
615
- rate: 0.98
616
- };
617
- let type;
618
- if ($$.isDonutType(id)) {
619
- type = "donut";
620
- }
621
- else if ($$.isGaugeType(id)) {
622
- type = "gauge";
623
- }
624
- else if ($$.isPieType(id)) {
625
- type = "pie";
626
- }
627
- return type ? config[`${type}_expand_${key}`] : def[key];
628
- },
629
- shouldExpand(id) {
630
- const $$ = this;
631
- const { config } = $$;
632
- const type = $$.isDonutType(id) ?
633
- "donut" :
634
- $$.isGaugeType(id) ?
635
- "gauge" :
636
- $$.isPieType(id) ?
637
- "pie" :
638
- null;
639
- return type ? !!config[`${type}_expand`] : false;
640
- },
641
- shouldShowArcLabel() {
642
- const $$ = this;
643
- const { config } = $$;
644
- return ARC_TYPES
645
- .some(v => $$.hasType(v) && config[`${v}_label_show`]);
646
- },
647
- getArcLabelConfig(name = "format") {
648
- const $$ = this;
649
- const { config } = $$;
650
- let fn = v => v;
651
- ARC_TYPES
652
- .filter($$.hasType.bind($$))
653
- .forEach(v => {
654
- fn = config[`${v}_label_${name}`];
655
- });
656
- if (name === "format") {
657
- return isFunction(fn) ? fn.bind($$.api) : fn;
658
- }
659
- else {
660
- return fn;
661
- }
662
- },
663
- updateTargetsForArc(targets) {
664
- const $$ = this;
665
- const { $el } = $$;
666
- const hasGauge = $$.hasType("gauge");
667
- const classChartArc = $$.getChartClass("Arc");
668
- const classArcs = $$.getClass("arcs", true);
669
- const classFocus = $$.classFocus.bind($$);
670
- const chartArcs = $el.main.select(`.${$ARC.chartArcs}`);
671
- const mainPieUpdate = chartArcs
672
- .selectAll(`.${$ARC.chartArc}`)
673
- .data($$.pie(targets))
674
- .attr("class", d => classChartArc(d) + classFocus(d.data));
675
- const mainPieEnter = mainPieUpdate.enter().append("g")
676
- .attr("class", classChartArc)
677
- .call(this.setCssRule(false, `.${$ARC.chartArcs} text`, [
678
- "pointer-events:none",
679
- "text-anchor:middle"
680
- ]));
681
- mainPieEnter.append("g")
682
- .attr("class", classArcs)
683
- .merge(mainPieUpdate);
684
- mainPieEnter.append("text")
685
- .attr("dy", hasGauge && !$$.hasMultiTargets() ? "-.1em" : null)
686
- .style("opacity", "0")
687
- .style("text-anchor", $$.getStylePropValue("middle"))
688
- .style("pointer-events", $$.getStylePropValue("none"));
689
- $el.text = chartArcs.selectAll(`.${$COMMON.target} text`);
690
- // MEMO: can not keep same color..., but not bad to update color in redraw
691
- // mainPieUpdate.exit().remove();
692
- },
693
- initArc() {
694
- const $$ = this;
695
- const { $el } = $$;
696
- $el.arcs = $el.main.select(`.${$COMMON.chart}`)
697
- .append("g")
698
- .attr("class", $ARC.chartArcs)
699
- .attr("transform", $$.getTranslate("arc"));
700
- $$.setArcTitle();
701
- },
702
- /**
703
- * Set arc title text
704
- * @param {string} str Title text
705
- * @private
706
- */
707
- setArcTitle(str) {
708
- const $$ = this;
709
- const title = str || $$.getArcTitle();
710
- const hasGauge = $$.hasType("gauge");
711
- if (title) {
712
- const className = hasGauge ? $GAUGE.chartArcsGaugeTitle : $ARC.chartArcsTitle;
713
- let text = $$.$el.arcs.select(`.${className}`);
714
- if (text.empty()) {
715
- text = $$.$el.arcs.append("text")
716
- .attr("class", className)
717
- .style("text-anchor", "middle");
718
- }
719
- hasGauge && text.attr("dy", "-0.3em");
720
- setTextValue(text, title, hasGauge ? undefined : [-0.6, 1.35], true);
721
- }
722
- },
723
- /**
724
- * Return arc title text
725
- * @returns {string} Arc title text
726
- * @private
727
- */
728
- getArcTitle() {
729
- const $$ = this;
730
- const type = ($$.hasType("donut") && "donut") || ($$.hasType("gauge") && "gauge");
731
- return type ? $$.config[`${type}_title`] : "";
732
- },
733
- /**
734
- * Get arc title text with needle value
735
- * @returns {string|boolean} When title contains needle template string will return processed string, otherwise false
736
- * @private
737
- */
738
- getArcTitleWithNeedleValue() {
739
- const $$ = this;
740
- const { config, state } = $$;
741
- const title = $$.getArcTitle();
742
- if (title && $$.config.arc_needle_show && /{=[A-Z_]+}/.test(title)) {
743
- let value = state.current.needle;
744
- if (!isNumber(value)) {
745
- value = config.arc_needle_value;
746
- }
747
- return tplProcess(title, {
748
- NEEDLE_VALUE: ~~value
749
- });
750
- }
751
- return false;
752
- },
753
- redrawArc(duration, durationForExit, withTransform) {
754
- const $$ = this;
755
- const { config, state, $el: { main } } = $$;
756
- const hasInteraction = config.interaction_enabled;
757
- const isSelectable = hasInteraction && config.data_selection_isselectable;
758
- let mainArc = main.selectAll(`.${$ARC.arcs}`)
759
- .selectAll(`.${$ARC.arc}`)
760
- .data($$.arcData.bind($$));
761
- mainArc.exit()
762
- .transition()
763
- .duration(durationForExit)
764
- .style("opacity", "0")
765
- .remove();
766
- mainArc = mainArc.enter()
767
- .append("path")
768
- .attr("class", $$.getClass("arc", true))
769
- .style("fill", d => $$.color(d.data))
770
- .style("cursor", d => (isSelectable?.bind?.($$.api)(d) ? "pointer" : null))
771
- .style("opacity", "0")
772
- .each(function (d) {
773
- if ($$.isGaugeType(d.data)) {
774
- d.startAngle = config.gauge_startingAngle;
775
- d.endAngle = config.gauge_startingAngle;
776
- }
777
- this._current = d;
778
- })
779
- .merge(mainArc);
780
- if ($$.hasType("gauge")) {
781
- $$.updateGaugeMax();
782
- $$.hasMultiArcGauge() && $$.redrawArcGaugeLine();
783
- }
784
- mainArc
785
- .attr("transform", d => (!$$.isGaugeType(d.data) && withTransform ? "scale(0)" : ""))
786
- .style("opacity", function (d) {
787
- return d === this._current ? "0" : null;
788
- })
789
- .each(() => {
790
- state.transiting = true;
791
- })
792
- .transition()
793
- .duration(duration)
794
- .attrTween("d", function (d) {
795
- const updated = $$.updateAngle(d);
796
- if (!updated) {
797
- return () => "M 0 0";
798
- }
799
- if (isNaN(this._current.startAngle)) {
800
- this._current.startAngle = 0;
801
- }
802
- if (isNaN(this._current.endAngle)) {
803
- this._current.endAngle = this._current.startAngle;
804
- }
805
- const interpolate$1 = interpolate(this._current, updated);
806
- this._current = interpolate$1(0);
807
- return function (t) {
808
- const interpolated = interpolate$1(t);
809
- interpolated.data = d.data; // data.id will be updated by interporator
810
- return $$.getArc(interpolated, true);
811
- };
812
- })
813
- .attr("transform", withTransform ? "scale(1)" : "")
814
- .style("fill", d => {
815
- let color;
816
- if ($$.levelColor) {
817
- color = $$.levelColor(d.data.values[0].value);
818
- // update data's color
819
- config.data_colors[d.data.id] = color;
820
- }
821
- else {
822
- color = $$.color(d.data);
823
- }
824
- return color;
825
- })
826
- // Where gauge reading color would receive customization.
827
- .style("opacity", null)
828
- .call(endall, function () {
829
- if ($$.levelColor) {
830
- const path = select(this);
831
- const d = path.datum(this._current);
832
- $$.updateLegendItemColor(d.data.id, path.style("fill"));
833
- }
834
- state.transiting = false;
835
- // release the redraw snapshot when a no-transition redraw skipped
836
- // afterRedraw() because this arc transition was still running
837
- if (state.redrawing) {
838
- state.redrawing = false;
839
- state._targetsToShow = null;
840
- state._cachedDrawShape = null;
841
- }
842
- callFn(config.onrendered, $$.api);
843
- });
844
- // bind arc events
845
- hasInteraction && $$.bindArcEvent(mainArc);
846
- $$.hasType("polar") && $$.redrawPolar();
847
- $$.hasType("gauge") && $$.redrawBackgroundArcs();
848
- config.arc_needle_show && $$.redrawNeedle();
849
- $$.redrawArcText(duration);
850
- $$.redrawArcRangeText();
851
- },
852
- /**
853
- * Update needle element
854
- * @private
855
- */
856
- redrawNeedle() {
857
- const $$ = this;
858
- const { $el, config, state: { hiddenTargetIds, radius } } = $$;
859
- const length = (radius - 1) / 100 * config.arc_needle_length;
860
- const hasDataToShow = hiddenTargetIds.size !== $$.data.targets.length;
861
- let needle = $$.$el.arcs.select(`.${$ARC.needle}`);
862
- // needle options
863
- const pathFn = config.arc_needle_path;
864
- const baseWidth = config.arc_needle_bottom_width / 2;
865
- const topWidth = config.arc_needle_top_width / 2;
866
- const topRx = config.arc_needle_top_rx;
867
- const topRy = config.arc_needle_top_ry;
868
- const bottomLen = config.arc_needle_bottom_len;
869
- const bottomRx = config.arc_needle_bottom_rx;
870
- const bottomRy = config.arc_needle_bottom_ry;
871
- const needleAngle = $$.getNeedleAngle();
872
- const updateNeedleValue = () => {
873
- const title = $$.getArcTitleWithNeedleValue();
874
- title && $$.setArcTitle(title);
875
- };
876
- updateNeedleValue();
877
- if (needle.empty()) {
878
- needle = $el.arcs
879
- .append("path")
880
- .classed($ARC.needle, true);
881
- $el.needle = needle;
882
- /**
883
- * Function to be exposed as public to facilitate updating needle
884
- * @param {number} v Value to be updated
885
- * @param {boolean} updateConfig Weather update config's value
886
- * @private
887
- */
888
- $el.needle.updateHelper = (v, updateConfig = false) => {
889
- if ($el.needle.style("display") !== "none") {
890
- $$.$T($el.needle)
891
- .style("transform", `rotate(${$$.getNeedleAngle(v)}deg)`)
892
- .call(endall, () => {
893
- updateConfig && (config.arc_needle_value = v);
894
- updateNeedleValue();
895
- });
896
- }
897
- };
898
- }
899
- if (hasDataToShow) {
900
- const path = isFunction(pathFn) ?
901
- pathFn.call($$, length) :
902
- `M-${baseWidth} ${bottomLen} A${bottomRx} ${bottomRy} 0 0 0 ${baseWidth} ${bottomLen} L${topWidth} -${length} A${topRx} ${topRy} 0 0 0 -${topWidth} -${length} L-${baseWidth} ${bottomLen} Z`;
903
- $$.$T(needle)
904
- .attr("d", path)
905
- .style("fill", config.arc_needle_color)
906
- .style("display", null)
907
- .style("transform", `rotate(${needleAngle}deg)`);
908
- }
909
- else {
910
- needle.style("display", "none");
911
- }
912
- },
913
- /**
914
- * Get needle angle value relative given value
915
- * @param {number} v Value to be calculated angle
916
- * @returns {number} angle value
917
- * @private
918
- */
919
- getNeedleAngle(v) {
920
- const $$ = this;
921
- const { config, state } = $$;
922
- const arcLength = $$.getArcLength();
923
- const hasGauge = $$.hasType("gauge");
924
- const total = $$.getTotalDataSum(true);
925
- let value = isDefined(v) ? v : config.arc_needle_value;
926
- let startingAngle = config[`${config.data_type}_startingAngle`] || 0;
927
- let radian;
928
- if (!isNumber(value)) {
929
- value = hasGauge && $$.data.targets.length === 1 ? total : 0;
930
- }
931
- state.current.needle = value;
932
- if (hasGauge) {
933
- startingAngle = $$.getStartingAngle();
934
- const radius = config.gauge_fullCircle ? arcLength : startingAngle * -2;
935
- const { gauge_min: min, gauge_max: max } = config;
936
- radian = radius * ((value - min) / (max - min));
937
- }
938
- else {
939
- // guard against 0/0 = NaN when all data is zero or hidden
940
- radian = total ? arcLength * (value / total) : 0;
941
- }
942
- return (startingAngle + radian) * (180 / Math.PI);
943
- },
944
- redrawBackgroundArcs() {
945
- const $$ = this;
946
- const { config, state } = $$;
947
- const hasMultiArcGauge = $$.hasMultiArcGauge();
948
- const isFullCircle = config.gauge_fullCircle;
949
- const showEmptyTextLabel = $$.getTargetsToShow().length === 0 &&
950
- !!config.data_empty_label_text;
951
- const startAngle = $$.getStartingAngle();
952
- const endAngle = isFullCircle ? startAngle + $$.getArcLength() : startAngle * -1;
953
- let backgroundArc = $$.$el.arcs.select(`${hasMultiArcGauge ? "g" : ""}.${$ARC.chartArcsBackground}`);
954
- if (hasMultiArcGauge) {
955
- let index = 0;
956
- backgroundArc = backgroundArc
957
- .selectAll(`path.${$ARC.chartArcsBackground}`)
958
- .data($$.data.targets);
959
- backgroundArc.enter()
960
- .append("path")
961
- .attr("class", (d, i) => `${$ARC.chartArcsBackground} ${$ARC.chartArcsBackground}-${i}`)
962
- .merge(backgroundArc)
963
- .style("fill", (config.gauge_background) || null)
964
- .attr("d", ({ id }) => {
965
- if (showEmptyTextLabel || state.hiddenTargetIds.has(id)) {
966
- return "M 0 0";
967
- }
968
- const d = {
969
- data: [{ value: config.gauge_max }],
970
- startAngle,
971
- endAngle,
972
- index: index++
973
- };
974
- return $$.getArc(d, true, true);
975
- });
976
- backgroundArc.exit().remove();
977
- }
978
- else {
979
- backgroundArc.attr("d", showEmptyTextLabel ? "M 0 0" : () => {
980
- const d = {
981
- data: [{ value: config.gauge_max }],
982
- startAngle,
983
- endAngle
984
- };
985
- return $$.getArc(d, true, true);
986
- });
987
- }
988
- },
989
- bindArcEvent(arc) {
990
- const $$ = this;
991
- const { config, state } = $$;
992
- const isTouch = state.inputType === "touch";
993
- const isMouse = state.inputType === "mouse";
994
- const _getArcData = d => {
995
- const updated = $$.updateAngle(d);
996
- return updated ? $$.convertToArcData(updated) : null;
997
- };
998
- // eslint-disable-next-line
999
- function selectArc(_this, arcData, id) {
1000
- // transitions
1001
- $$.expandArc(id);
1002
- $$.api.focus(id);
1003
- $$.toggleFocusLegend(id, true);
1004
- $$.showTooltip([arcData], _this);
1005
- }
1006
- // eslint-disable-next-line
1007
- function unselectArc(arcData) {
1008
- const id = undefined;
1009
- $$.unexpandArc(id);
1010
- $$.api.revert();
1011
- $$.revertLegend();
1012
- $$.hideTooltip();
1013
- }
1014
- arc
1015
- .on("click", function (event, d, i) {
1016
- const arcData = _getArcData(d);
1017
- if (arcData) {
1018
- $$.toggleShape?.(this, arcData, i);
1019
- config.data_onclick.bind($$.api)(arcData, this);
1020
- }
1021
- });
1022
- // mouse events
1023
- if (isMouse) {
1024
- arc
1025
- .on("mouseover", function (event, d) {
1026
- if (state.transiting) { // skip while transiting
1027
- return;
1028
- }
1029
- state.event = event;
1030
- const arcData = _getArcData(d);
1031
- const id = arcData?.id || undefined;
1032
- selectArc(this, arcData, id);
1033
- $$.setOverOut(true, arcData);
1034
- })
1035
- .on("mouseout", (event, d) => {
1036
- if (state.transiting || !config.interaction_onout) { // skip while transiting
1037
- return;
1038
- }
1039
- state.event = event;
1040
- const arcData = _getArcData(d);
1041
- unselectArc();
1042
- $$.setOverOut(false, arcData);
1043
- })
1044
- .on("mousemove", function (event, d) {
1045
- const arcData = _getArcData(d);
1046
- state.event = event;
1047
- $$.showTooltip([arcData], this);
1048
- });
1049
- }
1050
- // touch events
1051
- if (isTouch && $$.hasArcType() && !$$.radars) {
1052
- const getEventArc = event => {
1053
- const { clientX, clientY } = event.changedTouches?.[0] ?? { clientX: 0, clientY: 0 };
1054
- const eventArc = select(doc.elementFromPoint(clientX, clientY));
1055
- return eventArc;
1056
- };
1057
- $$.$el.svg
1058
- .on("touchstart touchmove", function (event) {
1059
- if (state.transiting) { // skip while transiting
1060
- return;
1061
- }
1062
- state.event = event;
1063
- const eventArc = getEventArc(event);
1064
- const datum = eventArc.datum();
1065
- const updated = (datum?.data && datum.data.id) ? $$.updateAngle(datum) : null;
1066
- const arcData = updated ? $$.convertToArcData(updated) : null;
1067
- const id = arcData?.id || undefined;
1068
- $$.callOverOutForTouch(arcData);
1069
- isUndefined(id) ? unselectArc() : selectArc(this, arcData, id);
1070
- }, { passive: true });
1071
- }
1072
- },
1073
- redrawArcText(duration) {
1074
- const $$ = this;
1075
- const { config, state, $el: { main, arcs } } = $$;
1076
- const hasGauge = $$.hasType("gauge");
1077
- const hasMultiArcGauge = $$.hasMultiArcGauge();
1078
- let text;
1079
- // for gauge type, update text when has no title & multi data
1080
- if (!(hasGauge && $$.data.targets.length === 1 && config.gauge_title)) {
1081
- text = main.selectAll(`.${$ARC.chartArc}`)
1082
- .select("text")
1083
- .style("opacity", "0")
1084
- .attr("class", d => ($$.isGaugeType(d.data) ? $GAUGE.gaugeValue : null))
1085
- .call($$.textForArcLabel.bind($$))
1086
- .style("font-size", d => ($$.isGaugeType(d.data) && $$.data.targets.length === 1 && !hasMultiArcGauge ?
1087
- `${Math.round(state.radius / 5)}px` :
1088
- null));
1089
- updateTextImage.call($$);
1090
- text
1091
- .attr("transform", function (d) {
1092
- return $$.transformForArcLabel.bind($$)(this, d);
1093
- })
1094
- .transition()
1095
- .duration(duration)
1096
- .style("opacity", d => ($$.isTargetToShow(d.data.id) && $$.isArcType(d.data) ? null : "0"));
1097
- hasMultiArcGauge && text.attr("dy", "-.1em");
1098
- }
1099
- main.select(`.${$ARC.chartArcsTitle}`)
1100
- .style("opacity", $$.hasType("donut") || hasGauge ? null : "0");
1101
- if (hasGauge) {
1102
- const isFullCircle = config.gauge_fullCircle;
1103
- isFullCircle &&
1104
- text?.attr("dy", `${hasMultiArcGauge ? 0 : Math.round(state.radius / 14)}`);
1105
- if (config.gauge_label_show) {
1106
- arcs.select(`.${$GAUGE.chartArcsGaugeUnit}`)
1107
- .attr("dy", `${isFullCircle ? 1.5 : 0.75}em`)
1108
- .text(config.gauge_units);
1109
- arcs.select(`.${$GAUGE.chartArcsGaugeMin}`)
1110
- .attr("dx", `${ -1 *
1111
- (state.innerRadius +
1112
- ((state.radius - state.innerRadius) / (isFullCircle ? 1 : 2)))}px`)
1113
- .attr("dy", "1.2em")
1114
- .text($$.textForGaugeMinMax(config.gauge_min, false));
1115
- // show max text when isn't fullCircle
1116
- !isFullCircle && arcs.select(`.${$GAUGE.chartArcsGaugeMax}`)
1117
- .attr("dx", `${state.innerRadius + ((state.radius - state.innerRadius) / 2)}px`)
1118
- .attr("dy", "1.2em")
1119
- .text($$.textForGaugeMinMax(config.gauge_max, true));
1120
- }
1121
- }
1122
- // Render connector lines for label with lines
1123
- isLabelWithLine.call($$) && redrawArcLabelLines.call($$, duration);
1124
- },
1125
- /**
1126
- * Get Arc element by id or index
1127
- * @param {string|number} value id or index of Arc
1128
- * @returns {d3Selection} Arc path element
1129
- * @private
1130
- */
1131
- getArcElementByIdOrIndex(value) {
1132
- const $$ = this;
1133
- const { $el: { arcs } } = $$;
1134
- const filterFn = isNumber(value) ? d => d.index === value : d => d.data.id === value;
1135
- return arcs?.selectAll(`.${$COMMON.target} path`)
1136
- .filter(filterFn);
1137
- }
209
+ var arc_default = {
210
+ initPie() {
211
+ const $$ = this;
212
+ const { config } = $$;
213
+ const dataType = config.data_type;
214
+ const padding = config[`${dataType}_padding`];
215
+ const startingAngle = config[`${dataType}_startingAngle`] || 0;
216
+ const padAngle = (padding ? padding * .01 : config[`${dataType}_padAngle`]) || 0;
217
+ $$.pie = pie().startAngle(startingAngle).endAngle(startingAngle + 2 * Math.PI).padAngle(padAngle).value((d) => d.values?.reduce((a, b) => a + b.value, 0) ?? d).sort($$.getSortCompareFn.bind($$)(true));
218
+ },
219
+ updateRadius() {
220
+ const $$ = this;
221
+ const { config, state } = $$;
222
+ const padding = config[`${config.data_type}_padding`];
223
+ const w = config.gauge_width || config.donut_width;
224
+ const gaugeArcWidth = $$.getTargetsToShow().length * config.gauge_arcs_minWidth;
225
+ const LABEL_RADIUS_RATIO = .85;
226
+ const labelWithLineRatio = isLabelWithLine.call($$) ? LABEL_RADIUS_RATIO : 1;
227
+ state.radiusExpanded = Math.min(state.arcWidth, state.arcHeight) / 2 * ($$.hasMultiArcGauge() && config.gauge_label_show ? LABEL_RADIUS_RATIO : labelWithLineRatio);
228
+ state.radius = state.radiusExpanded * .95;
229
+ state.innerRadiusRatio = w ? (state.radius - w) / state.radius : .6;
230
+ state.gaugeArcWidth = w || (gaugeArcWidth <= state.radius - state.innerRadius ? state.radius - state.innerRadius : gaugeArcWidth <= state.radius ? gaugeArcWidth : state.radius);
231
+ const innerRadius = config.pie_innerRadius || (padding ? padding * (state.innerRadiusRatio + .1) : 0);
232
+ state.outerRadius = config.pie_outerRadius;
233
+ state.innerRadius = $$.hasType("donut") || $$.hasType("gauge") ? state.radius * state.innerRadiusRatio : innerRadius;
234
+ },
235
+ /**
236
+ * Get pie's inner & outer radius value
237
+ * @param {object|undefined} d Data object
238
+ * @returns {object}
239
+ * @private
240
+ */
241
+ getRadius(d) {
242
+ const $$ = this;
243
+ const data = d?.data;
244
+ let { innerRadius, outerRadius } = $$.state;
245
+ if (!isNumber(innerRadius) && data) innerRadius = innerRadius[data.id] || 0;
246
+ if (isObject(outerRadius) && data && data.id in outerRadius) outerRadius = outerRadius[data.id];
247
+ else if (!isNumber(outerRadius)) outerRadius = $$.state.radius;
248
+ return {
249
+ innerRadius,
250
+ outerRadius
251
+ };
252
+ },
253
+ updateArc() {
254
+ const $$ = this;
255
+ $$.updateRadius();
256
+ $$.svgArc = $$.getSvgArc();
257
+ $$.svgArcExpanded = $$.getSvgArcExpanded();
258
+ },
259
+ getArcLength() {
260
+ const { config } = this;
261
+ const arcLengthInPercent = config.gauge_arcLength * 3.6;
262
+ let len = 2 * (arcLengthInPercent / 360);
263
+ if (arcLengthInPercent < -360) len = -2;
264
+ else if (arcLengthInPercent > 360) len = 2;
265
+ return len * Math.PI;
266
+ },
267
+ getStartingAngle() {
268
+ const $$ = this;
269
+ const { config } = $$;
270
+ const dataType = config.data_type;
271
+ const isFullCircle = $$.hasType("gauge") ? config.gauge_fullCircle : false;
272
+ const defaultStartAngle = -1 * Math.PI / 2;
273
+ const defaultEndAngle = Math.PI / 2;
274
+ let startAngle = config[`${dataType}_startingAngle`] || 0;
275
+ if (!isFullCircle && startAngle <= defaultStartAngle) startAngle = defaultStartAngle;
276
+ else if (!isFullCircle && startAngle >= defaultEndAngle) startAngle = defaultEndAngle;
277
+ else if (startAngle > Math.PI || startAngle < -1 * Math.PI) startAngle = Math.PI;
278
+ return startAngle;
279
+ },
280
+ /**
281
+ * Update angle data
282
+ * @param {object} dValue Data object
283
+ * @param {boolean} forRange Weather is for ranged text option(arc.rangeText.values)
284
+ * @returns {object|null} Updated angle data
285
+ * @private
286
+ */
287
+ updateAngle(dValue, forRange = false) {
288
+ const $$ = this;
289
+ const { config, state } = $$;
290
+ const hasGauge = forRange && $$.hasType("gauge");
291
+ let { pie } = $$;
292
+ let d = dValue;
293
+ let found = false;
294
+ if (!config) return null;
295
+ const gStart = $$.getStartingAngle();
296
+ const radius = config.gauge_fullCircle || forRange && !hasGauge ? $$.getArcLength() : gStart * -2;
297
+ const isSingleArcGauge = d.data && $$.isGaugeType(d.data) && !$$.hasMultiArcGauge();
298
+ if (isSingleArcGauge) {
299
+ const { gauge_min: gMin, gauge_max: gMax } = config;
300
+ const gEnd = radius * (($$.getTotalDataSum(state.rendered) - gMin) / (gMax - gMin));
301
+ pie = pie.startAngle(gStart).endAngle(gEnd + gStart);
302
+ }
303
+ if (forRange === false) {
304
+ let layout;
305
+ if (isSingleArcGauge) layout = pie($$.filterTargetsToShow());
306
+ else {
307
+ const cacheKey = "$arcPieLayout";
308
+ let cached = $$.cache.get(cacheKey);
309
+ if (!cached || cached.generation !== state.redrawGeneration) {
310
+ cached = {
311
+ generation: state.redrawGeneration,
312
+ layout: pie($$.filterTargetsToShow())
313
+ };
314
+ $$.cache.add(cacheKey, cached);
315
+ }
316
+ layout = cached.layout;
317
+ }
318
+ layout.forEach((t, i) => {
319
+ if (!found && t.data.id === d.data?.id) {
320
+ found = true;
321
+ d = t;
322
+ d.index = i;
323
+ }
324
+ });
325
+ }
326
+ if (isNaN(d.startAngle)) d.startAngle = 0;
327
+ if (isNaN(d.endAngle)) d.endAngle = d.startAngle;
328
+ if (forRange || d.data && (config.gauge_enforceMinMax || $$.hasMultiArcGauge())) {
329
+ const { gauge_min: gMin, gauge_max: gMax } = config;
330
+ const max = forRange && !hasGauge ? $$.getTotalDataSum(state.rendered) : gMax;
331
+ const gTic = radius / (max - gMin);
332
+ const value = d.value ?? 0;
333
+ const gValue = value < gMin ? 0 : value < max ? value - gMin : max - gMin;
334
+ d.startAngle = gStart;
335
+ d.endAngle = gStart + gTic * gValue;
336
+ }
337
+ return found || forRange ? d : null;
338
+ },
339
+ getSvgArc() {
340
+ const $$ = this;
341
+ const { inner, outer, corner } = _getRadiusFn.call($$);
342
+ const arc$1 = arc().innerRadius(inner).outerRadius(outer);
343
+ const newArc = function(d, withoutUpdate) {
344
+ let path = "M 0 0";
345
+ if (d.value || d.data) {
346
+ const data = withoutUpdate ? d : $$.updateAngle(d) ?? null;
347
+ if (data) path = arc$1.cornerRadius(corner(data, outer(data)))(data);
348
+ }
349
+ return path;
350
+ };
351
+ newArc.centroid = arc$1.centroid;
352
+ return newArc;
353
+ },
354
+ /**
355
+ * Get expanded arc path function
356
+ * @param {number} rate Expand rate
357
+ * @returns {function} Expanded arc path getter function
358
+ * @private
359
+ */
360
+ getSvgArcExpanded(rate = 1) {
361
+ const $$ = this;
362
+ const { inner, outer, corner } = _getRadiusFn.call($$, rate);
363
+ const arc$2 = arc().innerRadius(inner).outerRadius(outer);
364
+ return (d) => {
365
+ const updated = $$.updateAngle(d);
366
+ const outerR = outer(updated);
367
+ let cornerR = 0;
368
+ if (updated) cornerR = corner(updated, outerR);
369
+ return updated ? arc$2.cornerRadius(cornerR)(updated) || "M 0 0" : "M 0 0";
370
+ };
371
+ },
372
+ getArc(d, withoutUpdate, force) {
373
+ return force || this.isArcType(d.data) ? this.svgArc(d, withoutUpdate) : "M 0 0";
374
+ },
375
+ /**
376
+ * Render range value text
377
+ * @private
378
+ */
379
+ redrawArcRangeText() {
380
+ const $$ = this;
381
+ const { config, $el: { arcs }, state, $T } = $$;
382
+ const format = config.arc_rangeText_format;
383
+ const fixed = $$.hasType("gauge") && config.arc_rangeText_fixed;
384
+ let values = config.arc_rangeText_values;
385
+ if (values?.length) {
386
+ const isPercent = config.arc_rangeText_unit === "%";
387
+ const totalSum = $$.getTotalDataSum(state.rendered);
388
+ if (isPercent) values = values.map((v) => totalSum / 100 * v);
389
+ const pieData = $$.pie(values).map((d, i) => (d.index = i, d));
390
+ let rangeText = arcs.selectAll(`.${$ARC.arcRange}`).data(values);
391
+ rangeText.exit().remove();
392
+ rangeText = $T(rangeText.enter().append("text").attr("class", $ARC.arcRange).style("text-anchor", "middle").style("pointer-events", "none").style("opacity", "0").text((v) => {
393
+ const range = isPercent ? v / totalSum * 100 : v;
394
+ return isFunction(format) ? format(range) : `${range}${isPercent ? "%" : ""}`;
395
+ }).merge(rangeText));
396
+ if ((!state.rendered || state.rendered && !fixed) && totalSum > 0) rangeText.attr("transform", function(d, i) {
397
+ return $$.transformForArcLabel(this, pieData[i], true);
398
+ });
399
+ rangeText.style("opacity", (d) => !fixed && (d > totalSum || totalSum === 0) ? "0" : null);
400
+ }
401
+ },
402
+ /**
403
+ * Set transform attributes to arc label text
404
+ * @param {SVGTextElement} textNode Text node element
405
+ * @param {object} d Data object
406
+ * @param {boolean} forRange Weather is for ranged text option(arc.rangeText.values)
407
+ * @returns {string} Translate attribute string
408
+ * @private
409
+ */
410
+ transformForArcLabel(textNode, d, forRange = false) {
411
+ const $$ = this;
412
+ const updated = $$.updateAngle(d, forRange);
413
+ if (!updated) return "";
414
+ let pos;
415
+ let ratio = 1;
416
+ if (forRange || $$.hasMultiArcGauge()) pos = _calculateRangeOrGaugePosition($$, d, updated, forRange);
417
+ else if (!$$.hasType("gauge") || $$.data.targets.length > 1) {
418
+ const result = _calculateStandardArcPosition($$, d, updated);
419
+ pos = result.pos;
420
+ ratio = result.ratio;
421
+ } else return "";
422
+ updateTextImagePos.call($$, textNode, pos);
423
+ return `translate(${pos.x * ratio},${pos.y * ratio})`;
424
+ },
425
+ convertToArcData(d) {
426
+ return this.addName({
427
+ id: "data" in d ? d.data.id : d.id,
428
+ value: d.value,
429
+ ratio: this.getRatio("arc", d),
430
+ index: d.index
431
+ });
432
+ },
433
+ textForArcLabel(selection) {
434
+ const $$ = this;
435
+ const hasGauge = $$.hasType("gauge");
436
+ const chartType = ARC_TYPES.filter($$.hasType.bind($$))?.[0];
437
+ if ($$.shouldShowArcLabel()) selection.style("fill", $$.updateTextColor.bind($$)).attr("filter", (d) => $$.updateTextBGColor.bind($$)(d, $$.config.data_labels_backgroundColors)).each(function(d) {
438
+ const node = select(this);
439
+ const updated = $$.updateAngle(d);
440
+ const ratio = $$.getRatio("arc", updated);
441
+ const meetsThreshold = meetsLabelThreshold.call($$, ratio, chartType);
442
+ d._cache = {
443
+ updated,
444
+ ratio,
445
+ meetsThreshold
446
+ };
447
+ if (meetsThreshold) {
448
+ const { value } = updated || d;
449
+ setTextValue(node, ($$.getArcLabelConfig("format") || $$.defaultArcValueFormat)(value, ratio, d.data.id).toString(), [-1, 1], hasGauge);
450
+ } else node.text("");
451
+ });
452
+ },
453
+ expandArc(targetIds) {
454
+ const $$ = this;
455
+ const { state: { transiting }, $el } = $$;
456
+ if (transiting) {
457
+ const interval = setInterval(() => {
458
+ if (!$$.state.transiting) {
459
+ clearInterval(interval);
460
+ $el.legend.selectAll(`.${$FOCUS.legendItemFocused}`).size() > 0 && $$.expandArc(targetIds);
461
+ }
462
+ }, 10);
463
+ return;
464
+ }
465
+ const newTargetIds = $$.mapToTargetIds(targetIds);
466
+ $el.svg.selectAll($$.selectorTargets(newTargetIds, `.${$ARC.chartArc}`)).each(function(d) {
467
+ if (!$$.shouldExpand(d.data.id)) return;
468
+ const expandDuration = $$.getExpandConfig(d.data.id, "duration");
469
+ const svgArcExpandedSub = $$.getSvgArcExpanded($$.getExpandConfig(d.data.id, "rate"));
470
+ select(this).selectAll("path").transition().duration(expandDuration).attrTween("d", _getAttrTweenFn($$.svgArcExpanded.bind($$))).transition().duration(expandDuration * 2).attrTween("d", _getAttrTweenFn(svgArcExpandedSub.bind($$)));
471
+ });
472
+ },
473
+ unexpandArc(targetIds) {
474
+ const $$ = this;
475
+ const { state: { transiting }, $el: { svg } } = $$;
476
+ if (transiting) return;
477
+ const newTargetIds = $$.mapToTargetIds(targetIds);
478
+ svg.selectAll($$.selectorTargets(newTargetIds, `.${$ARC.chartArc}`)).selectAll("path").transition().duration((d) => $$.getExpandConfig(d.data.id, "duration")).attrTween("d", _getAttrTweenFn($$.svgArc.bind($$)));
479
+ svg.selectAll(`${$ARC.arc}`).style("opacity", null);
480
+ },
481
+ /**
482
+ * Get expand config value
483
+ * @param {string} id data ID
484
+ * @param {string} key config key: 'duration | rate'
485
+ * @returns {number}
486
+ * @private
487
+ */
488
+ getExpandConfig(id, key) {
489
+ const $$ = this;
490
+ const { config } = $$;
491
+ const def = {
492
+ duration: 50,
493
+ rate: .98
494
+ };
495
+ let type;
496
+ if ($$.isDonutType(id)) type = "donut";
497
+ else if ($$.isGaugeType(id)) type = "gauge";
498
+ else if ($$.isPieType(id)) type = "pie";
499
+ return type ? config[`${type}_expand_${key}`] : def[key];
500
+ },
501
+ shouldExpand(id) {
502
+ const $$ = this;
503
+ const { config } = $$;
504
+ const type = $$.isDonutType(id) ? "donut" : $$.isGaugeType(id) ? "gauge" : $$.isPieType(id) ? "pie" : null;
505
+ return type ? !!config[`${type}_expand`] : false;
506
+ },
507
+ shouldShowArcLabel() {
508
+ const $$ = this;
509
+ const { config } = $$;
510
+ return ARC_TYPES.some((v) => $$.hasType(v) && config[`${v}_label_show`]);
511
+ },
512
+ getArcLabelConfig(name = "format") {
513
+ const $$ = this;
514
+ const { config } = $$;
515
+ let fn = (v) => v;
516
+ ARC_TYPES.filter($$.hasType.bind($$)).forEach((v) => {
517
+ fn = config[`${v}_label_${name}`];
518
+ });
519
+ if (name === "format") return isFunction(fn) ? fn.bind($$.api) : fn;
520
+ else return fn;
521
+ },
522
+ updateTargetsForArc(targets) {
523
+ const $$ = this;
524
+ const { $el } = $$;
525
+ const hasGauge = $$.hasType("gauge");
526
+ const classChartArc = $$.getChartClass("Arc");
527
+ const classArcs = $$.getClass("arcs", true);
528
+ const classFocus = $$.classFocus.bind($$);
529
+ const chartArcs = $el.main.select(`.${$ARC.chartArcs}`);
530
+ const mainPieUpdate = chartArcs.selectAll(`.${$ARC.chartArc}`).data($$.pie(targets)).attr("class", (d) => classChartArc(d) + classFocus(d.data));
531
+ const mainPieEnter = mainPieUpdate.enter().append("g").attr("class", classChartArc).call(this.setCssRule(false, `.${$ARC.chartArcs} text`, ["pointer-events:none", "text-anchor:middle"]));
532
+ mainPieEnter.append("g").attr("class", classArcs).merge(mainPieUpdate);
533
+ mainPieEnter.append("text").attr("dy", hasGauge && !$$.hasMultiTargets() ? "-.1em" : null).style("opacity", "0").style("text-anchor", $$.getStylePropValue("middle")).style("pointer-events", $$.getStylePropValue("none"));
534
+ $el.text = chartArcs.selectAll(`.${$COMMON.target} text`);
535
+ },
536
+ initArc() {
537
+ const $$ = this;
538
+ const { $el } = $$;
539
+ $el.arcs = $el.main.select(`.${$COMMON.chart}`).append("g").attr("class", $ARC.chartArcs).attr("transform", $$.getTranslate("arc"));
540
+ $$.setArcTitle();
541
+ },
542
+ /**
543
+ * Set arc title text
544
+ * @param {string} str Title text
545
+ * @private
546
+ */
547
+ setArcTitle(str) {
548
+ const $$ = this;
549
+ const title = str || $$.getArcTitle();
550
+ const hasGauge = $$.hasType("gauge");
551
+ if (title) {
552
+ const className = hasGauge ? $GAUGE.chartArcsGaugeTitle : $ARC.chartArcsTitle;
553
+ let text = $$.$el.arcs.select(`.${className}`);
554
+ if (text.empty()) text = $$.$el.arcs.append("text").attr("class", className).style("text-anchor", "middle");
555
+ hasGauge && text.attr("dy", "-0.3em");
556
+ setTextValue(text, title, hasGauge ? void 0 : [-.6, 1.35], true);
557
+ }
558
+ },
559
+ /**
560
+ * Return arc title text
561
+ * @returns {string} Arc title text
562
+ * @private
563
+ */
564
+ getArcTitle() {
565
+ const $$ = this;
566
+ const type = $$.hasType("donut") && "donut" || $$.hasType("gauge") && "gauge";
567
+ return type ? $$.config[`${type}_title`] : "";
568
+ },
569
+ /**
570
+ * Get arc title text with needle value
571
+ * @returns {string|boolean} When title contains needle template string will return processed string, otherwise false
572
+ * @private
573
+ */
574
+ getArcTitleWithNeedleValue() {
575
+ const $$ = this;
576
+ const { config, state } = $$;
577
+ const title = $$.getArcTitle();
578
+ if (title && $$.config.arc_needle_show && /{=[A-Z_]+}/.test(title)) {
579
+ let value = state.current.needle;
580
+ if (!isNumber(value)) value = config.arc_needle_value;
581
+ return tplProcess(title, { NEEDLE_VALUE: ~~value });
582
+ }
583
+ return false;
584
+ },
585
+ redrawArc(duration, durationForExit, withTransform) {
586
+ const $$ = this;
587
+ const { config, state, $el: { main } } = $$;
588
+ const hasInteraction = config.interaction_enabled;
589
+ const isSelectable = hasInteraction && config.data_selection_isselectable;
590
+ let mainArc = main.selectAll(`.${$ARC.arcs}`).selectAll(`.${$ARC.arc}`).data($$.arcData.bind($$));
591
+ mainArc.exit().transition().duration(durationForExit).style("opacity", "0").remove();
592
+ mainArc = mainArc.enter().append("path").attr("class", $$.getClass("arc", true)).style("fill", (d) => $$.color(d.data)).style("cursor", (d) => isSelectable?.bind?.($$.api)(d) ? "pointer" : null).style("opacity", "0").each(function(d) {
593
+ if ($$.isGaugeType(d.data)) {
594
+ d.startAngle = config.gauge_startingAngle;
595
+ d.endAngle = config.gauge_startingAngle;
596
+ }
597
+ this._current = d;
598
+ }).merge(mainArc);
599
+ if ($$.hasType("gauge")) {
600
+ $$.updateGaugeMax();
601
+ $$.hasMultiArcGauge() && $$.redrawArcGaugeLine();
602
+ }
603
+ mainArc.attr("transform", (d) => !$$.isGaugeType(d.data) && withTransform ? "scale(0)" : "").style("opacity", function(d) {
604
+ return d === this._current ? "0" : null;
605
+ }).each(() => {
606
+ state.transiting = true;
607
+ }).transition().duration(duration).attrTween("d", function(d) {
608
+ const updated = $$.updateAngle(d);
609
+ if (!updated) return () => "M 0 0";
610
+ if (isNaN(this._current.startAngle)) this._current.startAngle = 0;
611
+ if (isNaN(this._current.endAngle)) this._current.endAngle = this._current.startAngle;
612
+ const interpolate$2 = interpolate(this._current, updated);
613
+ this._current = interpolate$2(0);
614
+ return function(t) {
615
+ const interpolated = interpolate$2(t);
616
+ interpolated.data = d.data;
617
+ return $$.getArc(interpolated, true);
618
+ };
619
+ }).attr("transform", withTransform ? "scale(1)" : "").style("fill", (d) => {
620
+ let color;
621
+ if ($$.levelColor) {
622
+ color = $$.levelColor(d.data.values[0].value);
623
+ config.data_colors[d.data.id] = color;
624
+ } else color = $$.color(d.data);
625
+ return color;
626
+ }).style("opacity", null).call(endall, function() {
627
+ if ($$.levelColor) {
628
+ const path = select(this);
629
+ const d = path.datum(this._current);
630
+ $$.updateLegendItemColor(d.data.id, path.style("fill"));
631
+ }
632
+ state.transiting = false;
633
+ if (state.redrawing) {
634
+ state.redrawing = false;
635
+ state._targetsToShow = null;
636
+ state._cachedDrawShape = null;
637
+ }
638
+ callFn(config.onrendered, $$.api);
639
+ });
640
+ hasInteraction && $$.bindArcEvent(mainArc);
641
+ $$.hasType("polar") && $$.redrawPolar();
642
+ $$.hasType("gauge") && $$.redrawBackgroundArcs();
643
+ config.arc_needle_show && $$.redrawNeedle();
644
+ $$.redrawArcText(duration);
645
+ $$.redrawArcRangeText();
646
+ },
647
+ /**
648
+ * Update needle element
649
+ * @private
650
+ */
651
+ redrawNeedle() {
652
+ const $$ = this;
653
+ const { $el, config, state: { hiddenTargetIds, radius } } = $$;
654
+ const length = (radius - 1) / 100 * config.arc_needle_length;
655
+ const hasDataToShow = hiddenTargetIds.size !== $$.data.targets.length;
656
+ let needle = $$.$el.arcs.select(`.${$ARC.needle}`);
657
+ const pathFn = config.arc_needle_path;
658
+ const baseWidth = config.arc_needle_bottom_width / 2;
659
+ const topWidth = config.arc_needle_top_width / 2;
660
+ const topRx = config.arc_needle_top_rx;
661
+ const topRy = config.arc_needle_top_ry;
662
+ const bottomLen = config.arc_needle_bottom_len;
663
+ const bottomRx = config.arc_needle_bottom_rx;
664
+ const bottomRy = config.arc_needle_bottom_ry;
665
+ const needleAngle = $$.getNeedleAngle();
666
+ const updateNeedleValue = () => {
667
+ const title = $$.getArcTitleWithNeedleValue();
668
+ title && $$.setArcTitle(title);
669
+ };
670
+ updateNeedleValue();
671
+ if (needle.empty()) {
672
+ needle = $el.arcs.append("path").classed($ARC.needle, true);
673
+ $el.needle = needle;
674
+ /**
675
+ * Function to be exposed as public to facilitate updating needle
676
+ * @param {number} v Value to be updated
677
+ * @param {boolean} updateConfig Weather update config's value
678
+ * @private
679
+ */
680
+ $el.needle.updateHelper = (v, updateConfig = false) => {
681
+ if ($el.needle.style("display") !== "none") $$.$T($el.needle).style("transform", `rotate(${$$.getNeedleAngle(v)}deg)`).call(endall, () => {
682
+ updateConfig && (config.arc_needle_value = v);
683
+ updateNeedleValue();
684
+ });
685
+ };
686
+ }
687
+ if (hasDataToShow) {
688
+ const path = isFunction(pathFn) ? pathFn.call($$, length) : `M-${baseWidth} ${bottomLen} A${bottomRx} ${bottomRy} 0 0 0 ${baseWidth} ${bottomLen} L${topWidth} -${length} A${topRx} ${topRy} 0 0 0 -${topWidth} -${length} L-${baseWidth} ${bottomLen} Z`;
689
+ $$.$T(needle).attr("d", path).style("fill", config.arc_needle_color).style("display", null).style("transform", `rotate(${needleAngle}deg)`);
690
+ } else needle.style("display", "none");
691
+ },
692
+ /**
693
+ * Get needle angle value relative given value
694
+ * @param {number} v Value to be calculated angle
695
+ * @returns {number} angle value
696
+ * @private
697
+ */
698
+ getNeedleAngle(v) {
699
+ const $$ = this;
700
+ const { config, state } = $$;
701
+ const arcLength = $$.getArcLength();
702
+ const hasGauge = $$.hasType("gauge");
703
+ const total = $$.getTotalDataSum(true);
704
+ let value = isDefined(v) ? v : config.arc_needle_value;
705
+ let startingAngle = config[`${config.data_type}_startingAngle`] || 0;
706
+ let radian;
707
+ if (!isNumber(value)) value = hasGauge && $$.data.targets.length === 1 ? total : 0;
708
+ state.current.needle = value;
709
+ if (hasGauge) {
710
+ startingAngle = $$.getStartingAngle();
711
+ const radius = config.gauge_fullCircle ? arcLength : startingAngle * -2;
712
+ const { gauge_min: min, gauge_max: max } = config;
713
+ radian = radius * ((value - min) / (max - min));
714
+ } else radian = total ? arcLength * (value / total) : 0;
715
+ return (startingAngle + radian) * (180 / Math.PI);
716
+ },
717
+ redrawBackgroundArcs() {
718
+ const $$ = this;
719
+ const { config, state } = $$;
720
+ const hasMultiArcGauge = $$.hasMultiArcGauge();
721
+ const isFullCircle = config.gauge_fullCircle;
722
+ const showEmptyTextLabel = $$.getTargetsToShow().length === 0 && !!config.data_empty_label_text;
723
+ const startAngle = $$.getStartingAngle();
724
+ const endAngle = isFullCircle ? startAngle + $$.getArcLength() : startAngle * -1;
725
+ let backgroundArc = $$.$el.arcs.select(`${hasMultiArcGauge ? "g" : ""}.${$ARC.chartArcsBackground}`);
726
+ if (hasMultiArcGauge) {
727
+ let index = 0;
728
+ backgroundArc = backgroundArc.selectAll(`path.${$ARC.chartArcsBackground}`).data($$.data.targets);
729
+ backgroundArc.enter().append("path").attr("class", (d, i) => `${$ARC.chartArcsBackground} ${$ARC.chartArcsBackground}-${i}`).merge(backgroundArc).style("fill", config.gauge_background || null).attr("d", ({ id }) => {
730
+ if (showEmptyTextLabel || state.hiddenTargetIds.has(id)) return "M 0 0";
731
+ const d = {
732
+ data: [{ value: config.gauge_max }],
733
+ startAngle,
734
+ endAngle,
735
+ index: index++
736
+ };
737
+ return $$.getArc(d, true, true);
738
+ });
739
+ backgroundArc.exit().remove();
740
+ } else backgroundArc.attr("d", showEmptyTextLabel ? "M 0 0" : () => {
741
+ return $$.getArc({
742
+ data: [{ value: config.gauge_max }],
743
+ startAngle,
744
+ endAngle
745
+ }, true, true);
746
+ });
747
+ },
748
+ bindArcEvent(arc) {
749
+ const $$ = this;
750
+ const { config, state } = $$;
751
+ const isTouch = state.inputType === "touch";
752
+ const isMouse = state.inputType === "mouse";
753
+ const _getArcData = (d) => {
754
+ const updated = $$.updateAngle(d);
755
+ return updated ? $$.convertToArcData(updated) : null;
756
+ };
757
+ function selectArc(_this, arcData, id) {
758
+ $$.expandArc(id);
759
+ $$.api.focus(id);
760
+ $$.toggleFocusLegend(id, true);
761
+ $$.showTooltip([arcData], _this);
762
+ }
763
+ function unselectArc(arcData) {
764
+ $$.unexpandArc(arcData?.id || void 0);
765
+ $$.api.revert();
766
+ $$.revertLegend();
767
+ $$.hideTooltip();
768
+ }
769
+ arc.on("click", function(event, d, i) {
770
+ const arcData = _getArcData(d);
771
+ if (arcData) {
772
+ $$.toggleShape?.(this, arcData, i);
773
+ config.data_onclick.bind($$.api)(arcData, this);
774
+ }
775
+ });
776
+ if (isMouse) arc.on("mouseover", function(event, d) {
777
+ if (state.transiting) return;
778
+ state.event = event;
779
+ const arcData = _getArcData(d);
780
+ const id = arcData?.id || void 0;
781
+ selectArc(this, arcData, id);
782
+ $$.setOverOut(true, arcData);
783
+ }).on("mouseout", (event, d) => {
784
+ if (state.transiting || !config.interaction_onout) return;
785
+ state.event = event;
786
+ const arcData = _getArcData(d);
787
+ unselectArc();
788
+ $$.setOverOut(false, arcData);
789
+ }).on("mousemove", function(event, d) {
790
+ const arcData = _getArcData(d);
791
+ state.event = event;
792
+ $$.showTooltip([arcData], this);
793
+ });
794
+ if (isTouch && $$.hasArcType() && !$$.radars) {
795
+ const getEventArc = (event) => {
796
+ const { clientX, clientY } = event.changedTouches?.[0] ?? {
797
+ clientX: 0,
798
+ clientY: 0
799
+ };
800
+ return select(doc.elementFromPoint(clientX, clientY));
801
+ };
802
+ $$.$el.svg.on("touchstart touchmove", function(event) {
803
+ if (state.transiting) return;
804
+ state.event = event;
805
+ const datum = getEventArc(event).datum();
806
+ const updated = datum?.data && datum.data.id ? $$.updateAngle(datum) : null;
807
+ const arcData = updated ? $$.convertToArcData(updated) : null;
808
+ const id = arcData?.id || void 0;
809
+ $$.callOverOutForTouch(arcData);
810
+ isUndefined(id) ? unselectArc() : selectArc(this, arcData, id);
811
+ }, { passive: true });
812
+ }
813
+ },
814
+ redrawArcText(duration) {
815
+ const $$ = this;
816
+ const { config, state, $el: { main, arcs } } = $$;
817
+ const hasGauge = $$.hasType("gauge");
818
+ const hasMultiArcGauge = $$.hasMultiArcGauge();
819
+ let text;
820
+ if (!(hasGauge && $$.data.targets.length === 1 && config.gauge_title)) {
821
+ text = main.selectAll(`.${$ARC.chartArc}`).select("text").style("opacity", "0").attr("class", (d) => $$.isGaugeType(d.data) ? $GAUGE.gaugeValue : null).call($$.textForArcLabel.bind($$)).style("font-size", (d) => $$.isGaugeType(d.data) && $$.data.targets.length === 1 && !hasMultiArcGauge ? `${Math.round(state.radius / 5)}px` : null);
822
+ updateTextImage.call($$);
823
+ text.attr("transform", function(d) {
824
+ return $$.transformForArcLabel.bind($$)(this, d);
825
+ }).transition().duration(duration).style("opacity", (d) => $$.isTargetToShow(d.data.id) && $$.isArcType(d.data) ? null : "0");
826
+ hasMultiArcGauge && text.attr("dy", "-.1em");
827
+ }
828
+ main.select(`.${$ARC.chartArcsTitle}`).style("opacity", $$.hasType("donut") || hasGauge ? null : "0");
829
+ if (hasGauge) {
830
+ const isFullCircle = config.gauge_fullCircle;
831
+ isFullCircle && text?.attr("dy", `${hasMultiArcGauge ? 0 : Math.round(state.radius / 14)}`);
832
+ if (config.gauge_label_show) {
833
+ arcs.select(`.${$GAUGE.chartArcsGaugeUnit}`).attr("dy", `${isFullCircle ? 1.5 : .75}em`).text(config.gauge_units);
834
+ arcs.select(`.${$GAUGE.chartArcsGaugeMin}`).attr("dx", `${-1 * (state.innerRadius + (state.radius - state.innerRadius) / (isFullCircle ? 1 : 2))}px`).attr("dy", "1.2em").text($$.textForGaugeMinMax(config.gauge_min, false));
835
+ !isFullCircle && arcs.select(`.${$GAUGE.chartArcsGaugeMax}`).attr("dx", `${state.innerRadius + (state.radius - state.innerRadius) / 2}px`).attr("dy", "1.2em").text($$.textForGaugeMinMax(config.gauge_max, true));
836
+ }
837
+ }
838
+ isLabelWithLine.call($$) && redrawArcLabelLines.call($$, duration);
839
+ },
840
+ /**
841
+ * Get Arc element by id or index
842
+ * @param {string|number} value id or index of Arc
843
+ * @returns {d3Selection} Arc path element
844
+ * @private
845
+ */
846
+ getArcElementByIdOrIndex(value) {
847
+ const { $el: { arcs } } = this;
848
+ const filterFn = isNumber(value) ? (d) => d.index === value : (d) => d.data.id === value;
849
+ return arcs?.selectAll(`.${$COMMON.target} path`).filter(filterFn);
850
+ }
1138
851
  };
1139
-
1140
- export { shapeArc as default };
852
+ //#endregion
853
+ export { arc_default as default };