billboard.js 4.0.3 → 4.1.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (271) hide show
  1. package/README.md +82 -7
  2. package/dist/billboard.css +1 -1
  3. package/dist/billboard.js +1848 -494
  4. package/dist/billboard.min.css +1 -1
  5. package/dist/billboard.min.js +19 -24
  6. package/dist/billboard.pkgd.js +1844 -679
  7. package/dist/billboard.pkgd.min.js +24 -29
  8. package/dist/billboard.react.js +205 -0
  9. package/dist/billboard.react.min.js +9 -0
  10. package/dist/billboard.worker.js +10 -0
  11. package/dist/plugin/billboardjs-plugin-bubblecompare.js +5 -3
  12. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  13. package/dist/plugin/billboardjs-plugin-sparkline.js +6 -3
  14. package/dist/plugin/billboardjs-plugin-sparkline.min.js +3 -3
  15. package/dist/plugin/billboardjs-plugin-stanford.js +6 -3
  16. package/dist/plugin/billboardjs-plugin-stanford.min.js +3 -3
  17. package/dist/plugin/billboardjs-plugin-tableview.js +59 -27
  18. package/dist/plugin/billboardjs-plugin-tableview.min.js +5 -5
  19. package/dist/plugin/billboardjs-plugin-textoverlap.js +75 -55
  20. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  21. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +5 -3
  22. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +2 -2
  23. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +6 -3
  24. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +3 -3
  25. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +6 -3
  26. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +2 -2
  27. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +59 -27
  28. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +11 -11
  29. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +68 -3557
  30. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +8 -8
  31. package/dist/theme/dark.css +1 -1
  32. package/dist/theme/dark.min.css +1 -1
  33. package/dist/theme/datalab.css +1 -1
  34. package/dist/theme/datalab.min.css +1 -1
  35. package/dist/theme/graph.css +1 -1
  36. package/dist/theme/graph.min.css +1 -1
  37. package/dist/theme/insight.css +1 -1
  38. package/dist/theme/insight.min.css +1 -1
  39. package/dist/theme/modern.css +1 -1
  40. package/dist/theme/modern.min.css +1 -1
  41. package/dist-esm/Chart/Chart.js +134 -152
  42. package/dist-esm/Chart/api/axis.js +217 -237
  43. package/dist-esm/Chart/api/category.js +54 -54
  44. package/dist-esm/Chart/api/chart.js +172 -215
  45. package/dist-esm/Chart/api/color.js +21 -21
  46. package/dist-esm/Chart/api/data.js +172 -173
  47. package/dist-esm/Chart/api/export.js +242 -262
  48. package/dist-esm/Chart/api/flow.js +198 -254
  49. package/dist-esm/Chart/api/focus.js +136 -143
  50. package/dist-esm/Chart/api/grid.js +191 -190
  51. package/dist-esm/Chart/api/group.js +31 -34
  52. package/dist-esm/Chart/api/legend.js +54 -63
  53. package/dist-esm/Chart/api/load.js +237 -257
  54. package/dist-esm/Chart/api/regions.js +148 -168
  55. package/dist-esm/Chart/api/selection.js +181 -139
  56. package/dist-esm/Chart/api/show.js +133 -147
  57. package/dist-esm/Chart/api/stubs.js +43 -42
  58. package/dist-esm/Chart/api/subchart.js +155 -172
  59. package/dist-esm/Chart/api/tooltip.js +132 -177
  60. package/dist-esm/Chart/api/x.js +67 -71
  61. package/dist-esm/Chart/api/zoom.js +183 -220
  62. package/dist-esm/ChartInternal/Axis/Axis.js +1059 -1266
  63. package/dist-esm/ChartInternal/Axis/AxisRenderer.js +408 -540
  64. package/dist-esm/ChartInternal/Axis/AxisRendererHelper.js +113 -149
  65. package/dist-esm/ChartInternal/ChartInternal.js +573 -749
  66. package/dist-esm/ChartInternal/data/convert.helper.js +133 -159
  67. package/dist-esm/ChartInternal/data/convert.js +200 -229
  68. package/dist-esm/ChartInternal/data/data.js +967 -1153
  69. package/dist-esm/ChartInternal/data/load.js +145 -197
  70. package/dist-esm/ChartInternal/interactions/drag.js +86 -122
  71. package/dist-esm/ChartInternal/interactions/eventrect.js +455 -621
  72. package/dist-esm/ChartInternal/interactions/flow.js +151 -215
  73. package/dist-esm/ChartInternal/interactions/interaction.js +214 -252
  74. package/dist-esm/ChartInternal/interactions/subchart.js +425 -300
  75. package/dist-esm/ChartInternal/interactions/zoom.js +321 -440
  76. package/dist-esm/ChartInternal/internals/category.js +18 -18
  77. package/dist-esm/ChartInternal/internals/class.js +89 -99
  78. package/dist-esm/ChartInternal/internals/clip.js +88 -119
  79. package/dist-esm/ChartInternal/internals/color.js +233 -288
  80. package/dist-esm/ChartInternal/internals/domain.js +452 -588
  81. package/dist-esm/ChartInternal/internals/format.js +64 -77
  82. package/dist-esm/ChartInternal/internals/grid.js +333 -457
  83. package/dist-esm/ChartInternal/internals/legend.js +675 -927
  84. package/dist-esm/ChartInternal/internals/redraw.js +200 -289
  85. package/dist-esm/ChartInternal/internals/region.js +106 -159
  86. package/dist-esm/ChartInternal/internals/scale.js +186 -215
  87. package/dist-esm/ChartInternal/internals/selection.js +132 -159
  88. package/dist-esm/ChartInternal/internals/size.axis.js +92 -139
  89. package/dist-esm/ChartInternal/internals/size.js +286 -394
  90. package/dist-esm/ChartInternal/internals/style.js +39 -41
  91. package/dist-esm/ChartInternal/internals/subchart.util.js +49 -0
  92. package/dist-esm/ChartInternal/internals/text.arc.js +155 -219
  93. package/dist-esm/ChartInternal/internals/text.js +368 -528
  94. package/dist-esm/ChartInternal/internals/text.util.js +179 -239
  95. package/dist-esm/ChartInternal/internals/title.js +96 -121
  96. package/dist-esm/ChartInternal/internals/tooltip.js +450 -586
  97. package/dist-esm/ChartInternal/internals/transform.js +79 -97
  98. package/dist-esm/ChartInternal/internals/type.js +285 -236
  99. package/dist-esm/ChartInternal/shape/arc.js +825 -1112
  100. package/dist-esm/ChartInternal/shape/area.js +73 -94
  101. package/dist-esm/ChartInternal/shape/bar.js +227 -288
  102. package/dist-esm/ChartInternal/shape/bubble.js +9 -8
  103. package/dist-esm/ChartInternal/shape/candlestick.js +110 -138
  104. package/dist-esm/ChartInternal/shape/core/barRadius.js +197 -133
  105. package/dist-esm/ChartInternal/shape/core/bubble.js +64 -73
  106. package/dist-esm/ChartInternal/shape/core/candlestick.js +93 -86
  107. package/dist-esm/ChartInternal/shape/core/dataRegion.js +68 -75
  108. package/dist-esm/ChartInternal/shape/core/geometry.js +112 -112
  109. package/dist-esm/ChartInternal/shape/core/path.js +142 -115
  110. package/dist-esm/ChartInternal/shape/core/point.js +105 -125
  111. package/dist-esm/ChartInternal/shape/core/treemap.js +83 -88
  112. package/dist-esm/ChartInternal/shape/funnel.js +310 -338
  113. package/dist-esm/ChartInternal/shape/gauge.js +71 -103
  114. package/dist-esm/ChartInternal/shape/line.js +208 -278
  115. package/dist-esm/ChartInternal/shape/point.js +310 -425
  116. package/dist-esm/ChartInternal/shape/polar.js +84 -109
  117. package/dist-esm/ChartInternal/shape/radar.js +228 -318
  118. package/dist-esm/ChartInternal/shape/shape.js +782 -843
  119. package/dist-esm/ChartInternal/shape/treemap.js +152 -190
  120. package/dist-esm/canvas/CanvasAxisRenderer.js +1180 -1328
  121. package/dist-esm/canvas/CanvasEngine.js +148 -166
  122. package/dist-esm/canvas/CanvasPainter.js +395 -411
  123. package/dist-esm/canvas/CanvasRenderer.js +1584 -1834
  124. package/dist-esm/canvas/CanvasTheme.js +899 -802
  125. package/dist-esm/canvas/HitDetector.js +394 -463
  126. package/dist-esm/canvas/axisTicks.js +672 -786
  127. package/dist-esm/canvas/classes.js +19 -17
  128. package/dist-esm/canvas/color.js +40 -59
  129. package/dist-esm/canvas/geometry.js +38 -38
  130. package/dist-esm/canvas/labels.js +318 -371
  131. package/dist-esm/canvas/pointPattern.js +578 -580
  132. package/dist-esm/canvas/util.js +242 -262
  133. package/dist-esm/config/Options/Options.js +29 -32
  134. package/dist-esm/config/Options/axis/axis.js +101 -101
  135. package/dist-esm/config/Options/axis/x.js +759 -755
  136. package/dist-esm/config/Options/axis/y.js +525 -522
  137. package/dist-esm/config/Options/axis/y2.js +501 -485
  138. package/dist-esm/config/Options/common/boost.js +93 -32
  139. package/dist-esm/config/Options/common/color.js +88 -87
  140. package/dist-esm/config/Options/common/grid.js +74 -73
  141. package/dist-esm/config/Options/common/legend.js +180 -179
  142. package/dist-esm/config/Options/common/main.js +474 -473
  143. package/dist-esm/config/Options/common/point.js +160 -159
  144. package/dist-esm/config/Options/common/title.js +47 -46
  145. package/dist-esm/config/Options/common/tooltip.js +253 -252
  146. package/dist-esm/config/Options/data/axis.js +173 -172
  147. package/dist-esm/config/Options/data/data.js +958 -957
  148. package/dist-esm/config/Options/data/selection.js +131 -130
  149. package/dist-esm/config/Options/interaction/interaction.js +53 -52
  150. package/dist-esm/config/Options/interaction/subchart.js +164 -73
  151. package/dist-esm/config/Options/interaction/zoom.js +86 -85
  152. package/dist-esm/config/Options/shape/arc.js +150 -149
  153. package/dist-esm/config/Options/shape/area.js +69 -68
  154. package/dist-esm/config/Options/shape/bar.js +147 -146
  155. package/dist-esm/config/Options/shape/bubble.js +35 -34
  156. package/dist-esm/config/Options/shape/candlestick.js +61 -60
  157. package/dist-esm/config/Options/shape/donut.js +181 -180
  158. package/dist-esm/config/Options/shape/funnel.js +49 -48
  159. package/dist-esm/config/Options/shape/gauge.js +237 -236
  160. package/dist-esm/config/Options/shape/line.js +58 -57
  161. package/dist-esm/config/Options/shape/pie.js +185 -184
  162. package/dist-esm/config/Options/shape/polar.js +167 -166
  163. package/dist-esm/config/Options/shape/radar.js +76 -75
  164. package/dist-esm/config/Options/shape/scatter.js +36 -36
  165. package/dist-esm/config/Options/shape/spline.js +46 -46
  166. package/dist-esm/config/Options/shape/treemap.js +80 -79
  167. package/dist-esm/config/Store/Element.js +64 -62
  168. package/dist-esm/config/Store/State.js +189 -200
  169. package/dist-esm/config/Store/Store.js +25 -26
  170. package/dist-esm/config/classes.js +157 -155
  171. package/dist-esm/config/config.js +26 -35
  172. package/dist-esm/config/const.js +120 -128
  173. package/dist-esm/config/resolver/axis.core.js +25 -25
  174. package/dist-esm/config/resolver/axis.js +26 -27
  175. package/dist-esm/config/resolver/canvas.js +2071 -2472
  176. package/dist-esm/config/resolver/canvasShape.js +201 -177
  177. package/dist-esm/config/resolver/category.js +26 -27
  178. package/dist-esm/config/resolver/export.js +24 -26
  179. package/dist-esm/config/resolver/flow.js +29 -31
  180. package/dist-esm/config/resolver/grid.js +34 -35
  181. package/dist-esm/config/resolver/interaction/selection.js +17 -17
  182. package/dist-esm/config/resolver/interaction/subchart.js +17 -17
  183. package/dist-esm/config/resolver/interaction/zoom.js +17 -17
  184. package/dist-esm/config/resolver/regions.js +30 -31
  185. package/dist-esm/config/resolver/shape/arc.helpers.js +19 -19
  186. package/dist-esm/config/resolver/shape/area.js +17 -17
  187. package/dist-esm/config/resolver/shape/axis.helpers.js +28 -25
  188. package/dist-esm/config/resolver/shape/bar.js +13 -13
  189. package/dist-esm/config/resolver/shape/bubble.js +18 -14
  190. package/dist-esm/config/resolver/shape/candlestick.js +13 -13
  191. package/dist-esm/config/resolver/shape/donut.js +11 -11
  192. package/dist-esm/config/resolver/shape/funnel.js +11 -11
  193. package/dist-esm/config/resolver/shape/gauge.js +12 -12
  194. package/dist-esm/config/resolver/shape/line.js +10 -10
  195. package/dist-esm/config/resolver/shape/pie.js +11 -11
  196. package/dist-esm/config/resolver/shape/polar.js +12 -12
  197. package/dist-esm/config/resolver/shape/radar.js +22 -14
  198. package/dist-esm/config/resolver/shape/scatter.js +13 -13
  199. package/dist-esm/config/resolver/shape/treemap.js +11 -11
  200. package/dist-esm/core.js +208 -211
  201. package/dist-esm/index.canvas.js +14 -13
  202. package/dist-esm/index.esm.js +25 -24
  203. package/dist-esm/module/Cache.js +117 -129
  204. package/dist-esm/module/browser.js +30 -35
  205. package/dist-esm/module/dsv.js +107 -127
  206. package/dist-esm/module/error.js +45 -52
  207. package/dist-esm/module/generator.js +75 -83
  208. package/dist-esm/module/sanitize.js +302 -399
  209. package/dist-esm/module/util/brush.js +27 -38
  210. package/dist-esm/module/util/dom.js +288 -348
  211. package/dist-esm/module/util/object.js +277 -341
  212. package/dist-esm/module/util/type-checks.js +21 -25
  213. package/dist-esm/module/worker.js +312 -130
  214. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +185 -198
  215. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +442 -450
  216. package/dist-esm/plugin/billboardjs-plugin-stanford.js +813 -950
  217. package/dist-esm/plugin/billboardjs-plugin-tableview.js +708 -788
  218. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +344 -301
  219. package/dist-esm/react/index.js +157 -0
  220. package/package.json +28 -8
  221. package/src/Chart/api/selection.ts +130 -5
  222. package/src/ChartInternal/Axis/Axis.ts +164 -65
  223. package/src/ChartInternal/Axis/AxisRenderer.ts +41 -8
  224. package/src/ChartInternal/Axis/AxisRendererHelper.ts +1 -1
  225. package/src/ChartInternal/ChartInternal.ts +1 -1
  226. package/src/ChartInternal/data/convert.ts +54 -4
  227. package/src/ChartInternal/data/data.ts +4 -1
  228. package/src/ChartInternal/interactions/eventrect.ts +8 -2
  229. package/src/ChartInternal/interactions/subchart.ts +437 -66
  230. package/src/ChartInternal/internals/color.ts +2 -2
  231. package/src/ChartInternal/internals/domain.ts +15 -3
  232. package/src/ChartInternal/internals/grid.ts +21 -1
  233. package/src/ChartInternal/internals/scale.ts +9 -2
  234. package/src/ChartInternal/internals/selection.ts +1 -1
  235. package/src/ChartInternal/internals/subchart.util.ts +55 -0
  236. package/src/ChartInternal/internals/text.arc.ts +3 -1
  237. package/src/ChartInternal/internals/text.ts +18 -5
  238. package/src/ChartInternal/internals/transform.ts +8 -2
  239. package/src/ChartInternal/internals/type.ts +105 -1
  240. package/src/ChartInternal/shape/IShape.ts +6 -3
  241. package/src/ChartInternal/shape/bar.ts +62 -31
  242. package/src/ChartInternal/shape/core/barRadius.ts +129 -0
  243. package/src/ChartInternal/shape/core/candlestick.ts +1 -1
  244. package/src/ChartInternal/shape/core/path.ts +76 -9
  245. package/src/ChartInternal/shape/funnel.ts +2 -3
  246. package/src/ChartInternal/shape/point.ts +2 -2
  247. package/src/ChartInternal/shape/shape.ts +149 -17
  248. package/src/Plugin/stanford/index.ts +0 -4
  249. package/src/Plugin/tableview/index.ts +85 -3
  250. package/src/Plugin/textoverlap/index.ts +9 -15
  251. package/src/canvas/CanvasAxisRenderer.ts +184 -36
  252. package/src/canvas/CanvasRenderer.ts +247 -160
  253. package/src/canvas/CanvasTheme.ts +212 -0
  254. package/src/canvas/axisTicks.ts +122 -40
  255. package/src/config/Options/axis/y2.ts +13 -0
  256. package/src/config/Options/common/boost.ts +64 -4
  257. package/src/config/Options/common/color.ts +2 -2
  258. package/src/config/Options/interaction/subchart.ts +98 -1
  259. package/src/config/Options/shape/gauge.ts +1 -1
  260. package/src/config/Options/shape/treemap.ts +2 -2
  261. package/src/config/Store/Element.ts +3 -1
  262. package/src/config/Store/State.ts +1 -0
  263. package/src/config/classes.ts +1 -0
  264. package/src/config/resolver/canvas.ts +92 -10
  265. package/src/module/util/type-checks.ts +3 -1
  266. package/src/module/voronoi.ts +119 -0
  267. package/src/module/worker.entry.ts +61 -0
  268. package/src/module/worker.ts +346 -63
  269. package/src/react/index.ts +193 -0
  270. package/types/options.d.ts +206 -3
  271. package/types/react/index.d.ts +27 -0
@@ -5,844 +5,730 @@
5
5
  * billboard.js, JavaScript chart library
6
6
  * https://naver.github.io/billboard.js/
7
7
  *
8
- * @version 4.0.3
9
- */
10
- import { getScale } from '../ChartInternal/internals/scale.js';
11
- import { AXIS_DEFAULT_TICK_COUNT, AXIS_TICK_LINE_OVERLAP_PADDING } from '../config/const.js';
12
- import { getCanvasComparableXDomain, getCanvasComparableValue } from './util.js';
13
- import { parseDate } from '../module/util/object.js';
14
-
15
- /**
16
- * Get explicitly configured tick values.
17
- * @param {Array|function} values Tick values option
18
- * @param {object} api Chart API
19
- * @returns {Array} Tick values
20
- * @private
21
- */
8
+ * @version 4.1.0-next.2
9
+ */
10
+ import { parseDate } from "../module/util/object.js";
11
+ import { getScale } from "../ChartInternal/internals/scale.js";
12
+ import { getCanvasComparableValue, getCanvasComparableXDomain } from "./util.js";
13
+ //#region src/canvas/axisTicks.ts
14
+ /**
15
+ * Get tick option value for main/subchart canvas axes.
16
+ * @param {object} config Chart config
17
+ * @param {string} id Base axis id
18
+ * @param {string} key Tick option key
19
+ * @param {string} prefix Option prefix
20
+ * @returns {boolean|number|string|Array|object|function|null|undefined} Tick option value
21
+ * @private
22
+ */
23
+ function getAxisTickOption(config, id, key, prefix = `axis_${id}`) {
24
+ const value = config[`${prefix}_tick_${key}`];
25
+ return value !== void 0 ? value : config[`axis_${id}_tick_${key}`];
26
+ }
27
+ /**
28
+ * Get explicitly configured tick values.
29
+ * @param {Array|function} values Tick values option
30
+ * @param {object} api Chart API
31
+ * @returns {Array} Tick values
32
+ * @private
33
+ */
22
34
  function getOptionTickValues(values, api) {
23
- const resolved = typeof values === "function" ? values.call(api) : values;
24
- return resolved?.length ? resolved : undefined;
35
+ const resolved = typeof values === "function" ? values.call(api) : values;
36
+ return resolved?.length ? resolved : void 0;
25
37
  }
26
38
  /**
27
- * Normalize axis values that can be expressed as category names, dates or numbers.
28
- * @param {object} $$ ChartInternal context
29
- * @param {number|Date|string} value Axis value
30
- * @param {string} id Axis id
31
- * @returns {number|Date|string} Scale-compatible value
32
- * @private
33
- */
39
+ * Normalize axis values that can be expressed as category names, dates or numbers.
40
+ * @param {object} $$ ChartInternal context
41
+ * @param {number|Date|string} value Axis value
42
+ * @param {string} id Axis id
43
+ * @returns {number|Date|string} Scale-compatible value
44
+ * @private
45
+ */
34
46
  function normalizeAxisValue($$, value, id) {
35
- if ($$.axis?.isTimeSeries?.(id)) {
36
- return value instanceof Date ? value : parseDate.call($$, value);
37
- }
38
- if (id === "x" && $$.axis?.isCategorized?.() && typeof value === "string") {
39
- const index = $$.config.axis_x_categories.indexOf(value);
40
- return index >= 0 ? index : value;
41
- }
42
- if ($$.axis?.isLog?.(id) && value !== null && value !== undefined) {
43
- return +value;
44
- }
45
- return value;
46
- }
47
- /**
48
- * Normalize x values that can be expressed as category names, dates or numbers.
49
- * @param {object} $$ ChartInternal context
50
- * @param {number|Date|string} value X value
51
- * @returns {number|Date|string} Scale-compatible value
52
- * @private
53
- */
47
+ if ($$.axis?.isTimeSeries?.(id)) return value instanceof Date ? value : parseDate.call($$, value);
48
+ if (id === "x" && $$.axis?.isCategorized?.() && typeof value === "string") {
49
+ const index = $$.config.axis_x_categories.indexOf(value);
50
+ return index >= 0 ? index : value;
51
+ }
52
+ if ($$.axis?.isLog?.(id) && value !== null && value !== void 0) return +value;
53
+ return value;
54
+ }
55
+ /**
56
+ * Normalize x values that can be expressed as category names, dates or numbers.
57
+ * @param {object} $$ ChartInternal context
58
+ * @param {number|Date|string} value X value
59
+ * @returns {number|Date|string} Scale-compatible value
60
+ * @private
61
+ */
54
62
  function normalizeXValue($$, value) {
55
- return normalizeAxisValue($$, value, "x");
63
+ return normalizeAxisValue($$, value, "x");
56
64
  }
57
65
  /**
58
- * Normalize y/y2 tick or grid values.
59
- * @param {object} $$ ChartInternal context
60
- * @param {number|Date|string} value Axis value
61
- * @param {string} id Axis id
62
- * @returns {number|Date|string} Scale-compatible value
63
- * @private
64
- */
66
+ * Normalize y/y2 tick or grid values.
67
+ * @param {object} $$ ChartInternal context
68
+ * @param {number|Date|string} value Axis value
69
+ * @param {string} id Axis id
70
+ * @returns {number|Date|string} Scale-compatible value
71
+ * @private
72
+ */
65
73
  function normalizeYValue($$, value, id = "y") {
66
- return normalizeAxisValue($$, value, id);
74
+ return normalizeAxisValue($$, value, id);
67
75
  }
68
76
  /**
69
- * Normalize y/y2 tick values.
70
- * @param {object} $$ ChartInternal context
71
- * @param {Array} values Tick values
72
- * @param {string} id Axis id
73
- * @returns {Array} Scale-compatible tick values
74
- * @private
75
- */
77
+ * Normalize y/y2 tick values.
78
+ * @param {object} $$ ChartInternal context
79
+ * @param {Array} values Tick values
80
+ * @param {string} id Axis id
81
+ * @returns {Array} Scale-compatible tick values
82
+ * @private
83
+ */
76
84
  function normalizeYTickValues($$, values, id = "y") {
77
- return values.map(value => normalizeYValue($$, value, id));
85
+ return values.map((value) => normalizeYValue($$, value, id));
78
86
  }
79
87
  /**
80
- * Normalize x tick values.
81
- * @param {object} $$ ChartInternal context
82
- * @param {Array} values Tick values
83
- * @returns {Array} Scale-compatible tick values
84
- * @private
85
- */
88
+ * Normalize x tick values.
89
+ * @param {object} $$ ChartInternal context
90
+ * @param {Array} values Tick values
91
+ * @returns {Array} Scale-compatible tick values
92
+ * @private
93
+ */
86
94
  function normalizeXTickValues($$, values) {
87
- return values
88
- .map(value => normalizeXValue($$, value))
89
- .filter(value => !(typeof value === "string" && $$.axis?.isCategorized?.()));
95
+ return values.map((value) => normalizeXValue($$, value)).filter((value) => !(typeof value === "string" && $$.axis?.isCategorized?.()));
90
96
  }
91
97
  /**
92
- * Get tick values from scale.
93
- * @param {object} scale Scale function
94
- * @param {number} count Tick count
95
- * @returns {Array} Tick values
96
- * @private
97
- */
98
+ * Get tick values from scale.
99
+ * @param {object} scale Scale function
100
+ * @param {number} count Tick count
101
+ * @returns {Array} Tick values
102
+ * @private
103
+ */
98
104
  function getScaleTicks(scale, count) {
99
- const tickCount = typeof count === "function" ? count() : count;
100
- return scale.ticks ? scale.ticks(tickCount) : scale.domain();
105
+ const tickCount = typeof count === "function" ? count() : count;
106
+ return scale.ticks ? scale.ticks(tickCount) : scale.domain();
101
107
  }
102
108
  /**
103
- * Generate ticks for billboard log axes using the same SVG helper behavior.
104
- * @param {object} scale Symlog display scale
105
- * @param {number|function} count Optional tick count
106
- * @returns {Array} Tick values
107
- * @private
108
- */
109
+ * Generate ticks for billboard log axes using the same SVG helper behavior.
110
+ * @param {object} scale Symlog display scale
111
+ * @param {number|function} count Optional tick count
112
+ * @returns {Array} Tick values
113
+ * @private
114
+ */
109
115
  function getLogScaleTicks(scale, count) {
110
- const [start, end] = scale.domain();
111
- const numericStart = +start;
112
- const numericEnd = +end;
113
- if (count ||
114
- !Number.isFinite(numericStart) ||
115
- !Number.isFinite(numericEnd) ||
116
- numericEnd <= 0) {
117
- return getScaleTicks(scale, count);
118
- }
119
- const logScale = getScale("_log")
120
- .domain([numericStart > 0 ? numericStart : 1, numericEnd])
121
- .range(scale.range());
122
- let ticks = logScale.ticks();
123
- for (let cnt = numericEnd.toFixed().length; ticks.length > 15; cnt--) {
124
- ticks = logScale.ticks(cnt);
125
- }
126
- if (ticks.length) {
127
- ticks.splice(0, 1, start);
128
- ticks.splice(ticks.length - 1, 1, end);
129
- }
130
- return ticks;
131
- }
132
- /**
133
- * Check whether two tick values are equivalent.
134
- * @param {number|Date|string} a First value
135
- * @param {number|Date|string} b Second value
136
- * @returns {boolean} Whether values are equivalent
137
- * @private
138
- */
116
+ const [start, end] = scale.domain();
117
+ const numericStart = +start;
118
+ const numericEnd = +end;
119
+ if (count || !Number.isFinite(numericStart) || !Number.isFinite(numericEnd) || numericEnd <= 0) return getScaleTicks(scale, count);
120
+ const logScale = getScale("_log").domain([numericStart > 0 ? numericStart : 1, numericEnd]).range(scale.range());
121
+ let ticks = logScale.ticks();
122
+ for (let cnt = numericEnd.toFixed().length; ticks.length > 15; cnt--) ticks = logScale.ticks(cnt);
123
+ if (ticks.length) {
124
+ ticks.splice(0, 1, start);
125
+ ticks.splice(ticks.length - 1, 1, end);
126
+ }
127
+ return ticks;
128
+ }
129
+ /**
130
+ * Check whether two tick values are equivalent.
131
+ * @param {number|Date|string} a First value
132
+ * @param {number|Date|string} b Second value
133
+ * @returns {boolean} Whether values are equivalent
134
+ * @private
135
+ */
139
136
  function isSameTickValue(a, b) {
140
- const av = +a;
141
- const bv = +b;
142
- return Number.isFinite(av) && Number.isFinite(bv) ? Math.abs(av - bv) < 1e-6 : a === b;
137
+ const av = +a;
138
+ const bv = +b;
139
+ return Number.isFinite(av) && Number.isFinite(bv) ? Math.abs(av - bv) < 1e-6 : a === b;
143
140
  }
144
141
  /**
145
- * Keep the visible domain edges in generated canvas ticks.
146
- * @param {Array} ticks Generated tick values
147
- * @param {Array} domain Current x domain
148
- * @returns {Array} Tick values including domain edges
149
- * @private
150
- */
142
+ * Keep the visible domain edges in generated canvas ticks.
143
+ * @param {Array} ticks Generated tick values
144
+ * @param {Array} domain Current x domain
145
+ * @returns {Array} Tick values including domain edges
146
+ * @private
147
+ */
151
148
  function includeDomainEndpoints(ticks, domain) {
152
- const [start, end] = domain;
153
- const values = ticks.slice();
154
- if (start !== undefined && !values.some(value => isSameTickValue(value, start))) {
155
- values.unshift(start);
156
- }
157
- if (end !== undefined && !values.some(value => isSameTickValue(value, end))) {
158
- values.push(end);
159
- }
160
- return values;
161
- }
162
- /**
163
- * Convert an x value to a comparable number.
164
- * @param {object} $$ ChartInternal context
165
- * @param {number|Date|string} value X value
166
- * @returns {number|null} Comparable value
167
- * @private
168
- */
149
+ const [start, end] = domain;
150
+ const values = ticks.slice();
151
+ if (start !== void 0 && !values.some((value) => isSameTickValue(value, start))) values.unshift(start);
152
+ if (end !== void 0 && !values.some((value) => isSameTickValue(value, end))) values.push(end);
153
+ return values;
154
+ }
155
+ /**
156
+ * Convert an x value to a comparable number.
157
+ * @param {object} $$ ChartInternal context
158
+ * @param {number|Date|string} value X value
159
+ * @returns {number|null} Comparable value
160
+ * @private
161
+ */
169
162
  function toComparableValue($$, value) {
170
- const normalized = normalizeXValue($$, value);
171
- return getCanvasComparableValue(normalized);
163
+ return getCanvasComparableValue(normalizeXValue($$, value));
172
164
  }
173
165
  /**
174
- * Check whether a zoom scale is showing a narrowed x domain.
175
- * @param {object} $$ ChartInternal context
176
- * @returns {boolean} Whether zoom scale should be used
177
- * @private
178
- */
166
+ * Check whether a zoom scale is showing a narrowed x domain.
167
+ * @param {object} $$ ChartInternal context
168
+ * @returns {boolean} Whether zoom scale should be used
169
+ * @private
170
+ */
179
171
  function hasActiveXZoom($$) {
180
- const { scale } = $$;
181
- const zoomDomain = scale.zoom?.domain?.();
182
- const xDomain = scale.subX?.domain?.() || scale.x?.orgDomain?.() || scale.x?.domain?.();
183
- if (!zoomDomain?.length || !xDomain?.length) {
184
- return false;
185
- }
186
- return !isSameTickValue(zoomDomain[0], xDomain[0]) ||
187
- !isSameTickValue(zoomDomain[1], xDomain[1]);
188
- }
189
- /**
190
- * Get current x scale, using zoom scale when active.
191
- * @param {object} $$ ChartInternal context
192
- * @returns {function} X scale
193
- * @private
194
- */
172
+ const { scale } = $$;
173
+ const zoomDomain = scale.zoom?.domain?.();
174
+ const xDomain = scale.subX?.domain?.() || scale.x?.orgDomain?.() || scale.x?.domain?.();
175
+ if (!zoomDomain?.length || !xDomain?.length) return false;
176
+ return !isSameTickValue(zoomDomain[0], xDomain[0]) || !isSameTickValue(zoomDomain[1], xDomain[1]);
177
+ }
178
+ /**
179
+ * Get current x scale, using zoom scale when active.
180
+ * @param {object} $$ ChartInternal context
181
+ * @returns {function} X scale
182
+ * @private
183
+ */
195
184
  function getXScale($$) {
196
- return hasActiveXZoom($$) ? $$.scale.zoom : $$.scale.x;
185
+ return hasActiveXZoom($$) ? $$.scale.zoom : $$.scale.x;
197
186
  }
198
187
  /**
199
- * Check if an x tick is inside the current x scale domain.
200
- * @param {object} $$ ChartInternal context
201
- * @param {number|Date|string} value Tick value
202
- * @param {number} tolerance Domain tolerance
203
- * @returns {boolean} Whether value is visible in current domain
204
- * @private
205
- */
188
+ * Check if an x tick is inside the current x scale domain.
189
+ * @param {object} $$ ChartInternal context
190
+ * @param {number|Date|string} value Tick value
191
+ * @param {number} tolerance Domain tolerance
192
+ * @returns {boolean} Whether value is visible in current domain
193
+ * @private
194
+ */
206
195
  function isInCurrentXDomain($$, value, tolerance = 0) {
207
- const domain = getXScale($$).domain?.();
208
- if (!domain?.length) {
209
- return true;
210
- }
211
- const target = toComparableValue($$, value);
212
- const min = +domain[0];
213
- const max = +domain[1];
214
- if (target === null || !Number.isFinite(min) || !Number.isFinite(max)) {
215
- return true;
216
- }
217
- return target >= Math.min(min, max) - tolerance &&
218
- target <= Math.max(min, max) + tolerance;
219
- }
220
- /**
221
- * Get half-distance to the nearest neighboring x data point.
222
- * @param {Array} comparableValues Comparable x values
223
- * @param {number} index Current index
224
- * @returns {number} Half-distance tolerance
225
- * @private
226
- */
196
+ const domain = getXScale($$).domain?.();
197
+ if (!domain?.length) return true;
198
+ const target = toComparableValue($$, value);
199
+ const min = +domain[0];
200
+ const max = +domain[1];
201
+ if (target === null || !Number.isFinite(min) || !Number.isFinite(max)) return true;
202
+ return target >= Math.min(min, max) - tolerance && target <= Math.max(min, max) + tolerance;
203
+ }
204
+ /**
205
+ * Get half-distance to the nearest neighboring x data point.
206
+ * @param {Array} comparableValues Comparable x values
207
+ * @param {number} index Current index
208
+ * @returns {number} Half-distance tolerance
209
+ * @private
210
+ */
227
211
  function getHalfNeighborDistance(comparableValues, index) {
228
- const distances = [
229
- index > 0 ? Math.abs(comparableValues[index] - comparableValues[index - 1]) : Infinity,
230
- index < comparableValues.length - 1 ?
231
- Math.abs(comparableValues[index + 1] - comparableValues[index]) :
232
- Infinity
233
- ].filter(Number.isFinite);
234
- const distance = Math.min(...distances);
235
- return Number.isFinite(distance) ? (distance / 2) : 0;
236
- }
237
- /**
238
- * Find the first numeric value greater than or equal to the target.
239
- * @param {Array} values Sorted numbers
240
- * @param {number} target Target value
241
- * @returns {number} Value index
242
- * @private
243
- */
212
+ const distances = [index > 0 ? Math.abs(comparableValues[index] - comparableValues[index - 1]) : Infinity, index < comparableValues.length - 1 ? Math.abs(comparableValues[index + 1] - comparableValues[index]) : Infinity].filter(Number.isFinite);
213
+ const distance = Math.min(...distances);
214
+ return Number.isFinite(distance) ? distance / 2 : 0;
215
+ }
216
+ /**
217
+ * Find the first numeric value greater than or equal to the target.
218
+ * @param {Array} values Sorted numbers
219
+ * @param {number} target Target value
220
+ * @returns {number} Value index
221
+ * @private
222
+ */
244
223
  function lowerBoundNumbers(values, target) {
245
- let low = 0;
246
- let high = values.length;
247
- while (low < high) {
248
- const mid = (low + high) >> 1;
249
- if (values[mid] < target) {
250
- low = mid + 1;
251
- }
252
- else {
253
- high = mid;
254
- }
255
- }
256
- return low;
257
- }
258
- /**
259
- * Find the first numeric value greater than the target.
260
- * @param {Array} values Sorted numbers
261
- * @param {number} target Target value
262
- * @returns {number} Value index
263
- * @private
264
- */
224
+ let low = 0;
225
+ let high = values.length;
226
+ while (low < high) {
227
+ const mid = low + high >> 1;
228
+ if (values[mid] < target) low = mid + 1;
229
+ else high = mid;
230
+ }
231
+ return low;
232
+ }
233
+ /**
234
+ * Find the first numeric value greater than the target.
235
+ * @param {Array} values Sorted numbers
236
+ * @param {number} target Target value
237
+ * @returns {number} Value index
238
+ * @private
239
+ */
265
240
  function upperBoundNumbers(values, target) {
266
- let low = 0;
267
- let high = values.length;
268
- while (low < high) {
269
- const mid = (low + high) >> 1;
270
- if (values[mid] <= target) {
271
- low = mid + 1;
272
- }
273
- else {
274
- high = mid;
275
- }
276
- }
277
- return low;
278
- }
279
- /**
280
- * Get cached sorted x data ticks and numeric values.
281
- * @param {object} $$ ChartInternal context
282
- * @param {Array} targets Visible targets
283
- * @returns {object} Cached data ticks
284
- * @private
285
- */
241
+ let low = 0;
242
+ let high = values.length;
243
+ while (low < high) {
244
+ const mid = low + high >> 1;
245
+ if (values[mid] <= target) low = mid + 1;
246
+ else high = mid;
247
+ }
248
+ return low;
249
+ }
250
+ /**
251
+ * Get cached sorted x data ticks and numeric values.
252
+ * @param {object} $$ ChartInternal context
253
+ * @param {Array} targets Visible targets
254
+ * @returns {object} Cached data ticks
255
+ * @private
256
+ */
286
257
  function getCachedXDataTicks($$, targets) {
287
- const { axis, state } = $$;
288
- const key = [
289
- state.dataGeneration,
290
- axis?.isTimeSeries?.() ? 1 : 0,
291
- targets.map(target => `${target.id}:${target.values.length}`).join(",")
292
- ].join("|");
293
- const cached = state._canvasXDataTickCache;
294
- if (cached?.key === key) {
295
- return cached;
296
- }
297
- const values = $$.mapTargetsToUniqueXs(targets);
298
- const entry = {
299
- key,
300
- values,
301
- comparable: values.map(value => toComparableValue($$, value) ?? NaN)
302
- };
303
- state._canvasXDataTickCache = entry;
304
- return entry;
305
- }
306
- /**
307
- * Include the nearest data ticks at zoom boundaries.
308
- * @param {object} $$ ChartInternal context
309
- * @param {object} dataTicks Cached data x ticks
310
- * @returns {Array} Data ticks visible in current zoom domain
311
- * @private
312
- */
258
+ const { axis, state } = $$;
259
+ const key = [
260
+ state.dataGeneration,
261
+ axis?.isTimeSeries?.() ? 1 : 0,
262
+ targets.map((target) => `${target.id}:${target.values.length}`).join(",")
263
+ ].join("|");
264
+ const cached = state._canvasXDataTickCache;
265
+ if (cached?.key === key) return cached;
266
+ const values = $$.mapTargetsToUniqueXs(targets);
267
+ const entry = {
268
+ key,
269
+ values,
270
+ comparable: values.map((value) => toComparableValue($$, value) ?? NaN)
271
+ };
272
+ state._canvasXDataTickCache = entry;
273
+ return entry;
274
+ }
275
+ /**
276
+ * Include the nearest data ticks at zoom boundaries.
277
+ * @param {object} $$ ChartInternal context
278
+ * @param {object} dataTicks Cached data x ticks
279
+ * @returns {Array} Data ticks visible in current zoom domain
280
+ * @private
281
+ */
313
282
  function filterXDataTicksForZoom($$, dataTicks) {
314
- const { values: ticks, comparable } = dataTicks;
315
- if (!hasActiveXZoom($$)) {
316
- return ticks;
317
- }
318
- const domain = getCanvasComparableXDomain($$);
319
- if (!domain || comparable.length !== ticks.length || !Number.isFinite(comparable[0])) {
320
- return ticks.filter(value => isInCurrentXDomain($$, value));
321
- }
322
- const [start, end] = domain;
323
- let startIndex = lowerBoundNumbers(comparable, start);
324
- let endIndex = upperBoundNumbers(comparable, end);
325
- const includeNearest = (edge) => {
326
- const index = lowerBoundNumbers(comparable, edge);
327
- let nearestIndex = -1;
328
- let nearestDistance = Infinity;
329
- for (const candidate of [index - 1, index]) {
330
- const value = comparable[candidate];
331
- const distance = Math.abs(value - edge);
332
- if (distance < nearestDistance) {
333
- nearestDistance = distance;
334
- nearestIndex = candidate;
335
- }
336
- }
337
- if (nearestIndex > -1 &&
338
- nearestIndex < comparable.length &&
339
- nearestDistance <= getHalfNeighborDistance(comparable, nearestIndex) + 1e-6) {
340
- startIndex = Math.min(startIndex, nearestIndex);
341
- endIndex = Math.max(endIndex, nearestIndex + 1);
342
- }
343
- };
344
- includeNearest(start);
345
- includeNearest(end);
346
- return ticks.slice(Math.max(0, startIndex), Math.min(ticks.length, endIndex));
347
- }
348
- /**
349
- * Get stable key part for configured explicit tick values.
350
- * @param {Array|function} values Tick values option
351
- * @param {number} generation Current redraw generation
352
- * @returns {string} Cache key
353
- * @private
354
- */
283
+ const { values: ticks, comparable } = dataTicks;
284
+ if (!hasActiveXZoom($$)) return ticks;
285
+ const domain = getCanvasComparableXDomain($$);
286
+ if (!domain || comparable.length !== ticks.length || !Number.isFinite(comparable[0])) return ticks.filter((value) => isInCurrentXDomain($$, value));
287
+ const [start, end] = domain;
288
+ let startIndex = lowerBoundNumbers(comparable, start);
289
+ let endIndex = upperBoundNumbers(comparable, end);
290
+ const includeNearest = (edge) => {
291
+ const index = lowerBoundNumbers(comparable, edge);
292
+ let nearestIndex = -1;
293
+ let nearestDistance = Infinity;
294
+ for (const candidate of [index - 1, index]) {
295
+ const distance = Math.abs(comparable[candidate] - edge);
296
+ if (distance < nearestDistance) {
297
+ nearestDistance = distance;
298
+ nearestIndex = candidate;
299
+ }
300
+ }
301
+ if (nearestIndex > -1 && nearestIndex < comparable.length && nearestDistance <= getHalfNeighborDistance(comparable, nearestIndex) + 1e-6) {
302
+ startIndex = Math.min(startIndex, nearestIndex);
303
+ endIndex = Math.max(endIndex, nearestIndex + 1);
304
+ }
305
+ };
306
+ includeNearest(start);
307
+ includeNearest(end);
308
+ return ticks.slice(Math.max(0, startIndex), Math.min(ticks.length, endIndex));
309
+ }
310
+ /**
311
+ * Get stable key part for configured explicit tick values.
312
+ * @param {Array|function} values Tick values option
313
+ * @param {number} generation Current redraw generation
314
+ * @returns {string} Cache key
315
+ * @private
316
+ */
355
317
  function getTickOptionCacheKey(values, generation) {
356
- if (typeof values === "function") {
357
- return `fn:${generation}`;
358
- }
359
- return Array.isArray(values) ?
360
- values.map(value => value instanceof Date ? +value : String(value)).join(",") :
361
- "";
362
- }
363
- /**
364
- * Get x tick cache key for the current draw inputs.
365
- * @param {object} $$ ChartInternal context
366
- * @param {boolean} cull Whether ticks are text-culled
367
- * @returns {string} Cache key
368
- * @private
369
- */
318
+ if (typeof values === "function") return `fn:${generation}`;
319
+ return Array.isArray(values) ? values.map((value) => value instanceof Date ? +value : String(value)).join(",") : "";
320
+ }
321
+ /**
322
+ * Get x tick cache key for the current draw inputs.
323
+ * @param {object} $$ ChartInternal context
324
+ * @param {boolean} cull Whether ticks are text-culled
325
+ * @returns {string} Cache key
326
+ * @private
327
+ */
370
328
  function getXTickCacheKey($$, cull) {
371
- const { config, state } = $$;
372
- const domain = getXScale($$).domain?.() || [];
373
- const domainKey = domain.map(value => value instanceof Date ? +value : String(value)).join(",");
374
- const size = config.axis_rotated ? state.height : state.width;
375
- return [
376
- cull ? 1 : 0,
377
- state.dataGeneration,
378
- domainKey,
379
- size,
380
- config.axis_x_tick_fit ? 1 : 0,
381
- config.axis_x_tick_count || "",
382
- config.axis_x_tick_culling,
383
- config.axis_x_tick_culling_max || "",
384
- config.axis_x_tick_culling_reverse ? 1 : 0,
385
- config.axis_x_categories?.length || 0,
386
- getTickOptionCacheKey(config.axis_x_tick_values, state.redrawGeneration)
387
- ].join("|");
388
- }
389
- /**
390
- * Generate tick values reusing the axis helper when available.
391
- * @param {object} $$ ChartInternal context
392
- * @param {Array} values Base values
393
- * @param {number} count Tick count
394
- * @param {boolean} forTimeSeries Whether values are timeseries
395
- * @returns {Array} Tick values
396
- * @private
397
- */
329
+ const { config, state } = $$;
330
+ const domainKey = (getXScale($$).domain?.() || []).map((value) => value instanceof Date ? +value : String(value)).join(",");
331
+ return [
332
+ cull ? 1 : 0,
333
+ state.dataGeneration,
334
+ domainKey,
335
+ config.axis_rotated ? state.height : state.width,
336
+ config.axis_x_tick_fit ? 1 : 0,
337
+ config.axis_x_tick_count || "",
338
+ config.axis_x_tick_culling,
339
+ config.axis_x_tick_culling_max || "",
340
+ config.axis_x_tick_culling_reverse ? 1 : 0,
341
+ config.axis_x_categories?.length || 0,
342
+ getTickOptionCacheKey(config.axis_x_tick_values, state.redrawGeneration)
343
+ ].join("|");
344
+ }
345
+ /**
346
+ * Generate tick values reusing the axis helper when available.
347
+ * @param {object} $$ ChartInternal context
348
+ * @param {Array} values Base values
349
+ * @param {number} count Tick count
350
+ * @param {boolean} forTimeSeries Whether values are timeseries
351
+ * @returns {Array} Tick values
352
+ * @private
353
+ */
398
354
  function generateTickValues($$, values, count, forTimeSeries = false) {
399
- return $$.axis?.generateTickValues ?
400
- $$.axis.generateTickValues(values, count, forTimeSeries) :
401
- values;
355
+ return $$.axis?.generateTickValues ? $$.axis.generateTickValues(values, count, forTimeSeries) : values;
402
356
  }
403
357
  /**
404
- * Get step ticks for y axis.
405
- * @param {Array} domain Scale domain
406
- * @param {number} stepSize Step size
407
- * @returns {Array} Tick values
408
- * @private
409
- */
358
+ * Get step ticks for y axis.
359
+ * @param {Array} domain Scale domain
360
+ * @param {number} stepSize Step size
361
+ * @returns {Array} Tick values
362
+ * @private
363
+ */
410
364
  function getStepTicks(domain, stepSize) {
411
- const [start, end] = domain;
412
- const ticks = [];
413
- if (!stepSize || !Number.isFinite(stepSize)) {
414
- return ticks;
415
- }
416
- for (let value = Math.round(start); value <= end; value += stepSize) {
417
- ticks.push(value);
418
- }
419
- return ticks;
420
- }
421
- /**
422
- * Get x ticks for indexed/linear canvas mode.
423
- * @param {object} $$ ChartInternal context
424
- * @param {boolean} cull Whether to cull tick values
425
- * @returns {Array} Tick values
426
- * @private
427
- */
365
+ const [start, end] = domain;
366
+ const ticks = [];
367
+ if (!stepSize || !Number.isFinite(stepSize)) return ticks;
368
+ for (let value = Math.round(start); value <= end; value += stepSize) ticks.push(value);
369
+ return ticks;
370
+ }
371
+ /**
372
+ * Get x ticks for indexed/linear canvas mode.
373
+ * @param {object} $$ ChartInternal context
374
+ * @param {boolean} cull Whether to cull tick values
375
+ * @returns {Array} Tick values
376
+ * @private
377
+ */
428
378
  function getXTickValues($$, cull = true) {
429
- const { axis, config } = $$;
430
- const targetScale = getXScale($$);
431
- const targetsToShow = $$.getTargetsToShow?.() || $$.filterTargetsToShow();
432
- const cache = $$.state._canvasXTickValuesCache ||
433
- ($$.state._canvasXTickValuesCache = new Map());
434
- const cacheKey = getXTickCacheKey($$, cull);
435
- const cached = cache.get(cacheKey);
436
- if (cached) {
437
- return cached;
438
- }
439
- const setCache = (ticks) => {
440
- cache.set(cacheKey, ticks);
441
- return ticks;
442
- };
443
- if (!targetsToShow?.length) {
444
- return setCache([]);
445
- }
446
- const explicit = getOptionTickValues(config.axis_x_tick_values, $$.api);
447
- if (explicit) {
448
- const values = normalizeXTickValues($$, explicit);
449
- return setCache(cull ? cullDataTicks($$, values) : values);
450
- }
451
- if (config.axis_x_tick_fit && targetsToShow?.length && $$.mapTargetsToUniqueXs) {
452
- const dataTicks = getCachedXDataTicks($$, targetsToShow);
453
- const values = filterXDataTicksForZoom($$, dataTicks);
454
- const generated = generateTickValues($$, values, config.axis_x_tick_count, axis?.isTimeSeries?.());
455
- return setCache(cull ? cullDataTicks($$, generated, true) : generated);
456
- }
457
- if (hasActiveXZoom($$) && !axis?.isCategorized?.()) {
458
- const domain = $$.zoom?.getDomain?.() || targetScale.domain();
459
- const generated = includeDomainEndpoints(getScaleTicks(targetScale, config.axis_x_tick_count || AXIS_DEFAULT_TICK_COUNT), domain);
460
- return setCache(cull ? cullTicks(generated, getXTickCullMax($$)) : generated);
461
- }
462
- if (axis?.isCategorized?.() && config.axis_x_categories?.length) {
463
- const generated = config.axis_x_categories.map((_, i) => i);
464
- return setCache(cull ? cullTicks(generated, getXTickCullMax($$)) : generated);
465
- }
466
- const generated = getScaleTicks(targetScale, config.axis_x_tick_count || AXIS_DEFAULT_TICK_COUNT);
467
- return setCache(cull ? cullTicks(generated, getXTickCullMax($$)) : generated);
468
- }
469
- /**
470
- * Get max number of subchart x ticks to render.
471
- * @param {object} $$ ChartInternal context
472
- * @returns {number|undefined} Max tick count
473
- * @private
474
- */
379
+ const { axis, config } = $$;
380
+ const targetScale = getXScale($$);
381
+ const targetsToShow = $$.getTargetsToShow?.() || $$.filterTargetsToShow();
382
+ const cache = $$.state._canvasXTickValuesCache || ($$.state._canvasXTickValuesCache = /* @__PURE__ */ new Map());
383
+ const cacheKey = getXTickCacheKey($$, cull);
384
+ const cached = cache.get(cacheKey);
385
+ if (cached) return cached;
386
+ const setCache = (ticks) => {
387
+ cache.set(cacheKey, ticks);
388
+ return ticks;
389
+ };
390
+ if (!targetsToShow?.length) return setCache([]);
391
+ const explicit = getOptionTickValues(config.axis_x_tick_values, $$.api);
392
+ if (explicit) {
393
+ const values = normalizeXTickValues($$, explicit);
394
+ return setCache(cull ? cullDataTicks($$, values) : values);
395
+ }
396
+ if (config.axis_x_tick_fit && targetsToShow?.length && $$.mapTargetsToUniqueXs) {
397
+ const generated = generateTickValues($$, filterXDataTicksForZoom($$, getCachedXDataTicks($$, targetsToShow)), config.axis_x_tick_count, axis?.isTimeSeries?.());
398
+ return setCache(cull ? cullDataTicks($$, generated, true) : generated);
399
+ }
400
+ if (hasActiveXZoom($$) && !axis?.isCategorized?.()) {
401
+ const domain = $$.zoom?.getDomain?.() || targetScale.domain();
402
+ const generated = includeDomainEndpoints(getScaleTicks(targetScale, config.axis_x_tick_count || 10), domain);
403
+ return setCache(cull ? cullTicks(generated, getXTickCullMax($$)) : generated);
404
+ }
405
+ if (axis?.isCategorized?.() && config.axis_x_categories?.length) {
406
+ const generated = config.axis_x_categories.map((_, i) => i);
407
+ return setCache(cull ? cullTicks(generated, getXTickCullMax($$)) : generated);
408
+ }
409
+ const generated = getScaleTicks(targetScale, config.axis_x_tick_count || 10);
410
+ return setCache(cull ? cullTicks(generated, getXTickCullMax($$)) : generated);
411
+ }
412
+ /**
413
+ * Get max number of subchart x ticks to render.
414
+ * @param {object} $$ ChartInternal context
415
+ * @returns {number|undefined} Max tick count
416
+ * @private
417
+ */
475
418
  function getSubXTickCullMax($$) {
476
- const { config, state: { height2, width2 } } = $$;
477
- const size = config.axis_rotated ? height2 : width2;
478
- if (config.axis_x_tick_count) {
479
- return config.axis_x_tick_count;
480
- }
481
- if (config.axis_x_tick_culling !== false) {
482
- return Math.min(config.axis_x_tick_culling_max || AXIS_DEFAULT_TICK_COUNT, Math.max(2, Math.floor(size / 70)));
483
- }
484
- return undefined;
485
- }
486
- /**
487
- * Get x ticks for the canvas subchart axis.
488
- * @param {object} $$ ChartInternal context
489
- * @returns {Array} Tick values
490
- * @private
491
- */
492
- function getSubXTickValues($$) {
493
- const { axis, config, scale } = $$;
494
- const targetScale = scale.subX;
495
- const targetsToShow = $$.getTargetsToShow?.() || $$.filterTargetsToShow();
496
- const cullMax = getSubXTickCullMax($$);
497
- const cull = (ticks) => cullTicks(ticks, cullMax);
498
- if (!targetScale || !targetsToShow?.length) {
499
- return [];
500
- }
501
- const explicit = getOptionTickValues(config.axis_x_tick_values, $$.api);
502
- if (explicit) {
503
- return cull(normalizeXTickValues($$, explicit));
504
- }
505
- if (config.axis_x_tick_fit && $$.mapTargetsToUniqueXs) {
506
- const generated = generateTickValues($$, $$.mapTargetsToUniqueXs(targetsToShow), config.axis_x_tick_count, axis?.isTimeSeries?.());
507
- return cull(generated);
508
- }
509
- if (axis?.isCategorized?.() && config.axis_x_categories?.length) {
510
- return cull(config.axis_x_categories.map((_, i) => i));
511
- }
512
- const generated = getScaleTicks(targetScale, config.axis_x_tick_count || AXIS_DEFAULT_TICK_COUNT);
513
- return cull(generated);
514
- }
515
- /**
516
- * Get raw category boundary tick values for x axis tick lines.
517
- * @param {object} $$ ChartInternal context
518
- * @returns {Array} Category boundary values
519
- * @private
520
- */
521
- function getCategoryXTickLineValues($$) {
522
- const scale = getXScale($$);
523
- const domain = scale.orgDomain?.() || scale.domain?.();
524
- if (!domain?.length) {
525
- return [];
526
- }
527
- const start = +domain[0];
528
- const end = +domain[domain.length - 1];
529
- if (!Number.isFinite(start) || !Number.isFinite(end)) {
530
- return [];
531
- }
532
- const min = Math.ceil(Math.min(start, end));
533
- const max = Math.floor(Math.max(start, end));
534
- const values = Array.from({ length: Math.max(0, max - min + 1) }, (_, i) => min + i);
535
- return $$.config.axis_x_tick_outer ? values.slice(1, -1) : values;
536
- }
537
- /**
538
- * Resolve x tick line coordinate. Category tick lines are drawn on raw scale boundaries.
539
- * @param {object} $$ ChartInternal context
540
- * @param {number|Date|string} value X tick value
541
- * @param {function} targetScale X scale
542
- * @returns {number} Pixel coordinate relative to plot area
543
- * @private
544
- */
419
+ const { config, state: { height2, width2 } } = $$;
420
+ const size = config.axis_rotated ? height2 : width2;
421
+ const count = getAxisTickOption(config, "x", "count", "subchart_axis_x");
422
+ const culling = getAxisTickOption(config, "x", "culling", "subchart_axis_x");
423
+ const cullingMax = getAxisTickOption(config, "x", "culling_max", "subchart_axis_x");
424
+ if (count) return count;
425
+ if (culling !== false) return Math.min(cullingMax || 10, Math.max(2, Math.floor(size / 70)));
426
+ }
427
+ /**
428
+ * Get x ticks for the canvas subchart axis.
429
+ * @param {object} $$ ChartInternal context
430
+ * @param {boolean} culling Whether to cull tick values
431
+ * @returns {Array} Tick values
432
+ * @private
433
+ */
434
+ function getSubXTickValues($$, culling = true) {
435
+ const { axis, config, scale } = $$;
436
+ const targetScale = scale.subX;
437
+ const targetsToShow = $$.getTargetsToShow?.() || $$.filterTargetsToShow();
438
+ const tickCount = getAxisTickOption(config, "x", "count", "subchart_axis_x");
439
+ const cullMax = getSubXTickCullMax($$);
440
+ const cullData = (ticks, sorted = false) => culling ? cullDataTicks($$, ticks, sorted, "subchart_axis_x", cullMax) : ticks;
441
+ if (!targetScale || !targetsToShow?.length) return [];
442
+ const explicit = getOptionTickValues(getAxisTickOption(config, "x", "values", "subchart_axis_x"), $$.api);
443
+ if (explicit) return cullData(normalizeXTickValues($$, explicit));
444
+ if (config.axis_x_tick_fit && $$.mapTargetsToUniqueXs) return cullData(generateTickValues($$, $$.mapTargetsToUniqueXs(targetsToShow), tickCount, axis?.isTimeSeries?.()), true);
445
+ if (axis?.isCategorized?.() && config.axis_x_categories?.length) return cullData(config.axis_x_categories.map((_, i) => i), true);
446
+ return cullData(getScaleTicks(targetScale, tickCount || 10), true);
447
+ }
448
+ /**
449
+ * Get raw category boundary tick values for x axis tick lines.
450
+ * @param {object} $$ ChartInternal context
451
+ * @param {function} targetScale X scale
452
+ * @param {boolean} outerTick Whether outer ticks are shown
453
+ * @returns {Array} Category boundary values
454
+ * @private
455
+ */
456
+ function getCategoryXTickLineValues($$, targetScale = getXScale($$), outerTick = $$.config.axis_x_tick_outer) {
457
+ const scale = targetScale;
458
+ const domain = scale.orgDomain?.() || scale.domain?.();
459
+ if (!domain?.length) return [];
460
+ const start = +domain[0];
461
+ const end = +domain[domain.length - 1];
462
+ if (!Number.isFinite(start) || !Number.isFinite(end)) return [];
463
+ const min = Math.ceil(Math.min(start, end));
464
+ const values = Array.from({ length: Math.max(0, Math.floor(Math.max(start, end)) - min + 1) }, (_, i) => min + i);
465
+ return outerTick ? values.slice(1, -1) : values;
466
+ }
467
+ /**
468
+ * Resolve x tick line coordinate. Category tick lines are drawn on raw scale boundaries.
469
+ * @param {object} $$ ChartInternal context
470
+ * @param {number|Date|string} value X tick value
471
+ * @param {function} targetScale X scale
472
+ * @returns {number} Pixel coordinate relative to plot area
473
+ * @private
474
+ */
545
475
  function getXTickLinePosition($$, value, targetScale = getXScale($$)) {
546
- const scale = targetScale;
547
- const normalized = normalizeXValue($$, value);
548
- if ($$.axis?.isCategorized?.()) {
549
- const rawScale = scale.orgScale?.();
550
- if (rawScale) {
551
- return rawScale(normalized);
552
- }
553
- const offset = $$.axis.x?.tickOffset?.() || ((scale(1) - scale(0)) / 2);
554
- return scale(normalized) - offset;
555
- }
556
- return scale(normalized);
557
- }
558
- /**
559
- * Check whether adjacent x tick line intervals overlap on canvas.
560
- * @param {object} $$ ChartInternal context
561
- * @param {Array} ticks Sorted tick values
562
- * @param {number} tickLineWidth Tick line stroke width
563
- * @returns {boolean} Whether tick lines should follow culled text ticks
564
- * @private
565
- */
566
- function hasOverlappedXTickLineIntervals($$, ticks, tickLineWidth) {
567
- if (ticks.length < 2) {
568
- return false;
569
- }
570
- const halfWidth = Math.max(1, tickLineWidth) / 2;
571
- const positions = ticks
572
- .map(tick => getXTickLinePosition($$, tick))
573
- .filter(Number.isFinite)
574
- .sort((a, b) => a - b);
575
- if (positions.length < 2) {
576
- return false;
577
- }
578
- let previousEnd = positions[0] + halfWidth;
579
- for (let i = 1; i < positions.length; i++) {
580
- const start = positions[i] - halfWidth;
581
- const end = positions[i] + halfWidth;
582
- if (start <= previousEnd + AXIS_TICK_LINE_OVERLAP_PADDING) {
583
- return true;
584
- }
585
- previousEnd = Math.max(previousEnd, end);
586
- }
587
- return false;
588
- }
589
- /**
590
- * Remove line ticks that map to the same canvas pixel.
591
- * @param {object} $$ ChartInternal context
592
- * @param {Array} ticks Tick values
593
- * @returns {Array} Pixel-deduped tick values
594
- * @private
595
- */
596
- function dedupeXTickLineValues($$, ticks) {
597
- const seen = new Set();
598
- return ticks.filter(tick => {
599
- const pos = getXTickLinePosition($$, tick);
600
- const key = Math.round(pos);
601
- if (!Number.isFinite(pos) || seen.has(key)) {
602
- return false;
603
- }
604
- seen.add(key);
605
- return true;
606
- });
607
- }
608
- /**
609
- * Get x tick values for tick lines, following SVG culling options.
610
- * @param {object} $$ ChartInternal context
611
- * @param {Array} textTicks Text tick values
612
- * @param {number} tickLineWidth Tick line stroke width
613
- * @returns {Array} Tick line values
614
- * @private
615
- */
476
+ const scale = targetScale;
477
+ const normalized = normalizeXValue($$, value);
478
+ if ($$.axis?.isCategorized?.()) {
479
+ const rawScale = scale.orgScale?.();
480
+ if (rawScale) return rawScale(normalized);
481
+ const offset = $$.axis.x?.tickOffset?.() || (scale(1) - scale(0)) / 2;
482
+ return scale(normalized) - offset;
483
+ }
484
+ return scale(normalized);
485
+ }
486
+ /**
487
+ * Check whether adjacent x tick line intervals overlap on canvas.
488
+ * @param {object} $$ ChartInternal context
489
+ * @param {Array} ticks Sorted tick values
490
+ * @param {number} tickLineWidth Tick line stroke width
491
+ * @param {function} targetScale X scale
492
+ * @returns {boolean} Whether tick lines should follow culled text ticks
493
+ * @private
494
+ */
495
+ function hasOverlappedXTickLineIntervals($$, ticks, tickLineWidth, targetScale = getXScale($$)) {
496
+ if (ticks.length < 2) return false;
497
+ const halfWidth = Math.max(1, tickLineWidth) / 2;
498
+ const positions = ticks.map((tick) => getXTickLinePosition($$, tick, targetScale)).filter(Number.isFinite).sort((a, b) => a - b);
499
+ if (positions.length < 2) return false;
500
+ let previousEnd = positions[0] + halfWidth;
501
+ for (let i = 1; i < positions.length; i++) {
502
+ const start = positions[i] - halfWidth;
503
+ const end = positions[i] + halfWidth;
504
+ if (start <= previousEnd + 1) return true;
505
+ previousEnd = Math.max(previousEnd, end);
506
+ }
507
+ return false;
508
+ }
509
+ /**
510
+ * Remove line ticks that map to the same canvas pixel.
511
+ * @param {object} $$ ChartInternal context
512
+ * @param {Array} ticks Tick values
513
+ * @param {function} targetScale X scale
514
+ * @returns {Array} Pixel-deduped tick values
515
+ * @private
516
+ */
517
+ function dedupeXTickLineValues($$, ticks, targetScale = getXScale($$)) {
518
+ const seen = /* @__PURE__ */ new Set();
519
+ return ticks.filter((tick) => {
520
+ const pos = getXTickLinePosition($$, tick, targetScale);
521
+ const key = Math.round(pos);
522
+ if (!Number.isFinite(pos) || seen.has(key)) return false;
523
+ seen.add(key);
524
+ return true;
525
+ });
526
+ }
527
+ /**
528
+ * Get x tick values for tick lines, following SVG culling options.
529
+ * @param {object} $$ ChartInternal context
530
+ * @param {Array} textTicks Text tick values
531
+ * @param {number} tickLineWidth Tick line stroke width
532
+ * @returns {Array} Tick line values
533
+ * @private
534
+ */
616
535
  function getXTickLineValues($$, textTicks, tickLineWidth = 1) {
617
- const { axis, config } = $$;
618
- if (axis?.isCategorized?.()) {
619
- const categoryLineTicks = getCategoryXTickLineValues($$);
620
- return dedupeXTickLineValues($$, categoryLineTicks);
621
- }
622
- if (config.axis_x_tick_culling === false || config.axis_x_tick_culling_lines === false) {
623
- return textTicks;
624
- }
625
- const lineTicks = getXTickValues($$, false);
626
- return hasOverlappedXTickLineIntervals($$, lineTicks, tickLineWidth) ?
627
- textTicks :
628
- dedupeXTickLineValues($$, lineTicks);
629
- }
630
- /**
631
- * Get y ticks for indexed/linear canvas mode.
632
- * @param {object} $$ ChartInternal context
633
- * @param {string} id Axis id
634
- * @param {number} count Optional tick count override
635
- * @param {boolean} culling Whether to apply tick culling
636
- * @returns {Array} Tick values
637
- * @private
638
- */
639
- function getYTickValues($$, id = "y", count, culling = true) {
640
- const { axis, config, scale } = $$;
641
- const prefix = `axis_${id}`;
642
- const targetScale = scale[id];
643
- const explicit = getOptionTickValues(config[`${prefix}_tick_values`], $$.api);
644
- const maybeCull = (ticks) => culling ? cullAxisTicks($$, id, ticks) : ticks;
645
- if (explicit) {
646
- return maybeCull(normalizeYTickValues($$, explicit, id));
647
- }
648
- const stepTicks = getStepTicks(targetScale.domain(), config[`${prefix}_tick_stepSize`]);
649
- if (stepTicks.length) {
650
- return maybeCull(stepTicks);
651
- }
652
- const tickCount = config[`${prefix}_tick_count`];
653
- if (axis?.isTimeSeries?.(id) && config[`${prefix}_tick_time_value`]) {
654
- return maybeCull(getScaleTicks(targetScale, config[`${prefix}_tick_time_value`]));
655
- }
656
- if (axis?.isLog?.(id)) {
657
- return maybeCull(getLogScaleTicks(targetScale, tickCount));
658
- }
659
- if (tickCount) {
660
- const domain = targetScale.domain();
661
- return maybeCull(generateTickValues($$, domain, domain.every(v => v === 0) ? 1 : tickCount, axis?.isTimeSeries?.(id)));
662
- }
663
- return maybeCull(getScaleTicks(targetScale, AXIS_DEFAULT_TICK_COUNT));
664
- }
665
- /**
666
- * Get scale for an additional axis.
667
- * @param {object} $$ ChartInternal context
668
- * @param {string} id Axis id
669
- * @param {object} axisConfig Additional axis config
670
- * @returns {function} Scale
671
- * @private
672
- */
536
+ const { axis, config } = $$;
537
+ if (axis?.isCategorized?.()) return dedupeXTickLineValues($$, getCategoryXTickLineValues($$));
538
+ if (config.axis_x_tick_culling === false || config.axis_x_tick_culling_lines === false) return textTicks;
539
+ const lineTicks = getXTickValues($$, false);
540
+ return hasOverlappedXTickLineIntervals($$, lineTicks, tickLineWidth) ? textTicks : dedupeXTickLineValues($$, lineTicks);
541
+ }
542
+ /**
543
+ * Get subchart x tick values for tick lines, following SVG culling options.
544
+ * @param {object} $$ ChartInternal context
545
+ * @param {Array} textTicks Text tick values
546
+ * @param {number} tickLineWidth Tick line stroke width
547
+ * @returns {Array} Tick line values
548
+ * @private
549
+ */
550
+ function getSubXTickLineValues($$, textTicks, tickLineWidth = 1) {
551
+ const { axis, config, scale } = $$;
552
+ const targetScale = scale.subX;
553
+ const culling = getAxisTickOption(config, "x", "culling", "subchart_axis_x");
554
+ const cullingLines = getAxisTickOption(config, "x", "culling_lines", "subchart_axis_x");
555
+ const outerTick = getAxisTickOption(config, "x", "outer", "subchart_axis_x");
556
+ if (!targetScale) return [];
557
+ if (axis?.isCategorized?.()) return dedupeXTickLineValues($$, getCategoryXTickLineValues($$, targetScale, outerTick), targetScale);
558
+ if (culling === false || cullingLines === false) return textTicks;
559
+ const lineTicks = getSubXTickValues($$, false);
560
+ return hasOverlappedXTickLineIntervals($$, lineTicks, tickLineWidth, targetScale) ? textTicks : dedupeXTickLineValues($$, lineTicks, targetScale);
561
+ }
562
+ /**
563
+ * Get y ticks for indexed/linear canvas mode.
564
+ * @param {object} $$ ChartInternal context
565
+ * @param {string} id Axis id
566
+ * @param {number} count Optional tick count override
567
+ * @param {boolean} culling Whether to apply tick culling
568
+ * @param {d3Scale} targetScale Scale to generate ticks from
569
+ * @param {string} optionPrefix Tick option prefix
570
+ * @returns {Array} Tick values
571
+ * @private
572
+ */
573
+ function getYTickValues($$, id = "y", count, culling = true, targetScale = $$.scale[id], optionPrefix = `axis_${id}`) {
574
+ const { axis, config } = $$;
575
+ const prefix = `axis_${id}`;
576
+ const explicit = getOptionTickValues(getAxisTickOption(config, id, "values", optionPrefix), $$.api);
577
+ const maybeCull = (ticks) => culling ? cullAxisTicks($$, id, ticks, optionPrefix) : ticks;
578
+ if (explicit) return maybeCull(normalizeYTickValues($$, explicit, id));
579
+ const stepTicks = getStepTicks(targetScale.domain(), config[`${prefix}_tick_stepSize`]);
580
+ if (stepTicks.length) return maybeCull(stepTicks);
581
+ const tickCount = count ?? getAxisTickOption(config, id, "count", optionPrefix);
582
+ if (axis?.isTimeSeries?.(id) && config[`${prefix}_tick_time_value`]) return maybeCull(getScaleTicks(targetScale, config[`${prefix}_tick_time_value`]));
583
+ if (axis?.isLog?.(id)) return maybeCull(getLogScaleTicks(targetScale, tickCount));
584
+ if (tickCount) {
585
+ const domain = targetScale.domain();
586
+ return maybeCull(generateTickValues($$, domain, domain.every((v) => v === 0) ? 1 : tickCount, axis?.isTimeSeries?.(id)));
587
+ }
588
+ return maybeCull(getScaleTicks(targetScale, 10));
589
+ }
590
+ /**
591
+ * Get scale for an additional axis.
592
+ * @param {object} $$ ChartInternal context
593
+ * @param {string} id Axis id
594
+ * @param {object} axisConfig Additional axis config
595
+ * @returns {function} Scale
596
+ * @private
597
+ */
673
598
  function getAdditionalAxisScale($$, id, axisConfig) {
674
- const baseScale = id === "x" ? getXScale($$) : $$.scale[id];
675
- const scale = baseScale?.copy ? baseScale.copy() : baseScale;
676
- if (axisConfig.domain && scale?.domain) {
677
- scale.domain(axisConfig.domain);
678
- }
679
- return scale;
680
- }
681
- /**
682
- * Get tick values for an additional axis.
683
- * @param {object} $$ ChartInternal context
684
- * @param {string} id Axis id
685
- * @param {function} scale Axis scale
686
- * @param {object} axisConfig Additional axis config
687
- * @returns {Array} Tick values
688
- * @private
689
- */
599
+ const baseScale = id === "x" ? getXScale($$) : $$.scale[id];
600
+ const scale = baseScale?.copy ? baseScale.copy() : baseScale;
601
+ if (axisConfig.domain && scale?.domain) scale.domain(axisConfig.domain);
602
+ return scale;
603
+ }
604
+ /**
605
+ * Get tick values for an additional axis.
606
+ * @param {object} $$ ChartInternal context
607
+ * @param {string} id Axis id
608
+ * @param {function} scale Axis scale
609
+ * @param {object} axisConfig Additional axis config
610
+ * @returns {Array} Tick values
611
+ * @private
612
+ */
690
613
  function getAdditionalAxisTickValues($$, id, scale, axisConfig) {
691
- const tick = axisConfig.tick || {};
692
- const explicit = getOptionTickValues(tick.values, $$.api);
693
- if (explicit) {
694
- return id === "x" ?
695
- normalizeXTickValues($$, explicit) :
696
- normalizeYTickValues($$, explicit, id);
697
- }
698
- if (id !== "x" && $$.axis?.isLog?.(id)) {
699
- return getLogScaleTicks(scale, tick.count);
700
- }
701
- return getScaleTicks(scale, tick.count ?? AXIS_DEFAULT_TICK_COUNT);
702
- }
703
- /**
704
- * Get tick formatter for an additional axis.
705
- * @param {object} $$ ChartInternal context
706
- * @param {object} axisConfig Additional axis config
707
- * @returns {function} Formatter
708
- * @private
709
- */
614
+ const tick = axisConfig.tick || {};
615
+ const explicit = getOptionTickValues(tick.values, $$.api);
616
+ if (explicit) return id === "x" ? normalizeXTickValues($$, explicit) : normalizeYTickValues($$, explicit, id);
617
+ if (id !== "x" && $$.axis?.isLog?.(id)) return getLogScaleTicks(scale, tick.count);
618
+ return getScaleTicks(scale, tick.count ?? 10);
619
+ }
620
+ /**
621
+ * Get tick formatter for an additional axis.
622
+ * @param {object} $$ ChartInternal context
623
+ * @param {object} axisConfig Additional axis config
624
+ * @returns {function} Formatter
625
+ * @private
626
+ */
710
627
  function getAdditionalAxisTickFormat($$, axisConfig) {
711
- const format = axisConfig.tick?.format;
712
- return typeof format === "function" ? format.bind($$.api) : (value => value);
628
+ const format = axisConfig.tick?.format;
629
+ return typeof format === "function" ? format.bind($$.api) : ((value) => value);
713
630
  }
714
631
  /**
715
- * Cull generated ticks like AxisRenderer.getGeneratedTicks().
716
- * @param {Array} ticks Tick values
717
- * @param {number} count Target count
718
- * @returns {Array} Culled tick values
719
- * @private
720
- */
632
+ * Cull generated ticks like AxisRenderer.getGeneratedTicks().
633
+ * @param {Array} ticks Tick values
634
+ * @param {number} count Target count
635
+ * @returns {Array} Culled tick values
636
+ * @private
637
+ */
721
638
  function cullTicks(ticks, count) {
722
- const len = ticks.length - 1;
723
- if (count && len > count) {
724
- const last = ticks.length - 1;
725
- if (count <= 1) {
726
- return [ticks[0]];
727
- }
728
- return Array.from({ length: count }, (_, i) => ticks[Math.round(i * last / (count - 1))]);
729
- }
730
- return ticks;
731
- }
732
- /**
733
- * Cull axis ticks following SVG manual culling.
734
- * @param {object} $$ ChartInternal context
735
- * @param {string} id Axis id
736
- * @param {Array} ticks Tick values
737
- * @returns {Array} Culled tick values
738
- * @private
739
- */
740
- function cullAxisTicks($$, id, ticks) {
741
- const { config } = $$;
742
- const prefix = `axis_${id}_tick_culling`;
743
- if (!config[prefix]) {
744
- return ticks;
745
- }
746
- const sortedTicks = ticks.slice().sort((a, b) => {
747
- const av = +a;
748
- const bv = +b;
749
- const order = Number.isFinite(av) && Number.isFinite(bv) ?
750
- av - bv :
751
- String(a).localeCompare(String(b));
752
- return config[`${prefix}_reverse`] ? -order : order;
753
- });
754
- const tickSize = sortedTicks.length;
755
- const cullingMax = config[`${prefix}_max`] || AXIS_DEFAULT_TICK_COUNT;
756
- let intervalForCulling = 0;
757
- for (let i = 1; i < tickSize; i++) {
758
- if (tickSize / i < cullingMax) {
759
- intervalForCulling = i;
760
- break;
761
- }
762
- }
763
- if (!intervalForCulling) {
764
- return ticks;
765
- }
766
- const visible = new Set(sortedTicks.filter((_, i) => i % intervalForCulling === 0));
767
- return ticks.filter(tick => visible.has(tick));
768
- }
769
- /**
770
- * Cull data-based x ticks like the SVG axis manual culling path.
771
- * @param {object} $$ ChartInternal context
772
- * @param {Array} ticks Tick values
773
- * @param {boolean} sorted Whether ticks are already sorted in x order
774
- * @returns {Array} Culled tick values
775
- * @private
776
- */
777
- function cullDataTicks($$, ticks, sorted = false) {
778
- const { config } = $$;
779
- if (config.axis_x_tick_culling === false) {
780
- return ticks;
781
- }
782
- const cullingMax = config.axis_x_tick_culling_max || AXIS_DEFAULT_TICK_COUNT;
783
- const sortedTicks = sorted ? ticks : ticks
784
- .slice()
785
- .sort((a, b) => {
786
- const av = +a;
787
- const bv = +b;
788
- if (Number.isFinite(av) && Number.isFinite(bv)) {
789
- return config.axis_x_tick_culling_reverse ? bv - av : av - bv;
790
- }
791
- return config.axis_x_tick_culling_reverse ?
792
- String(b).localeCompare(String(a)) :
793
- String(a).localeCompare(String(b));
794
- });
795
- const tickSize = sortedTicks.length;
796
- let intervalForCulling = 0;
797
- for (let i = 1; i < tickSize; i++) {
798
- if (tickSize / i < cullingMax) {
799
- intervalForCulling = i;
800
- break;
801
- }
802
- }
803
- if (!intervalForCulling) {
804
- return ticks;
805
- }
806
- if (sorted) {
807
- return ticks.filter((_, i) => config.axis_x_tick_culling_reverse ?
808
- (tickSize - 1 - i) % intervalForCulling === 0 :
809
- i % intervalForCulling === 0);
810
- }
811
- const visible = new Set(sortedTicks.filter((_, i) => i % intervalForCulling === 0));
812
- return ticks.filter(tick => visible.has(tick));
813
- }
814
- /**
815
- * Get max number of x ticks to render.
816
- * @param {object} $$ ChartInternal context
817
- * @returns {number|undefined} Max tick count
818
- * @private
819
- */
639
+ const len = ticks.length - 1;
640
+ if (count && len > count) {
641
+ const last = ticks.length - 1;
642
+ if (count <= 1) return [ticks[0]];
643
+ return Array.from({ length: count }, (_, i) => ticks[Math.round(i * last / (count - 1))]);
644
+ }
645
+ return ticks;
646
+ }
647
+ /**
648
+ * Cull axis ticks following SVG manual culling.
649
+ * @param {object} $$ ChartInternal context
650
+ * @param {string} id Axis id
651
+ * @param {Array} ticks Tick values
652
+ * @param {string} optionPrefix Tick option prefix
653
+ * @returns {Array} Culled tick values
654
+ * @private
655
+ */
656
+ function cullAxisTicks($$, id, ticks, optionPrefix = `axis_${id}`) {
657
+ const { config } = $$;
658
+ if (!getAxisTickOption(config, id, "culling", optionPrefix)) return ticks;
659
+ const cullingMax = getAxisTickOption(config, id, "culling_max", optionPrefix) || 10;
660
+ const reverse = getAxisTickOption(config, id, "culling_reverse", optionPrefix);
661
+ const sortedTicks = ticks.slice().sort((a, b) => {
662
+ const av = +a;
663
+ const bv = +b;
664
+ const order = Number.isFinite(av) && Number.isFinite(bv) ? av - bv : String(a).localeCompare(String(b));
665
+ return reverse ? -order : order;
666
+ });
667
+ const tickSize = sortedTicks.length;
668
+ let intervalForCulling = 0;
669
+ for (let i = 1; i < tickSize; i++) if (tickSize / i < cullingMax) {
670
+ intervalForCulling = i;
671
+ break;
672
+ }
673
+ if (!intervalForCulling) return ticks;
674
+ const visible = new Set(sortedTicks.filter((_, i) => i % intervalForCulling === 0));
675
+ return ticks.filter((tick) => visible.has(tick));
676
+ }
677
+ /**
678
+ * Cull data-based x ticks like the SVG axis manual culling path.
679
+ * @param {object} $$ ChartInternal context
680
+ * @param {Array} ticks Tick values
681
+ * @param {boolean} sorted Whether ticks are already sorted in x order
682
+ * @param {string} optionPrefix Tick option prefix
683
+ * @param {number} max Optional culling max override
684
+ * @returns {Array} Culled tick values
685
+ * @private
686
+ */
687
+ function cullDataTicks($$, ticks, sorted = false, optionPrefix = "axis_x", max) {
688
+ const { config } = $$;
689
+ if (getAxisTickOption(config, "x", "culling", optionPrefix) === false) return ticks;
690
+ const cullingMax = max || getAxisTickOption(config, "x", "culling_max", optionPrefix) || 10;
691
+ const reverse = getAxisTickOption(config, "x", "culling_reverse", optionPrefix);
692
+ const sortedTicks = sorted ? ticks : ticks.slice().sort((a, b) => {
693
+ const av = +a;
694
+ const bv = +b;
695
+ if (Number.isFinite(av) && Number.isFinite(bv)) return reverse ? bv - av : av - bv;
696
+ return reverse ? String(b).localeCompare(String(a)) : String(a).localeCompare(String(b));
697
+ });
698
+ const tickSize = sortedTicks.length;
699
+ let intervalForCulling = 0;
700
+ for (let i = 1; i < tickSize; i++) if (tickSize / i < cullingMax) {
701
+ intervalForCulling = i;
702
+ break;
703
+ }
704
+ if (!intervalForCulling) return ticks;
705
+ if (sorted) return ticks.filter((_, i) => reverse ? (tickSize - 1 - i) % intervalForCulling === 0 : i % intervalForCulling === 0);
706
+ const visible = new Set(sortedTicks.filter((_, i) => i % intervalForCulling === 0));
707
+ return ticks.filter((tick) => visible.has(tick));
708
+ }
709
+ /**
710
+ * Get max number of x ticks to render.
711
+ * @param {object} $$ ChartInternal context
712
+ * @returns {number|undefined} Max tick count
713
+ * @private
714
+ */
820
715
  function getXTickCullMax($$) {
821
- const { config, state: { height, width } } = $$;
822
- const size = config.axis_rotated ? height : width;
823
- if (config.axis_x_tick_count) {
824
- return config.axis_x_tick_count;
825
- }
826
- if (config.axis_x_tick_culling !== false) {
827
- return Math.min(config.axis_x_tick_culling_max || AXIS_DEFAULT_TICK_COUNT, Math.max(2, Math.floor(size / 70)));
828
- }
829
- return undefined;
830
- }
831
- /**
832
- * Get y grid ticks.
833
- * @param {object} $$ ChartInternal context
834
- * @returns {Array} Tick values
835
- * @private
836
- */
716
+ const { config, state: { height, width } } = $$;
717
+ const size = config.axis_rotated ? height : width;
718
+ if (config.axis_x_tick_count) return config.axis_x_tick_count;
719
+ if (config.axis_x_tick_culling !== false) return Math.min(config.axis_x_tick_culling_max || 10, Math.max(2, Math.floor(size / 70)));
720
+ }
721
+ /**
722
+ * Get y grid ticks.
723
+ * @param {object} $$ ChartInternal context
724
+ * @returns {Array} Tick values
725
+ * @private
726
+ */
837
727
  function getYGridTickValues($$) {
838
- const { axis, config } = $$;
839
- const generated = axis?.y?.getGeneratedTicks?.(config.grid_y_ticks);
840
- if (generated?.length) {
841
- return generated;
842
- }
843
- return config.grid_y_ticks ?
844
- cullTicks(getYTickValues($$, "y", undefined, false), config.grid_y_ticks) :
845
- getYTickValues($$, "y", undefined, false);
846
- }
847
-
848
- export { getAdditionalAxisScale, getAdditionalAxisTickFormat, getAdditionalAxisTickValues, getSubXTickValues, getXScale, getXTickLinePosition, getXTickLineValues, getXTickValues, getYGridTickValues, getYTickValues, isSameTickValue, normalizeXValue, normalizeYValue };
728
+ const { axis, config } = $$;
729
+ const generated = axis?.y?.getGeneratedTicks?.(config.grid_y_ticks);
730
+ if (generated?.length) return generated;
731
+ return config.grid_y_ticks ? cullTicks(getYTickValues($$, "y", void 0, false), config.grid_y_ticks) : getYTickValues($$, "y", void 0, false);
732
+ }
733
+ //#endregion
734
+ export { getAdditionalAxisScale, getAdditionalAxisTickFormat, getAdditionalAxisTickValues, getSubXTickLineValues, getSubXTickValues, getXScale, getXTickLinePosition, getXTickLineValues, getXTickValues, getYGridTickValues, getYTickValues, isSameTickValue, normalizeXValue, normalizeYValue };