@tabler/charts 0.0.0-stage → 0.0.1-alpha.0

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 (324) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +248 -2
  3. package/dist/annotations-Bp7HwtF5.d.ts +86 -0
  4. package/dist/annotations-BszTTjf9.js +202 -0
  5. package/dist/annotations-BszTTjf9.js.map +1 -0
  6. package/dist/annotations-DpETO8dE.cjs +213 -0
  7. package/dist/annotations-DpETO8dE.cjs.map +1 -0
  8. package/dist/annotations-lyt0I3HU.d.cts +86 -0
  9. package/dist/annotations.cjs +14 -0
  10. package/dist/annotations.cjs.map +1 -0
  11. package/dist/annotations.d.cts +2 -0
  12. package/dist/annotations.d.ts +2 -0
  13. package/dist/annotations.js +12 -0
  14. package/dist/annotations.js.map +1 -0
  15. package/dist/area-BFvkc-ZM.d.cts +20 -0
  16. package/dist/area-DQsLERhx.js +26 -0
  17. package/dist/area-DQsLERhx.js.map +1 -0
  18. package/dist/area-DaO4MQl4.d.ts +20 -0
  19. package/dist/area-sHCE3pg5.cjs +31 -0
  20. package/dist/area-sHCE3pg5.cjs.map +1 -0
  21. package/dist/area.cjs +3 -0
  22. package/dist/area.d.cts +2 -0
  23. package/dist/area.d.ts +2 -0
  24. package/dist/area.js +2 -0
  25. package/dist/band-DTcNDAFO.d.cts +50 -0
  26. package/dist/band-DTcNDAFO.d.ts +50 -0
  27. package/dist/bar-C-7zR2qp.cjs +243 -0
  28. package/dist/bar-C-7zR2qp.cjs.map +1 -0
  29. package/dist/bar-DGuUN3nc.cjs +67 -0
  30. package/dist/bar-DGuUN3nc.cjs.map +1 -0
  31. package/dist/bar-DM16NUvV.js +56 -0
  32. package/dist/bar-DM16NUvV.js.map +1 -0
  33. package/dist/bar-DdsDxk3W.d.ts +43 -0
  34. package/dist/bar-a0h9KC8A.d.cts +43 -0
  35. package/dist/bar-jZEoao74.js +238 -0
  36. package/dist/bar-jZEoao74.js.map +1 -0
  37. package/dist/bar.cjs +3 -0
  38. package/dist/bar.d.cts +2 -0
  39. package/dist/bar.d.ts +2 -0
  40. package/dist/bar.js +2 -0
  41. package/dist/candlestick-B5r1w3kc.cjs +150 -0
  42. package/dist/candlestick-B5r1w3kc.cjs.map +1 -0
  43. package/dist/candlestick-BKdPyorY.d.cts +44 -0
  44. package/dist/candlestick-BnUG1SGi.d.ts +44 -0
  45. package/dist/candlestick-DuXwAFID.js +145 -0
  46. package/dist/candlestick-DuXwAFID.js.map +1 -0
  47. package/dist/candlestick.cjs +11 -0
  48. package/dist/candlestick.cjs.map +1 -0
  49. package/dist/candlestick.d.cts +2 -0
  50. package/dist/candlestick.d.ts +2 -0
  51. package/dist/candlestick.js +10 -0
  52. package/dist/candlestick.js.map +1 -0
  53. package/dist/cartesian-BoDfgBCV.cjs +900 -0
  54. package/dist/cartesian-BoDfgBCV.cjs.map +1 -0
  55. package/dist/cartesian-Cr0AF0nG.js +709 -0
  56. package/dist/cartesian-Cr0AF0nG.js.map +1 -0
  57. package/dist/chart-BF2CK9I_.js +790 -0
  58. package/dist/chart-BF2CK9I_.js.map +1 -0
  59. package/dist/chart-CowF_lWY.cjs +903 -0
  60. package/dist/chart-CowF_lWY.cjs.map +1 -0
  61. package/dist/chart-Qa417fJo.d.cts +927 -0
  62. package/dist/chart-iJGxMz9z.d.ts +927 -0
  63. package/dist/circle-BQMuAfls.cjs +12 -0
  64. package/dist/circle-BQMuAfls.cjs.map +1 -0
  65. package/dist/circle-Z7YfCoCM.js +7 -0
  66. package/dist/circle-Z7YfCoCM.js.map +1 -0
  67. package/dist/clean-Byl6kzf0.cjs +115 -0
  68. package/dist/clean-Byl6kzf0.cjs.map +1 -0
  69. package/dist/clean-o1vDEhFV.js +56 -0
  70. package/dist/clean-o1vDEhFV.js.map +1 -0
  71. package/dist/core-C7fPm6t7.cjs +976 -0
  72. package/dist/core-C7fPm6t7.cjs.map +1 -0
  73. package/dist/core-CjgbhS_v.d.ts +219 -0
  74. package/dist/core-CnGFKojH.d.cts +219 -0
  75. package/dist/core-plobgBC7.js +875 -0
  76. package/dist/core-plobgBC7.js.map +1 -0
  77. package/dist/core.cjs +113 -0
  78. package/dist/core.d.cts +20 -0
  79. package/dist/core.d.ts +20 -0
  80. package/dist/core.js +24 -0
  81. package/dist/dates-Btm7Zm6W.cjs +32 -0
  82. package/dist/dates-Btm7Zm6W.cjs.map +1 -0
  83. package/dist/dates-CG-FvioW.js +27 -0
  84. package/dist/dates-CG-FvioW.js.map +1 -0
  85. package/dist/decimate-BGg9XgF0.d.ts +17 -0
  86. package/dist/decimate-C87cl_Sp.js +84 -0
  87. package/dist/decimate-C87cl_Sp.js.map +1 -0
  88. package/dist/decimate-CNSpgGa5.d.cts +17 -0
  89. package/dist/decimate-tLhDk1ys.cjs +95 -0
  90. package/dist/decimate-tLhDk1ys.cjs.map +1 -0
  91. package/dist/decimate.cjs +14 -0
  92. package/dist/decimate.cjs.map +1 -0
  93. package/dist/decimate.d.cts +2 -0
  94. package/dist/decimate.d.ts +2 -0
  95. package/dist/decimate.js +12 -0
  96. package/dist/decimate.js.map +1 -0
  97. package/dist/dom-CLF868Qs.cjs +222 -0
  98. package/dist/dom-CLF868Qs.cjs.map +1 -0
  99. package/dist/dom-vP3IcMak.js +175 -0
  100. package/dist/dom-vP3IcMak.js.map +1 -0
  101. package/dist/export-chart-9w8t3rjZ.js +232 -0
  102. package/dist/export-chart-9w8t3rjZ.js.map +1 -0
  103. package/dist/export-chart-BhhYgksr.cjs +249 -0
  104. package/dist/export-chart-BhhYgksr.cjs.map +1 -0
  105. package/dist/export.cjs +18 -0
  106. package/dist/export.cjs.map +1 -0
  107. package/dist/export.d.cts +2 -0
  108. package/dist/export.d.ts +2 -0
  109. package/dist/export.js +15 -0
  110. package/dist/export.js.map +1 -0
  111. package/dist/extent-BAMZo0Nq.js +19 -0
  112. package/dist/extent-BAMZo0Nq.js.map +1 -0
  113. package/dist/extent-DsFWvAHJ.cjs +24 -0
  114. package/dist/extent-DsFWvAHJ.cjs.map +1 -0
  115. package/dist/fade-Cs74puQS.cjs +217 -0
  116. package/dist/fade-Cs74puQS.cjs.map +1 -0
  117. package/dist/fade-D3NxH5Qg.js +200 -0
  118. package/dist/fade-D3NxH5Qg.js.map +1 -0
  119. package/dist/features-BclHgg2W.cjs +48 -0
  120. package/dist/features-BclHgg2W.cjs.map +1 -0
  121. package/dist/features-wASyHGic.js +25 -0
  122. package/dist/features-wASyHGic.js.map +1 -0
  123. package/dist/format-B0yKXBTH.cjs +183 -0
  124. package/dist/format-B0yKXBTH.cjs.map +1 -0
  125. package/dist/format-lStwuc1L.js +142 -0
  126. package/dist/format-lStwuc1L.js.map +1 -0
  127. package/dist/gauge-CEfkWXSu.cjs +235 -0
  128. package/dist/gauge-CEfkWXSu.cjs.map +1 -0
  129. package/dist/gauge-Cu9jttC0.d.ts +65 -0
  130. package/dist/gauge-Cu_OFxBd.d.cts +65 -0
  131. package/dist/gauge-_ljQHrMN.js +230 -0
  132. package/dist/gauge-_ljQHrMN.js.map +1 -0
  133. package/dist/gauge.cjs +3 -0
  134. package/dist/gauge.d.cts +2 -0
  135. package/dist/gauge.d.ts +2 -0
  136. package/dist/gauge.js +2 -0
  137. package/dist/heatmap-BK18EBgJ.cjs +247 -0
  138. package/dist/heatmap-BK18EBgJ.cjs.map +1 -0
  139. package/dist/heatmap-BwS-y0c6.d.cts +81 -0
  140. package/dist/heatmap-DSZ2bVIa.js +242 -0
  141. package/dist/heatmap-DSZ2bVIa.js.map +1 -0
  142. package/dist/heatmap-PhLPXIg1.d.ts +81 -0
  143. package/dist/heatmap.cjs +3 -0
  144. package/dist/heatmap.d.cts +2 -0
  145. package/dist/heatmap.d.ts +2 -0
  146. package/dist/heatmap.js +2 -0
  147. package/dist/hydrate-CTTmQy0x.d.cts +10 -0
  148. package/dist/hydrate-CxwTXDqO.cjs +60 -0
  149. package/dist/hydrate-CxwTXDqO.cjs.map +1 -0
  150. package/dist/hydrate-CzfxLfTv.d.ts +10 -0
  151. package/dist/hydrate-DDNIHYv_.js +55 -0
  152. package/dist/hydrate-DDNIHYv_.js.map +1 -0
  153. package/dist/hydrate.cjs +13 -0
  154. package/dist/hydrate.cjs.map +1 -0
  155. package/dist/hydrate.d.cts +2 -0
  156. package/dist/hydrate.d.ts +2 -0
  157. package/dist/hydrate.js +12 -0
  158. package/dist/hydrate.js.map +1 -0
  159. package/dist/index.cjs +211 -0
  160. package/dist/index.cjs.map +1 -0
  161. package/dist/index.d.cts +45 -0
  162. package/dist/index.d.ts +45 -0
  163. package/dist/index.js +113 -0
  164. package/dist/index.js.map +1 -0
  165. package/dist/layout-B3hiqVEw.js +69 -0
  166. package/dist/layout-B3hiqVEw.js.map +1 -0
  167. package/dist/layout-CtMBhNd9.cjs +98 -0
  168. package/dist/layout-CtMBhNd9.cjs.map +1 -0
  169. package/dist/line-B3Ed6u7j.js +120 -0
  170. package/dist/line-B3Ed6u7j.js.map +1 -0
  171. package/dist/line-CMDGH6q5.d.cts +47 -0
  172. package/dist/line-D5kb8e6w.d.ts +47 -0
  173. package/dist/line-fQbtP_jL.cjs +131 -0
  174. package/dist/line-fQbtP_jL.cjs.map +1 -0
  175. package/dist/line.cjs +14 -0
  176. package/dist/line.cjs.map +1 -0
  177. package/dist/line.d.cts +2 -0
  178. package/dist/line.d.ts +2 -0
  179. package/dist/line.js +13 -0
  180. package/dist/line.js.map +1 -0
  181. package/dist/log-CaofN3-n.d.cts +48 -0
  182. package/dist/log-CaofN3-n.d.ts +48 -0
  183. package/dist/log-axis-83rSpvL5.cjs +130 -0
  184. package/dist/log-axis-83rSpvL5.cjs.map +1 -0
  185. package/dist/log-axis-B_uvvOFc.js +113 -0
  186. package/dist/log-axis-B_uvvOFc.js.map +1 -0
  187. package/dist/log.cjs +17 -0
  188. package/dist/log.cjs.map +1 -0
  189. package/dist/log.d.cts +2 -0
  190. package/dist/log.d.ts +2 -0
  191. package/dist/log.js +16 -0
  192. package/dist/log.js.map +1 -0
  193. package/dist/morph-BMxz3X2b.d.cts +10 -0
  194. package/dist/morph-BMxz3X2b.d.ts +10 -0
  195. package/dist/morph-Bgg-24l8.js +36 -0
  196. package/dist/morph-Bgg-24l8.js.map +1 -0
  197. package/dist/morph-CqYDu1bY.cjs +41 -0
  198. package/dist/morph-CqYDu1bY.cjs.map +1 -0
  199. package/dist/morph.cjs +14 -0
  200. package/dist/morph.cjs.map +1 -0
  201. package/dist/morph.d.cts +2 -0
  202. package/dist/morph.d.ts +2 -0
  203. package/dist/morph.js +13 -0
  204. package/dist/morph.js.map +1 -0
  205. package/dist/named-BWWb5LQJ.cjs +50 -0
  206. package/dist/named-BWWb5LQJ.cjs.map +1 -0
  207. package/dist/named-DE15TOgh.js +33 -0
  208. package/dist/named-DE15TOgh.js.map +1 -0
  209. package/dist/path-CwB28da0.d.cts +29 -0
  210. package/dist/path-CwB28da0.d.ts +29 -0
  211. package/dist/patterns-DtgcnA8o.js +85 -0
  212. package/dist/patterns-DtgcnA8o.js.map +1 -0
  213. package/dist/patterns-LfcQAWCy.cjs +102 -0
  214. package/dist/patterns-LfcQAWCy.cjs.map +1 -0
  215. package/dist/patterns.cjs +15 -0
  216. package/dist/patterns.cjs.map +1 -0
  217. package/dist/patterns.d.cts +2 -0
  218. package/dist/patterns.d.ts +2 -0
  219. package/dist/patterns.js +12 -0
  220. package/dist/patterns.js.map +1 -0
  221. package/dist/pie-B8UlOZiq.d.ts +58 -0
  222. package/dist/pie-C1Pa6W_l.cjs +211 -0
  223. package/dist/pie-C1Pa6W_l.cjs.map +1 -0
  224. package/dist/pie-DnQQmxkk.d.cts +58 -0
  225. package/dist/pie-RnMTQWMS.js +200 -0
  226. package/dist/pie-RnMTQWMS.js.map +1 -0
  227. package/dist/pie.cjs +4 -0
  228. package/dist/pie.d.cts +2 -0
  229. package/dist/pie.d.ts +2 -0
  230. package/dist/pie.js +2 -0
  231. package/dist/point-shapes-CGl4dugc.cjs +166 -0
  232. package/dist/point-shapes-CGl4dugc.cjs.map +1 -0
  233. package/dist/point-shapes-DI84NNpI.js +155 -0
  234. package/dist/point-shapes-DI84NNpI.js.map +1 -0
  235. package/dist/point-shapes.cjs +15 -0
  236. package/dist/point-shapes.cjs.map +1 -0
  237. package/dist/point-shapes.d.cts +2 -0
  238. package/dist/point-shapes.d.ts +2 -0
  239. package/dist/point-shapes.js +13 -0
  240. package/dist/point-shapes.js.map +1 -0
  241. package/dist/radar-BB13CGmq.d.cts +60 -0
  242. package/dist/radar-CYPab_I4.js +285 -0
  243. package/dist/radar-CYPab_I4.js.map +1 -0
  244. package/dist/radar-CoGUNNSb.cjs +290 -0
  245. package/dist/radar-CoGUNNSb.cjs.map +1 -0
  246. package/dist/radar-pFI6fvOq.d.ts +60 -0
  247. package/dist/radar.cjs +3 -0
  248. package/dist/radar.d.cts +2 -0
  249. package/dist/radar.d.ts +2 -0
  250. package/dist/radar.js +2 -0
  251. package/dist/sankey-B4PNKusJ.js +420 -0
  252. package/dist/sankey-B4PNKusJ.js.map +1 -0
  253. package/dist/sankey-B9JYnx7e.d.cts +67 -0
  254. package/dist/sankey-Bacx4fVe.cjs +425 -0
  255. package/dist/sankey-Bacx4fVe.cjs.map +1 -0
  256. package/dist/sankey-Bm518bqL.d.ts +67 -0
  257. package/dist/sankey.cjs +3 -0
  258. package/dist/sankey.d.cts +2 -0
  259. package/dist/sankey.d.ts +2 -0
  260. package/dist/sankey.js +2 -0
  261. package/dist/scatter-Bl7nasE6.d.ts +61 -0
  262. package/dist/scatter-DgMN9zRy.cjs +250 -0
  263. package/dist/scatter-DgMN9zRy.cjs.map +1 -0
  264. package/dist/scatter-DrJ8xYz4.d.cts +61 -0
  265. package/dist/scatter-kgtgR318.js +245 -0
  266. package/dist/scatter-kgtgR318.js.map +1 -0
  267. package/dist/scatter.cjs +3 -0
  268. package/dist/scatter.d.cts +2 -0
  269. package/dist/scatter.d.ts +2 -0
  270. package/dist/scatter.js +2 -0
  271. package/dist/sparkline-BG13V4Pz.d.cts +43 -0
  272. package/dist/sparkline-BQzt27Fr.js +171 -0
  273. package/dist/sparkline-BQzt27Fr.js.map +1 -0
  274. package/dist/sparkline-BS9-hltA.cjs +176 -0
  275. package/dist/sparkline-BS9-hltA.cjs.map +1 -0
  276. package/dist/sparkline-iWuXbKpd.d.ts +43 -0
  277. package/dist/sparkline.cjs +3 -0
  278. package/dist/sparkline.d.cts +2 -0
  279. package/dist/sparkline.d.ts +2 -0
  280. package/dist/sparkline.js +2 -0
  281. package/dist/stack-CpR6RGKd.d.cts +6 -0
  282. package/dist/stack-CpR6RGKd.d.ts +6 -0
  283. package/dist/stack-DRbwTeF3.js +66 -0
  284. package/dist/stack-DRbwTeF3.js.map +1 -0
  285. package/dist/stack-DVhJWaki.cjs +77 -0
  286. package/dist/stack-DVhJWaki.cjs.map +1 -0
  287. package/dist/style.css +2 -0
  288. package/dist/sweep-Duowaput.cjs +369 -0
  289. package/dist/sweep-Duowaput.cjs.map +1 -0
  290. package/dist/sweep-WSgn2etB.js +334 -0
  291. package/dist/sweep-WSgn2etB.js.map +1 -0
  292. package/dist/time-CHjiY9Q4.d.ts +112 -0
  293. package/dist/time-CNVnt-B2.d.cts +112 -0
  294. package/dist/time-axis-Bc9eHX1r.js +365 -0
  295. package/dist/time-axis-Bc9eHX1r.js.map +1 -0
  296. package/dist/time-axis-VSX34_Tb.cjs +382 -0
  297. package/dist/time-axis-VSX34_Tb.cjs.map +1 -0
  298. package/dist/time.cjs +22 -0
  299. package/dist/time.cjs.map +1 -0
  300. package/dist/time.d.cts +2 -0
  301. package/dist/time.d.ts +2 -0
  302. package/dist/time.js +20 -0
  303. package/dist/time.js.map +1 -0
  304. package/dist/tween-BCYd0RTY.js +40 -0
  305. package/dist/tween-BCYd0RTY.js.map +1 -0
  306. package/dist/tween-CIGBlryn.cjs +51 -0
  307. package/dist/tween-CIGBlryn.cjs.map +1 -0
  308. package/dist/value-labels-B0WJoJ7x.cjs +134 -0
  309. package/dist/value-labels-B0WJoJ7x.cjs.map +1 -0
  310. package/dist/value-labels-IZIQPhfk.js +123 -0
  311. package/dist/value-labels-IZIQPhfk.js.map +1 -0
  312. package/dist/value-labels.cjs +14 -0
  313. package/dist/value-labels.cjs.map +1 -0
  314. package/dist/value-labels.d.cts +2 -0
  315. package/dist/value-labels.d.ts +2 -0
  316. package/dist/value-labels.js +12 -0
  317. package/dist/value-labels.js.map +1 -0
  318. package/dist/vnode-BUflsBsa.d.cts +66 -0
  319. package/dist/vnode-BUflsBsa.d.ts +66 -0
  320. package/dist/vnode-CkQ27Cxe.cjs +110 -0
  321. package/dist/vnode-CkQ27Cxe.cjs.map +1 -0
  322. package/dist/vnode-tCWItoUH.js +93 -0
  323. package/dist/vnode-tCWItoUH.js.map +1 -0
  324. package/package.json +310 -3
@@ -0,0 +1,183 @@
1
+ //#region src/format.ts
2
+ const MAX_CACHE = 64;
3
+ const numberCache = /* @__PURE__ */ new Map();
4
+ const dateCache = /* @__PURE__ */ new Map();
5
+ function cached(cache, key, create) {
6
+ let value = cache.get(key);
7
+ if (value === void 0) {
8
+ if (cache.size >= MAX_CACHE) cache.clear();
9
+ value = create();
10
+ cache.set(key, value);
11
+ }
12
+ return value;
13
+ }
14
+ function cacheKey(locale, options) {
15
+ return `${JSON.stringify(locale ?? null)}|${JSON.stringify(options)}`;
16
+ }
17
+ /** Shared, cached `Intl.NumberFormat` instance. */
18
+ function getNumberFormat(locale, options = {}) {
19
+ return cached(numberCache, cacheKey(locale, options), () => new Intl.NumberFormat(locale, options));
20
+ }
21
+ /** Shared, cached `Intl.DateTimeFormat` instance. */
22
+ function getDateFormat(locale, options = {}) {
23
+ return cached(dateCache, cacheKey(locale, options), () => new Intl.DateTimeFormat(locale, options));
24
+ }
25
+ /** Avoid `-0` rendering as "-0". */
26
+ const unsignedZero = (value) => value === 0 ? 0 : value;
27
+ /**
28
+ * Create a number formatter.
29
+ *
30
+ * ```ts
31
+ * formatNumber({ style: 'currency', currency: 'PLN' }, 'pl-PL')(1234.5) // "1234,50 zł"
32
+ * ```
33
+ */
34
+ function formatNumber(format, locale) {
35
+ if (typeof format === "function") return format;
36
+ const { compactSymbols, ...options } = format ?? {};
37
+ if (compactSymbols) return formatCompact(compactSymbols === true ? SYMBOLS : compactSymbols, options, locale);
38
+ const nf = getNumberFormat(locale, options);
39
+ return (value) => nf.format(unsignedZero(value));
40
+ }
41
+ const SYMBOLS = [
42
+ "K",
43
+ "M",
44
+ "B",
45
+ "T"
46
+ ];
47
+ /**
48
+ * Compact notation with the given suffixes: the value divided by its power
49
+ * of a thousand, formatted by `Intl` (separators, currency, sign) with the
50
+ * suffix after the digits. Without digits of its own it rounds like `Intl`'s
51
+ * compact notation: two significant digits below 10, whole numbers above.
52
+ */
53
+ function formatCompact(symbols, { notation, compactDisplay, ...options }, locale) {
54
+ const own = digitsOf(options);
55
+ const small = getNumberFormat(locale, own ? options : {
56
+ ...options,
57
+ maximumSignificantDigits: 2
58
+ });
59
+ const large = own ? small : getNumberFormat(locale, {
60
+ ...options,
61
+ maximumFractionDigits: 0
62
+ });
63
+ return (value) => {
64
+ for (let exp = 0;; exp++) {
65
+ const scaled = unsignedZero(value / 1e3 ** exp);
66
+ const parts = (Math.abs(scaled) < 10 ? small : large).formatToParts(scaled);
67
+ let digits = "";
68
+ let last;
69
+ for (const part of parts) {
70
+ if (part.type === "integer") digits += part.value;
71
+ if (part.type === "integer" || part.type === "fraction") last = part;
72
+ }
73
+ if (digits.length < 4 || exp >= symbols.length) {
74
+ if (exp && last) last.value += symbols[exp - 1];
75
+ return parts.map((part) => part.value).join("");
76
+ }
77
+ }
78
+ };
79
+ }
80
+ /** Whether number options write compact numbers ("25K"). */
81
+ const compactOf = (o) => o.notation === "compact" || !!o.compactSymbols;
82
+ /** Whether number options set their digits (fraction or significant). */
83
+ const digitsOf = (o) => (o.minimumFractionDigits ?? o.maximumFractionDigits ?? o.minimumSignificantDigits ?? o.maximumSignificantDigits) !== void 0;
84
+ /**
85
+ * A formatter for values read one at a time (tooltips, data tables) in an
86
+ * axis format. Compact notation suits ticks ("$25K") but hides the
87
+ * difference between values: unless the format sets its own precision, it
88
+ * keeps three significant digits ("$24.8K").
89
+ */
90
+ function formatDetail(format, locale) {
91
+ return formatNumber(typeof format === "object" && compactOf(format) && !digitsOf(format) ? {
92
+ ...format,
93
+ maximumSignificantDigits: 3
94
+ } : format, locale);
95
+ }
96
+ /**
97
+ * Number of fraction digits needed to tell apart ticks `step` apart,
98
+ * e.g. `1 → 0`, `0.2 → 1`, `0.05 → 2`.
99
+ */
100
+ function stepPrecision(step) {
101
+ const abs = Math.abs(step);
102
+ if (!Number.isFinite(abs) || abs === 0) return 0;
103
+ return Math.max(0, -Math.floor(Math.log10(abs) + 1e-9));
104
+ }
105
+ function hasPrecision(options) {
106
+ return digitsOf(options) || !!options.compactSymbols || (options.notation ?? "standard") !== "standard";
107
+ }
108
+ /**
109
+ * Create a formatter for axis ticks `step` apart. Unless `format` sets its
110
+ * own precision, every tick gets the same number of fraction digits, derived
111
+ * from the step (`0, 0.5, 1` → `0.0, 0.5, 1.0`).
112
+ */
113
+ function formatTicks(step, format, locale) {
114
+ if (typeof format === "function") return format;
115
+ const options = format ?? {};
116
+ if (hasPrecision(options)) return formatNumber(options, locale);
117
+ let digits = stepPrecision(step);
118
+ if (options.style === "percent") digits = Math.max(0, digits - 2);
119
+ const fmt = formatNumber({
120
+ ...options,
121
+ minimumFractionDigits: digits,
122
+ maximumFractionDigits: digits
123
+ }, locale);
124
+ const epsilon = Math.abs(step) * 1e-9;
125
+ return (value) => fmt(Math.abs(value) < epsilon ? 0 : value);
126
+ }
127
+ /**
128
+ * Create a date formatter accepting `Date` objects or timestamps.
129
+ *
130
+ * ```ts
131
+ * formatDate({ month: 'short', day: 'numeric' }, 'en-US')(new Date(2026, 0, 5)) // "Jan 5"
132
+ * ```
133
+ */
134
+ function formatDate(format, locale) {
135
+ if (typeof format === "function") return (value) => format(typeof value === "number" ? new Date(value) : value);
136
+ const df = getDateFormat(locale, format);
137
+ return (value) => df.format(value);
138
+ }
139
+ //#endregion
140
+ Object.defineProperty(exports, "formatDate", {
141
+ enumerable: true,
142
+ get: function() {
143
+ return formatDate;
144
+ }
145
+ });
146
+ Object.defineProperty(exports, "formatDetail", {
147
+ enumerable: true,
148
+ get: function() {
149
+ return formatDetail;
150
+ }
151
+ });
152
+ Object.defineProperty(exports, "formatNumber", {
153
+ enumerable: true,
154
+ get: function() {
155
+ return formatNumber;
156
+ }
157
+ });
158
+ Object.defineProperty(exports, "formatTicks", {
159
+ enumerable: true,
160
+ get: function() {
161
+ return formatTicks;
162
+ }
163
+ });
164
+ Object.defineProperty(exports, "getDateFormat", {
165
+ enumerable: true,
166
+ get: function() {
167
+ return getDateFormat;
168
+ }
169
+ });
170
+ Object.defineProperty(exports, "getNumberFormat", {
171
+ enumerable: true,
172
+ get: function() {
173
+ return getNumberFormat;
174
+ }
175
+ });
176
+ Object.defineProperty(exports, "stepPrecision", {
177
+ enumerable: true,
178
+ get: function() {
179
+ return stepPrecision;
180
+ }
181
+ });
182
+
183
+ //# sourceMappingURL=format-B0yKXBTH.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-B0yKXBTH.cjs","names":[],"sources":["../src/format.ts"],"sourcesContent":["/**\n * Number and date formatting built on `Intl` — locale aware, zero bytes of\n * locale data shipped.\n *\n * Formats are plain data (`Intl` options) or functions, so chart configs stay\n * serializable (JSON attributes, SSR). Pass an explicit `locale` when\n * rendering on the server, otherwise server and browser may disagree.\n */\n\n/** Locale(s) passed to `Intl`; `undefined` uses the runtime default. */\nexport type Locale = string | readonly string[] | undefined\n\n/** `Intl.NumberFormat` options, plus suffixes of our own for compact notation. */\nexport interface NumberFormatOptions extends Intl.NumberFormatOptions {\n /**\n * Compact notation with these suffixes for thousands, millions, billions…\n * instead of the locale's words: `['k', 'M', 'G']` writes 1500 as \"1.5k\",\n * or \"1,5k\" in Polish, where the locale itself writes \"1,5 tys.\". `true`\n * stands for `['K', 'M', 'B', 'T']`. Larger numbers keep the last suffix.\n */\n compactSymbols?: boolean | readonly string[]\n}\n\n/** Number format options or a custom formatter. */\nexport type NumberFormat = NumberFormatOptions | ((value: number) => string)\n\n/** `Intl.DateTimeFormat` options or a custom formatter. */\nexport type DateFormat = Intl.DateTimeFormatOptions | ((value: Date) => string)\n\nconst MAX_CACHE = 64\nconst numberCache = /* @__PURE__ */ new Map<string, Intl.NumberFormat>()\nconst dateCache = /* @__PURE__ */ new Map<string, Intl.DateTimeFormat>()\n\nfunction cached<T>(cache: Map<string, T>, key: string, create: () => T): T {\n let value = cache.get(key)\n if (value === undefined) {\n if (cache.size >= MAX_CACHE) cache.clear()\n value = create()\n cache.set(key, value)\n }\n return value\n}\n\nfunction cacheKey(locale: Locale, options: object): string {\n return `${JSON.stringify(locale ?? null)}|${JSON.stringify(options)}`\n}\n\n/** Shared, cached `Intl.NumberFormat` instance. */\nexport function getNumberFormat(\n locale?: Locale,\n options: Intl.NumberFormatOptions = {},\n): Intl.NumberFormat {\n return cached(\n numberCache,\n cacheKey(locale, options),\n () => new Intl.NumberFormat(locale as string | string[] | undefined, options),\n )\n}\n\n/** Shared, cached `Intl.DateTimeFormat` instance. */\nexport function getDateFormat(\n locale?: Locale,\n options: Intl.DateTimeFormatOptions = {},\n): Intl.DateTimeFormat {\n return cached(\n dateCache,\n cacheKey(locale, options),\n () => new Intl.DateTimeFormat(locale as string | string[] | undefined, options),\n )\n}\n\n/** Avoid `-0` rendering as \"-0\". */\nconst unsignedZero = (value: number): number => (value === 0 ? 0 : value)\n\n/**\n * Create a number formatter.\n *\n * ```ts\n * formatNumber({ style: 'currency', currency: 'PLN' }, 'pl-PL')(1234.5) // \"1234,50 zł\"\n * ```\n */\nexport function formatNumber(format?: NumberFormat, locale?: Locale): (value: number) => string {\n if (typeof format === 'function') return format\n const { compactSymbols, ...options } = format ?? {}\n if (compactSymbols) {\n return formatCompact(compactSymbols === true ? SYMBOLS : compactSymbols, options, locale)\n }\n const nf = getNumberFormat(locale, options)\n return (value) => nf.format(unsignedZero(value))\n}\n\nconst SYMBOLS = ['K', 'M', 'B', 'T']\n\n/**\n * Compact notation with the given suffixes: the value divided by its power\n * of a thousand, formatted by `Intl` (separators, currency, sign) with the\n * suffix after the digits. Without digits of its own it rounds like `Intl`'s\n * compact notation: two significant digits below 10, whole numbers above.\n */\nfunction formatCompact(\n symbols: readonly string[],\n // `notation` and `compactDisplay` are taken out: the suffixes replace them.\n { notation, compactDisplay, ...options }: Intl.NumberFormatOptions,\n locale: Locale,\n): (value: number) => string {\n const own = digitsOf(options)\n const small = getNumberFormat(locale, own ? options : { ...options, maximumSignificantDigits: 2 })\n const large = own ? small : getNumberFormat(locale, { ...options, maximumFractionDigits: 0 })\n return (value) => {\n for (let exp = 0; ; exp++) {\n const scaled = unsignedZero(value / 1000 ** exp)\n const parts = (Math.abs(scaled) < 10 ? small : large).formatToParts(scaled)\n let digits = ''\n let last: Intl.NumberFormatPart | undefined\n for (const part of parts) {\n if (part.type === 'integer') digits += part.value\n if (part.type === 'integer' || part.type === 'fraction') last = part\n }\n // Four digits or more: a thousand times smaller, with the next suffix\n // (so 999 950 rounds up to \"1M\", not \"1000K\").\n if (digits.length < 4 || exp >= symbols.length) {\n if (exp && last) last.value += symbols[exp - 1]\n return parts.map((part) => part.value).join('')\n }\n }\n }\n}\n\n/** Whether number options write compact numbers (\"25K\"). */\nconst compactOf = (o: NumberFormatOptions): boolean =>\n o.notation === 'compact' || !!o.compactSymbols\n\n/** Whether number options set their digits (fraction or significant). */\nconst digitsOf = (o: Intl.NumberFormatOptions): boolean =>\n (o.minimumFractionDigits ??\n o.maximumFractionDigits ??\n o.minimumSignificantDigits ??\n o.maximumSignificantDigits) !== undefined\n\n/**\n * A formatter for values read one at a time (tooltips, data tables) in an\n * axis format. Compact notation suits ticks (\"$25K\") but hides the\n * difference between values: unless the format sets its own precision, it\n * keeps three significant digits (\"$24.8K\").\n */\nexport function formatDetail(format?: NumberFormat, locale?: Locale): (value: number) => string {\n return formatNumber(\n typeof format === 'object' && compactOf(format) && !digitsOf(format)\n ? { ...format, maximumSignificantDigits: 3 }\n : format,\n locale,\n )\n}\n/**\n * Number of fraction digits needed to tell apart ticks `step` apart,\n * e.g. `1 → 0`, `0.2 → 1`, `0.05 → 2`.\n */\nexport function stepPrecision(step: number): number {\n const abs = Math.abs(step)\n if (!Number.isFinite(abs) || abs === 0) return 0\n return Math.max(0, -Math.floor(Math.log10(abs) + 1e-9))\n}\n\nfunction hasPrecision(options: NumberFormatOptions): boolean {\n return (\n digitsOf(options) || !!options.compactSymbols || (options.notation ?? 'standard') !== 'standard'\n )\n}\n/**\n * Create a formatter for axis ticks `step` apart. Unless `format` sets its\n * own precision, every tick gets the same number of fraction digits, derived\n * from the step (`0, 0.5, 1` → `0.0, 0.5, 1.0`).\n */\nexport function formatTicks(\n step: number,\n format?: NumberFormat,\n locale?: Locale,\n): (value: number) => string {\n if (typeof format === 'function') return format\n const options = format ?? {}\n if (hasPrecision(options)) return formatNumber(options, locale)\n\n let digits = stepPrecision(step)\n if (options.style === 'percent') digits = Math.max(0, digits - 2)\n const fmt = formatNumber(\n { ...options, minimumFractionDigits: digits, maximumFractionDigits: digits },\n locale,\n )\n // Values within floating point noise of zero (e.g. 1e-17) print as zero.\n const epsilon = Math.abs(step) * 1e-9\n return (value) => fmt(Math.abs(value) < epsilon ? 0 : value)\n}\n\n/**\n * Create a date formatter accepting `Date` objects or timestamps.\n *\n * ```ts\n * formatDate({ month: 'short', day: 'numeric' }, 'en-US')(new Date(2026, 0, 5)) // \"Jan 5\"\n * ```\n */\nexport function formatDate(format?: DateFormat, locale?: Locale): (value: Date | number) => string {\n if (typeof format === 'function') {\n return (value) => format(typeof value === 'number' ? new Date(value) : value)\n }\n const df = getDateFormat(locale, format)\n return (value) => df.format(value)\n}\n"],"mappings":";AA6BA,MAAM,YAAY;AAClB,MAAM,8BAA8B,IAAI,IAA+B;AACvE,MAAM,4BAA4B,IAAI,IAAiC;AAEvE,SAAS,OAAU,OAAuB,KAAa,QAAoB;CAC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AI,OAAO,WAAW,YAAY,OAAO;CACzC,MAAM,UAAU,UAAU,CAAC;CAC3B,IAAI,aAAa,OAAO,GAAG,OAAO,aAAa,SAAS,MAAM;CAE9D,IAAI,SAAS,cAAc,IAAI;CAC/B,IAAI,QAAQ,UAAU,WAAW,SAAS,KAAK,IAAI,GAAG,SAAS,CAAC;CAChE,MAAM,MAAM,aACV;EAAE,GAAG;EAAS,uBAAuB;EAAQ,uBAAuB;CAAO,GAC3E,MACF;CAEA,MAAM,UAAU,KAAK,IAAI,IAAI,IAAI;CACjC,QAAQ,UAAU,IAAI,KAAK,IAAI,KAAK,IAAI,UAAU,IAAI,KAAK;AAC7D;;;;;;;;AASA,SAAgB,WAAW,QAAqB,QAAmD;CACjG,IAAI,OAAO,WAAW,YACpB,QAAQ,UAAU,OAAO,OAAO,UAAU,WAAW,IAAI,KAAK,KAAK,IAAI,KAAK;CAE9E,MAAM,KAAK,cAAc,QAAQ,MAAM;CACvC,QAAQ,UAAU,GAAG,OAAO,KAAK;AACnC"}
@@ -0,0 +1,142 @@
1
+ //#region src/format.ts
2
+ const MAX_CACHE = 64;
3
+ const numberCache = /* @__PURE__ */ new Map();
4
+ const dateCache = /* @__PURE__ */ new Map();
5
+ function cached(cache, key, create) {
6
+ let value = cache.get(key);
7
+ if (value === void 0) {
8
+ if (cache.size >= MAX_CACHE) cache.clear();
9
+ value = create();
10
+ cache.set(key, value);
11
+ }
12
+ return value;
13
+ }
14
+ function cacheKey(locale, options) {
15
+ return `${JSON.stringify(locale ?? null)}|${JSON.stringify(options)}`;
16
+ }
17
+ /** Shared, cached `Intl.NumberFormat` instance. */
18
+ function getNumberFormat(locale, options = {}) {
19
+ return cached(numberCache, cacheKey(locale, options), () => new Intl.NumberFormat(locale, options));
20
+ }
21
+ /** Shared, cached `Intl.DateTimeFormat` instance. */
22
+ function getDateFormat(locale, options = {}) {
23
+ return cached(dateCache, cacheKey(locale, options), () => new Intl.DateTimeFormat(locale, options));
24
+ }
25
+ /** Avoid `-0` rendering as "-0". */
26
+ const unsignedZero = (value) => value === 0 ? 0 : value;
27
+ /**
28
+ * Create a number formatter.
29
+ *
30
+ * ```ts
31
+ * formatNumber({ style: 'currency', currency: 'PLN' }, 'pl-PL')(1234.5) // "1234,50 zł"
32
+ * ```
33
+ */
34
+ function formatNumber(format, locale) {
35
+ if (typeof format === "function") return format;
36
+ const { compactSymbols, ...options } = format ?? {};
37
+ if (compactSymbols) return formatCompact(compactSymbols === true ? SYMBOLS : compactSymbols, options, locale);
38
+ const nf = getNumberFormat(locale, options);
39
+ return (value) => nf.format(unsignedZero(value));
40
+ }
41
+ const SYMBOLS = [
42
+ "K",
43
+ "M",
44
+ "B",
45
+ "T"
46
+ ];
47
+ /**
48
+ * Compact notation with the given suffixes: the value divided by its power
49
+ * of a thousand, formatted by `Intl` (separators, currency, sign) with the
50
+ * suffix after the digits. Without digits of its own it rounds like `Intl`'s
51
+ * compact notation: two significant digits below 10, whole numbers above.
52
+ */
53
+ function formatCompact(symbols, { notation, compactDisplay, ...options }, locale) {
54
+ const own = digitsOf(options);
55
+ const small = getNumberFormat(locale, own ? options : {
56
+ ...options,
57
+ maximumSignificantDigits: 2
58
+ });
59
+ const large = own ? small : getNumberFormat(locale, {
60
+ ...options,
61
+ maximumFractionDigits: 0
62
+ });
63
+ return (value) => {
64
+ for (let exp = 0;; exp++) {
65
+ const scaled = unsignedZero(value / 1e3 ** exp);
66
+ const parts = (Math.abs(scaled) < 10 ? small : large).formatToParts(scaled);
67
+ let digits = "";
68
+ let last;
69
+ for (const part of parts) {
70
+ if (part.type === "integer") digits += part.value;
71
+ if (part.type === "integer" || part.type === "fraction") last = part;
72
+ }
73
+ if (digits.length < 4 || exp >= symbols.length) {
74
+ if (exp && last) last.value += symbols[exp - 1];
75
+ return parts.map((part) => part.value).join("");
76
+ }
77
+ }
78
+ };
79
+ }
80
+ /** Whether number options write compact numbers ("25K"). */
81
+ const compactOf = (o) => o.notation === "compact" || !!o.compactSymbols;
82
+ /** Whether number options set their digits (fraction or significant). */
83
+ const digitsOf = (o) => (o.minimumFractionDigits ?? o.maximumFractionDigits ?? o.minimumSignificantDigits ?? o.maximumSignificantDigits) !== void 0;
84
+ /**
85
+ * A formatter for values read one at a time (tooltips, data tables) in an
86
+ * axis format. Compact notation suits ticks ("$25K") but hides the
87
+ * difference between values: unless the format sets its own precision, it
88
+ * keeps three significant digits ("$24.8K").
89
+ */
90
+ function formatDetail(format, locale) {
91
+ return formatNumber(typeof format === "object" && compactOf(format) && !digitsOf(format) ? {
92
+ ...format,
93
+ maximumSignificantDigits: 3
94
+ } : format, locale);
95
+ }
96
+ /**
97
+ * Number of fraction digits needed to tell apart ticks `step` apart,
98
+ * e.g. `1 → 0`, `0.2 → 1`, `0.05 → 2`.
99
+ */
100
+ function stepPrecision(step) {
101
+ const abs = Math.abs(step);
102
+ if (!Number.isFinite(abs) || abs === 0) return 0;
103
+ return Math.max(0, -Math.floor(Math.log10(abs) + 1e-9));
104
+ }
105
+ function hasPrecision(options) {
106
+ return digitsOf(options) || !!options.compactSymbols || (options.notation ?? "standard") !== "standard";
107
+ }
108
+ /**
109
+ * Create a formatter for axis ticks `step` apart. Unless `format` sets its
110
+ * own precision, every tick gets the same number of fraction digits, derived
111
+ * from the step (`0, 0.5, 1` → `0.0, 0.5, 1.0`).
112
+ */
113
+ function formatTicks(step, format, locale) {
114
+ if (typeof format === "function") return format;
115
+ const options = format ?? {};
116
+ if (hasPrecision(options)) return formatNumber(options, locale);
117
+ let digits = stepPrecision(step);
118
+ if (options.style === "percent") digits = Math.max(0, digits - 2);
119
+ const fmt = formatNumber({
120
+ ...options,
121
+ minimumFractionDigits: digits,
122
+ maximumFractionDigits: digits
123
+ }, locale);
124
+ const epsilon = Math.abs(step) * 1e-9;
125
+ return (value) => fmt(Math.abs(value) < epsilon ? 0 : value);
126
+ }
127
+ /**
128
+ * Create a date formatter accepting `Date` objects or timestamps.
129
+ *
130
+ * ```ts
131
+ * formatDate({ month: 'short', day: 'numeric' }, 'en-US')(new Date(2026, 0, 5)) // "Jan 5"
132
+ * ```
133
+ */
134
+ function formatDate(format, locale) {
135
+ if (typeof format === "function") return (value) => format(typeof value === "number" ? new Date(value) : value);
136
+ const df = getDateFormat(locale, format);
137
+ return (value) => df.format(value);
138
+ }
139
+ //#endregion
140
+ export { getDateFormat as a, formatTicks as i, formatDetail as n, getNumberFormat as o, formatNumber as r, stepPrecision as s, formatDate as t };
141
+
142
+ //# sourceMappingURL=format-lStwuc1L.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-lStwuc1L.js","names":[],"sources":["../src/format.ts"],"sourcesContent":["/**\n * Number and date formatting built on `Intl` — locale aware, zero bytes of\n * locale data shipped.\n *\n * Formats are plain data (`Intl` options) or functions, so chart configs stay\n * serializable (JSON attributes, SSR). Pass an explicit `locale` when\n * rendering on the server, otherwise server and browser may disagree.\n */\n\n/** Locale(s) passed to `Intl`; `undefined` uses the runtime default. */\nexport type Locale = string | readonly string[] | undefined\n\n/** `Intl.NumberFormat` options, plus suffixes of our own for compact notation. */\nexport interface NumberFormatOptions extends Intl.NumberFormatOptions {\n /**\n * Compact notation with these suffixes for thousands, millions, billions…\n * instead of the locale's words: `['k', 'M', 'G']` writes 1500 as \"1.5k\",\n * or \"1,5k\" in Polish, where the locale itself writes \"1,5 tys.\". `true`\n * stands for `['K', 'M', 'B', 'T']`. Larger numbers keep the last suffix.\n */\n compactSymbols?: boolean | readonly string[]\n}\n\n/** Number format options or a custom formatter. */\nexport type NumberFormat = NumberFormatOptions | ((value: number) => string)\n\n/** `Intl.DateTimeFormat` options or a custom formatter. */\nexport type DateFormat = Intl.DateTimeFormatOptions | ((value: Date) => string)\n\nconst MAX_CACHE = 64\nconst numberCache = /* @__PURE__ */ new Map<string, Intl.NumberFormat>()\nconst dateCache = /* @__PURE__ */ new Map<string, Intl.DateTimeFormat>()\n\nfunction cached<T>(cache: Map<string, T>, key: string, create: () => T): T {\n let value = cache.get(key)\n if (value === undefined) {\n if (cache.size >= MAX_CACHE) cache.clear()\n value = create()\n cache.set(key, value)\n }\n return value\n}\n\nfunction cacheKey(locale: Locale, options: object): string {\n return `${JSON.stringify(locale ?? null)}|${JSON.stringify(options)}`\n}\n\n/** Shared, cached `Intl.NumberFormat` instance. */\nexport function getNumberFormat(\n locale?: Locale,\n options: Intl.NumberFormatOptions = {},\n): Intl.NumberFormat {\n return cached(\n numberCache,\n cacheKey(locale, options),\n () => new Intl.NumberFormat(locale as string | string[] | undefined, options),\n )\n}\n\n/** Shared, cached `Intl.DateTimeFormat` instance. */\nexport function getDateFormat(\n locale?: Locale,\n options: Intl.DateTimeFormatOptions = {},\n): Intl.DateTimeFormat {\n return cached(\n dateCache,\n cacheKey(locale, options),\n () => new Intl.DateTimeFormat(locale as string | string[] | undefined, options),\n )\n}\n\n/** Avoid `-0` rendering as \"-0\". */\nconst unsignedZero = (value: number): number => (value === 0 ? 0 : value)\n\n/**\n * Create a number formatter.\n *\n * ```ts\n * formatNumber({ style: 'currency', currency: 'PLN' }, 'pl-PL')(1234.5) // \"1234,50 zł\"\n * ```\n */\nexport function formatNumber(format?: NumberFormat, locale?: Locale): (value: number) => string {\n if (typeof format === 'function') return format\n const { compactSymbols, ...options } = format ?? {}\n if (compactSymbols) {\n return formatCompact(compactSymbols === true ? SYMBOLS : compactSymbols, options, locale)\n }\n const nf = getNumberFormat(locale, options)\n return (value) => nf.format(unsignedZero(value))\n}\n\nconst SYMBOLS = ['K', 'M', 'B', 'T']\n\n/**\n * Compact notation with the given suffixes: the value divided by its power\n * of a thousand, formatted by `Intl` (separators, currency, sign) with the\n * suffix after the digits. Without digits of its own it rounds like `Intl`'s\n * compact notation: two significant digits below 10, whole numbers above.\n */\nfunction formatCompact(\n symbols: readonly string[],\n // `notation` and `compactDisplay` are taken out: the suffixes replace them.\n { notation, compactDisplay, ...options }: Intl.NumberFormatOptions,\n locale: Locale,\n): (value: number) => string {\n const own = digitsOf(options)\n const small = getNumberFormat(locale, own ? options : { ...options, maximumSignificantDigits: 2 })\n const large = own ? small : getNumberFormat(locale, { ...options, maximumFractionDigits: 0 })\n return (value) => {\n for (let exp = 0; ; exp++) {\n const scaled = unsignedZero(value / 1000 ** exp)\n const parts = (Math.abs(scaled) < 10 ? small : large).formatToParts(scaled)\n let digits = ''\n let last: Intl.NumberFormatPart | undefined\n for (const part of parts) {\n if (part.type === 'integer') digits += part.value\n if (part.type === 'integer' || part.type === 'fraction') last = part\n }\n // Four digits or more: a thousand times smaller, with the next suffix\n // (so 999 950 rounds up to \"1M\", not \"1000K\").\n if (digits.length < 4 || exp >= symbols.length) {\n if (exp && last) last.value += symbols[exp - 1]\n return parts.map((part) => part.value).join('')\n }\n }\n }\n}\n\n/** Whether number options write compact numbers (\"25K\"). */\nconst compactOf = (o: NumberFormatOptions): boolean =>\n o.notation === 'compact' || !!o.compactSymbols\n\n/** Whether number options set their digits (fraction or significant). */\nconst digitsOf = (o: Intl.NumberFormatOptions): boolean =>\n (o.minimumFractionDigits ??\n o.maximumFractionDigits ??\n o.minimumSignificantDigits ??\n o.maximumSignificantDigits) !== undefined\n\n/**\n * A formatter for values read one at a time (tooltips, data tables) in an\n * axis format. Compact notation suits ticks (\"$25K\") but hides the\n * difference between values: unless the format sets its own precision, it\n * keeps three significant digits (\"$24.8K\").\n */\nexport function formatDetail(format?: NumberFormat, locale?: Locale): (value: number) => string {\n return formatNumber(\n typeof format === 'object' && compactOf(format) && !digitsOf(format)\n ? { ...format, maximumSignificantDigits: 3 }\n : format,\n locale,\n )\n}\n/**\n * Number of fraction digits needed to tell apart ticks `step` apart,\n * e.g. `1 → 0`, `0.2 → 1`, `0.05 → 2`.\n */\nexport function stepPrecision(step: number): number {\n const abs = Math.abs(step)\n if (!Number.isFinite(abs) || abs === 0) return 0\n return Math.max(0, -Math.floor(Math.log10(abs) + 1e-9))\n}\n\nfunction hasPrecision(options: NumberFormatOptions): boolean {\n return (\n digitsOf(options) || !!options.compactSymbols || (options.notation ?? 'standard') !== 'standard'\n )\n}\n/**\n * Create a formatter for axis ticks `step` apart. Unless `format` sets its\n * own precision, every tick gets the same number of fraction digits, derived\n * from the step (`0, 0.5, 1` → `0.0, 0.5, 1.0`).\n */\nexport function formatTicks(\n step: number,\n format?: NumberFormat,\n locale?: Locale,\n): (value: number) => string {\n if (typeof format === 'function') return format\n const options = format ?? {}\n if (hasPrecision(options)) return formatNumber(options, locale)\n\n let digits = stepPrecision(step)\n if (options.style === 'percent') digits = Math.max(0, digits - 2)\n const fmt = formatNumber(\n { ...options, minimumFractionDigits: digits, maximumFractionDigits: digits },\n locale,\n )\n // Values within floating point noise of zero (e.g. 1e-17) print as zero.\n const epsilon = Math.abs(step) * 1e-9\n return (value) => fmt(Math.abs(value) < epsilon ? 0 : value)\n}\n\n/**\n * Create a date formatter accepting `Date` objects or timestamps.\n *\n * ```ts\n * formatDate({ month: 'short', day: 'numeric' }, 'en-US')(new Date(2026, 0, 5)) // \"Jan 5\"\n * ```\n */\nexport function formatDate(format?: DateFormat, locale?: Locale): (value: Date | number) => string {\n if (typeof format === 'function') {\n return (value) => format(typeof value === 'number' ? new Date(value) : value)\n }\n const df = getDateFormat(locale, format)\n return (value) => df.format(value)\n}\n"],"mappings":";AA6BA,MAAM,YAAY;AAClB,MAAM,8BAA8B,IAAI,IAA+B;AACvE,MAAM,4BAA4B,IAAI,IAAiC;AAEvE,SAAS,OAAU,OAAuB,KAAa,QAAoB;CACzE,IAAI,QAAQ,MAAM,IAAI,GAAG;CACzB,IAAI,UAAU,KAAA,GAAW;EACvB,IAAI,MAAM,QAAQ,WAAW,MAAM,MAAM;EACzC,QAAQ,OAAO;EACf,MAAM,IAAI,KAAK,KAAK;CACtB;CACA,OAAO;AACT;AAEA,SAAS,SAAS,QAAgB,SAAyB;CACzD,OAAO,GAAG,KAAK,UAAU,UAAU,IAAI,EAAE,GAAG,KAAK,UAAU,OAAO;AACpE;;AAGA,SAAgB,gBACd,QACA,UAAoC,CAAC,GAClB;CACnB,OAAO,OACL,aACA,SAAS,QA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KAAK,IAAI,KAAK,IAAI,UAAU,IAAI,KAAK;AAC7D;;;;;;;;AASA,SAAgB,WAAW,QAAqB,QAAmD;CACjG,IAAI,OAAO,WAAW,YACpB,QAAQ,UAAU,OAAO,OAAO,UAAU,WAAW,IAAI,KAAK,KAAK,IAAI,KAAK;CAE9E,MAAM,KAAK,cAAc,QAAQ,MAAM;CACvC,QAAQ,UAAU,GAAG,OAAO,KAAK;AACnC"}
@@ -0,0 +1,235 @@
1
+ const require_layout = require("./layout-CtMBhNd9.cjs");
2
+ const require_vnode = require("./vnode-CkQ27Cxe.cjs");
3
+ const require_format = require("./format-B0yKXBTH.cjs");
4
+ const require_features = require("./features-BclHgg2W.cjs");
5
+ const require_clean = require("./clean-Byl6kzf0.cjs");
6
+ const require_named = require("./named-BWWb5LQJ.cjs");
7
+ const require_sweep = require("./sweep-Duowaput.cjs");
8
+ //#region src/charts/gauge.ts
9
+ /** Space kept around the gauge for the hover halo. */
10
+ const HALF_PI = Math.PI / 2;
11
+ function ringsOf(options) {
12
+ const { data } = options;
13
+ if (typeof data === "number") return [{
14
+ name: "",
15
+ value: data
16
+ }];
17
+ return Array.isArray(data) ? data : [data];
18
+ }
19
+ /** The visible rings with clamped values. */
20
+ function layoutRings(options, hidden) {
21
+ const max = options.max ?? 100;
22
+ return ringsOf(options).map((data, index) => ({
23
+ data,
24
+ index,
25
+ max: data.max ?? max
26
+ })).filter((ring) => !hidden.has(require_named.keyOf(ring.data))).map((ring, position) => ({
27
+ ...ring,
28
+ position,
29
+ value: Math.min(ring.max, Math.max(0, ring.data.value || 0))
30
+ }));
31
+ }
32
+ /**
33
+ * Radius and center that fit the swept ring (plus the text in the middle)
34
+ * into `area`: a dial or half ring is centered by its own outline, not by
35
+ * the full circle it is cut from.
36
+ */
37
+ function fitGauge(area, start, sweep, textTop, textBottom) {
38
+ const unit = [[0, 0]];
39
+ const end = start + sweep;
40
+ unit.push([Math.sin(start), -Math.cos(start)], [Math.sin(end), -Math.cos(end)]);
41
+ for (let a = Math.ceil(start / HALF_PI) * HALF_PI, n = 0; n < 5 && a <= end + 1e-9; n++) {
42
+ unit.push([Math.sin(a), -Math.cos(a)]);
43
+ a += HALF_PI;
44
+ }
45
+ let outer = Math.min(area.width, area.height) / 2;
46
+ let box = {
47
+ x0: 0,
48
+ y0: 0,
49
+ x1: 0,
50
+ y1: 0
51
+ };
52
+ for (let i = 0; i < 4; i++) {
53
+ box = {
54
+ x0: 0,
55
+ y0: textTop,
56
+ x1: 0,
57
+ y1: textBottom
58
+ };
59
+ for (const [x, y] of unit) {
60
+ box.x0 = Math.min(box.x0, x * outer);
61
+ box.x1 = Math.max(box.x1, x * outer);
62
+ box.y0 = Math.min(box.y0, y * outer);
63
+ box.y1 = Math.max(box.y1, y * outer);
64
+ }
65
+ const scale = Math.min(area.width / (box.x1 - box.x0), area.height / (box.y1 - box.y0));
66
+ if (Math.abs(scale - 1) < .001) break;
67
+ outer = Math.max(0, outer * scale);
68
+ }
69
+ return {
70
+ outer,
71
+ cx: area.x + (area.width - (box.x1 - box.x0)) / 2 - box.x0,
72
+ cy: area.y + (area.height - (box.y1 - box.y0)) / 2 - box.y0
73
+ };
74
+ }
75
+ function renderGauge(options, ctx) {
76
+ const { width, height, locale } = ctx;
77
+ const thickness = Math.max(1, options.thickness ?? 12);
78
+ const gap = Math.max(0, options.gap ?? 4);
79
+ const cornerRadius = options.cornerRadius ?? thickness / 2;
80
+ const pad = require_layout.insets(options.padding, 0);
81
+ const area = require_layout.innerRect(width, height, {
82
+ top: pad.top + 8,
83
+ right: pad.right + 8,
84
+ bottom: pad.bottom + 8,
85
+ left: pad.left + 8
86
+ });
87
+ const start = (options.startAngle ?? 0) * require_sweep.DEG;
88
+ const sweep = Math.min(360, Math.max(0, options.angle ?? 360)) * require_sweep.DEG;
89
+ const rings = layoutRings(options, ctx.hidden);
90
+ const center = options.center;
91
+ const first = rings[0];
92
+ const showCenter = center !== false && first !== void 0;
93
+ const centerLabel = showCenter ? center?.label ?? (first.data.name || void 0) : void 0;
94
+ const { outer, cx, cy } = fitGauge(area, start, sweep, showCenter ? -1.4 * ctx.fontSize : 0, showCenter ? (centerLabel ? 2 : .7) * ctx.fontSize : 0);
95
+ const value = require_format.formatNumber(options.format, locale);
96
+ const share = require_format.getNumberFormat(locale, {
97
+ style: "percent",
98
+ maximumFractionDigits: 1
99
+ });
100
+ const radii = (ring, grow = 0) => {
101
+ const r1 = Math.max(0, outer - ring.position * (thickness + gap));
102
+ return {
103
+ innerRadius: Math.max(0, r1 - thickness - grow),
104
+ outerRadius: r1 + grow
105
+ };
106
+ };
107
+ const fraction = (ring) => ring.max > 0 ? ring.value / ring.max : 0;
108
+ const geometry = (ring, grow = 0) => ({
109
+ ...radii(ring, grow),
110
+ startAngle: start,
111
+ endAngle: start + sweep * fraction(ring),
112
+ cornerRadius
113
+ });
114
+ const hitFor = (ring) => {
115
+ const [x, y] = require_sweep.arcCentroid(geometry(ring));
116
+ const item = {
117
+ name: ring.data.name,
118
+ seriesIndex: ring.index,
119
+ value: ring.value,
120
+ text: `${value(ring.value)} (${share.format(fraction(ring))})`,
121
+ x: cx + x,
122
+ y: cy + y
123
+ };
124
+ if (ring.data.color) item.color = ring.data.color;
125
+ return {
126
+ index: ring.position,
127
+ label: ring.data.name,
128
+ title: "",
129
+ x: cx + x,
130
+ area: {
131
+ x: cx - outer,
132
+ y: cy - outer,
133
+ width: outer * 2,
134
+ height: outer * 2
135
+ },
136
+ items: [item],
137
+ seriesIndex: ring.index,
138
+ mark: {
139
+ d: require_sweep.arcPathStable(geometry(ring, 2)),
140
+ x: cx,
141
+ y: cy
142
+ }
143
+ };
144
+ };
145
+ const interaction = {
146
+ count: rings.length,
147
+ hitIndex: (position) => {
148
+ const ring = rings[position];
149
+ return ring ? hitFor(ring) : null;
150
+ },
151
+ hitTest(px, py) {
152
+ const r = Math.hypot(px - cx, py - cy);
153
+ const ring = rings.find((ring) => {
154
+ const { innerRadius, outerRadius } = radii(ring, 2);
155
+ return r >= innerRadius && r <= outerRadius;
156
+ });
157
+ return ring ? hitFor(ring) : null;
158
+ }
159
+ };
160
+ ctx.onHitTest(interaction);
161
+ const groups = rings.map((ring) => require_vnode.h("g", require_named.groupAttrs(ring.data, ring.index), require_sweep.arcNode("tc-gauge-track", {
162
+ ...geometry(ring),
163
+ endAngle: start + sweep
164
+ }), require_sweep.arcNode("tc-gauge-arc", geometry(ring))));
165
+ const centerValue = showCenter ? center?.value ?? share.format(fraction(first)) : "";
166
+ return [require_vnode.h("g", {
167
+ class: "tc-gauge",
168
+ style: `transform:translate(${cx}px,${cy}px)`
169
+ }, require_vnode.h("g", { class: "tc-gauge-rings" }, groups)), showCenter && require_vnode.h("g", {
170
+ class: "tc-gauge-center",
171
+ "aria-hidden": "true"
172
+ }, require_vnode.h("text", {
173
+ class: "tc-gauge-value",
174
+ x: cx,
175
+ y: cy,
176
+ dy: centerLabel ? "0" : "0.35em",
177
+ "text-anchor": "middle"
178
+ }, centerValue), centerLabel && require_vnode.h("text", {
179
+ class: "tc-gauge-label",
180
+ x: cx,
181
+ y: cy,
182
+ dy: "1.6em",
183
+ "text-anchor": "middle"
184
+ }, centerLabel))];
185
+ }
186
+ function gaugeTable(options, ctx) {
187
+ const value = require_format.formatNumber(options.format, ctx.locale);
188
+ const share = require_format.getNumberFormat(ctx.locale, {
189
+ style: "percent",
190
+ maximumFractionDigits: 1
191
+ });
192
+ return {
193
+ columns: [
194
+ "",
195
+ "Value",
196
+ "Share"
197
+ ],
198
+ rows: layoutRings(options, ctx.hidden).map((ring) => [
199
+ ring.data.name,
200
+ value(ring.value),
201
+ share.format(ring.max > 0 ? ring.value / ring.max : 0)
202
+ ])
203
+ };
204
+ }
205
+ /**
206
+ * Gauge (radial bar): progress towards a maximum as an arc on a track, with
207
+ * the share in the middle. Several rings nest from the outside in.
208
+ *
209
+ * ```ts
210
+ * new Chart('#el', { type: gauge, data: 58 })
211
+ * new Chart('#el', { type: gauge, data: { name: 'completed', value: 1392, max: 2400 } })
212
+ * ```
213
+ */
214
+ const gauge = {
215
+ name: "gauge",
216
+ clean: require_clean.cleanData((data) => require_clean.cleanItems(typeof data === "number" ? [{
217
+ name: "",
218
+ value: data
219
+ }] : require_clean.isRecord(data) ? [data] : data)),
220
+ render: (options, ctx) => {
221
+ require_features.features.sweep = require_sweep.sweep;
222
+ return renderGauge(options, ctx);
223
+ },
224
+ legend: (options) => require_named.legendItems(ringsOf(options)),
225
+ table: gaugeTable
226
+ };
227
+ //#endregion
228
+ Object.defineProperty(exports, "gauge", {
229
+ enumerable: true,
230
+ get: function() {
231
+ return gauge;
232
+ }
233
+ });
234
+
235
+ //# sourceMappingURL=gauge-CEfkWXSu.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gauge-CEfkWXSu.cjs","names":["keyOf","insets","innerRect","DEG","formatNumber","getNumberFormat","arcCentroid","arcPathStable","h","groupAttrs","arcNode","cleanData","cleanItems","isRecord","sweepArcs","legendItems"],"sources":["../src/charts/gauge.ts"],"sourcesContent":["import type { DataTable } from '../a11y.ts'\nimport type { ChartType, RenderContext } from '../chart.ts'\nimport { features } from '../features.ts'\nimport { formatNumber, getNumberFormat, type NumberFormat } from '../format.ts'\nimport type { Hit, HitItem, Interaction } from '../interaction.ts'\nimport { type InsetsInput, innerRect, insets } from '../layout.ts'\nimport { arcNode, sweep as sweepArcs } from '../render/sweep.ts'\nimport { arcCentroid, arcPathStable, DEG, HALO } from '../shapes/arc.ts'\nimport { type ChildInput, type ClassValue, h } from '../vnode.ts'\nimport { cleanData, cleanItems, isRecord } from './clean.ts'\nimport { groupAttrs, keyOf, legendItems } from './named.ts'\n\n/** One ring of a gauge. */\nexport interface GaugeRing {\n name: string\n /** Current value, clamped to `0…max`. */\n value: number\n /** Full-ring value of this ring; overrides `GaugeOptions.max`. */\n max?: number\n /** Stable identity for keyed updates and legend toggles. Defaults to `name`. */\n id?: string\n /**\n * Custom color; overrides the palette slot via `--tc-series-color`.\n * Values that could inject CSS (`;`, quotes, `url()` …) are ignored, so colors from user data are safe.\n */\n color?: string\n /** Extra classes on the ring group. */\n class?: ClassValue\n /** Start hidden (toggle it back from the legend). */\n hidden?: boolean\n}\n\nexport interface GaugeOptions {\n /** A single value, one ring, or concentric rings (outermost first). */\n data: number | GaugeRing | readonly GaugeRing[]\n /** Full-ring value. Defaults to `100`. */\n max?: number\n /** Where the arc starts, in degrees clockwise from 12 o'clock. Defaults to `0`. */\n startAngle?: number\n /** Degrees the full ring spans, `0…360`. Defaults to `360`; use e.g. `270` for a dial. */\n angle?: number\n /** Ring thickness in pixels. Defaults to `12`. */\n thickness?: number\n /** Space between rings in pixels. Defaults to `4`. */\n gap?: number\n /** Corner radius of the arcs. Defaults to half the thickness (round caps). */\n cornerRadius?: number\n /** Format of the values (tooltip, table). */\n format?: NumberFormat\n /**\n * Text in the middle: the first ring's share of `max` and its name by\n * default; `false` hides it, or give your own `value` / `label`.\n */\n center?: false | { value?: string; label?: string }\n /** Extra space around the gauge, in pixels. */\n padding?: InsetsInput\n}\n\n/** Space kept around the gauge for the hover halo. */\nconst HALF_PI = Math.PI / 2\n\ninterface Ring {\n data: GaugeRing\n index: number\n value: number\n max: number\n /** Slot among the visible rings, from the outside in. */\n position: number\n}\n\nfunction ringsOf(options: GaugeOptions): GaugeRing[] {\n const { data } = options\n if (typeof data === 'number') return [{ name: '', value: data }]\n return Array.isArray(data) ? (data as GaugeRing[]) : [data as GaugeRing]\n}\n\n/** The visible rings with clamped values. */\nfunction layoutRings(options: GaugeOptions, hidden: ReadonlySet<string>): Ring[] {\n const max = options.max ?? 100\n return ringsOf(options)\n .map((data, index) => ({ data, index, max: data.max ?? max }))\n .filter((ring) => !hidden.has(keyOf(ring.data)))\n .map((ring, position) => ({\n ...ring,\n position,\n value: Math.min(ring.max, Math.max(0, ring.data.value || 0)),\n }))\n}\n\n/**\n * Radius and center that fit the swept ring (plus the text in the middle)\n * into `area`: a dial or half ring is centered by its own outline, not by\n * the full circle it is cut from.\n */\nfunction fitGauge(\n area: { x: number; y: number; width: number; height: number },\n start: number,\n sweep: number,\n textTop: number,\n textBottom: number,\n): { outer: number; cx: number; cy: number } {\n // Points of the outline, in units of the outer radius: both ends of the arc\n // and every axis extreme it passes; the origin covers the inner edge.\n const unit: [number, number][] = [[0, 0]]\n const end = start + sweep\n unit.push([Math.sin(start), -Math.cos(start)], [Math.sin(end), -Math.cos(end)])\n // (At most a full turn of them: a huge start angle is beyond what adding a quarter turn changes.)\n for (let a = Math.ceil(start / HALF_PI) * HALF_PI, n = 0; n < 5 && a <= end + 1e-9; n++) {\n unit.push([Math.sin(a), -Math.cos(a)])\n a += HALF_PI\n }\n let outer = Math.min(area.width, area.height) / 2\n let box = { x0: 0, y0: 0, x1: 0, y1: 0 }\n // The text does not scale with the radius, so converge in a few rounds.\n for (let i = 0; i < 4; i++) {\n box = { x0: 0, y0: textTop, x1: 0, y1: textBottom }\n for (const [x, y] of unit) {\n box.x0 = Math.min(box.x0, x * outer)\n box.x1 = Math.max(box.x1, x * outer)\n box.y0 = Math.min(box.y0, y * outer)\n box.y1 = Math.max(box.y1, y * outer)\n }\n const scale = Math.min(area.width / (box.x1 - box.x0), area.height / (box.y1 - box.y0))\n if (Math.abs(scale - 1) < 1e-3) break\n outer = Math.max(0, outer * scale)\n }\n return {\n outer,\n cx: area.x + (area.width - (box.x1 - box.x0)) / 2 - box.x0,\n cy: area.y + (area.height - (box.y1 - box.y0)) / 2 - box.y0,\n }\n}\n\nfunction renderGauge(options: GaugeOptions, ctx: RenderContext): ChildInput {\n const { width, height, locale } = ctx\n const thickness = Math.max(1, options.thickness ?? 12)\n const gap = Math.max(0, options.gap ?? 4)\n const cornerRadius = options.cornerRadius ?? thickness / 2\n const pad = insets(options.padding, 0)\n const area = innerRect(width, height, {\n top: pad.top + HALO,\n right: pad.right + HALO,\n bottom: pad.bottom + HALO,\n left: pad.left + HALO,\n })\n const start = (options.startAngle ?? 0) * DEG\n const sweep = Math.min(360, Math.max(0, options.angle ?? 360)) * DEG\n const rings = layoutRings(options, ctx.hidden)\n const center = options.center\n const first = rings[0]\n const showCenter = center !== false && first !== undefined\n const centerLabel = showCenter ? (center?.label ?? (first.data.name || undefined)) : undefined\n const { outer, cx, cy } = fitGauge(\n area,\n start,\n sweep,\n showCenter ? -1.4 * ctx.fontSize : 0,\n showCenter ? (centerLabel ? 2 : 0.7) * ctx.fontSize : 0,\n )\n const value = formatNumber(options.format, locale)\n const share = getNumberFormat(locale, { style: 'percent', maximumFractionDigits: 1 })\n\n const radii = (ring: Ring, grow = 0) => {\n const r1 = Math.max(0, outer - ring.position * (thickness + gap))\n return { innerRadius: Math.max(0, r1 - thickness - grow), outerRadius: r1 + grow }\n }\n const fraction = (ring: Ring) => (ring.max > 0 ? ring.value / ring.max : 0)\n const geometry = (ring: Ring, grow = 0) => ({\n ...radii(ring, grow),\n startAngle: start,\n endAngle: start + sweep * fraction(ring),\n cornerRadius,\n })\n\n const hitFor = (ring: Ring): Hit => {\n const [x, y] = arcCentroid(geometry(ring))\n const item: HitItem = {\n name: ring.data.name,\n seriesIndex: ring.index,\n value: ring.value,\n text: `${value(ring.value)} (${share.format(fraction(ring))})`,\n x: cx + x,\n y: cy + y,\n }\n if (ring.data.color) item.color = ring.data.color\n return {\n index: ring.position,\n label: ring.data.name,\n title: '',\n x: cx + x,\n area: { x: cx - outer, y: cy - outer, width: outer * 2, height: outer * 2 },\n items: [item],\n seriesIndex: ring.index,\n // The value arc, slightly enlarged.\n mark: { d: arcPathStable(geometry(ring, 2)), x: cx, y: cy },\n }\n }\n\n const interaction: Interaction = {\n count: rings.length,\n hitIndex: (position) => {\n const ring = rings[position]\n return ring ? hitFor(ring) : null\n },\n hitTest(px, py) {\n const r = Math.hypot(px - cx, py - cy)\n const ring = rings.find((ring) => {\n const { innerRadius, outerRadius } = radii(ring, 2)\n return r >= innerRadius && r <= outerRadius\n })\n return ring ? hitFor(ring) : null\n },\n }\n ctx.onHitTest(interaction)\n\n const groups = rings.map((ring) =>\n h(\n 'g',\n groupAttrs(ring.data, ring.index),\n // Each path keeps its arc, so a new value (or a new shape of the gauge)\n // sweeps it around the center (see `sweep`).\n arcNode('tc-gauge-track', { ...geometry(ring), endAngle: start + sweep }),\n arcNode('tc-gauge-arc', geometry(ring)),\n ),\n )\n\n const centerValue = showCenter ? (center?.value ?? share.format(fraction(first))) : ''\n\n return [\n // Rings sit in their own group: the entrance animation transforms it, not the translated parent.\n h(\n 'g',\n { class: 'tc-gauge', style: `transform:translate(${cx}px,${cy}px)` },\n h('g', { class: 'tc-gauge-rings' }, groups),\n ),\n showCenter &&\n h(\n 'g',\n { class: 'tc-gauge-center', 'aria-hidden': 'true' },\n h(\n 'text',\n {\n class: 'tc-gauge-value',\n x: cx,\n y: cy,\n dy: centerLabel ? '0' : '0.35em',\n 'text-anchor': 'middle',\n },\n centerValue,\n ),\n centerLabel &&\n h(\n 'text',\n { class: 'tc-gauge-label', x: cx, y: cy, dy: '1.6em', 'text-anchor': 'middle' },\n centerLabel,\n ),\n ),\n ]\n}\n\nfunction gaugeTable(options: GaugeOptions, ctx: RenderContext): DataTable {\n const value = formatNumber(options.format, ctx.locale)\n const share = getNumberFormat(ctx.locale, { style: 'percent', maximumFractionDigits: 1 })\n return {\n columns: ['', 'Value', 'Share'],\n rows: layoutRings(options, ctx.hidden).map((ring) => [\n ring.data.name,\n value(ring.value),\n share.format(ring.max > 0 ? ring.value / ring.max : 0),\n ]),\n }\n}\n\n/**\n * Gauge (radial bar): progress towards a maximum as an arc on a track, with\n * the share in the middle. Several rings nest from the outside in.\n *\n * ```ts\n * new Chart('#el', { type: gauge, data: 58 })\n * new Chart('#el', { type: gauge, data: { name: 'completed', value: 1392, max: 2400 } })\n * ```\n */\nexport const gauge: ChartType<GaugeOptions> = {\n name: 'gauge',\n clean: cleanData((data) =>\n cleanItems(\n typeof data === 'number' ? [{ name: '', value: data }] : isRecord(data) ? [data] : data,\n ),\n ),\n render: (options, ctx): ChildInput => {\n // Set here, not as the module loads (see pie).\n features.sweep = sweepArcs\n return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