billboard.js 4.0.3 → 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 (270) hide show
  1. package/README.md +82 -7
  2. package/dist/billboard.css +1 -1
  3. package/dist/billboard.js +1841 -491
  4. package/dist/billboard.min.css +1 -1
  5. package/dist/billboard.min.js +19 -24
  6. package/dist/billboard.pkgd.js +1837 -676
  7. package/dist/billboard.pkgd.min.js +24 -29
  8. package/dist/billboard.react.js +205 -0
  9. package/dist/billboard.react.min.js +9 -0
  10. package/dist/billboard.worker.js +10 -0
  11. package/dist/plugin/billboardjs-plugin-bubblecompare.js +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 -143
  50. package/dist-esm/Chart/api/grid.js +191 -190
  51. package/dist-esm/Chart/api/group.js +31 -34
  52. package/dist-esm/Chart/api/legend.js +54 -63
  53. package/dist-esm/Chart/api/load.js +237 -257
  54. package/dist-esm/Chart/api/regions.js +148 -168
  55. package/dist-esm/Chart/api/selection.js +181 -139
  56. package/dist-esm/Chart/api/show.js +133 -147
  57. package/dist-esm/Chart/api/stubs.js +43 -42
  58. package/dist-esm/Chart/api/subchart.js +155 -172
  59. package/dist-esm/Chart/api/tooltip.js +132 -177
  60. package/dist-esm/Chart/api/x.js +67 -71
  61. package/dist-esm/Chart/api/zoom.js +183 -220
  62. package/dist-esm/ChartInternal/Axis/Axis.js +1059 -1266
  63. package/dist-esm/ChartInternal/Axis/AxisRenderer.js +408 -540
  64. package/dist-esm/ChartInternal/Axis/AxisRendererHelper.js +113 -149
  65. package/dist-esm/ChartInternal/ChartInternal.js +573 -749
  66. package/dist-esm/ChartInternal/data/convert.helper.js +133 -159
  67. package/dist-esm/ChartInternal/data/convert.js +200 -229
  68. package/dist-esm/ChartInternal/data/data.js +967 -1153
  69. package/dist-esm/ChartInternal/data/load.js +145 -197
  70. package/dist-esm/ChartInternal/interactions/drag.js +86 -122
  71. package/dist-esm/ChartInternal/interactions/eventrect.js +455 -621
  72. package/dist-esm/ChartInternal/interactions/flow.js +151 -215
  73. package/dist-esm/ChartInternal/interactions/interaction.js +214 -252
  74. package/dist-esm/ChartInternal/interactions/subchart.js +425 -300
  75. package/dist-esm/ChartInternal/interactions/zoom.js +321 -440
  76. package/dist-esm/ChartInternal/internals/category.js +18 -18
  77. package/dist-esm/ChartInternal/internals/class.js +89 -99
  78. package/dist-esm/ChartInternal/internals/clip.js +88 -119
  79. package/dist-esm/ChartInternal/internals/color.js +233 -288
  80. package/dist-esm/ChartInternal/internals/domain.js +452 -588
  81. package/dist-esm/ChartInternal/internals/format.js +64 -77
  82. package/dist-esm/ChartInternal/internals/grid.js +333 -457
  83. package/dist-esm/ChartInternal/internals/legend.js +675 -927
  84. package/dist-esm/ChartInternal/internals/redraw.js +200 -289
  85. package/dist-esm/ChartInternal/internals/region.js +106 -159
  86. package/dist-esm/ChartInternal/internals/scale.js +186 -215
  87. package/dist-esm/ChartInternal/internals/selection.js +132 -159
  88. package/dist-esm/ChartInternal/internals/size.axis.js +92 -139
  89. package/dist-esm/ChartInternal/internals/size.js +286 -394
  90. package/dist-esm/ChartInternal/internals/style.js +39 -41
  91. package/dist-esm/ChartInternal/internals/subchart.util.js +49 -0
  92. package/dist-esm/ChartInternal/internals/text.arc.js +155 -219
  93. package/dist-esm/ChartInternal/internals/text.js +368 -528
  94. package/dist-esm/ChartInternal/internals/text.util.js +179 -239
  95. package/dist-esm/ChartInternal/internals/title.js +96 -121
  96. package/dist-esm/ChartInternal/internals/tooltip.js +450 -586
  97. package/dist-esm/ChartInternal/internals/transform.js +79 -97
  98. package/dist-esm/ChartInternal/internals/type.js +285 -236
  99. package/dist-esm/ChartInternal/shape/arc.js +825 -1112
  100. package/dist-esm/ChartInternal/shape/area.js +73 -94
  101. package/dist-esm/ChartInternal/shape/bar.js +227 -288
  102. package/dist-esm/ChartInternal/shape/bubble.js +9 -8
  103. package/dist-esm/ChartInternal/shape/candlestick.js +110 -138
  104. package/dist-esm/ChartInternal/shape/core/barRadius.js +197 -133
  105. package/dist-esm/ChartInternal/shape/core/bubble.js +64 -73
  106. package/dist-esm/ChartInternal/shape/core/candlestick.js +93 -86
  107. package/dist-esm/ChartInternal/shape/core/dataRegion.js +68 -75
  108. package/dist-esm/ChartInternal/shape/core/geometry.js +112 -112
  109. package/dist-esm/ChartInternal/shape/core/path.js +142 -115
  110. package/dist-esm/ChartInternal/shape/core/point.js +105 -125
  111. package/dist-esm/ChartInternal/shape/core/treemap.js +83 -88
  112. package/dist-esm/ChartInternal/shape/funnel.js +310 -338
  113. package/dist-esm/ChartInternal/shape/gauge.js +71 -103
  114. package/dist-esm/ChartInternal/shape/line.js +208 -278
  115. package/dist-esm/ChartInternal/shape/point.js +310 -425
  116. package/dist-esm/ChartInternal/shape/polar.js +84 -109
  117. package/dist-esm/ChartInternal/shape/radar.js +228 -318
  118. package/dist-esm/ChartInternal/shape/shape.js +782 -843
  119. package/dist-esm/ChartInternal/shape/treemap.js +152 -190
  120. package/dist-esm/canvas/CanvasAxisRenderer.js +1180 -1328
  121. package/dist-esm/canvas/CanvasEngine.js +148 -166
  122. package/dist-esm/canvas/CanvasPainter.js +395 -411
  123. package/dist-esm/canvas/CanvasRenderer.js +1584 -1834
  124. package/dist-esm/canvas/CanvasTheme.js +899 -802
  125. package/dist-esm/canvas/HitDetector.js +394 -463
  126. package/dist-esm/canvas/axisTicks.js +672 -786
  127. package/dist-esm/canvas/classes.js +19 -17
  128. package/dist-esm/canvas/color.js +40 -59
  129. package/dist-esm/canvas/geometry.js +38 -38
  130. package/dist-esm/canvas/labels.js +318 -371
  131. package/dist-esm/canvas/pointPattern.js +578 -580
  132. package/dist-esm/canvas/util.js +242 -262
  133. package/dist-esm/config/Options/Options.js +29 -32
  134. package/dist-esm/config/Options/axis/axis.js +101 -101
  135. package/dist-esm/config/Options/axis/x.js +759 -755
  136. package/dist-esm/config/Options/axis/y.js +525 -522
  137. package/dist-esm/config/Options/axis/y2.js +501 -485
  138. package/dist-esm/config/Options/common/boost.js +93 -32
  139. package/dist-esm/config/Options/common/color.js +88 -87
  140. package/dist-esm/config/Options/common/grid.js +74 -73
  141. package/dist-esm/config/Options/common/legend.js +180 -179
  142. package/dist-esm/config/Options/common/main.js +474 -473
  143. package/dist-esm/config/Options/common/point.js +160 -159
  144. package/dist-esm/config/Options/common/title.js +47 -46
  145. package/dist-esm/config/Options/common/tooltip.js +253 -252
  146. package/dist-esm/config/Options/data/axis.js +173 -172
  147. package/dist-esm/config/Options/data/data.js +958 -957
  148. package/dist-esm/config/Options/data/selection.js +131 -130
  149. package/dist-esm/config/Options/interaction/interaction.js +53 -52
  150. package/dist-esm/config/Options/interaction/subchart.js +164 -73
  151. package/dist-esm/config/Options/interaction/zoom.js +86 -85
  152. package/dist-esm/config/Options/shape/arc.js +150 -149
  153. package/dist-esm/config/Options/shape/area.js +69 -68
  154. package/dist-esm/config/Options/shape/bar.js +147 -146
  155. package/dist-esm/config/Options/shape/bubble.js +35 -34
  156. package/dist-esm/config/Options/shape/candlestick.js +61 -60
  157. package/dist-esm/config/Options/shape/donut.js +181 -180
  158. package/dist-esm/config/Options/shape/funnel.js +49 -48
  159. package/dist-esm/config/Options/shape/gauge.js +237 -236
  160. package/dist-esm/config/Options/shape/line.js +58 -57
  161. package/dist-esm/config/Options/shape/pie.js +185 -184
  162. package/dist-esm/config/Options/shape/polar.js +167 -166
  163. package/dist-esm/config/Options/shape/radar.js +76 -75
  164. package/dist-esm/config/Options/shape/scatter.js +36 -36
  165. package/dist-esm/config/Options/shape/spline.js +46 -46
  166. package/dist-esm/config/Options/shape/treemap.js +80 -79
  167. package/dist-esm/config/Store/Element.js +64 -62
  168. package/dist-esm/config/Store/State.js +189 -200
  169. package/dist-esm/config/Store/Store.js +25 -26
  170. package/dist-esm/config/classes.js +157 -155
  171. package/dist-esm/config/config.js +26 -35
  172. package/dist-esm/config/const.js +120 -128
  173. package/dist-esm/config/resolver/axis.core.js +25 -25
  174. package/dist-esm/config/resolver/axis.js +26 -27
  175. package/dist-esm/config/resolver/canvas.js +2071 -2472
  176. package/dist-esm/config/resolver/canvasShape.js +201 -177
  177. package/dist-esm/config/resolver/category.js +26 -27
  178. package/dist-esm/config/resolver/export.js +24 -26
  179. package/dist-esm/config/resolver/flow.js +29 -31
  180. package/dist-esm/config/resolver/grid.js +34 -35
  181. package/dist-esm/config/resolver/interaction/selection.js +17 -17
  182. package/dist-esm/config/resolver/interaction/subchart.js +17 -17
  183. package/dist-esm/config/resolver/interaction/zoom.js +17 -17
  184. package/dist-esm/config/resolver/regions.js +30 -31
  185. package/dist-esm/config/resolver/shape/arc.helpers.js +19 -19
  186. package/dist-esm/config/resolver/shape/area.js +17 -17
  187. package/dist-esm/config/resolver/shape/axis.helpers.js +28 -25
  188. package/dist-esm/config/resolver/shape/bar.js +13 -13
  189. package/dist-esm/config/resolver/shape/bubble.js +18 -14
  190. package/dist-esm/config/resolver/shape/candlestick.js +13 -13
  191. package/dist-esm/config/resolver/shape/donut.js +11 -11
  192. package/dist-esm/config/resolver/shape/funnel.js +11 -11
  193. package/dist-esm/config/resolver/shape/gauge.js +12 -12
  194. package/dist-esm/config/resolver/shape/line.js +10 -10
  195. package/dist-esm/config/resolver/shape/pie.js +11 -11
  196. package/dist-esm/config/resolver/shape/polar.js +12 -12
  197. package/dist-esm/config/resolver/shape/radar.js +22 -14
  198. package/dist-esm/config/resolver/shape/scatter.js +13 -13
  199. package/dist-esm/config/resolver/shape/treemap.js +11 -11
  200. package/dist-esm/core.js +208 -211
  201. package/dist-esm/index.canvas.js +14 -13
  202. package/dist-esm/index.esm.js +25 -24
  203. package/dist-esm/module/Cache.js +117 -129
  204. package/dist-esm/module/browser.js +30 -35
  205. package/dist-esm/module/dsv.js +107 -127
  206. package/dist-esm/module/error.js +45 -52
  207. package/dist-esm/module/generator.js +75 -83
  208. package/dist-esm/module/sanitize.js +302 -399
  209. package/dist-esm/module/util/brush.js +27 -38
  210. package/dist-esm/module/util/dom.js +288 -348
  211. package/dist-esm/module/util/object.js +277 -341
  212. package/dist-esm/module/util/type-checks.js +21 -25
  213. package/dist-esm/module/worker.js +312 -130
  214. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +185 -198
  215. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +442 -450
  216. package/dist-esm/plugin/billboardjs-plugin-stanford.js +813 -950
  217. package/dist-esm/plugin/billboardjs-plugin-tableview.js +708 -788
  218. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +344 -301
  219. package/dist-esm/react/index.js +157 -0
  220. package/package.json +28 -8
  221. package/src/Chart/api/selection.ts +130 -5
  222. package/src/ChartInternal/Axis/Axis.ts +164 -65
  223. package/src/ChartInternal/Axis/AxisRenderer.ts +41 -8
  224. package/src/ChartInternal/Axis/AxisRendererHelper.ts +1 -1
  225. package/src/ChartInternal/ChartInternal.ts +1 -1
  226. package/src/ChartInternal/data/convert.ts +54 -4
  227. package/src/ChartInternal/data/data.ts +4 -1
  228. package/src/ChartInternal/interactions/eventrect.ts +6 -0
  229. package/src/ChartInternal/interactions/subchart.ts +437 -66
  230. package/src/ChartInternal/internals/color.ts +2 -2
  231. package/src/ChartInternal/internals/domain.ts +15 -3
  232. package/src/ChartInternal/internals/grid.ts +21 -1
  233. package/src/ChartInternal/internals/scale.ts +9 -2
  234. package/src/ChartInternal/internals/selection.ts +1 -1
  235. package/src/ChartInternal/internals/subchart.util.ts +55 -0
  236. package/src/ChartInternal/internals/text.arc.ts +3 -1
  237. package/src/ChartInternal/internals/text.ts +18 -5
  238. package/src/ChartInternal/internals/transform.ts +8 -2
  239. package/src/ChartInternal/internals/type.ts +105 -1
  240. package/src/ChartInternal/shape/IShape.ts +6 -3
  241. package/src/ChartInternal/shape/bar.ts +62 -31
  242. package/src/ChartInternal/shape/core/barRadius.ts +129 -0
  243. package/src/ChartInternal/shape/core/candlestick.ts +1 -1
  244. package/src/ChartInternal/shape/core/path.ts +76 -9
  245. package/src/ChartInternal/shape/funnel.ts +2 -3
  246. package/src/ChartInternal/shape/point.ts +2 -2
  247. package/src/ChartInternal/shape/shape.ts +149 -17
  248. package/src/Plugin/stanford/index.ts +0 -4
  249. package/src/Plugin/tableview/index.ts +85 -3
  250. package/src/Plugin/textoverlap/index.ts +9 -15
  251. package/src/canvas/CanvasAxisRenderer.ts +184 -36
  252. package/src/canvas/CanvasRenderer.ts +247 -160
  253. package/src/canvas/CanvasTheme.ts +212 -0
  254. package/src/canvas/axisTicks.ts +122 -40
  255. package/src/config/Options/axis/y2.ts +13 -0
  256. package/src/config/Options/common/boost.ts +64 -4
  257. package/src/config/Options/common/color.ts +2 -2
  258. package/src/config/Options/interaction/subchart.ts +98 -1
  259. package/src/config/Options/shape/gauge.ts +1 -1
  260. package/src/config/Options/shape/treemap.ts +2 -2
  261. package/src/config/Store/Element.ts +3 -1
  262. package/src/config/Store/State.ts +1 -0
  263. package/src/config/classes.ts +1 -0
  264. package/src/config/resolver/canvas.ts +92 -10
  265. package/src/module/voronoi.ts +119 -0
  266. package/src/module/worker.entry.ts +61 -0
  267. package/src/module/worker.ts +346 -63
  268. package/src/react/index.ts +193 -0
  269. package/types/options.d.ts +206 -3
  270. package/types/react/index.d.ts +27 -0
@@ -5,871 +5,810 @@
5
5
  * billboard.js, JavaScript chart library
6
6
  * https://naver.github.io/billboard.js/
7
7
  *
8
- * @version 4.0.3
8
+ * @version 4.1.0-next.1
9
9
  */
10
- import { select } from 'd3-selection';
11
- import { curveStepBefore, curveStepAfter, curveStep, curveLinear, curveLinearClosed, curveNatural, curveMonotoneY, curveMonotoneX, curveCatmullRomOpen, curveCatmullRomClosed, curveCatmullRom, curveCardinalOpen, curveCardinalClosed, curveCardinal, curveBundle, curveBasisOpen, curveBasisClosed, curveBasis } from 'd3-shape';
12
- import CLASS from '../../config/classes.js';
13
- import { KEY } from '../../module/Cache.js';
14
- import { getPointer, getRectSegList } from '../../module/util/dom.js';
15
- import { isValue, isObjectType, isFunction, isNumber, notEmpty, isUndefined } from '../../module/util/type-checks.js';
16
- import { parseDate, getUnique, capitalize } from '../../module/util/object.js';
17
-
10
+ import { TYPE } from "../../config/const.js";
11
+ import { isFunction, isNumber, isObjectType, isUndefined, isValue, notEmpty } from "../../module/util/type-checks.js";
12
+ import { capitalize, getUnique, parseDate } from "../../module/util/object.js";
13
+ import { getPointer, getRectSegList } from "../../module/util/dom.js";
14
+ import classes_default from "../../config/classes.js";
15
+ import { KEY } from "../../module/Cache.js";
16
+ import { select } from "d3-selection";
17
+ import { curveBasis, curveBasisClosed, curveBasisOpen, curveBundle, curveCardinal, curveCardinalClosed, curveCardinalOpen, curveCatmullRom, curveCatmullRomClosed, curveCatmullRomOpen, curveLinear, curveLinearClosed, curveMonotoneX, curveMonotoneY, curveNatural, curveStep, curveStepAfter, curveStepBefore } from "d3-shape";
18
+ //#region src/ChartInternal/shape/shape.ts
18
19
  /**
19
- * Copyright (c) 2017 ~ present NAVER Corp.
20
- * billboard.js project is licensed under the MIT license
21
- */
22
- // Module-level constant: avoids re-creating the lookup object on every getInterpolate() call
20
+ * Copyright (c) 2017 ~ present NAVER Corp.
21
+ * billboard.js project is licensed under the MIT license
22
+ */
23
23
  const CURVE_MAP = {
24
- basis: curveBasis,
25
- "basis-closed": curveBasisClosed,
26
- "basis-open": curveBasisOpen,
27
- bundle: curveBundle,
28
- cardinal: curveCardinal,
29
- "cardinal-closed": curveCardinalClosed,
30
- "cardinal-open": curveCardinalOpen,
31
- "catmull-rom": curveCatmullRom,
32
- "catmull-rom-closed": curveCatmullRomClosed,
33
- "catmull-rom-open": curveCatmullRomOpen,
34
- "monotone-x": curveMonotoneX,
35
- "monotone-y": curveMonotoneY,
36
- natural: curveNatural,
37
- "linear-closed": curveLinearClosed,
38
- linear: curveLinear,
39
- step: curveStep,
40
- "step-after": curveStepAfter,
41
- "step-before": curveStepBefore
24
+ basis: curveBasis,
25
+ "basis-closed": curveBasisClosed,
26
+ "basis-open": curveBasisOpen,
27
+ bundle: curveBundle,
28
+ cardinal: curveCardinal,
29
+ "cardinal-closed": curveCardinalClosed,
30
+ "cardinal-open": curveCardinalOpen,
31
+ "catmull-rom": curveCatmullRom,
32
+ "catmull-rom-closed": curveCatmullRomClosed,
33
+ "catmull-rom-open": curveCatmullRomOpen,
34
+ "monotone-x": curveMonotoneX,
35
+ "monotone-y": curveMonotoneY,
36
+ natural: curveNatural,
37
+ "linear-closed": curveLinearClosed,
38
+ linear: curveLinear,
39
+ step: curveStep,
40
+ "step-after": curveStepAfter,
41
+ "step-before": curveStepBefore
42
42
  };
43
43
  /**
44
- * Check if a target can use line-like grouped point offsets.
45
- * @param {object} $$ ChartInternal instance
46
- * @param {object|string} d Data value, target or id
47
- * @returns {boolean} Whether target uses point-like y coordinates
48
- * @private
49
- */
44
+ * Check if a target can use line-like grouped point offsets.
45
+ * @param {object} $$ ChartInternal instance
46
+ * @param {object|string} d Data value, target or id
47
+ * @returns {boolean} Whether target uses point-like y coordinates
48
+ * @private
49
+ */
50
50
  function isLinePointGroupType($$, d) {
51
- return $$.isLineType(d) || $$.isScatterType?.(d) || $$.isBubbleType?.(d);
51
+ return $$.isLineType(d) || $$.isScatterType?.(d) || $$.isBubbleType?.(d);
52
52
  }
53
53
  /**
54
- * Get type filter for grouped line-like point offsets.
55
- * @param {object} $$ ChartInternal instance
56
- * @returns {function} Type filter
57
- * @private
58
- */
54
+ * Get type filter for grouped line-like point offsets.
55
+ * @param {object} $$ ChartInternal instance
56
+ * @returns {function} Type filter
57
+ * @private
58
+ */
59
59
  function getLinePointGroupTypeFilter($$) {
60
- return d => isLinePointGroupType($$, d);
60
+ return (d) => isLinePointGroupType($$, d);
61
61
  }
62
62
  /**
63
- * Get numeric value used for stacked offset calculation.
64
- * @param {object} $$ ChartInternal instance
65
- * @param {object} d Data row
66
- * @returns {number|Array|object|null} Offset value
67
- * @private
68
- */
69
- function getShapeOffsetValue($$, d) {
70
- if ($$.isCandlestickType?.(d)) {
71
- return $$.getCandlestickData?.(d)?.close;
72
- }
73
- return $$.getBaseValue(d);
63
+ * Get numeric value used for stacked offset calculation.
64
+ * @param {object} $$ ChartInternal instance
65
+ * @param {object} d Data row
66
+ * @param {boolean} isSub Whether coordinates are for the subchart
67
+ * @returns {number|Array|object|null} Offset value
68
+ * @private
69
+ */
70
+ function getShapeOffsetValue($$, d, isSub) {
71
+ const subchartCandlestickValue = isSub ? getSubchartCandlestickShapeValue($$, d, isSub) : void 0;
72
+ if (isNumber(subchartCandlestickValue)) return subchartCandlestickValue;
73
+ if ($$.isCandlestickType?.(d)) return $$.getCandlestickData?.(d)?.close;
74
+ return $$.getBaseValue(d);
74
75
  }
75
76
  /**
76
- * Get grouped data point function for y coordinate
77
- * @param {object} d data vlaue
78
- * @returns {function|undefined}
79
- * @private
80
- */
77
+ * Get candlestick data projected for alternate subchart shapes.
78
+ * @param {object} $$ ChartInternal instance
79
+ * @param {object} d Data row
80
+ * @param {boolean} isSub Whether coordinates are for the subchart
81
+ * @returns {number|undefined} Projected value
82
+ * @private
83
+ */
84
+ function getSubchartCandlestickShapeValue($$, d, isSub) {
85
+ if (!isSub || $$.isCandlestickType?.(d) || !$$.isSubchartSourceTypeOf?.(d, TYPE.CANDLESTICK)) return;
86
+ const value = $$.getCandlestickData?.(d);
87
+ if (!value) return;
88
+ if ($$.isBarType(d)) return isNumber(value.open) && isNumber(value.close) ? value._isUp ? value.close : value.open : void 0;
89
+ return isNumber(value.close) ? value.close : void 0;
90
+ }
91
+ /**
92
+ * Check whether candlestick data can be projected as a subchart bar value.
93
+ * @param {object} $$ ChartInternal instance
94
+ * @param {object} d Data row
95
+ * @param {boolean} isSub Whether coordinates are for the subchart
96
+ * @returns {boolean}
97
+ * @private
98
+ */
99
+ function isSubchartCandlestickBarValue($$, d, isSub) {
100
+ return isNumber(getSubchartCandlestickShapeValue($$, d, isSub)) && $$.isBarType(d);
101
+ }
102
+ /**
103
+ * Get subchart bar color projected from candlestick up/down state.
104
+ * @param {object} $$ ChartInternal instance
105
+ * @param {object} d Data row
106
+ * @param {boolean} isSub Whether coordinates are for the subchart
107
+ * @returns {string|null} Bar color
108
+ * @private
109
+ */
110
+ function getSubchartCandlestickBarColor($$, d, isSub) {
111
+ if (!isSubchartCandlestickBarValue($$, d, isSub)) return null;
112
+ if (($$.getCandlestickData?.(d))?._isUp) return $$.color(d);
113
+ const downColor = $$.config.candlestick_color_down;
114
+ return (downColor && typeof downColor === "object" ? downColor[d.id] : downColor) || $$.color(d);
115
+ }
116
+ /**
117
+ * Get grouped data point function for y coordinate
118
+ * @param {object} d data vlaue
119
+ * @returns {function|undefined}
120
+ * @private
121
+ */
81
122
  function _getGroupedDataPointsFn(d) {
82
- const $$ = this;
83
- let fn;
84
- if (isLinePointGroupType($$, d)) {
85
- const typeFilter = getLinePointGroupTypeFilter($$);
86
- fn = $$.generateGetLinePoints($$.getShapeIndices(typeFilter), false, typeFilter);
87
- }
88
- else if ($$.isBarType(d)) {
89
- fn = $$.generateGetBarPoints($$.getShapeIndices($$.isBarType));
90
- }
91
- else if ($$.isCandlestickType?.(d)) {
92
- fn = $$.generateGetCandlestickPoints?.($$.getShapeIndices($$.isCandlestickType));
93
- }
94
- return fn;
123
+ const $$ = this;
124
+ let fn;
125
+ if (isLinePointGroupType($$, d)) {
126
+ const typeFilter = getLinePointGroupTypeFilter($$);
127
+ fn = $$.generateGetLinePoints($$.getShapeIndices(typeFilter), false, typeFilter);
128
+ } else if ($$.isBarType(d)) fn = $$.generateGetBarPoints($$.getShapeIndices($$.isBarType));
129
+ else if ($$.isCandlestickType?.(d)) fn = $$.generateGetCandlestickPoints?.($$.getShapeIndices($$.isCandlestickType));
130
+ return fn;
95
131
  }
96
132
  /**
97
- * Get shape color with gradient support
98
- * @param {object} d Data object
99
- * @param {string} configKey Configuration key for linearGradient (e.g., 'bar_linearGradient', 'area_linearGradient')
100
- * @param {(d: IDataRow) => string | null} colorFn Fallback color function when gradient is not enabled
101
- * @returns {string | null} Color string or gradient URL
102
- * @private
103
- */
133
+ * Get shape color with gradient support
134
+ * @param {object} d Data object
135
+ * @param {string} configKey Configuration key for linearGradient (e.g., 'bar_linearGradient', 'area_linearGradient')
136
+ * @param {function(IDataRow): string|null} colorFn Fallback color function when gradient is not enabled
137
+ * @returns {string | null} Color string or gradient URL
138
+ * @private
139
+ */
104
140
  function getShapeColorWithGradient(d, configKey, colorFn) {
105
- return this.config[configKey] ? this.getGradienColortUrl(d.id) : colorFn(d);
141
+ return this.config[configKey] ? this.getGradienColortUrl(d.id) : colorFn(d);
106
142
  }
107
143
  /**
108
- * Initialize a shape element container
109
- * @param {ShapeElementConfig} config Configuration object
110
- * @private
111
- */
144
+ * Initialize a shape element container
145
+ * @param {ShapeElementConfig} config Configuration object
146
+ * @private
147
+ */
112
148
  function initShapeElement(config) {
113
- const { $el } = this;
114
- const { elKey, className, cssRules, position } = config;
115
- const container = $el.main.select(`.${CLASS.chart}`);
116
- $el[elKey] = position === "first" ?
117
- container.insert("g", ":first-child") :
118
- container.append("g");
119
- $el[elKey].attr("class", className);
120
- if (cssRules?.length) {
121
- $el[elKey].call(this.setCssRule(false, `.${className}`, cssRules));
122
- }
149
+ const { $el } = this;
150
+ const { elKey, className, cssRules, position } = config;
151
+ const container = $el.main.select(`.${classes_default.chart}`);
152
+ $el[elKey] = position === "first" ? container.insert("g", ":first-child") : container.append("g");
153
+ $el[elKey].attr("class", className);
154
+ if (cssRules?.length) $el[elKey].call(this.setCssRule(false, `.${className}`, cssRules));
123
155
  }
124
156
  /**
125
- * Common update targets pattern for shapes
126
- * @param {Array} targets Target data
127
- * @param {UpdateTargetsConfig} config Configuration object
128
- * @returns {d3Selection} Enter selection for additional setup
129
- * @private
130
- */
157
+ * Common update targets pattern for shapes
158
+ * @param {Array} targets Target data
159
+ * @param {UpdateTargetsConfig} config Configuration object
160
+ * @returns {d3Selection} Enter selection for additional setup
161
+ * @private
162
+ */
131
163
  function updateTargetsForShape(targets, config) {
132
- const $$ = this;
133
- const { $el } = $$;
134
- const { type, elKey, containerClass, itemClass, initFn, withFocus = true, withStyles = true } = config;
135
- if (!$el[elKey]) {
136
- initFn.call($$);
137
- }
138
- const classChart = $$.getChartClass(type);
139
- const classFocus = withFocus ? $$.classFocus.bind($$) : () => "";
140
- const mainUpdate = $el.main.select(`.${containerClass}`)
141
- .selectAll(`.${itemClass}`)
142
- .data($$.filterNullish(targets))
143
- .attr("class", d => classChart(d) + classFocus(d));
144
- const mainEnter = mainUpdate.enter().append("g")
145
- .attr("class", classChart);
146
- if (withStyles) {
147
- mainEnter
148
- .style("opacity", "0")
149
- .style("pointer-events", $$.getStylePropValue("none"));
150
- }
151
- return mainEnter;
164
+ const $$ = this;
165
+ const { $el } = $$;
166
+ const { type, elKey, containerClass, itemClass, initFn, withFocus = true, withStyles = true } = config;
167
+ if (!$el[elKey]) initFn.call($$);
168
+ const classChart = $$.getChartClass(type);
169
+ const classFocus = withFocus ? $$.classFocus.bind($$) : () => "";
170
+ const mainEnter = $el.main.select(`.${containerClass}`).selectAll(`.${itemClass}`).data($$.filterNullish(targets)).attr("class", (d) => classChart(d) + classFocus(d)).enter().append("g").attr("class", classChart);
171
+ if (withStyles) mainEnter.style("opacity", "0").style("pointer-events", $$.getStylePropValue("none"));
172
+ return mainEnter;
152
173
  }
153
- var shape = {
154
- /**
155
- * Get the shape draw function
156
- * @returns {object}
157
- * @private
158
- */
159
- getDrawShape() {
160
- const $$ = this;
161
- const isRotated = $$.config.axis_rotated;
162
- const { hasRadar, hasTreemap } = $$.state;
163
- const shape = { type: {}, indices: {}, pos: {} };
164
- !hasTreemap && ["bar", "candlestick", "line", "area"].forEach(v => {
165
- const name = capitalize(v);
166
- if ($$.hasType(v) || $$.hasTypeOf(name) || (v === "line" &&
167
- ($$.hasType("bubble") || $$.hasType("scatter")))) {
168
- const indices = $$.getShapeIndices($$[`is${name}Type`]);
169
- const drawFn = $$[`generateDraw${name}`];
170
- shape.indices[v] = indices;
171
- shape.type[v] = drawFn ? drawFn.bind($$)(indices, false) : undefined;
172
- }
173
- });
174
- if (!$$.hasArcType() || hasRadar || hasTreemap) {
175
- let cx;
176
- let cy;
177
- let xForText;
178
- let yForText;
179
- // generate circle x/y functions depending on updated params
180
- if (!hasTreemap) {
181
- cx = hasRadar ? $$.radarCircleX : (isRotated ? $$.circleY : $$.circleX);
182
- cy = hasRadar ? $$.radarCircleY : (isRotated ? $$.circleX : $$.circleY);
183
- }
184
- if (hasTreemap && $$.state.isCanvasMode) {
185
- xForText = yForText = function () { };
186
- }
187
- else {
188
- xForText = $$.generateXYForText(shape.indices, true);
189
- yForText = $$.generateXYForText(shape.indices, false);
190
- }
191
- shape.pos = {
192
- xForText,
193
- yForText,
194
- cx: (cx || function () { }).bind($$),
195
- cy: (cy || function () { }).bind($$)
196
- };
197
- }
198
- return shape;
199
- },
200
- /**
201
- * Get shape's indices according it's position within each axis tick.
202
- *
203
- * From the below example, indices will be:
204
- * ==> {data1: 0, data2: 0, data3: 1, data4: 1, __max__: 1}
205
- *
206
- * data1 data3 data1 data3
207
- * data2 data4 data2 data4
208
- * -------------------------
209
- * 0 1
210
- * @param {function} typeFilter Chart type filter function
211
- * @returns {object} Indices object with its position
212
- */
213
- getShapeIndices(typeFilter) {
214
- const $$ = this;
215
- const { config } = $$;
216
- const xs = config.data_xs;
217
- const hasXs = notEmpty(xs);
218
- const indices = {};
219
- let i = hasXs ? {} : 0;
220
- if (hasXs) {
221
- getUnique(Object.keys(xs).map(v => xs[v]))
222
- .forEach(v => {
223
- i[v] = 0;
224
- indices[v] = {};
225
- });
226
- }
227
- $$.filterTargetsToShow($$.data.targets.filter(typeFilter, $$))
228
- .forEach(d => {
229
- const xKey = d.id in xs ? xs[d.id] : "";
230
- const ind = xKey ? indices[xKey] : indices;
231
- for (let j = 0, groups; (groups = config.data_groups[j]); j++) {
232
- if (groups.indexOf(d.id) < 0) {
233
- continue;
234
- }
235
- for (let k = 0, key; (key = groups[k]); k++) {
236
- if (key in ind) {
237
- ind[d.id] = ind[key];
238
- break;
239
- }
240
- // for same grouped data, add other data to same indices
241
- if (d.id !== key && xKey) {
242
- ind[key] = ind[d.id] ?? i[xKey];
243
- }
244
- }
245
- }
246
- if (isUndefined(ind[d.id])) {
247
- ind[d.id] = xKey ? i[xKey]++ : i++;
248
- ind.__max__ = (xKey ? i[xKey] : i) - 1;
249
- }
250
- });
251
- return indices;
252
- },
253
- /**
254
- * Get indices value based on data ID value
255
- * @param {object} indices Indices object
256
- * @param {object} d Data row
257
- * @param {string} caller Caller function name (Used only for 'sparkline' plugin)
258
- * @returns {object} Indices object
259
- * @private
260
- */
261
- getIndices(indices, d, caller) {
262
- const $$ = this;
263
- const { data_xs: xs, bar_indices_removeNull: removeNull } = $$.config;
264
- const { id, index } = d;
265
- if ($$.isBarType(id) && removeNull) {
266
- const ind = {};
267
- // redefine bar indices order
268
- $$.getAllValuesOnIndex(index, true)
269
- .forEach((v, i) => {
270
- ind[v.id] = i;
271
- ind.__max__ = i;
272
- });
273
- return ind;
274
- }
275
- return notEmpty(xs) ? indices[xs[id]] : indices;
276
- },
277
- /**
278
- * Get indices max number
279
- * @param {object} indices Indices object
280
- * @returns {number} Max number
281
- * @private
282
- */
283
- getIndicesMax(indices) {
284
- if (!notEmpty(this.config.data_xs)) {
285
- return indices.__max__;
286
- }
287
- // if is multiple xs, return total sum of xs' __max__ value
288
- let total = 0;
289
- for (const key in indices) {
290
- total += indices[key].__max__ || 0;
291
- }
292
- return total;
293
- },
294
- getShapeX(offset, indices, isSub) {
295
- const $$ = this;
296
- const { config, scale } = $$;
297
- const currScale = isSub ? scale.subX : (scale.zoom || scale.x);
298
- const barOverlap = config.bar_overlap;
299
- const barPadding = config.bar_padding;
300
- const sum = (p, c) => p + c;
301
- // total shapes half width
302
- const halfWidth = isObjectType(offset) && (offset._$total.length ? offset._$total.reduce(sum) / 2 : 0);
303
- // Pre-compute prefix sums to avoid O(n) slice+reduce on every bar datum
304
- const prefixSums = [];
305
- if (halfWidth && isObjectType(offset) && offset._$total.length) {
306
- let acc = 0;
307
- for (const v of offset._$total) {
308
- acc += v;
309
- prefixSums.push(acc);
310
- }
311
- }
312
- return d => {
313
- const ind = $$.getIndices(indices, d, "getShapeX");
314
- const index = d.id in ind ? ind[d.id] : 0;
315
- const targetsNum = (ind.__max__ || 0) + 1;
316
- let x = 0;
317
- if (notEmpty(d.x)) {
318
- const xPos = currScale(d.x, true);
319
- if (halfWidth) {
320
- const offsetWidth = offset[d.id] || offset._$width;
321
- x = barOverlap ? xPos - offsetWidth / 2 : xPos - offsetWidth +
322
- (prefixSums[index] ?? offset._$total.slice(0, index + 1).reduce(sum)) -
323
- halfWidth;
324
- }
325
- else {
326
- x = xPos - (isNumber(offset) ? offset : offset._$width) *
327
- (targetsNum / 2 - (barOverlap ? 1 : index));
328
- }
329
- }
330
- // adjust x position for bar.padding option
331
- if (offset && x && targetsNum > 1 && barPadding) {
332
- if (index) {
333
- x += barPadding * index;
334
- }
335
- if (targetsNum > 2) {
336
- x -= (targetsNum - 1) * barPadding / 2;
337
- }
338
- else if (targetsNum === 2) {
339
- x -= barPadding / 2;
340
- }
341
- }
342
- return x;
343
- };
344
- },
345
- getShapeY(isSub) {
346
- const $$ = this;
347
- const isStackNormalized = $$.isStackNormalized();
348
- return d => {
349
- let { value } = d;
350
- if (isNumber(d)) {
351
- value = d;
352
- }
353
- else if ($$.isAreaRangeType(d)) {
354
- value = $$.getBaseValue(d, "mid");
355
- }
356
- else if (isStackNormalized) {
357
- value = $$.getRatio("index", d, true);
358
- }
359
- else if ($$.isBubbleZType(d)) {
360
- value = $$.getBubbleZData(d.value, "y");
361
- }
362
- else if ($$.isBarRangeType(d)) {
363
- // TODO use range.getEnd() like method
364
- value = value[1];
365
- }
366
- return $$.getYScaleById(d.id, isSub)(value);
367
- };
368
- },
369
- /**
370
- * Get shape based y Axis min value
371
- * @param {string} id Data id
372
- * @returns {number}
373
- * @private
374
- */
375
- getShapeYMin(id) {
376
- const $$ = this;
377
- const axisId = $$.axis.getId(id);
378
- const scale = $$.scale[axisId];
379
- const [yMin] = scale.domain();
380
- const inverted = $$.config[`axis_${axisId}_inverted`];
381
- return !$$.isGrouped(id) && !inverted && yMin > 0 ? yMin : 0;
382
- },
383
- /**
384
- * Get Shape's offset data
385
- * @param {function} typeFilter Type filter function
386
- * @returns {object}
387
- * @private
388
- */
389
- getShapeOffsetData(typeFilter) {
390
- const $$ = this;
391
- const targets = $$.orderTargets($$.filterTargetsToShow($$.data.targets.filter(typeFilter, $$)));
392
- // Same IDs can receive new values through load()/flow(), so ID-only
393
- // caching can leave stacked offsets pointing at stale row maps.
394
- const dataGeneration = $$.state.dataGeneration;
395
- const targetIds = targets.map(t => t.id).join("_");
396
- const cacheKey = `${KEY.shapeOffset}_${targetIds}`;
397
- // Check if result is already cached
398
- const cachedData = $$.cache.get(cacheKey);
399
- if (cachedData?.generation === dataGeneration) {
400
- return cachedData;
401
- }
402
- const isStackNormalized = $$.isStackNormalized();
403
- const shapeOffsetTargets = targets.map(target => {
404
- let rowValues = target.values;
405
- const values = {};
406
- if ($$.isStepType(target)) {
407
- rowValues = $$.convertValuesToStep(rowValues);
408
- }
409
- const rowValueMapByXValue = rowValues.reduce((out, d) => {
410
- const key = Number(d.x);
411
- const value = getShapeOffsetValue($$, d);
412
- out[key] = d;
413
- values[key] = isStackNormalized ? $$.getRatio("index", d, true) : value;
414
- return out;
415
- }, {});
416
- return {
417
- id: target.id,
418
- rowValues,
419
- rowValueMapByXValue,
420
- values
421
- };
422
- });
423
- const indexMapByTargetId = targets.reduce((out, { id }, index) => {
424
- out[id] = index;
425
- return out;
426
- }, {});
427
- const result = { generation: dataGeneration, indexMapByTargetId, shapeOffsetTargets };
428
- // Cache the result
429
- $$.cache.add(cacheKey, result);
430
- return result;
431
- },
432
- getShapeOffset(typeFilter, indices, isSub) {
433
- const $$ = this;
434
- const { shapeOffsetTargets, indexMapByTargetId } = $$.getShapeOffsetData(typeFilter);
435
- const groupsZeroAs = $$.config.data_groupsZeroAs;
436
- // Pre-build per-series same-stacking-group lookup to avoid .filter() on every datum.
437
- // bar_indices_removeNull recomputes group membership per-datum index, so fall back there.
438
- let sameGroupByTargetId = null;
439
- if (!$$.config.bar_indices_removeNull) {
440
- sameGroupByTargetId = new Map();
441
- for (const target of shapeOffsetTargets) {
442
- const ind = $$.getIndices(indices, { id: target.id, index: 0 });
443
- sameGroupByTargetId.set(target.id, shapeOffsetTargets.filter(t => t.id !== target.id && ind[t.id] === ind[target.id]));
444
- }
445
- }
446
- return (d, idx) => {
447
- const { id, value, x } = d;
448
- const baseValue = getShapeOffsetValue($$, d);
449
- const ind = $$.getIndices(indices, d);
450
- const scale = $$.getYScaleById(id, isSub);
451
- if ($$.isBarRangeType(d)) {
452
- // TODO use range.getStart()
453
- return scale(value[0]);
454
- }
455
- const dataXAsNumber = Number(x);
456
- const y0 = scale(groupsZeroAs === "zero" ? 0 : $$.getShapeYMin(id));
457
- let offset = y0;
458
- const sameGroupTargets = sameGroupByTargetId?.get(id) ??
459
- shapeOffsetTargets.filter(t => t.id !== id && ind[t.id] === ind[id]);
460
- for (const t of sameGroupTargets) {
461
- const { id: tid, rowValueMapByXValue, rowValues, values: tvalues } = t;
462
- // for same stacked group (ind[tid] === ind[id])
463
- if (indexMapByTargetId[tid] < indexMapByTargetId[id]) {
464
- const rValue = tvalues[dataXAsNumber];
465
- let row = rowValues[idx];
466
- // check if the x values line up
467
- if (!row || Number(row.x) !== dataXAsNumber) {
468
- row = rowValueMapByXValue[dataXAsNumber];
469
- }
470
- const rowValue = row && getShapeOffsetValue($$, row);
471
- if (isNumber(rowValue) &&
472
- isNumber(baseValue) &&
473
- rowValue * baseValue >= 0 &&
474
- isNumber(rValue)) {
475
- const addOffset = baseValue === 0 ?
476
- ((groupsZeroAs === "positive" &&
477
- rValue > 0) ||
478
- (groupsZeroAs === "negative" && rValue < 0)) :
479
- true;
480
- if (addOffset) {
481
- offset += scale(rValue) - y0;
482
- }
483
- }
484
- }
485
- }
486
- return offset;
487
- };
488
- },
489
- /**
490
- * Generate line coordinate points from shared geometry.
491
- * @param {object} lineIndices Data order within x axis
492
- * @param {boolean} isSub Whether the coordinates are for subchart
493
- * @param {function} typeFilter Type filter for offset targets
494
- * @returns {function} Line point generator
495
- * @private
496
- */
497
- generateGetLinePoints(lineIndices, isSub, typeFilter) {
498
- const $$ = this;
499
- const { config } = $$;
500
- const x = $$.getShapeX(0, lineIndices, isSub);
501
- const y = $$.getShapeY(isSub);
502
- const lineOffset = $$.getShapeOffset(typeFilter || $$.isLineType, lineIndices, isSub);
503
- const yScale = $$.getYScaleById.bind($$);
504
- return (d, i) => {
505
- const y0 = yScale.call($$, d.id, isSub)($$.getShapeYMin(d.id));
506
- const offset = lineOffset(d, i) || y0;
507
- const posX = x(d);
508
- let posY = y(d);
509
- if (config.axis_rotated && ((d.value > 0 && posY < y0) || (d.value < 0 && y0 < posY))) {
510
- posY = y0;
511
- }
512
- const point = [posX, posY - (y0 - offset)];
513
- return [
514
- point,
515
- point,
516
- point,
517
- point
518
- ];
519
- };
520
- },
521
- /**
522
- * Generate area coordinate points from shared geometry.
523
- * @param {object} areaIndices Data order within x axis
524
- * @param {boolean} isSub Whether the coordinates are for subchart
525
- * @returns {function} Area point generator
526
- * @private
527
- */
528
- generateGetAreaPoints(areaIndices, isSub) {
529
- const $$ = this;
530
- const { config } = $$;
531
- const x = $$.getShapeX(0, areaIndices, isSub);
532
- const y = $$.getShapeY(!!isSub);
533
- const areaOffset = $$.getShapeOffset($$.isAreaType, areaIndices, isSub);
534
- const yScale = $$.getYScaleById.bind($$);
535
- // per-series cache: y0 depends only on the id and is stable within one draw pass
536
- const y0Cache = new Map();
537
- return function (d, i) {
538
- let y0 = y0Cache.get(d.id);
539
- if (y0 === undefined) {
540
- y0 = yScale.call($$, d.id, isSub)($$.getShapeYMin(d.id));
541
- y0Cache.set(d.id, y0);
542
- }
543
- const offset = areaOffset(d, i) || y0;
544
- const posX = x(d);
545
- const value = d.value;
546
- let posY = y(d);
547
- if (config.axis_rotated && ((value > 0 && posY < y0) || (value < 0 && y0 < posY))) {
548
- posY = y0;
549
- }
550
- return [
551
- [posX, offset],
552
- [posX, posY - (y0 - offset)],
553
- [posX, posY - (y0 - offset)],
554
- [posX, offset]
555
- ];
556
- };
557
- },
558
- /**
559
- * Generate bar coordinate points from shared geometry.
560
- * @param {object} barIndices Data order within x axis
561
- * @param {boolean} isSub Whether the coordinates are for subchart
562
- * @returns {function} Bar point generator
563
- * @private
564
- */
565
- generateGetBarPoints(barIndices, isSub) {
566
- const $$ = this;
567
- const { config } = $$;
568
- const axis = isSub ? $$.axis.subX : $$.axis.x;
569
- const barTargetsNum = $$.getIndicesMax(barIndices) + 1;
570
- const barW = $$.getBarW("bar", axis, barTargetsNum);
571
- const barX = $$.getShapeX(barW, barIndices, !!isSub);
572
- const barY = $$.getShapeY(!!isSub);
573
- const barOffset = $$.getShapeOffset($$.isBarType, barIndices, !!isSub);
574
- const yScale = $$.getYScaleById.bind($$);
575
- // per-series cache: y0/isInverted depend only on the id and are stable within one draw pass
576
- const idCache = new Map();
577
- return (d, i) => {
578
- const { id } = d;
579
- let idInfo = idCache.get(id);
580
- if (!idInfo) {
581
- idInfo = {
582
- y0: yScale.call($$, id, isSub)($$.getShapeYMin(id)),
583
- isInverted: config[`axis_${$$.axis.getId(id)}_inverted`]
584
- };
585
- idCache.set(id, idInfo);
586
- }
587
- const { y0, isInverted } = idInfo;
588
- const offset = barOffset(d, i) || y0;
589
- const width = isNumber(barW) ? barW : barW[d.id] || barW._$width;
590
- const value = d.value;
591
- const posX = barX(d);
592
- let posY = barY(d);
593
- if (config.axis_rotated && !isInverted && ((value > 0 && posY < y0) || (value < 0 && y0 < posY))) {
594
- posY = y0;
595
- }
596
- if (!$$.isBarRangeType(d)) {
597
- posY -= y0 - offset;
598
- }
599
- const startPosX = posX + width;
600
- return [
601
- [posX, offset],
602
- [posX, posY],
603
- [startPosX, posY],
604
- [startPosX, offset]
605
- ];
606
- };
607
- },
608
- /**
609
- * Get data's y coordinate
610
- * @param {object} d Target data
611
- * @param {number} i Index number
612
- * @returns {number} y coordinate
613
- * @private
614
- */
615
- circleY(d, i) {
616
- const $$ = this;
617
- const id = d.id;
618
- let points;
619
- if ($$.isGrouped(id)) {
620
- points = _getGroupedDataPointsFn.bind($$)(d);
621
- }
622
- return points ? points(d, i)[0][1] : $$.getYScaleById(id)($$.getBaseValue(d));
623
- },
624
- /**
625
- * Get data point x coordinate.
626
- * @param {object} d Data row
627
- * @returns {number|null} X coordinate
628
- * @private
629
- */
630
- circleX(d) {
631
- return this.xx(d);
632
- },
633
- /**
634
- * Generate data point y coordinate accessor.
635
- * @param {boolean} isSub Whether the coordinates are for subchart
636
- * @returns {function} Y coordinate accessor
637
- * @private
638
- */
639
- updateCircleY(isSub = false) {
640
- const $$ = this;
641
- const typeFilter = getLinePointGroupTypeFilter($$);
642
- const getPoints = $$.generateGetLinePoints($$.getShapeIndices(typeFilter), isSub, typeFilter);
643
- return (d, i) => {
644
- const id = d.id;
645
- return $$.isGrouped(id) && isLinePointGroupType($$, d) ?
646
- getPoints(d, i)[0][1] :
647
- $$.getYScaleById(id, isSub)($$.getBaseValue(d));
648
- };
649
- },
650
- /**
651
- * Get point radius.
652
- * @param {object} d Data row
653
- * @returns {number} Point radius
654
- * @private
655
- */
656
- pointR(d) {
657
- const $$ = this;
658
- const { config } = $$;
659
- const pointR = config.point_r;
660
- let r = pointR;
661
- if ($$.isBubbleType(d)) {
662
- r = $$.getBubbleR(d);
663
- }
664
- else if (isFunction(pointR)) {
665
- r = pointR.bind($$.api)(d);
666
- }
667
- d.r = r;
668
- return r;
669
- },
670
- /**
671
- * Get focused point radius.
672
- * @param {object} d Data row
673
- * @returns {number} Focused point radius
674
- * @private
675
- */
676
- pointExpandedR(d) {
677
- const $$ = this;
678
- const { config } = $$;
679
- const scale = $$.isBubbleType(d) ? 1.15 : 1.75;
680
- return config.point_focus_expand_enabled ?
681
- (config.point_focus_expand_r || $$.pointR(d) * scale) :
682
- $$.pointR(d);
683
- },
684
- /**
685
- * Get selected point radius.
686
- * @param {object} d Data row
687
- * @returns {number} Selected point radius
688
- * @private
689
- */
690
- pointSelectR(d) {
691
- const $$ = this;
692
- const selectR = $$.config.point_select_r;
693
- return isFunction(selectR) ? selectR(d) : (selectR || $$.pointR(d) * 4);
694
- },
695
- /**
696
- * Check if point.focus.only option can be applied.
697
- * @returns {boolean} Whether focus-only point rendering is active
698
- * @private
699
- */
700
- isPointFocusOnly() {
701
- const $$ = this;
702
- return $$.config.point_focus_only &&
703
- !$$.hasType("bubble") && !$$.hasType("scatter") && !$$.hasArcType(null, ["radar"]);
704
- },
705
- /**
706
- * Get data point sensitivity radius.
707
- * @param {object} d Data point
708
- * @returns {number} Sensitivity radius
709
- * @private
710
- */
711
- getPointSensitivity(d) {
712
- const $$ = this;
713
- let sensitivity = $$.config.point_sensitivity;
714
- if (!d) {
715
- return sensitivity;
716
- }
717
- else if (isFunction(sensitivity)) {
718
- sensitivity = sensitivity.call($$.api, d);
719
- }
720
- else if (sensitivity === "radius") {
721
- sensitivity = d.r;
722
- }
723
- return sensitivity;
724
- },
725
- getBarW(type, axis, targetsNum) {
726
- const $$ = this;
727
- const { config, org, scale, state } = $$;
728
- const maxDataCount = $$.getMaxDataCount();
729
- const isGrouped = type === "bar" && config.data_groups?.length;
730
- const configName = `${type}_width`;
731
- const { k } = $$.getZoomTransform?.() ?? { k: 1 };
732
- const xMinMax = [
733
- config.axis_x_min ?? org.xDomain[0],
734
- config.axis_x_max ?? org.xDomain[1]
735
- ].map(v => ($$.axis.isTimeSeries() ? parseDate.call($$, v) : Number(v)));
736
- let tickInterval = axis.tickInterval(maxDataCount);
737
- if (scale.zoom && !$$.axis.isCategorized() && k > 1) {
738
- const isSameMinMax = xMinMax.every((v, i) => v === org.xDomain[i]);
739
- tickInterval = org.xDomain.map((v, i) => {
740
- const value = isSameMinMax ? v : v - Math.abs(xMinMax[i]);
741
- return scale.zoom(value);
742
- }).reduce((a, c) => Math.abs(a) + c) / maxDataCount;
743
- }
744
- const getWidth = (id) => {
745
- const width = id ? config[configName][id] : config[configName];
746
- const ratio = id ? width.ratio : config[`${configName}_ratio`];
747
- const max = id ? width.max : config[`${configName}_max`];
748
- const w = isNumber(width) ? width : (isFunction(width) ?
749
- width.call($$, state.width, targetsNum, maxDataCount) :
750
- (targetsNum ? (tickInterval * ratio) / targetsNum : 0));
751
- return max && w > max ? max : w;
752
- };
753
- let result = getWidth();
754
- if (!isGrouped && isObjectType(config[configName])) {
755
- result = { _$width: result, _$total: [] };
756
- $$.getTargetsToShow().forEach(v => {
757
- if (config[configName][v.id]) {
758
- result[v.id] = getWidth(v.id);
759
- result._$total.push(result[v.id] || result._$width);
760
- }
761
- });
762
- }
763
- return result;
764
- },
765
- /**
766
- * Get shape element
767
- * @param {string} shapeName Shape string
768
- * @param {number} i Index number
769
- * @param {string} id Data series id
770
- * @returns {d3Selection}
771
- * @private
772
- */
773
- getShapeByIndex(shapeName, i, id) {
774
- const $$ = this;
775
- const { $el } = $$;
776
- const suffix = isValue(i) ? `-${i}` : ``;
777
- let shape = $el[shapeName];
778
- // filter from shape reference if has
779
- if (shape && !shape.empty()) {
780
- shape = shape
781
- .filter(d => (id ? d.id === id : true))
782
- .filter(d => (isValue(i) ? d.index === i : true));
783
- }
784
- else {
785
- shape = (id ?
786
- $el.main
787
- .selectAll(`.${CLASS[`${shapeName}s`]}${$$.getTargetSelectorSuffix(id)}`) :
788
- $el.main)
789
- .selectAll(`.${CLASS[shapeName]}${suffix}`);
790
- }
791
- return shape;
792
- },
793
- isWithinShape(that, d) {
794
- const $$ = this;
795
- const shape = select(that);
796
- let isWithin;
797
- if (!$$.isTargetToShow(d.id)) {
798
- isWithin = false;
799
- }
800
- else if ($$.hasValidPointType?.(that.nodeName)) {
801
- isWithin = $$.isStepType(d) ?
802
- $$.isWithinStep(that, $$.getYScaleById(d.id)($$.getBaseValue(d))) :
803
- $$.isWithinCircle(that, $$.isBubbleType(d) ? $$.pointSelectR(d) * 1.5 : 0);
804
- }
805
- else if (that.nodeName === "path") {
806
- isWithin = shape.classed(CLASS.bar) ? $$.isWithinBar(that) : true;
807
- }
808
- return isWithin;
809
- },
810
- getInterpolate(d) {
811
- const $$ = this;
812
- const interpolation = $$.getInterpolateType(d);
813
- return CURVE_MAP[interpolation];
814
- },
815
- /**
816
- * Get curve generator for line-like shapes.
817
- * @param {object} d Data target
818
- * @returns {function} Curve generator
819
- * @private
820
- */
821
- getCurve(d) {
822
- const $$ = this;
823
- const isRotatedStepType = $$.config.axis_rotated && $$.isStepType(d);
824
- // when is step & rotated, should be computed in different way
825
- // https://github.com/naver/billboard.js/issues/471
826
- return isRotatedStepType ?
827
- context => {
828
- const step = $$.getInterpolate(d)(context);
829
- // keep the original method
830
- step.orgPoint = step.point;
831
- // to get rotated path data
832
- step.pointRotated = function (x, y) {
833
- this._point === 1 && (this._point = 2);
834
- const y1 = this._y * (1 - this._t) + y * this._t;
835
- this._context.lineTo(this._x, y1);
836
- this._context.lineTo(x, y1);
837
- this._x = x;
838
- this._y = y;
839
- };
840
- step.point = function (x, y) {
841
- this._point === 0 ? this.orgPoint(x, y) : this.pointRotated(x, y);
842
- };
843
- return step;
844
- } :
845
- $$.getInterpolate(d);
846
- },
847
- getInterpolateType(d) {
848
- const $$ = this;
849
- const { config } = $$;
850
- const type = config.spline_interpolation_type;
851
- const interpolation = $$.isInterpolationType(type) ? type : "cardinal";
852
- return $$.isSplineType(d) ? interpolation : ($$.isStepType(d) ? config.line_step_type : "linear");
853
- },
854
- isWithinBar(that) {
855
- const mouse = getPointer(this.state.event, that);
856
- const list = getRectSegList(that);
857
- const [seg0, seg1, seg2] = list;
858
- const x = Math.min(seg0.x, seg1.x);
859
- const y = Math.min(seg0.y, seg1.y);
860
- const offset = this.config.bar_sensitivity;
861
- const width = Math.abs(seg2.x - seg1.x);
862
- const height = Math.abs(seg0.y - seg1.y);
863
- const sx = x - offset;
864
- const ex = x + width + offset;
865
- const sy = y + height + offset;
866
- const ey = y - offset;
867
- const isWithin = sx < mouse[0] &&
868
- mouse[0] < ex &&
869
- ey < mouse[1] &&
870
- mouse[1] < sy;
871
- return isWithin;
872
- }
174
+ var shape_default = {
175
+ /**
176
+ * Get the shape draw function
177
+ * @returns {object}
178
+ * @private
179
+ */
180
+ getDrawShape() {
181
+ const $$ = this;
182
+ const isRotated = $$.config.axis_rotated;
183
+ const { hasRadar, hasTreemap } = $$.state;
184
+ const shape = {
185
+ type: {},
186
+ indices: {},
187
+ pos: {}
188
+ };
189
+ !hasTreemap && [
190
+ "bar",
191
+ "candlestick",
192
+ "line",
193
+ "area"
194
+ ].forEach((v) => {
195
+ const name = capitalize(v);
196
+ if ($$.hasType(v) || $$.hasTypeOf(name) || v === "line" && ($$.hasType("bubble") || $$.hasType("scatter"))) {
197
+ const indices = $$.getShapeIndices($$[`is${name}Type`]);
198
+ const drawFn = $$[`generateDraw${name}`];
199
+ shape.indices[v] = indices;
200
+ shape.type[v] = drawFn ? drawFn.bind($$)(indices, false) : void 0;
201
+ }
202
+ });
203
+ if (!$$.hasArcType() || hasRadar || hasTreemap) {
204
+ let cx;
205
+ let cy;
206
+ let xForText;
207
+ let yForText;
208
+ if (!hasTreemap) {
209
+ cx = hasRadar ? $$.radarCircleX : isRotated ? $$.circleY : $$.circleX;
210
+ cy = hasRadar ? $$.radarCircleY : isRotated ? $$.circleX : $$.circleY;
211
+ }
212
+ if (hasTreemap && $$.state.isCanvasMode) xForText = yForText = function() {};
213
+ else {
214
+ xForText = $$.generateXYForText(shape.indices, true);
215
+ yForText = $$.generateXYForText(shape.indices, false);
216
+ }
217
+ shape.pos = {
218
+ xForText,
219
+ yForText,
220
+ cx: (cx || function() {}).bind($$),
221
+ cy: (cy || function() {}).bind($$)
222
+ };
223
+ }
224
+ return shape;
225
+ },
226
+ /**
227
+ * Get shape's indices according it's position within each axis tick.
228
+ *
229
+ * From the below example, indices will be:
230
+ * ==> {data1: 0, data2: 0, data3: 1, data4: 1, __max__: 1}
231
+ *
232
+ * data1 data3 data1 data3
233
+ * data2 data4 data2 data4
234
+ * -------------------------
235
+ * 0 1
236
+ * @param {function} typeFilter Chart type filter function
237
+ * @returns {object} Indices object with its position
238
+ */
239
+ getShapeIndices(typeFilter) {
240
+ const $$ = this;
241
+ const { config } = $$;
242
+ const xs = config.data_xs;
243
+ const hasXs = notEmpty(xs);
244
+ const indices = {};
245
+ let i = hasXs ? {} : 0;
246
+ if (hasXs) getUnique(Object.keys(xs).map((v) => xs[v])).forEach((v) => {
247
+ i[v] = 0;
248
+ indices[v] = {};
249
+ });
250
+ $$.filterTargetsToShow($$.data.targets.filter(typeFilter, $$)).forEach((d) => {
251
+ const xKey = d.id in xs ? xs[d.id] : "";
252
+ const ind = xKey ? indices[xKey] : indices;
253
+ for (let j = 0, groups; groups = config.data_groups[j]; j++) {
254
+ if (groups.indexOf(d.id) < 0) continue;
255
+ for (let k = 0, key; key = groups[k]; k++) {
256
+ if (key in ind) {
257
+ ind[d.id] = ind[key];
258
+ break;
259
+ }
260
+ if (d.id !== key && xKey) ind[key] = ind[d.id] ?? i[xKey];
261
+ }
262
+ }
263
+ if (isUndefined(ind[d.id])) {
264
+ ind[d.id] = xKey ? i[xKey]++ : i++;
265
+ ind.__max__ = (xKey ? i[xKey] : i) - 1;
266
+ }
267
+ });
268
+ return indices;
269
+ },
270
+ /**
271
+ * Get indices value based on data ID value
272
+ * @param {object} indices Indices object
273
+ * @param {object} d Data row
274
+ * @param {string} caller Caller function name (Used only for 'sparkline' plugin)
275
+ * @returns {object} Indices object
276
+ * @private
277
+ */
278
+ getIndices(indices, d, caller) {
279
+ const $$ = this;
280
+ const { data_xs: xs, bar_indices_removeNull: removeNull } = $$.config;
281
+ const { id, index } = d;
282
+ if ($$.isBarType(id) && removeNull) {
283
+ const ind = {};
284
+ $$.getAllValuesOnIndex(index, true).forEach((v, i) => {
285
+ ind[v.id] = i;
286
+ ind.__max__ = i;
287
+ });
288
+ return ind;
289
+ }
290
+ return notEmpty(xs) ? indices[xs[id]] : indices;
291
+ },
292
+ /**
293
+ * Get indices max number
294
+ * @param {object} indices Indices object
295
+ * @returns {number} Max number
296
+ * @private
297
+ */
298
+ getIndicesMax(indices) {
299
+ if (!notEmpty(this.config.data_xs)) return indices.__max__;
300
+ let total = 0;
301
+ for (const key in indices) total += indices[key].__max__ || 0;
302
+ return total;
303
+ },
304
+ getShapeX(offset, indices, isSub) {
305
+ const $$ = this;
306
+ const { config, scale } = $$;
307
+ const currScale = isSub ? scale.subX : scale.zoom || scale.x;
308
+ const barOverlap = config.bar_overlap;
309
+ const barPadding = config.bar_padding;
310
+ const sum = (p, c) => p + c;
311
+ const halfWidth = isObjectType(offset) && (offset._$total.length ? offset._$total.reduce(sum) / 2 : 0);
312
+ const prefixSums = [];
313
+ if (halfWidth && isObjectType(offset) && offset._$total.length) {
314
+ let acc = 0;
315
+ for (const v of offset._$total) {
316
+ acc += v;
317
+ prefixSums.push(acc);
318
+ }
319
+ }
320
+ return (d) => {
321
+ const ind = $$.getIndices(indices, d, "getShapeX");
322
+ const index = d.id in ind ? ind[d.id] : 0;
323
+ const targetsNum = (ind.__max__ || 0) + 1;
324
+ let x = 0;
325
+ if (notEmpty(d.x)) {
326
+ const xPos = currScale(d.x, true);
327
+ if (halfWidth) {
328
+ const offsetWidth = offset[d.id] || offset._$width;
329
+ x = barOverlap ? xPos - offsetWidth / 2 : xPos - offsetWidth + (prefixSums[index] ?? offset._$total.slice(0, index + 1).reduce(sum)) - halfWidth;
330
+ } else x = xPos - (isNumber(offset) ? offset : offset._$width) * (targetsNum / 2 - (barOverlap ? 1 : index));
331
+ }
332
+ if (offset && x && targetsNum > 1 && barPadding) {
333
+ if (index) x += barPadding * index;
334
+ if (targetsNum > 2) x -= (targetsNum - 1) * barPadding / 2;
335
+ else if (targetsNum === 2) x -= barPadding / 2;
336
+ }
337
+ return x;
338
+ };
339
+ },
340
+ getShapeY(isSub) {
341
+ const $$ = this;
342
+ const isStackNormalized = $$.isStackNormalized();
343
+ return (d) => {
344
+ let { value } = d;
345
+ const subchartCandlestickValue = isSub ? getSubchartCandlestickShapeValue($$, d, isSub) : void 0;
346
+ if (isNumber(d)) value = d;
347
+ else if (isNumber(subchartCandlestickValue)) value = subchartCandlestickValue;
348
+ else if ($$.isAreaRangeType(d)) value = $$.getBaseValue(d, "mid");
349
+ else if (isStackNormalized) value = $$.getRatio("index", d, true);
350
+ else if ($$.isBubbleZType(d)) value = $$.getBubbleZData(d.value, "y");
351
+ else if ($$.isBarRangeType(d)) value = value[1];
352
+ return $$.getYScaleById(d.id, isSub)(value);
353
+ };
354
+ },
355
+ /**
356
+ * Get shape based y Axis min value
357
+ * @param {string} id Data id
358
+ * @param {boolean} isSub Whether to use subchart scale
359
+ * @returns {number}
360
+ * @private
361
+ */
362
+ getShapeYMin(id, isSub = false) {
363
+ const $$ = this;
364
+ const axisId = $$.axis.getId(id);
365
+ const [yMin] = $$.getYScaleById(id, isSub).domain();
366
+ const inverted = $$.config[`axis_${axisId}_inverted`];
367
+ return !$$.isGrouped(id) && !inverted && yMin > 0 ? yMin : 0;
368
+ },
369
+ /**
370
+ * Get Shape's offset data
371
+ * @param {function} typeFilter Type filter function
372
+ * @param {boolean} isSub Whether coordinates are for the subchart
373
+ * @returns {object}
374
+ * @private
375
+ */
376
+ getShapeOffsetData(typeFilter, isSub) {
377
+ const $$ = this;
378
+ const targets = $$.orderTargets($$.filterTargetsToShow($$.data.targets.filter(typeFilter, $$)));
379
+ const dataGeneration = $$.state.dataGeneration;
380
+ const targetIds = targets.map((t) => t.id).join("_");
381
+ const cacheKey = `${KEY.shapeOffset}_${isSub ? "sub" : "main"}_${targetIds}`;
382
+ const cachedData = $$.cache.get(cacheKey);
383
+ if (cachedData?.generation === dataGeneration) return cachedData;
384
+ const isStackNormalized = $$.isStackNormalized();
385
+ const shapeOffsetTargets = targets.map((target) => {
386
+ let rowValues = target.values;
387
+ const values = {};
388
+ if ($$.isStepType(target)) rowValues = $$.convertValuesToStep(rowValues);
389
+ const rowValueMapByXValue = rowValues.reduce((out, d) => {
390
+ const key = Number(d.x);
391
+ const value = getShapeOffsetValue($$, d, isSub);
392
+ out[key] = d;
393
+ values[key] = isStackNormalized ? $$.getRatio("index", d, true) : value;
394
+ return out;
395
+ }, {});
396
+ return {
397
+ id: target.id,
398
+ rowValues,
399
+ rowValueMapByXValue,
400
+ values
401
+ };
402
+ });
403
+ const result = {
404
+ generation: dataGeneration,
405
+ indexMapByTargetId: targets.reduce((out, { id }, index) => {
406
+ out[id] = index;
407
+ return out;
408
+ }, {}),
409
+ shapeOffsetTargets
410
+ };
411
+ $$.cache.add(cacheKey, result);
412
+ return result;
413
+ },
414
+ getShapeOffset(typeFilter, indices, isSub) {
415
+ const $$ = this;
416
+ const { shapeOffsetTargets, indexMapByTargetId } = $$.getShapeOffsetData(typeFilter, isSub);
417
+ const groupsZeroAs = $$.config.data_groupsZeroAs;
418
+ let sameGroupByTargetId = null;
419
+ if (!$$.config.bar_indices_removeNull) {
420
+ sameGroupByTargetId = /* @__PURE__ */ new Map();
421
+ for (const target of shapeOffsetTargets) {
422
+ const ind = $$.getIndices(indices, {
423
+ id: target.id,
424
+ index: 0
425
+ });
426
+ sameGroupByTargetId.set(target.id, shapeOffsetTargets.filter((t) => t.id !== target.id && ind[t.id] === ind[target.id]));
427
+ }
428
+ }
429
+ return (d, idx) => {
430
+ const { id, value, x } = d;
431
+ const baseValue = getShapeOffsetValue($$, d, isSub);
432
+ const ind = $$.getIndices(indices, d);
433
+ const scale = $$.getYScaleById(id, isSub);
434
+ if ($$.isBarRangeType(d)) return scale(value[0]);
435
+ const dataXAsNumber = Number(x);
436
+ const y0 = scale(groupsZeroAs === "zero" ? 0 : $$.getShapeYMin(id, isSub));
437
+ let offset = y0;
438
+ const sameGroupTargets = sameGroupByTargetId?.get(id) ?? shapeOffsetTargets.filter((t) => t.id !== id && ind[t.id] === ind[id]);
439
+ for (const t of sameGroupTargets) {
440
+ const { id: tid, rowValueMapByXValue, rowValues, values: tvalues } = t;
441
+ if (indexMapByTargetId[tid] < indexMapByTargetId[id]) {
442
+ const rValue = tvalues[dataXAsNumber];
443
+ let row = rowValues[idx];
444
+ if (!row || Number(row.x) !== dataXAsNumber) row = rowValueMapByXValue[dataXAsNumber];
445
+ const rowValue = row && getShapeOffsetValue($$, row, isSub);
446
+ if (isNumber(rowValue) && isNumber(baseValue) && rowValue * baseValue >= 0 && isNumber(rValue)) {
447
+ if (baseValue === 0 ? groupsZeroAs === "positive" && rValue > 0 || groupsZeroAs === "negative" && rValue < 0 : true) offset += scale(rValue) - y0;
448
+ }
449
+ }
450
+ }
451
+ return offset;
452
+ };
453
+ },
454
+ /**
455
+ * Generate line coordinate points from shared geometry.
456
+ * @param {object} lineIndices Data order within x axis
457
+ * @param {boolean} isSub Whether the coordinates are for subchart
458
+ * @param {function} typeFilter Type filter for offset targets
459
+ * @returns {function} Line point generator
460
+ * @private
461
+ */
462
+ generateGetLinePoints(lineIndices, isSub, typeFilter) {
463
+ const $$ = this;
464
+ const { config } = $$;
465
+ const x = $$.getShapeX(0, lineIndices, isSub);
466
+ const y = $$.getShapeY(isSub);
467
+ const lineOffset = $$.getShapeOffset(typeFilter || $$.isLineType, lineIndices, isSub);
468
+ const yScale = $$.getYScaleById.bind($$);
469
+ const y0Cache = /* @__PURE__ */ new Map();
470
+ return (d, i) => {
471
+ let y0 = y0Cache.get(d.id);
472
+ if (y0 === void 0) {
473
+ y0 = yScale.call($$, d.id, isSub)($$.getShapeYMin(d.id, isSub));
474
+ y0Cache.set(d.id, y0);
475
+ }
476
+ const offset = lineOffset(d, i) || y0;
477
+ const posX = x(d);
478
+ let posY = y(d);
479
+ if (config.axis_rotated && (d.value > 0 && posY < y0 || d.value < 0 && y0 < posY)) posY = y0;
480
+ const point = [posX, posY - (y0 - offset)];
481
+ return [
482
+ point,
483
+ point,
484
+ point,
485
+ point
486
+ ];
487
+ };
488
+ },
489
+ /**
490
+ * Generate area coordinate points from shared geometry.
491
+ * @param {object} areaIndices Data order within x axis
492
+ * @param {boolean} isSub Whether the coordinates are for subchart
493
+ * @returns {function} Area point generator
494
+ * @private
495
+ */
496
+ generateGetAreaPoints(areaIndices, isSub) {
497
+ const $$ = this;
498
+ const { config } = $$;
499
+ const x = $$.getShapeX(0, areaIndices, isSub);
500
+ const y = $$.getShapeY(!!isSub);
501
+ const areaOffset = $$.getShapeOffset($$.isAreaType, areaIndices, isSub);
502
+ const yScale = $$.getYScaleById.bind($$);
503
+ const y0Cache = /* @__PURE__ */ new Map();
504
+ return function(d, i) {
505
+ let y0 = y0Cache.get(d.id);
506
+ if (y0 === void 0) {
507
+ y0 = yScale.call($$, d.id, isSub)($$.getShapeYMin(d.id, isSub));
508
+ y0Cache.set(d.id, y0);
509
+ }
510
+ const offset = areaOffset(d, i) || y0;
511
+ const posX = x(d);
512
+ const value = d.value;
513
+ let posY = y(d);
514
+ if (config.axis_rotated && (value > 0 && posY < y0 || value < 0 && y0 < posY)) posY = y0;
515
+ return [
516
+ [posX, offset],
517
+ [posX, posY - (y0 - offset)],
518
+ [posX, posY - (y0 - offset)],
519
+ [posX, offset]
520
+ ];
521
+ };
522
+ },
523
+ /**
524
+ * Generate bar coordinate points from shared geometry.
525
+ * @param {object} barIndices Data order within x axis
526
+ * @param {boolean} isSub Whether the coordinates are for subchart
527
+ * @returns {function} Bar point generator
528
+ * @private
529
+ */
530
+ generateGetBarPoints(barIndices, isSub) {
531
+ const $$ = this;
532
+ const { config } = $$;
533
+ const axis = isSub ? $$.axis.subX : $$.axis.x;
534
+ const barTargetsNum = $$.getIndicesMax(barIndices) + 1;
535
+ const barW = $$.getBarW("bar", axis, barTargetsNum);
536
+ const barX = $$.getShapeX(barW, barIndices, !!isSub);
537
+ const barY = $$.getShapeY(!!isSub);
538
+ const barOffset = $$.getShapeOffset($$.isBarType, barIndices, !!isSub);
539
+ const yScale = $$.getYScaleById.bind($$);
540
+ const idCache = /* @__PURE__ */ new Map();
541
+ return (d, i) => {
542
+ const { id } = d;
543
+ let idInfo = idCache.get(id);
544
+ if (!idInfo) {
545
+ idInfo = {
546
+ y0: yScale.call($$, id, isSub)($$.getShapeYMin(id, isSub)),
547
+ isInverted: config[`axis_${$$.axis.getId(id)}_inverted`]
548
+ };
549
+ idCache.set(id, idInfo);
550
+ }
551
+ const { y0, isInverted } = idInfo;
552
+ const offset = barOffset(d, i) || y0;
553
+ const width = isNumber(barW) ? barW : barW[d.id] || barW._$width;
554
+ const value = d.value;
555
+ const posX = barX(d);
556
+ let posY = barY(d);
557
+ if (config.axis_rotated && !isInverted && (value > 0 && posY < y0 || value < 0 && y0 < posY)) posY = y0;
558
+ if (!$$.isBarRangeType(d)) posY -= y0 - offset;
559
+ const startPosX = posX + width;
560
+ return [
561
+ [posX, offset],
562
+ [posX, posY],
563
+ [startPosX, posY],
564
+ [startPosX, offset]
565
+ ];
566
+ };
567
+ },
568
+ /**
569
+ * Get data's y coordinate
570
+ * @param {object} d Target data
571
+ * @param {number} i Index number
572
+ * @returns {number} y coordinate
573
+ * @private
574
+ */
575
+ circleY(d, i) {
576
+ const $$ = this;
577
+ const id = d.id;
578
+ let points;
579
+ if ($$.isGrouped(id)) points = _getGroupedDataPointsFn.bind($$)(d);
580
+ return points ? points(d, i)[0][1] : $$.getYScaleById(id)($$.getBaseValue(d));
581
+ },
582
+ /**
583
+ * Get data point x coordinate.
584
+ * @param {object} d Data row
585
+ * @returns {number|null} X coordinate
586
+ * @private
587
+ */
588
+ circleX(d) {
589
+ return this.xx(d);
590
+ },
591
+ /**
592
+ * Generate data point y coordinate accessor.
593
+ * @param {boolean} isSub Whether the coordinates are for subchart
594
+ * @returns {function} Y coordinate accessor
595
+ * @private
596
+ */
597
+ updateCircleY(isSub = false) {
598
+ const $$ = this;
599
+ const typeFilter = getLinePointGroupTypeFilter($$);
600
+ const getPoints = $$.generateGetLinePoints($$.getShapeIndices(typeFilter), isSub, typeFilter);
601
+ const y = $$.getShapeY(isSub);
602
+ return (d, i) => {
603
+ return $$.isGrouped(d.id) && isLinePointGroupType($$, d) ? getPoints(d, i)[0][1] : y(d);
604
+ };
605
+ },
606
+ /**
607
+ * Get candlestick data projected for alternate subchart shapes.
608
+ * @param {object} d Data row
609
+ * @param {boolean} isSub Whether coordinates are for the subchart
610
+ * @returns {number|undefined} Projected value
611
+ * @private
612
+ */
613
+ getSubchartCandlestickShapeValue(d, isSub) {
614
+ return getSubchartCandlestickShapeValue(this, d, isSub);
615
+ },
616
+ /**
617
+ * Check whether the row should be drawn as a candlestick-derived subchart bar.
618
+ * @param {object} d Data row
619
+ * @param {boolean} isSub Whether coordinates are for the subchart
620
+ * @returns {boolean}
621
+ * @private
622
+ */
623
+ isSubchartCandlestickBarValue(d, isSub) {
624
+ return isSubchartCandlestickBarValue(this, d, isSub);
625
+ },
626
+ /**
627
+ * Get subchart bar color projected from candlestick up/down state.
628
+ * @param {object} d Data row
629
+ * @param {boolean} isSub Whether coordinates are for the subchart
630
+ * @returns {string|null} Bar color
631
+ * @private
632
+ */
633
+ getSubchartCandlestickBarColor(d, isSub) {
634
+ return getSubchartCandlestickBarColor(this, d, isSub);
635
+ },
636
+ /**
637
+ * Get point radius.
638
+ * @param {object} d Data row
639
+ * @returns {number} Point radius
640
+ * @private
641
+ */
642
+ pointR(d) {
643
+ const $$ = this;
644
+ const { config } = $$;
645
+ const pointR = config.point_r;
646
+ let r = pointR;
647
+ if ($$.isBubbleType(d)) r = $$.getBubbleR(d);
648
+ else if (isFunction(pointR)) r = pointR.bind($$.api)(d);
649
+ d.r = r;
650
+ return r;
651
+ },
652
+ /**
653
+ * Get focused point radius.
654
+ * @param {object} d Data row
655
+ * @returns {number} Focused point radius
656
+ * @private
657
+ */
658
+ pointExpandedR(d) {
659
+ const $$ = this;
660
+ const { config } = $$;
661
+ const scale = $$.isBubbleType(d) ? 1.15 : 1.75;
662
+ return config.point_focus_expand_enabled ? config.point_focus_expand_r || $$.pointR(d) * scale : $$.pointR(d);
663
+ },
664
+ /**
665
+ * Get selected point radius.
666
+ * @param {object} d Data row
667
+ * @returns {number} Selected point radius
668
+ * @private
669
+ */
670
+ pointSelectR(d) {
671
+ const $$ = this;
672
+ const selectR = $$.config.point_select_r;
673
+ return isFunction(selectR) ? selectR(d) : selectR || $$.pointR(d) * 4;
674
+ },
675
+ /**
676
+ * Check if point.focus.only option can be applied.
677
+ * @returns {boolean} Whether focus-only point rendering is active
678
+ * @private
679
+ */
680
+ isPointFocusOnly() {
681
+ const $$ = this;
682
+ return $$.config.point_focus_only && !$$.hasType("bubble") && !$$.hasType("scatter") && !$$.hasArcType(null, ["radar"]);
683
+ },
684
+ /**
685
+ * Get data point sensitivity radius.
686
+ * @param {object} d Data point
687
+ * @returns {number} Sensitivity radius
688
+ * @private
689
+ */
690
+ getPointSensitivity(d) {
691
+ const $$ = this;
692
+ let sensitivity = $$.config.point_sensitivity;
693
+ if (!d) return sensitivity;
694
+ else if (isFunction(sensitivity)) sensitivity = sensitivity.call($$.api, d);
695
+ else if (sensitivity === "radius") sensitivity = d.r;
696
+ return sensitivity;
697
+ },
698
+ getBarW(type, axis, targetsNum) {
699
+ const $$ = this;
700
+ const { config, org, scale, state } = $$;
701
+ const maxDataCount = $$.getMaxDataCount();
702
+ const isGrouped = type === "bar" && config.data_groups?.length;
703
+ const configName = `${type}_width`;
704
+ const { k } = $$.getZoomTransform?.() ?? { k: 1 };
705
+ const xMinMax = [config.axis_x_min ?? org.xDomain[0], config.axis_x_max ?? org.xDomain[1]].map((v) => $$.axis.isTimeSeries() ? parseDate.call($$, v) : Number(v));
706
+ let tickInterval = axis.tickInterval(maxDataCount);
707
+ if (scale.zoom && !$$.axis.isCategorized() && k > 1) {
708
+ const isSameMinMax = xMinMax.every((v, i) => v === org.xDomain[i]);
709
+ tickInterval = org.xDomain.map((v, i) => {
710
+ const value = isSameMinMax ? v : v - Math.abs(xMinMax[i]);
711
+ return scale.zoom(value);
712
+ }).reduce((a, c) => Math.abs(a) + c) / maxDataCount;
713
+ }
714
+ const getWidth = (id) => {
715
+ const width = id ? config[configName][id] : config[configName];
716
+ const ratio = id ? width.ratio : config[`${configName}_ratio`];
717
+ const max = id ? width.max : config[`${configName}_max`];
718
+ const w = isNumber(width) ? width : isFunction(width) ? width.call($$, state.width, targetsNum, maxDataCount) : targetsNum ? tickInterval * ratio / targetsNum : 0;
719
+ return max && w > max ? max : w;
720
+ };
721
+ let result = getWidth();
722
+ if (!isGrouped && isObjectType(config[configName])) {
723
+ result = {
724
+ _$width: result,
725
+ _$total: []
726
+ };
727
+ $$.getTargetsToShow().forEach((v) => {
728
+ if (config[configName][v.id]) {
729
+ result[v.id] = getWidth(v.id);
730
+ result._$total.push(result[v.id] || result._$width);
731
+ }
732
+ });
733
+ }
734
+ return result;
735
+ },
736
+ /**
737
+ * Get shape element
738
+ * @param {string} shapeName Shape string
739
+ * @param {number} i Index number
740
+ * @param {string} id Data series id
741
+ * @returns {d3Selection}
742
+ * @private
743
+ */
744
+ getShapeByIndex(shapeName, i, id) {
745
+ const $$ = this;
746
+ const { $el } = $$;
747
+ const suffix = isValue(i) ? `-${i}` : ``;
748
+ let shape = $el[shapeName];
749
+ if (shape && !shape.empty()) shape = shape.filter((d) => id ? d.id === id : true).filter((d) => isValue(i) ? d.index === i : true);
750
+ else shape = (id ? $el.main.selectAll(`.${classes_default[`${shapeName}s`]}${$$.getTargetSelectorSuffix(id)}`) : $el.main).selectAll(`.${classes_default[shapeName]}${suffix}`);
751
+ return shape;
752
+ },
753
+ isWithinShape(that, d) {
754
+ const $$ = this;
755
+ const shape = select(that);
756
+ let isWithin;
757
+ if (!$$.isTargetToShow(d.id)) isWithin = false;
758
+ else if ($$.hasValidPointType?.(that.nodeName)) isWithin = $$.isStepType(d) ? $$.isWithinStep(that, $$.getYScaleById(d.id)($$.getBaseValue(d))) : $$.isWithinCircle(that, $$.isBubbleType(d) ? $$.pointSelectR(d) * 1.5 : 0);
759
+ else if (that.nodeName === "path") isWithin = shape.classed(classes_default.bar) ? $$.isWithinBar(that) : true;
760
+ return isWithin;
761
+ },
762
+ getInterpolate(d) {
763
+ const interpolation = this.getInterpolateType(d);
764
+ return CURVE_MAP[interpolation];
765
+ },
766
+ /**
767
+ * Get curve generator for line-like shapes.
768
+ * @param {object} d Data target
769
+ * @returns {function} Curve generator
770
+ * @private
771
+ */
772
+ getCurve(d) {
773
+ const $$ = this;
774
+ return $$.config.axis_rotated && $$.isStepType(d) ? (context) => {
775
+ const step = $$.getInterpolate(d)(context);
776
+ step.orgPoint = step.point;
777
+ step.pointRotated = function(x, y) {
778
+ this._point === 1 && (this._point = 2);
779
+ const y1 = this._y * (1 - this._t) + y * this._t;
780
+ this._context.lineTo(this._x, y1);
781
+ this._context.lineTo(x, y1);
782
+ this._x = x;
783
+ this._y = y;
784
+ };
785
+ step.point = function(x, y) {
786
+ this._point === 0 ? this.orgPoint(x, y) : this.pointRotated(x, y);
787
+ };
788
+ return step;
789
+ } : $$.getInterpolate(d);
790
+ },
791
+ getInterpolateType(d) {
792
+ const $$ = this;
793
+ const { config } = $$;
794
+ const type = config.spline_interpolation_type;
795
+ const interpolation = $$.isInterpolationType(type) ? type : "cardinal";
796
+ return $$.isSplineType(d) ? interpolation : $$.isStepType(d) ? config.line_step_type : "linear";
797
+ },
798
+ isWithinBar(that) {
799
+ const mouse = getPointer(this.state.event, that);
800
+ const [seg0, seg1, seg2] = getRectSegList(that);
801
+ const x = Math.min(seg0.x, seg1.x);
802
+ const y = Math.min(seg0.y, seg1.y);
803
+ const offset = this.config.bar_sensitivity;
804
+ const width = Math.abs(seg2.x - seg1.x);
805
+ const height = Math.abs(seg0.y - seg1.y);
806
+ const sx = x - offset;
807
+ const ex = x + width + offset;
808
+ const sy = y + height + offset;
809
+ const ey = y - offset;
810
+ return sx < mouse[0] && mouse[0] < ex && ey < mouse[1] && mouse[1] < sy;
811
+ }
873
812
  };
874
-
875
- export { shape as default, getShapeColorWithGradient, initShapeElement, updateTargetsForShape };
813
+ //#endregion
814
+ export { shape_default as default, getShapeColorWithGradient, initShapeElement, updateTargetsForShape };