minerva-design 1.2.0 → 1.3.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 (256) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/charts/canvas.d.cts +4 -1
  3. package/dist/charts/canvas.d.ts +4 -1
  4. package/dist/charts/core.cjs +1 -1
  5. package/dist/charts/core.d.cts +5 -2
  6. package/dist/charts/core.d.ts +5 -2
  7. package/dist/charts/core.js +6 -4
  8. package/dist/charts/engine/canvas.cjs +1 -1
  9. package/dist/charts/engine/canvas.cjs.map +1 -1
  10. package/dist/charts/engine/canvas.js +65 -53
  11. package/dist/charts/engine/canvas.js.map +1 -1
  12. package/dist/charts/engine/chart.cjs +1 -2
  13. package/dist/charts/engine/chart.cjs.map +1 -1
  14. package/dist/charts/engine/chart.js +342 -323
  15. package/dist/charts/engine/chart.js.map +1 -1
  16. package/dist/charts/engine/color.cjs +1 -1
  17. package/dist/charts/engine/color.cjs.map +1 -1
  18. package/dist/charts/engine/color.d.cts +17 -0
  19. package/dist/charts/engine/color.d.ts +17 -0
  20. package/dist/charts/engine/color.js +27 -3
  21. package/dist/charts/engine/color.js.map +1 -1
  22. package/dist/charts/engine/controller.cjs +2 -2
  23. package/dist/charts/engine/controller.cjs.map +1 -1
  24. package/dist/charts/engine/controller.d.cts +6 -0
  25. package/dist/charts/engine/controller.d.ts +6 -0
  26. package/dist/charts/engine/controller.js +317 -253
  27. package/dist/charts/engine/controller.js.map +1 -1
  28. package/dist/charts/engine/curve.cjs +2 -0
  29. package/dist/charts/engine/curve.cjs.map +1 -0
  30. package/dist/charts/engine/curve.d.cts +15 -0
  31. package/dist/charts/engine/curve.d.ts +15 -0
  32. package/dist/charts/engine/curve.js +56 -0
  33. package/dist/charts/engine/curve.js.map +1 -0
  34. package/dist/charts/engine/data.cjs +1 -1
  35. package/dist/charts/engine/data.cjs.map +1 -1
  36. package/dist/charts/engine/data.d.cts +15 -2
  37. package/dist/charts/engine/data.d.ts +15 -2
  38. package/dist/charts/engine/data.js +98 -38
  39. package/dist/charts/engine/data.js.map +1 -1
  40. package/dist/charts/engine/dom.cjs +1 -1
  41. package/dist/charts/engine/dom.cjs.map +1 -1
  42. package/dist/charts/engine/dom.d.cts +5 -3
  43. package/dist/charts/engine/dom.d.ts +5 -3
  44. package/dist/charts/engine/dom.js +27 -22
  45. package/dist/charts/engine/dom.js.map +1 -1
  46. package/dist/charts/engine/items.cjs +1 -1
  47. package/dist/charts/engine/items.cjs.map +1 -1
  48. package/dist/charts/engine/items.js +132 -61
  49. package/dist/charts/engine/items.js.map +1 -1
  50. package/dist/charts/engine/model.cjs +1 -1
  51. package/dist/charts/engine/model.cjs.map +1 -1
  52. package/dist/charts/engine/model.d.cts +30 -3
  53. package/dist/charts/engine/model.d.ts +30 -3
  54. package/dist/charts/engine/model.js +225 -108
  55. package/dist/charts/engine/model.js.map +1 -1
  56. package/dist/charts/engine/overlay.cjs +1 -1
  57. package/dist/charts/engine/overlay.cjs.map +1 -1
  58. package/dist/charts/engine/overlay.d.cts +2 -0
  59. package/dist/charts/engine/overlay.d.ts +2 -0
  60. package/dist/charts/engine/overlay.js +16 -16
  61. package/dist/charts/engine/overlay.js.map +1 -1
  62. package/dist/charts/engine/presets.cjs +2 -2
  63. package/dist/charts/engine/presets.cjs.map +1 -1
  64. package/dist/charts/engine/presets.d.cts +71 -5
  65. package/dist/charts/engine/presets.d.ts +71 -5
  66. package/dist/charts/engine/presets.js +120 -33
  67. package/dist/charts/engine/presets.js.map +1 -1
  68. package/dist/charts/engine/renderers/canvas2d.cjs +1 -1
  69. package/dist/charts/engine/renderers/canvas2d.cjs.map +1 -1
  70. package/dist/charts/engine/renderers/canvas2d.js +149 -111
  71. package/dist/charts/engine/renderers/canvas2d.js.map +1 -1
  72. package/dist/charts/engine/renderers/range.cjs +1 -1
  73. package/dist/charts/engine/renderers/range.cjs.map +1 -1
  74. package/dist/charts/engine/renderers/range.js +4 -4
  75. package/dist/charts/engine/renderers/range.js.map +1 -1
  76. package/dist/charts/engine/renderers/shaders.cjs +37 -19
  77. package/dist/charts/engine/renderers/shaders.cjs.map +1 -1
  78. package/dist/charts/engine/renderers/shaders.d.cts +2 -2
  79. package/dist/charts/engine/renderers/shaders.d.ts +2 -2
  80. package/dist/charts/engine/renderers/shaders.js +37 -19
  81. package/dist/charts/engine/renderers/shaders.js.map +1 -1
  82. package/dist/charts/engine/renderers/types.cjs.map +1 -1
  83. package/dist/charts/engine/renderers/types.d.cts +11 -4
  84. package/dist/charts/engine/renderers/types.d.ts +11 -4
  85. package/dist/charts/engine/renderers/types.js.map +1 -1
  86. package/dist/charts/engine/renderers/webgl2.cjs +1 -1
  87. package/dist/charts/engine/renderers/webgl2.cjs.map +1 -1
  88. package/dist/charts/engine/renderers/webgl2.js +33 -12
  89. package/dist/charts/engine/renderers/webgl2.js.map +1 -1
  90. package/dist/charts/engine/renderers/webgpu.cjs +1 -1
  91. package/dist/charts/engine/renderers/webgpu.cjs.map +1 -1
  92. package/dist/charts/engine/renderers/webgpu.js +18 -15
  93. package/dist/charts/engine/renderers/webgpu.js.map +1 -1
  94. package/dist/charts/engine/scene.cjs +1 -1
  95. package/dist/charts/engine/scene.cjs.map +1 -1
  96. package/dist/charts/engine/scene.d.cts +19 -6
  97. package/dist/charts/engine/scene.d.ts +19 -6
  98. package/dist/charts/engine/scene.js +201 -89
  99. package/dist/charts/engine/scene.js.map +1 -1
  100. package/dist/charts/engine/shapes/canvas.cjs +2 -0
  101. package/dist/charts/engine/shapes/canvas.cjs.map +1 -0
  102. package/dist/charts/engine/shapes/canvas.d.cts +58 -0
  103. package/dist/charts/engine/shapes/canvas.d.ts +58 -0
  104. package/dist/charts/engine/shapes/canvas.js +159 -0
  105. package/dist/charts/engine/shapes/canvas.js.map +1 -0
  106. package/dist/charts/engine/shapes/chart.cjs +2 -0
  107. package/dist/charts/engine/shapes/chart.cjs.map +1 -0
  108. package/dist/charts/engine/shapes/chart.d.cts +6 -0
  109. package/dist/charts/engine/shapes/chart.d.ts +6 -0
  110. package/dist/charts/engine/shapes/chart.js +273 -0
  111. package/dist/charts/engine/shapes/chart.js.map +1 -0
  112. package/dist/charts/engine/shapes/draw.cjs +2 -0
  113. package/dist/charts/engine/shapes/draw.cjs.map +1 -0
  114. package/dist/charts/engine/shapes/draw.d.cts +20 -0
  115. package/dist/charts/engine/shapes/draw.d.ts +20 -0
  116. package/dist/charts/engine/shapes/draw.js +152 -0
  117. package/dist/charts/engine/shapes/draw.js.map +1 -0
  118. package/dist/charts/engine/shapes/funnel.cjs +2 -0
  119. package/dist/charts/engine/shapes/funnel.cjs.map +1 -0
  120. package/dist/charts/engine/shapes/funnel.d.cts +6 -0
  121. package/dist/charts/engine/shapes/funnel.d.ts +6 -0
  122. package/dist/charts/engine/shapes/funnel.js +149 -0
  123. package/dist/charts/engine/shapes/funnel.js.map +1 -0
  124. package/dist/charts/engine/shapes/gauge.cjs +2 -0
  125. package/dist/charts/engine/shapes/gauge.cjs.map +1 -0
  126. package/dist/charts/engine/shapes/gauge.d.cts +7 -0
  127. package/dist/charts/engine/shapes/gauge.d.ts +7 -0
  128. package/dist/charts/engine/shapes/gauge.js +173 -0
  129. package/dist/charts/engine/shapes/gauge.js.map +1 -0
  130. package/dist/charts/engine/shapes/hit.cjs +2 -0
  131. package/dist/charts/engine/shapes/hit.cjs.map +1 -0
  132. package/dist/charts/engine/shapes/hit.d.cts +28 -0
  133. package/dist/charts/engine/shapes/hit.d.ts +28 -0
  134. package/dist/charts/engine/shapes/hit.js +124 -0
  135. package/dist/charts/engine/shapes/hit.js.map +1 -0
  136. package/dist/charts/engine/shapes/index.d.cts +9 -0
  137. package/dist/charts/engine/shapes/index.d.ts +9 -0
  138. package/dist/charts/engine/shapes/layout.cjs +3 -0
  139. package/dist/charts/engine/shapes/layout.cjs.map +1 -0
  140. package/dist/charts/engine/shapes/layout.d.cts +88 -0
  141. package/dist/charts/engine/shapes/layout.d.ts +88 -0
  142. package/dist/charts/engine/shapes/layout.js +266 -0
  143. package/dist/charts/engine/shapes/layout.js.map +1 -0
  144. package/dist/charts/engine/shapes/pie.cjs +2 -0
  145. package/dist/charts/engine/shapes/pie.cjs.map +1 -0
  146. package/dist/charts/engine/shapes/pie.d.cts +20 -0
  147. package/dist/charts/engine/shapes/pie.d.ts +20 -0
  148. package/dist/charts/engine/shapes/pie.js +302 -0
  149. package/dist/charts/engine/shapes/pie.js.map +1 -0
  150. package/dist/charts/engine/shapes/radar.cjs +2 -0
  151. package/dist/charts/engine/shapes/radar.cjs.map +1 -0
  152. package/dist/charts/engine/shapes/radar.d.cts +8 -0
  153. package/dist/charts/engine/shapes/radar.d.ts +8 -0
  154. package/dist/charts/engine/shapes/radar.js +197 -0
  155. package/dist/charts/engine/shapes/radar.js.map +1 -0
  156. package/dist/charts/engine/shapes/runtime.cjs +2 -0
  157. package/dist/charts/engine/shapes/runtime.cjs.map +1 -0
  158. package/dist/charts/engine/shapes/runtime.d.cts +29 -0
  159. package/dist/charts/engine/shapes/runtime.d.ts +29 -0
  160. package/dist/charts/engine/shapes/runtime.js +97 -0
  161. package/dist/charts/engine/shapes/runtime.js.map +1 -0
  162. package/dist/charts/engine/shapes/scene.cjs +2 -0
  163. package/dist/charts/engine/shapes/scene.cjs.map +1 -0
  164. package/dist/charts/engine/shapes/scene.d.cts +257 -0
  165. package/dist/charts/engine/shapes/scene.d.ts +257 -0
  166. package/dist/charts/engine/shapes/scene.js +123 -0
  167. package/dist/charts/engine/shapes/scene.js.map +1 -0
  168. package/dist/charts/engine/shapes/treemap.cjs +2 -0
  169. package/dist/charts/engine/shapes/treemap.cjs.map +1 -0
  170. package/dist/charts/engine/shapes/treemap.d.cts +14 -0
  171. package/dist/charts/engine/shapes/treemap.d.ts +14 -0
  172. package/dist/charts/engine/shapes/treemap.js +213 -0
  173. package/dist/charts/engine/shapes/treemap.js.map +1 -0
  174. package/dist/charts/engine/shapes/types.d.cts +292 -0
  175. package/dist/charts/engine/shapes/types.d.ts +292 -0
  176. package/dist/charts/engine/signature.cjs +2 -0
  177. package/dist/charts/engine/signature.cjs.map +1 -0
  178. package/dist/charts/engine/signature.d.cts +9 -0
  179. package/dist/charts/engine/signature.d.ts +9 -0
  180. package/dist/charts/engine/signature.js +13 -0
  181. package/dist/charts/engine/signature.js.map +1 -0
  182. package/dist/charts/engine/theme.cjs +1 -1
  183. package/dist/charts/engine/theme.cjs.map +1 -1
  184. package/dist/charts/engine/theme.d.cts +10 -1
  185. package/dist/charts/engine/theme.d.ts +10 -1
  186. package/dist/charts/engine/theme.js +40 -16
  187. package/dist/charts/engine/theme.js.map +1 -1
  188. package/dist/charts/engine/types.d.cts +70 -9
  189. package/dist/charts/engine/types.d.ts +70 -9
  190. package/dist/charts/index.cjs +1 -1
  191. package/dist/charts/index.d.cts +4 -2
  192. package/dist/charts/index.d.ts +4 -2
  193. package/dist/charts/index.js +8 -5
  194. package/dist/charts/react/Chart.cjs +1 -1
  195. package/dist/charts/react/Chart.cjs.map +1 -1
  196. package/dist/charts/react/Chart.d.cts +8 -1
  197. package/dist/charts/react/Chart.d.ts +8 -1
  198. package/dist/charts/react/Chart.js +66 -47
  199. package/dist/charts/react/Chart.js.map +1 -1
  200. package/dist/charts/react/charts.cjs +1 -1
  201. package/dist/charts/react/charts.cjs.map +1 -1
  202. package/dist/charts/react/charts.d.cts +10 -2
  203. package/dist/charts/react/charts.d.ts +10 -2
  204. package/dist/charts/react/charts.js +174 -51
  205. package/dist/charts/react/charts.js.map +1 -1
  206. package/dist/charts/react/shapes.cjs +2 -0
  207. package/dist/charts/react/shapes.cjs.map +1 -0
  208. package/dist/charts/react/shapes.d.cts +255 -0
  209. package/dist/charts/react/shapes.d.ts +255 -0
  210. package/dist/charts/react/shapes.js +242 -0
  211. package/dist/charts/react/shapes.js.map +1 -0
  212. package/dist/charts/react/types.d.cts +73 -4
  213. package/dist/charts/react/types.d.ts +73 -4
  214. package/dist/native/charts/src/engine/color.cjs +1 -1
  215. package/dist/native/charts/src/engine/color.cjs.map +1 -1
  216. package/dist/native/charts/src/engine/color.js +12 -3
  217. package/dist/native/charts/src/engine/color.js.map +1 -1
  218. package/dist/native/charts/src/engine/controller.cjs +2 -2
  219. package/dist/native/charts/src/engine/controller.cjs.map +1 -1
  220. package/dist/native/charts/src/engine/controller.js +334 -270
  221. package/dist/native/charts/src/engine/controller.js.map +1 -1
  222. package/dist/native/charts/src/engine/curve.cjs +2 -0
  223. package/dist/native/charts/src/engine/curve.cjs.map +1 -0
  224. package/dist/native/charts/src/engine/curve.js +56 -0
  225. package/dist/native/charts/src/engine/curve.js.map +1 -0
  226. package/dist/native/charts/src/engine/data.cjs +1 -1
  227. package/dist/native/charts/src/engine/data.cjs.map +1 -1
  228. package/dist/native/charts/src/engine/data.js +98 -38
  229. package/dist/native/charts/src/engine/data.js.map +1 -1
  230. package/dist/native/charts/src/engine/model.cjs +1 -1
  231. package/dist/native/charts/src/engine/model.cjs.map +1 -1
  232. package/dist/native/charts/src/engine/model.js +229 -112
  233. package/dist/native/charts/src/engine/model.js.map +1 -1
  234. package/dist/native/charts/src/engine/overlay.cjs +1 -1
  235. package/dist/native/charts/src/engine/overlay.cjs.map +1 -1
  236. package/dist/native/charts/src/engine/overlay.js +16 -16
  237. package/dist/native/charts/src/engine/overlay.js.map +1 -1
  238. package/dist/native/charts/src/engine/presets.cjs +1 -1
  239. package/dist/native/charts/src/engine/presets.cjs.map +1 -1
  240. package/dist/native/charts/src/engine/presets.js +11 -4
  241. package/dist/native/charts/src/engine/presets.js.map +1 -1
  242. package/dist/native/charts/src/engine/scene.cjs +1 -1
  243. package/dist/native/charts/src/engine/scene.cjs.map +1 -1
  244. package/dist/native/charts/src/engine/scene.js +209 -97
  245. package/dist/native/charts/src/engine/scene.js.map +1 -1
  246. package/dist/native/charts/src/engine/theme.cjs.map +1 -1
  247. package/dist/native/charts/src/engine/theme.js.map +1 -1
  248. package/dist/native/components/Chart/scene.cjs +1 -1
  249. package/dist/native/components/Chart/scene.cjs.map +1 -1
  250. package/dist/native/components/Chart/scene.js +31 -19
  251. package/dist/native/components/Chart/scene.js.map +1 -1
  252. package/dist/native/source/components/Chart/scene.tsx +54 -20
  253. package/dist/taro/index.js +1059 -579
  254. package/dist/uni/charts-canvas.js +3 -1
  255. package/dist/weapp/controls.js +966 -225
  256. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"overlay.cjs","names":["toCss","require_color","font","theme","weight","size","crisp","v","textBox","s","px","a","plot","py","x","width","y","height","rectOf","xa","xb","ya","yb","left","right","top","bottom","drawBackground","input","scales","ctx","r","yTicks","xTicks","line","base","lastRight","order","i","b","w","text","overlaps","inside","haloText","halo","color","placeLabels","placed","label","labels","measure","gap","box","c","occupied","o","drawForeground","labelHeight","pos","tx","ty","textColor","t"],"sources":["../../../../charts/src/engine/overlay.ts"],"sourcesContent":["// Canvas2D layers around the data: background (areas, grid, axes, tick\n// labels) and foreground (reference lines, annotation and point labels).\n\nimport { toCss, type Rgba } from \"./color\";\nimport type { AxisTicks } from \"./axis\";\nimport type { Rect, Scales } from \"./layout\";\nimport type { AxisModel } from \"./model\";\nimport type { ChartTheme } from \"./theme\";\nimport type { ChartLabelPosition } from \"./types\";\n\nexport interface ResolvedRect {\n type: \"rect\";\n x0?: number;\n x1?: number;\n y0?: number;\n y1?: number;\n color: Rgba;\n opacity: number;\n label?: string;\n labelPosition: ChartLabelPosition;\n labelColor: Rgba;\n}\n\nexport interface ResolvedLine {\n type: \"line\";\n axis: \"x\" | \"y\";\n value: number;\n color: Rgba;\n width: number;\n dash: number[];\n label?: string;\n}\n\nexport interface ResolvedText {\n type: \"text\";\n x?: number;\n y?: number;\n text: string;\n anchor: \"center\" | \"top\" | \"bottom\" | \"left\" | \"right\";\n color: Rgba;\n weight: number;\n}\n\nexport type ResolvedAnnotation = ResolvedRect | ResolvedLine | ResolvedText;\n\nexport interface PointLabel {\n x: number;\n y: number;\n /** Radius of the dot */\n r: number;\n text: string;\n}\n\nexport const font = (theme: ChartTheme, size = theme.fontSize, weight = 400) =>\n `${weight} ${size}px ${theme.fontFamily}`;\n\nconst crisp = (v: number) => Math.round(v) + 0.5;\n\n/** Box of a text annotation, kept inside the plot */\nexport const textBox = (\n a: ResolvedText,\n s: Scales,\n width: number,\n height: number,\n): Rect => {\n const { plot } = s;\n const px = a.x === undefined ? plot.x + plot.width / 2 : s.xToPx(a.x);\n const py = a.y === undefined ? plot.y + plot.height / 2 : s.yToPx(a.y);\n const gap = 6;\n let x = px - width / 2;\n let y = py - height / 2;\n if (a.anchor === \"top\") y = py + gap;\n else if (a.anchor === \"bottom\") y = py - gap - height;\n else if (a.anchor === \"left\") x = px + gap;\n else if (a.anchor === \"right\") x = px - gap - width;\n x = Math.max(plot.x + gap, Math.min(x, plot.x + plot.width - gap - width));\n y = Math.max(plot.y + 2, Math.min(y, plot.y + plot.height - 2 - height));\n return { x, y, width, height };\n};\n\nconst rectOf = (a: ResolvedRect, s: Scales): Rect => {\n const { plot } = s;\n const xa = a.x0 === undefined ? -Infinity : s.xToPx(a.x0);\n const xb = a.x1 === undefined ? Infinity : s.xToPx(a.x1);\n const ya = a.y0 === undefined ? Infinity : s.yToPx(a.y0);\n const yb = a.y1 === undefined ? -Infinity : s.yToPx(a.y1);\n const left = Math.max(plot.x, Math.min(xa, xb));\n const right = Math.min(plot.x + plot.width, Math.max(xa, xb));\n const top = Math.max(plot.y, Math.min(ya, yb));\n const bottom = Math.min(plot.y + plot.height, Math.max(ya, yb));\n return { x: left, y: top, width: right - left, height: bottom - top };\n};\n\nexport interface BackgroundInput {\n width: number;\n height: number;\n scales: Scales;\n x: AxisModel;\n y: AxisModel;\n xTicks: AxisTicks;\n yTicks: AxisTicks;\n theme: ChartTheme;\n annotations: readonly ResolvedAnnotation[];\n}\n\nexport const drawBackground = (\n ctx: CanvasRenderingContext2D,\n input: BackgroundInput,\n) => {\n const { scales, theme, x, y, xTicks, yTicks } = input;\n const { plot } = scales;\n ctx.clearRect(0, 0, input.width, input.height);\n\n // areas\n ctx.save();\n ctx.beginPath();\n ctx.rect(plot.x, plot.y, plot.width, plot.height);\n ctx.clip();\n for (const a of input.annotations) {\n if (a.type !== \"rect\") continue;\n const r = rectOf(a, scales);\n if (r.width <= 0 || r.height <= 0) continue;\n ctx.fillStyle = toCss(a.color, a.opacity);\n ctx.fillRect(r.x, r.y, r.width, r.height);\n }\n ctx.restore();\n\n // grid\n ctx.lineWidth = 1;\n ctx.strokeStyle = toCss(theme.grid);\n ctx.beginPath();\n if (y.grid) {\n for (const v of yTicks.values) {\n const py = crisp(scales.yToPx(v));\n if (py < plot.y - 1 || py > plot.y + plot.height + 1) continue;\n ctx.moveTo(plot.x, py);\n ctx.lineTo(plot.x + plot.width, py);\n }\n }\n if (x.grid) {\n for (const v of xTicks.values) {\n const px = crisp(scales.xToPx(v));\n if (px < plot.x - 1 || px > plot.x + plot.width + 1) continue;\n ctx.moveTo(px, plot.y);\n ctx.lineTo(px, plot.y + plot.height);\n }\n }\n ctx.stroke();\n\n const line = Math.ceil(theme.fontSize * 1.4);\n ctx.font = font(theme);\n ctx.fillStyle = toCss(theme.textMuted);\n\n // x axis\n if (x.visible) {\n ctx.strokeStyle = toCss(theme.axis);\n ctx.beginPath();\n const base = crisp(plot.y + plot.height);\n ctx.moveTo(plot.x, base);\n ctx.lineTo(plot.x + plot.width, base);\n ctx.stroke();\n ctx.textBaseline = \"top\";\n ctx.textAlign = \"center\";\n let lastRight = -Infinity;\n // left to right (reversed axes list their ticks right to left)\n const order = xTicks.values\n .map((v, i) => ({ px: scales.xToPx(v), text: xTicks.labels[i] }))\n .sort((a, b) => a.px - b.px);\n for (const { px, text } of order) {\n if (px < plot.x - 0.5 || px > plot.x + plot.width + 0.5) continue;\n const w = ctx.measureText(text).width;\n const left = Math.max(0, Math.min(input.width - w, px - w / 2));\n if (left < lastRight + 6) continue;\n lastRight = left + w;\n ctx.fillText(text, left + w / 2, plot.y + plot.height + 7);\n }\n if (x.title) {\n ctx.font = font(theme, theme.fontSize + 1, 500);\n ctx.fillStyle = toCss(theme.text, 0.8);\n ctx.fillText(\n x.title,\n plot.x + plot.width / 2,\n plot.y + plot.height + line + 10,\n );\n }\n }\n\n // y axis\n if (y.visible) {\n ctx.font = font(theme);\n ctx.fillStyle = toCss(theme.textMuted);\n ctx.textAlign = \"right\";\n ctx.textBaseline = \"middle\";\n yTicks.values.forEach((v, i) => {\n const py = scales.yToPx(v);\n if (py < plot.y - 0.5 || py > plot.y + plot.height + 0.5) return;\n ctx.fillText(yTicks.labels[i], plot.x - 8, py);\n });\n if (y.title) {\n ctx.save();\n ctx.font = font(theme, theme.fontSize + 1, 500);\n ctx.fillStyle = toCss(theme.text, 0.8);\n ctx.translate(line / 2 + 4, plot.y + plot.height / 2);\n ctx.rotate(-Math.PI / 2);\n ctx.textAlign = \"center\";\n ctx.fillText(y.title, 0, 0);\n ctx.restore();\n }\n }\n};\n\nconst overlaps = (a: Rect, b: Rect) =>\n a.x < b.x + b.width &&\n b.x < a.x + a.width &&\n a.y < b.y + b.height &&\n b.y < a.y + a.height;\n\nconst inside = (r: Rect, plot: Rect) =>\n r.x >= plot.x &&\n r.y >= plot.y &&\n r.x + r.width <= plot.x + plot.width &&\n r.y + r.height <= plot.y + plot.height;\n\n/** Text with a halo in the background color (readable over data) */\nconst haloText = (\n ctx: CanvasRenderingContext2D,\n text: string,\n x: number,\n y: number,\n color: string,\n halo: string,\n) => {\n ctx.lineWidth = 3;\n ctx.lineJoin = \"round\";\n ctx.strokeStyle = halo;\n ctx.strokeText(text, x, y);\n ctx.fillStyle = color;\n ctx.fillText(text, x, y);\n};\n\n/** Greedy placement: right, left, above, below the dot; skipped when no slot is free */\nexport const placeLabels = (\n labels: readonly PointLabel[],\n plot: Rect,\n measure: (text: string) => number,\n height: number,\n occupied: Rect[] = [],\n): { label: PointLabel; box: Rect }[] => {\n const placed: { label: PointLabel; box: Rect }[] = [];\n for (const label of labels) {\n const w = measure(label.text);\n const gap = label.r + 4;\n const candidates: Rect[] = [\n { x: label.x + gap, y: label.y - height / 2, width: w, height },\n { x: label.x - gap - w, y: label.y - height / 2, width: w, height },\n { x: label.x - w / 2, y: label.y - gap - height, width: w, height },\n { x: label.x - w / 2, y: label.y + gap, width: w, height },\n ];\n const box = candidates.find(\n (c) => inside(c, plot) && !occupied.some((o) => overlaps(o, c)),\n );\n if (!box) continue;\n occupied.push(box);\n placed.push({ label, box });\n }\n return placed;\n};\n\nexport interface ForegroundInput {\n width: number;\n height: number;\n scales: Scales;\n theme: ChartTheme;\n annotations: readonly ResolvedAnnotation[];\n pointLabels: readonly PointLabel[];\n /**\n * Clears the canvas first (off when the layers share one canvas)\n * @default true\n */\n clear?: boolean;\n}\n\nexport const drawForeground = (\n ctx: CanvasRenderingContext2D,\n input: ForegroundInput,\n) => {\n const { scales, theme } = input;\n const { plot } = scales;\n if (input.clear !== false) ctx.clearRect(0, 0, input.width, input.height);\n ctx.save();\n ctx.beginPath();\n ctx.rect(plot.x, plot.y, plot.width, plot.height);\n ctx.clip();\n\n const halo = toCss(theme.background, 0.9);\n const occupied: Rect[] = [];\n const labelHeight = theme.fontSize + 4;\n\n for (const a of input.annotations) {\n if (a.type !== \"line\") continue;\n const color = toCss(a.color);\n ctx.strokeStyle = color;\n ctx.lineWidth = a.width;\n ctx.setLineDash(a.dash);\n ctx.beginPath();\n if (a.axis === \"y\") {\n const py = crisp(scales.yToPx(a.value));\n ctx.moveTo(plot.x, py);\n ctx.lineTo(plot.x + plot.width, py);\n ctx.stroke();\n if (a.label) {\n ctx.setLineDash([]);\n ctx.font = font(theme, theme.fontSize, 500);\n ctx.textAlign = \"right\";\n ctx.textBaseline = \"bottom\";\n haloText(ctx, a.label, plot.x + plot.width - 6, py - 3, color, halo);\n }\n } else {\n const px = crisp(scales.xToPx(a.value));\n ctx.moveTo(px, plot.y);\n ctx.lineTo(px, plot.y + plot.height);\n ctx.stroke();\n if (a.label) {\n ctx.setLineDash([]);\n ctx.font = font(theme, theme.fontSize, 500);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"top\";\n haloText(ctx, a.label, px + 5, plot.y + 5, color, halo);\n }\n }\n }\n ctx.setLineDash([]);\n\n // labels of areas\n ctx.font = font(theme, theme.fontSize + 1, 600);\n for (const a of input.annotations) {\n if (a.type !== \"rect\" || !a.label) continue;\n const r = rectOf(a, scales);\n if (r.width <= 0 || r.height <= 0) continue;\n const pad = 10;\n const w = ctx.measureText(a.label).width;\n const pos = a.labelPosition;\n const tx = pos.endsWith(\"left\")\n ? r.x + pad\n : pos.endsWith(\"right\")\n ? r.x + r.width - pad - w\n : r.x + (r.width - w) / 2;\n const ty = pos.startsWith(\"top\")\n ? r.y + pad\n : pos.startsWith(\"bottom\")\n ? r.y + r.height - pad - labelHeight\n : r.y + (r.height - labelHeight) / 2;\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"top\";\n ctx.fillStyle = toCss(a.labelColor);\n ctx.fillText(a.label, tx, ty);\n occupied.push({ x: tx, y: ty, width: w, height: labelHeight });\n }\n\n // free texts\n for (const a of input.annotations) {\n if (a.type !== \"text\" || !a.text) continue;\n ctx.font = font(theme, theme.fontSize, a.weight);\n const box = textBox(a, scales, ctx.measureText(a.text).width, labelHeight);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"middle\";\n haloText(ctx, a.text, box.x, box.y + box.height / 2, toCss(a.color), halo);\n occupied.push(box);\n }\n\n // point labels\n if (input.pointLabels.length) {\n ctx.font = font(theme);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"middle\";\n const textColor = toCss(theme.text, 0.85);\n const placed = placeLabels(\n input.pointLabels,\n plot,\n (t) => ctx.measureText(t).width,\n labelHeight - 2,\n occupied,\n );\n for (const { label, box } of placed) {\n haloText(ctx, label.text, box.x, box.y + box.height / 2, textColor, halo);\n }\n }\n ctx.restore();\n};\n"],"mappings":"+BAqDA,IAAaE,GAAQ,EAAmB,EAAOC,EAAM,SAAU,EAAS,MACtE,GAAGC,EAAO,GAAGC,EAAK,KAAKF,EAAM,aAEzBG,EA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KAAM,SAClC,EAAI,KAAOT,EAAKC,EAAOA,EAAM,SAAUQ,EAAE,MAAM,EAC/C,IAAM0C,EAAM7C,EAAQG,EAAGkB,EAAQC,EAAI,YAAYnB,EAAE,IAAI,CAAC,CAAC,MAAO+C,CAAW,EACzE,EAAI,UAAY,OAChB,EAAI,aAAe,SACnBd,EAASd,EAAKnB,EAAE,KAAM0C,EAAI,EAAGA,EAAI,EAAIA,EAAI,OAAS,EAAGrD,EAAAA,MAAMW,EAAE,KAAK,EAAGkC,CAAI,EACzEU,EAAS,KAAKF,CAAG,CACnB,CAGA,GAAIzB,EAAM,YAAY,OAAQ,CAC5B,EAAI,KAAO1B,EAAKC,CAAK,EACrB,EAAI,UAAY,OAChB,EAAI,aAAe,SACnB,IAAM2D,EAAY9D,EAAAA,MAAMG,EAAM,KAAM,GAAI,EAClC6C,EAASD,EACbnB,EAAM,YACNhB,EACC,GAAMkB,EAAI,YAAYiC,CAAC,CAAC,CAAC,MAC1BL,EAAc,EACdH,CACF,EACA,IAAK,GAAM,CAAE,QAAO,SAASP,EAC3BJ,EAASd,EAAKmB,EAAM,KAAMI,EAAI,EAAGA,EAAI,EAAIA,EAAI,OAAS,EAAGS,EAAWjB,CAAI,CAE5E,CACAf,EAAI,QAAQ,CACd"}
1
+ {"version":3,"file":"overlay.cjs","names":["toCss","require_color","font","theme","weight","size","crisp","v","textBox","s","px","a","plot","py","x","width","y","height","rectOf","xa","xb","ya","yb","left","right","top","bottom","drawBackground","input","scales","ctx","r","yTicks","xTicks","line","base","lastRight","order","i","b","w","text","overlaps","inside","haloText","halo","color","placeLabels","placed","label","labels","measure","gap","above","below","box","c","occupied","o","drawForeground","labelHeight","pos","tx","ty","textColor","t"],"sources":["../../../../charts/src/engine/overlay.ts"],"sourcesContent":["// Canvas2D layers around the data: background (areas, grid, axes, tick\n// labels) and foreground (reference lines, annotation and point labels).\n\nimport { toCss, type Rgba } from \"./color\";\nimport type { AxisTicks } from \"./axis\";\nimport type { Rect, Scales } from \"./layout\";\nimport type { AxisModel } from \"./model\";\nimport type { ChartTheme } from \"./theme\";\nimport type { ChartLabelPosition } from \"./types\";\n\nexport interface ResolvedRect {\n type: \"rect\";\n x0?: number;\n x1?: number;\n y0?: number;\n y1?: number;\n color: Rgba;\n opacity: number;\n label?: string;\n labelPosition: ChartLabelPosition;\n labelColor: Rgba;\n}\n\nexport interface ResolvedLine {\n type: \"line\";\n axis: \"x\" | \"y\";\n value: number;\n color: Rgba;\n width: number;\n dash: number[];\n label?: string;\n}\n\nexport interface ResolvedText {\n type: \"text\";\n x?: number;\n y?: number;\n text: string;\n anchor: \"center\" | \"top\" | \"bottom\" | \"left\" | \"right\";\n color: Rgba;\n weight: number;\n}\n\nexport type ResolvedAnnotation = ResolvedRect | ResolvedLine | ResolvedText;\n\nexport interface PointLabel {\n x: number;\n y: number;\n /** Radius of the dot */\n r: number;\n text: string;\n /** Fixed side (bar values); any free side around the dot otherwise */\n placement?: \"above\" | \"below\";\n}\n\nexport const font = (theme: ChartTheme, size = theme.fontSize, weight = 400) =>\n `${weight} ${size}px ${theme.fontFamily}`;\n\nconst crisp = (v: number) => Math.round(v) + 0.5;\n\n/** Box of a text annotation, kept inside the plot */\nexport const textBox = (\n a: ResolvedText,\n s: Scales,\n width: number,\n height: number,\n): Rect => {\n const { plot } = s;\n const px = a.x === undefined ? plot.x + plot.width / 2 : s.xToPx(a.x);\n const py = a.y === undefined ? plot.y + plot.height / 2 : s.yToPx(a.y);\n const gap = 6;\n let x = px - width / 2;\n let y = py - height / 2;\n if (a.anchor === \"top\") y = py + gap;\n else if (a.anchor === \"bottom\") y = py - gap - height;\n else if (a.anchor === \"left\") x = px + gap;\n else if (a.anchor === \"right\") x = px - gap - width;\n x = Math.max(plot.x + gap, Math.min(x, plot.x + plot.width - gap - width));\n y = Math.max(plot.y + 2, Math.min(y, plot.y + plot.height - 2 - height));\n return { x, y, width, height };\n};\n\nconst rectOf = (a: ResolvedRect, s: Scales): Rect => {\n const { plot } = s;\n const xa = a.x0 === undefined ? -Infinity : s.xToPx(a.x0);\n const xb = a.x1 === undefined ? Infinity : s.xToPx(a.x1);\n const ya = a.y0 === undefined ? Infinity : s.yToPx(a.y0);\n const yb = a.y1 === undefined ? -Infinity : s.yToPx(a.y1);\n const left = Math.max(plot.x, Math.min(xa, xb));\n const right = Math.min(plot.x + plot.width, Math.max(xa, xb));\n const top = Math.max(plot.y, Math.min(ya, yb));\n const bottom = Math.min(plot.y + plot.height, Math.max(ya, yb));\n return { x: left, y: top, width: right - left, height: bottom - top };\n};\n\nexport interface BackgroundInput {\n width: number;\n height: number;\n scales: Scales;\n x: AxisModel;\n y: AxisModel;\n xTicks: AxisTicks;\n yTicks: AxisTicks;\n theme: ChartTheme;\n annotations: readonly ResolvedAnnotation[];\n}\n\nexport const drawBackground = (\n ctx: CanvasRenderingContext2D,\n input: BackgroundInput,\n) => {\n const { scales, theme, x, y, xTicks, yTicks } = input;\n const { plot } = scales;\n ctx.clearRect(0, 0, input.width, input.height);\n\n // areas\n ctx.save();\n ctx.beginPath();\n ctx.rect(plot.x, plot.y, plot.width, plot.height);\n ctx.clip();\n for (const a of input.annotations) {\n if (a.type !== \"rect\") continue;\n const r = rectOf(a, scales);\n if (r.width <= 0 || r.height <= 0) continue;\n ctx.fillStyle = toCss(a.color, a.opacity);\n ctx.fillRect(r.x, r.y, r.width, r.height);\n }\n ctx.restore();\n\n // grid\n ctx.lineWidth = 1;\n ctx.strokeStyle = toCss(theme.grid);\n ctx.beginPath();\n if (y.grid) {\n for (const v of yTicks.values) {\n const py = crisp(scales.yToPx(v));\n if (py < plot.y - 1 || py > plot.y + plot.height + 1) continue;\n ctx.moveTo(plot.x, py);\n ctx.lineTo(plot.x + plot.width, py);\n }\n }\n if (x.grid) {\n for (const v of xTicks.values) {\n const px = crisp(scales.xToPx(v));\n if (px < plot.x - 1 || px > plot.x + plot.width + 1) continue;\n ctx.moveTo(px, plot.y);\n ctx.lineTo(px, plot.y + plot.height);\n }\n }\n ctx.stroke();\n\n const line = Math.ceil(theme.fontSize * 1.4);\n ctx.font = font(theme);\n ctx.fillStyle = toCss(theme.textMuted);\n\n // x axis\n if (x.visible) {\n ctx.strokeStyle = toCss(theme.axis);\n ctx.beginPath();\n const base = crisp(plot.y + plot.height);\n ctx.moveTo(plot.x, base);\n ctx.lineTo(plot.x + plot.width, base);\n ctx.stroke();\n ctx.textBaseline = \"top\";\n ctx.textAlign = \"center\";\n let lastRight = -Infinity;\n // left to right (reversed axes list their ticks right to left)\n const order = xTicks.values\n .map((v, i) => ({ px: scales.xToPx(v), text: xTicks.labels[i] }))\n .sort((a, b) => a.px - b.px);\n for (const { px, text } of order) {\n if (px < plot.x - 0.5 || px > plot.x + plot.width + 0.5) continue;\n const w = ctx.measureText(text).width;\n const left = Math.max(0, Math.min(input.width - w, px - w / 2));\n if (left < lastRight + 6) continue;\n lastRight = left + w;\n ctx.fillText(text, left + w / 2, plot.y + plot.height + 7);\n }\n if (x.title) {\n ctx.font = font(theme, theme.fontSize + 1, 500);\n ctx.fillStyle = toCss(theme.text, 0.8);\n ctx.fillText(\n x.title,\n plot.x + plot.width / 2,\n plot.y + plot.height + line + 10,\n );\n }\n }\n\n // y axis\n if (y.visible) {\n ctx.font = font(theme);\n ctx.fillStyle = toCss(theme.textMuted);\n ctx.textAlign = \"right\";\n ctx.textBaseline = \"middle\";\n yTicks.values.forEach((v, i) => {\n const py = scales.yToPx(v);\n if (py < plot.y - 0.5 || py > plot.y + plot.height + 0.5) return;\n ctx.fillText(yTicks.labels[i], plot.x - 8, py);\n });\n if (y.title) {\n ctx.save();\n ctx.font = font(theme, theme.fontSize + 1, 500);\n ctx.fillStyle = toCss(theme.text, 0.8);\n ctx.translate(line / 2 + 4, plot.y + plot.height / 2);\n ctx.rotate(-Math.PI / 2);\n ctx.textAlign = \"center\";\n ctx.fillText(y.title, 0, 0);\n ctx.restore();\n }\n }\n};\n\nconst overlaps = (a: Rect, b: Rect) =>\n a.x < b.x + b.width &&\n b.x < a.x + a.width &&\n a.y < b.y + b.height &&\n b.y < a.y + a.height;\n\nconst inside = (r: Rect, plot: Rect) =>\n r.x >= plot.x &&\n r.y >= plot.y &&\n r.x + r.width <= plot.x + plot.width &&\n r.y + r.height <= plot.y + plot.height;\n\n/** Text with a halo in the background color (readable over data) */\nconst haloText = (\n ctx: CanvasRenderingContext2D,\n text: string,\n x: number,\n y: number,\n color: string,\n halo: string,\n) => {\n ctx.lineWidth = 3;\n ctx.lineJoin = \"round\";\n ctx.strokeStyle = halo;\n ctx.strokeText(text, x, y);\n ctx.fillStyle = color;\n ctx.fillText(text, x, y);\n};\n\n/** Greedy placement: right, left, above, below the dot; skipped when no slot is free */\nexport const placeLabels = (\n labels: readonly PointLabel[],\n plot: Rect,\n measure: (text: string) => number,\n height: number,\n occupied: Rect[] = [],\n): { label: PointLabel; box: Rect }[] => {\n const placed: { label: PointLabel; box: Rect }[] = [];\n for (const label of labels) {\n const w = measure(label.text);\n const gap = label.r + 4;\n const above = {\n x: label.x - w / 2,\n y: label.y - gap - height,\n width: w,\n height,\n };\n const below = { x: label.x - w / 2, y: label.y + gap, width: w, height };\n const candidates: Rect[] =\n label.placement === \"above\"\n ? [above]\n : label.placement === \"below\"\n ? [below]\n : [\n { x: label.x + gap, y: label.y - height / 2, width: w, height },\n {\n x: label.x - gap - w,\n y: label.y - height / 2,\n width: w,\n height,\n },\n above,\n below,\n ];\n const box = candidates.find(\n (c) => inside(c, plot) && !occupied.some((o) => overlaps(o, c)),\n );\n if (!box) continue;\n occupied.push(box);\n placed.push({ label, box });\n }\n return placed;\n};\n\nexport interface ForegroundInput {\n width: number;\n height: number;\n scales: Scales;\n theme: ChartTheme;\n annotations: readonly ResolvedAnnotation[];\n pointLabels: readonly PointLabel[];\n /**\n * Clears the canvas first (off when the layers share one canvas)\n * @default true\n */\n clear?: boolean;\n}\n\nexport const drawForeground = (\n ctx: CanvasRenderingContext2D,\n input: ForegroundInput,\n) => {\n const { scales, theme } = input;\n const { plot } = scales;\n if (input.clear !== false) ctx.clearRect(0, 0, input.width, input.height);\n ctx.save();\n ctx.beginPath();\n ctx.rect(plot.x, plot.y, plot.width, plot.height);\n ctx.clip();\n\n const halo = toCss(theme.background, 0.9);\n const occupied: Rect[] = [];\n const labelHeight = theme.fontSize + 4;\n\n for (const a of input.annotations) {\n if (a.type !== \"line\") continue;\n const color = toCss(a.color);\n ctx.strokeStyle = color;\n ctx.lineWidth = a.width;\n ctx.setLineDash(a.dash);\n ctx.beginPath();\n if (a.axis === \"y\") {\n const py = crisp(scales.yToPx(a.value));\n ctx.moveTo(plot.x, py);\n ctx.lineTo(plot.x + plot.width, py);\n ctx.stroke();\n if (a.label) {\n ctx.setLineDash([]);\n ctx.font = font(theme, theme.fontSize, 500);\n ctx.textAlign = \"right\";\n ctx.textBaseline = \"bottom\";\n haloText(ctx, a.label, plot.x + plot.width - 6, py - 3, color, halo);\n }\n } else {\n const px = crisp(scales.xToPx(a.value));\n ctx.moveTo(px, plot.y);\n ctx.lineTo(px, plot.y + plot.height);\n ctx.stroke();\n if (a.label) {\n ctx.setLineDash([]);\n ctx.font = font(theme, theme.fontSize, 500);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"top\";\n haloText(ctx, a.label, px + 5, plot.y + 5, color, halo);\n }\n }\n }\n ctx.setLineDash([]);\n\n // labels of areas\n ctx.font = font(theme, theme.fontSize + 1, 600);\n for (const a of input.annotations) {\n if (a.type !== \"rect\" || !a.label) continue;\n const r = rectOf(a, scales);\n if (r.width <= 0 || r.height <= 0) continue;\n const pad = 10;\n const w = ctx.measureText(a.label).width;\n const pos = a.labelPosition;\n const tx = pos.endsWith(\"left\")\n ? r.x + pad\n : pos.endsWith(\"right\")\n ? r.x + r.width - pad - w\n : r.x + (r.width - w) / 2;\n const ty = pos.startsWith(\"top\")\n ? r.y + pad\n : pos.startsWith(\"bottom\")\n ? r.y + r.height - pad - labelHeight\n : r.y + (r.height - labelHeight) / 2;\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"top\";\n ctx.fillStyle = toCss(a.labelColor);\n ctx.fillText(a.label, tx, ty);\n occupied.push({ x: tx, y: ty, width: w, height: labelHeight });\n }\n\n // free texts\n for (const a of input.annotations) {\n if (a.type !== \"text\" || !a.text) continue;\n ctx.font = font(theme, theme.fontSize, a.weight);\n const box = textBox(a, scales, ctx.measureText(a.text).width, labelHeight);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"middle\";\n haloText(ctx, a.text, box.x, box.y + box.height / 2, toCss(a.color), halo);\n occupied.push(box);\n }\n\n // point labels\n if (input.pointLabels.length) {\n ctx.font = font(theme);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"middle\";\n const textColor = toCss(theme.text, 0.85);\n const placed = placeLabels(\n input.pointLabels,\n plot,\n (t) => ctx.measureText(t).width,\n labelHeight - 2,\n occupied,\n );\n for (const { label, box } of placed) {\n haloText(ctx, label.text, box.x, box.y + box.height / 2, textColor, halo);\n }\n }\n ctx.restore();\n};\n"],"mappings":"+BAuDA,IAAaE,GAAQ,EAAmB,EAAOC,EAAM,SAAU,EAAS,MACtE,GAAGC,EAAO,GAAGC,EAAK,KAAKF,EAAM,aAEzBG,EAAS,GAAc,KAAK,MAAMC,CAAC,EAAI,GAGhCC,GACX,EACA,EACA,EACA,IACS,CACT,GAAM,CAAE,QAASC,EACXC,EAAKC,EAAE,IAAM,IAAA,GAAYC,EAAK,EAAIA,EAAK,MAAQ,EAAIH,EAAE,MAAME,EAAE,CAAC,EAC9DE,EAAKF,EAAE,IAAM,IAAA,GAAYC,EAAK,EAAIA,EAAK,OAAS,EAAIH,EAAE,MAAME,EAAE,CAAC,EAEjEG,EAAIJ,EAAKK,EAAQ,EACjBC,EAAIH,EAAKI,EAAS,EAOtB,OANIN,EAAE,SAAW,MAAO,EAAIE,EAAK,EACxBF,EAAE,SAAW,SAAU,EAAIE,EAAK,EAAMI,EACtCN,EAAE,SAAW,OAAQ,EAAID,EAAK,EAC9BC,EAAE,SAAW,UAAS,EAAID,EAAK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AKC,CAAK,EACrB,EAAI,UAAY,OAChB,EAAI,aAAe,SACnB,IAAM6D,EAAYhE,EAAAA,MAAMG,EAAM,KAAM,GAAI,EAClC6C,EAASD,EACbnB,EAAM,YACNhB,EACC,GAAMkB,EAAI,YAAYmC,CAAC,CAAC,CAAC,MAC1BL,EAAc,EACdH,CACF,EACA,IAAK,GAAM,CAAE,QAAO,SAAST,EAC3BJ,EAASd,EAAKmB,EAAM,KAAMM,EAAI,EAAGA,EAAI,EAAIA,EAAI,OAAS,EAAGS,EAAWnB,CAAI,CAE5E,CACAf,EAAI,QAAQ,CACd"}
@@ -41,6 +41,8 @@ export interface PointLabel {
41
41
  /** Radius of the dot */
42
42
  r: number;
43
43
  text: string;
44
+ /** Fixed side (bar values); any free side around the dot otherwise */
45
+ placement?: "above" | "below";
44
46
  }
45
47
  export declare const font: (theme: ChartTheme, size?: number, weight?: number) => string;
46
48
  /** Box of a text annotation, kept inside the plot */
@@ -41,6 +41,8 @@ export interface PointLabel {
41
41
  /** Radius of the dot */
42
42
  r: number;
43
43
  text: string;
44
+ /** Fixed side (bar values); any free side around the dot otherwise */
45
+ placement?: "above" | "below";
44
46
  }
45
47
  export declare const font: (theme: ChartTheme, size?: number, weight?: number) => string;
46
48
  /** Box of a text annotation, kept inside the plot */
@@ -58,7 +58,17 @@ var t = (e, t = e.fontSize, n = 400) => `${n} ${t}px ${e.fontFamily}`, n = (e) =
58
58
  }, l = (e, t, n, r, i = []) => {
59
59
  let a = [];
60
60
  for (let c of e) {
61
- let e = n(c.text), l = c.r + 4, u = [
61
+ let e = n(c.text), l = c.r + 4, u = {
62
+ x: c.x - e / 2,
63
+ y: c.y - l - r,
64
+ width: e,
65
+ height: r
66
+ }, d = {
67
+ x: c.x - e / 2,
68
+ y: c.y + l,
69
+ width: e,
70
+ height: r
71
+ }, f = (c.placement === "above" ? [u] : c.placement === "below" ? [d] : [
62
72
  {
63
73
  x: c.x + l,
64
74
  y: c.y - r / 2,
@@ -71,22 +81,12 @@ var t = (e, t = e.fontSize, n = 400) => `${n} ${t}px ${e.fontFamily}`, n = (e) =
71
81
  width: e,
72
82
  height: r
73
83
  },
74
- {
75
- x: c.x - e / 2,
76
- y: c.y - l - r,
77
- width: e,
78
- height: r
79
- },
80
- {
81
- x: c.x - e / 2,
82
- y: c.y + l,
83
- width: e,
84
- height: r
85
- }
86
- ].find((e) => s(e, t) && !i.some((t) => o(t, e)));
87
- u && (i.push(u), a.push({
84
+ u,
85
+ d
86
+ ]).find((e) => s(e, t) && !i.some((t) => o(t, e)));
87
+ f && (i.push(f), a.push({
88
88
  label: c,
89
- box: u
89
+ box: f
90
90
  }));
91
91
  }
92
92
  return a;
@@ -1 +1 @@
1
- {"version":3,"file":"overlay.js","names":["font","theme","weight","size","crisp","v","textBox","s","px","a","plot","py","x","width","y","height","rectOf","xa","xb","ya","yb","left","right","top","bottom","drawBackground","input","scales","ctx","r","toCss","yTicks","xTicks","line","base","lastRight","order","i","b","w","text","overlaps","inside","haloText","halo","color","placeLabels","placed","label","labels","measure","gap","box","c","occupied","o","drawForeground","labelHeight","pos","tx","ty","textColor","t"],"sources":["../../../../charts/src/engine/overlay.ts"],"sourcesContent":["// Canvas2D layers around the data: background (areas, grid, axes, tick\n// labels) and foreground (reference lines, annotation and point labels).\n\nimport { toCss, type Rgba } from \"./color\";\nimport type { AxisTicks } from \"./axis\";\nimport type { Rect, Scales } from \"./layout\";\nimport type { AxisModel } from \"./model\";\nimport type { ChartTheme } from \"./theme\";\nimport type { ChartLabelPosition } from \"./types\";\n\nexport interface ResolvedRect {\n type: \"rect\";\n x0?: number;\n x1?: number;\n y0?: number;\n y1?: number;\n color: Rgba;\n opacity: number;\n label?: string;\n labelPosition: ChartLabelPosition;\n labelColor: Rgba;\n}\n\nexport interface ResolvedLine {\n type: \"line\";\n axis: \"x\" | \"y\";\n value: number;\n color: Rgba;\n width: number;\n dash: number[];\n label?: string;\n}\n\nexport interface ResolvedText {\n type: \"text\";\n x?: number;\n y?: number;\n text: string;\n anchor: \"center\" | \"top\" | \"bottom\" | \"left\" | \"right\";\n color: Rgba;\n weight: number;\n}\n\nexport type ResolvedAnnotation = ResolvedRect | ResolvedLine | ResolvedText;\n\nexport interface PointLabel {\n x: number;\n y: number;\n /** Radius of the dot */\n r: number;\n text: string;\n}\n\nexport const font = (theme: ChartTheme, size = theme.fontSize, weight = 400) =>\n `${weight} ${size}px ${theme.fontFamily}`;\n\nconst crisp = (v: number) => Math.round(v) + 0.5;\n\n/** Box of a text annotation, kept inside the plot */\nexport const textBox = (\n a: ResolvedText,\n s: Scales,\n width: number,\n height: number,\n): Rect => {\n const { plot } = s;\n const px = a.x === undefined ? plot.x + plot.width / 2 : s.xToPx(a.x);\n const py = a.y === undefined ? plot.y + plot.height / 2 : s.yToPx(a.y);\n const gap = 6;\n let x = px - width / 2;\n let y = py - height / 2;\n if (a.anchor === \"top\") y = py + gap;\n else if (a.anchor === \"bottom\") y = py - gap - height;\n else if (a.anchor === \"left\") x = px + gap;\n else if (a.anchor === \"right\") x = px - gap - width;\n x = Math.max(plot.x + gap, Math.min(x, plot.x + plot.width - gap - width));\n y = Math.max(plot.y + 2, Math.min(y, plot.y + plot.height - 2 - height));\n return { x, y, width, height };\n};\n\nconst rectOf = (a: ResolvedRect, s: Scales): Rect => {\n const { plot } = s;\n const xa = a.x0 === undefined ? -Infinity : s.xToPx(a.x0);\n const xb = a.x1 === undefined ? Infinity : s.xToPx(a.x1);\n const ya = a.y0 === undefined ? Infinity : s.yToPx(a.y0);\n const yb = a.y1 === undefined ? -Infinity : s.yToPx(a.y1);\n const left = Math.max(plot.x, Math.min(xa, xb));\n const right = Math.min(plot.x + plot.width, Math.max(xa, xb));\n const top = Math.max(plot.y, Math.min(ya, yb));\n const bottom = Math.min(plot.y + plot.height, Math.max(ya, yb));\n return { x: left, y: top, width: right - left, height: bottom - top };\n};\n\nexport interface BackgroundInput {\n width: number;\n height: number;\n scales: Scales;\n x: AxisModel;\n y: AxisModel;\n xTicks: AxisTicks;\n yTicks: AxisTicks;\n theme: ChartTheme;\n annotations: readonly ResolvedAnnotation[];\n}\n\nexport const drawBackground = (\n ctx: CanvasRenderingContext2D,\n input: BackgroundInput,\n) => {\n const { scales, theme, x, y, xTicks, yTicks } = input;\n const { plot } = scales;\n ctx.clearRect(0, 0, input.width, input.height);\n\n // areas\n ctx.save();\n ctx.beginPath();\n ctx.rect(plot.x, plot.y, plot.width, plot.height);\n ctx.clip();\n for (const a of input.annotations) {\n if (a.type !== \"rect\") continue;\n const r = rectOf(a, scales);\n if (r.width <= 0 || r.height <= 0) continue;\n ctx.fillStyle = toCss(a.color, a.opacity);\n ctx.fillRect(r.x, r.y, r.width, r.height);\n }\n ctx.restore();\n\n // grid\n ctx.lineWidth = 1;\n ctx.strokeStyle = toCss(theme.grid);\n ctx.beginPath();\n if (y.grid) {\n for (const v of yTicks.values) {\n const py = crisp(scales.yToPx(v));\n if (py < plot.y - 1 || py > plot.y + plot.height + 1) continue;\n ctx.moveTo(plot.x, py);\n ctx.lineTo(plot.x + plot.width, py);\n }\n }\n if (x.grid) {\n for (const v of xTicks.values) {\n const px = crisp(scales.xToPx(v));\n if (px < plot.x - 1 || px > plot.x + plot.width + 1) continue;\n ctx.moveTo(px, plot.y);\n ctx.lineTo(px, plot.y + plot.height);\n }\n }\n ctx.stroke();\n\n const line = Math.ceil(theme.fontSize * 1.4);\n ctx.font = font(theme);\n ctx.fillStyle = toCss(theme.textMuted);\n\n // x axis\n if (x.visible) {\n ctx.strokeStyle = toCss(theme.axis);\n ctx.beginPath();\n const base = crisp(plot.y + plot.height);\n ctx.moveTo(plot.x, base);\n ctx.lineTo(plot.x + plot.width, base);\n ctx.stroke();\n ctx.textBaseline = \"top\";\n ctx.textAlign = \"center\";\n let lastRight = -Infinity;\n // left to right (reversed axes list their ticks right to left)\n const order = xTicks.values\n .map((v, i) => ({ px: scales.xToPx(v), text: xTicks.labels[i] }))\n .sort((a, b) => a.px - b.px);\n for (const { px, text } of order) {\n if (px < plot.x - 0.5 || px > plot.x + plot.width + 0.5) continue;\n const w = ctx.measureText(text).width;\n const left = Math.max(0, Math.min(input.width - w, px - w / 2));\n if (left < lastRight + 6) continue;\n lastRight = left + w;\n ctx.fillText(text, left + w / 2, plot.y + plot.height + 7);\n }\n if (x.title) {\n ctx.font = font(theme, theme.fontSize + 1, 500);\n ctx.fillStyle = toCss(theme.text, 0.8);\n ctx.fillText(\n x.title,\n plot.x + plot.width / 2,\n plot.y + plot.height + line + 10,\n );\n }\n }\n\n // y axis\n if (y.visible) {\n ctx.font = font(theme);\n ctx.fillStyle = toCss(theme.textMuted);\n ctx.textAlign = \"right\";\n ctx.textBaseline = \"middle\";\n yTicks.values.forEach((v, i) => {\n const py = scales.yToPx(v);\n if (py < plot.y - 0.5 || py > plot.y + plot.height + 0.5) return;\n ctx.fillText(yTicks.labels[i], plot.x - 8, py);\n });\n if (y.title) {\n ctx.save();\n ctx.font = font(theme, theme.fontSize + 1, 500);\n ctx.fillStyle = toCss(theme.text, 0.8);\n ctx.translate(line / 2 + 4, plot.y + plot.height / 2);\n ctx.rotate(-Math.PI / 2);\n ctx.textAlign = \"center\";\n ctx.fillText(y.title, 0, 0);\n ctx.restore();\n }\n }\n};\n\nconst overlaps = (a: Rect, b: Rect) =>\n a.x < b.x + b.width &&\n b.x < a.x + a.width &&\n a.y < b.y + b.height &&\n b.y < a.y + a.height;\n\nconst inside = (r: Rect, plot: Rect) =>\n r.x >= plot.x &&\n r.y >= plot.y &&\n r.x + r.width <= plot.x + plot.width &&\n r.y + r.height <= plot.y + plot.height;\n\n/** Text with a halo in the background color (readable over data) */\nconst haloText = (\n ctx: CanvasRenderingContext2D,\n text: string,\n x: number,\n y: number,\n color: string,\n halo: string,\n) => {\n ctx.lineWidth = 3;\n ctx.lineJoin = \"round\";\n ctx.strokeStyle = halo;\n ctx.strokeText(text, x, y);\n ctx.fillStyle = color;\n ctx.fillText(text, x, y);\n};\n\n/** Greedy placement: right, left, above, below the dot; skipped when no slot is free */\nexport const placeLabels = (\n labels: readonly PointLabel[],\n plot: Rect,\n measure: (text: string) => number,\n height: number,\n occupied: Rect[] = [],\n): { label: PointLabel; box: Rect }[] => {\n const placed: { label: PointLabel; box: Rect }[] = [];\n for (const label of labels) {\n const w = measure(label.text);\n const gap = label.r + 4;\n const candidates: Rect[] = [\n { x: label.x + gap, y: label.y - height / 2, width: w, height },\n { x: label.x - gap - w, y: label.y - height / 2, width: w, height },\n { x: label.x - w / 2, y: label.y - gap - height, width: w, height },\n { x: label.x - w / 2, y: label.y + gap, width: w, height },\n ];\n const box = candidates.find(\n (c) => inside(c, plot) && !occupied.some((o) => overlaps(o, c)),\n );\n if (!box) continue;\n occupied.push(box);\n placed.push({ label, box });\n }\n return placed;\n};\n\nexport interface ForegroundInput {\n width: number;\n height: number;\n scales: Scales;\n theme: ChartTheme;\n annotations: readonly ResolvedAnnotation[];\n pointLabels: readonly PointLabel[];\n /**\n * Clears the canvas first (off when the layers share one canvas)\n * @default true\n */\n clear?: boolean;\n}\n\nexport const drawForeground = (\n ctx: CanvasRenderingContext2D,\n input: ForegroundInput,\n) => {\n const { scales, theme } = input;\n const { plot } = scales;\n if (input.clear !== false) ctx.clearRect(0, 0, input.width, input.height);\n ctx.save();\n ctx.beginPath();\n ctx.rect(plot.x, plot.y, plot.width, plot.height);\n ctx.clip();\n\n const halo = toCss(theme.background, 0.9);\n const occupied: Rect[] = [];\n const labelHeight = theme.fontSize + 4;\n\n for (const a of input.annotations) {\n if (a.type !== \"line\") continue;\n const color = toCss(a.color);\n ctx.strokeStyle = color;\n ctx.lineWidth = a.width;\n ctx.setLineDash(a.dash);\n ctx.beginPath();\n if (a.axis === \"y\") {\n const py = crisp(scales.yToPx(a.value));\n ctx.moveTo(plot.x, py);\n ctx.lineTo(plot.x + plot.width, py);\n ctx.stroke();\n if (a.label) {\n ctx.setLineDash([]);\n ctx.font = font(theme, theme.fontSize, 500);\n ctx.textAlign = \"right\";\n ctx.textBaseline = \"bottom\";\n haloText(ctx, a.label, plot.x + plot.width - 6, py - 3, color, halo);\n }\n } else {\n const px = crisp(scales.xToPx(a.value));\n ctx.moveTo(px, plot.y);\n ctx.lineTo(px, plot.y + plot.height);\n ctx.stroke();\n if (a.label) {\n ctx.setLineDash([]);\n ctx.font = font(theme, theme.fontSize, 500);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"top\";\n haloText(ctx, a.label, px + 5, plot.y + 5, color, halo);\n }\n }\n }\n ctx.setLineDash([]);\n\n // labels of areas\n ctx.font = font(theme, theme.fontSize + 1, 600);\n for (const a of input.annotations) {\n if (a.type !== \"rect\" || !a.label) continue;\n const r = rectOf(a, scales);\n if (r.width <= 0 || r.height <= 0) continue;\n const pad = 10;\n const w = ctx.measureText(a.label).width;\n const pos = a.labelPosition;\n const tx = pos.endsWith(\"left\")\n ? r.x + pad\n : pos.endsWith(\"right\")\n ? r.x + r.width - pad - w\n : r.x + (r.width - w) / 2;\n const ty = pos.startsWith(\"top\")\n ? r.y + pad\n : pos.startsWith(\"bottom\")\n ? r.y + r.height - pad - labelHeight\n : r.y + (r.height - labelHeight) / 2;\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"top\";\n ctx.fillStyle = toCss(a.labelColor);\n ctx.fillText(a.label, tx, ty);\n occupied.push({ x: tx, y: ty, width: w, height: labelHeight });\n }\n\n // free texts\n for (const a of input.annotations) {\n if (a.type !== \"text\" || !a.text) continue;\n ctx.font = font(theme, theme.fontSize, a.weight);\n const box = textBox(a, scales, ctx.measureText(a.text).width, labelHeight);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"middle\";\n haloText(ctx, a.text, box.x, box.y + box.height / 2, toCss(a.color), halo);\n occupied.push(box);\n }\n\n // point labels\n if (input.pointLabels.length) {\n ctx.font = font(theme);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"middle\";\n const textColor = toCss(theme.text, 0.85);\n const placed = placeLabels(\n input.pointLabels,\n plot,\n (t) => ctx.measureText(t).width,\n labelHeight - 2,\n occupied,\n );\n for (const { label, box } of placed) {\n haloText(ctx, label.text, box.x, box.y + box.height / 2, textColor, halo);\n }\n }\n ctx.restore();\n};\n"],"mappings":";;AAqDA,IAAaA,KAAQ,GAAmB,IAAOC,EAAM,UAAU,IAAS,QACtE,GAAGC,EAAO,GAAGC,EAAK,KAAKF,EAAM,cAEzBG,KAAS,MAAc,KAAK,MAAMC,CAAC,IAAI,IAGhCC,KACX,GACA,GACA,GACA,MACS;CACT,IAAM,EAAE,YAASC,GACXC,IAAKC,EAAE,MAAM,KAAA,IAAYC,EAAK,IAAIA,EAAK,QAAQ,IAAIH,EAAE,MAAME,EAAE,CAAC,GAC9DE,IAAKF,EAAE,MAAM,KAAA,IAAYC,EAAK,IAAIA,EAAK,SAAS,IAAIH,EAAE,MAAME,EAAE,CAAC,GAEjEG,IAAIJ,IAAKK,IAAQ,GACjBC,IAAIH,IAAKI,IAAS;CAOtB,OANIN,EAAE,WAAW,QAAO,IAAIE,IAAK,IACxBF,EAAE,WAAW,WAAU,IAAIE,IAAK,IAAMI,IACtCN,EAAE,WAAW,SAAQ,IAAID,IAAK,IAC9BC,EAAE,WAAW,YAAS,IAAID,IAAK,IAAMK,IAC9C,IAAI,KAAK,IAAIH,EAAK,IAAI,GAAK,KAAK,IAAIE,GAAGF,EAAK,IAAIA,EAAK,QAAQ,IAAMG,CAAK,CAAC,GACzE,IAAI,KAAK,IAAIH,EAAK,IAAI,GAAG,KAAK,IAAII,GAAGJ,EAAK,IAAIA,EAAK,SAAS,IAAIK,CAAM,CAAC,GAChE;EAAE;EAAG;EAAG;EAAO;CAAO;AAC/B,GAEMC,KAAU,GAAiB,MAAoB;CACnD,IAAM,EAAE,YAAST,GACXU,IAAKR,EAAE,OAAO,KAAA,IAAY,YAAYF,EAAE,MAAME,EAAE,EAAE,GAClDS,IAAKT,EAAE,OAAO,KAAA,IAAY,WAAWF,EAAE,MAAME,EAAE,EAAE,GACjDU,IAAKV,EAAE,OAAO,KAAA,IAAY,WAAWF,EAAE,MAA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EAAMrB,EAAE,UAAU,GAClCmB,EAAI,SAASnB,EAAE,OAAOkD,GAAIC,CAAE,GAC5BN,EAAS,KAAK;GAAE,GAAGK;GAAI,GAAGC;GAAI,OAAOrB;GAAG,QAAQkB;EAAY,CAAC;CAC/D;CAGA,KAAK,IAAMhD,KAAKiB,EAAM,aAAa;EACjC,IAAIjB,EAAE,SAAS,UAAU,CAACA,EAAE,MAAM;EAClC,EAAI,OAAOT,EAAKC,GAAOA,EAAM,UAAUQ,EAAE,MAAM;EAC/C,IAAM2C,IAAM9C,EAAQG,GAAGkB,GAAQC,EAAI,YAAYnB,EAAE,IAAI,CAAC,CAAC,OAAOgD,CAAW;EAIzE,AAHA,EAAI,YAAY,QAChB,EAAI,eAAe,UACnBd,EAASf,GAAKnB,EAAE,MAAM2C,EAAI,GAAGA,EAAI,IAAIA,EAAI,SAAS,GAAGtB,EAAMrB,EAAE,KAAK,GAAGmC,CAAI,GACzEU,EAAS,KAAKF,CAAG;CACnB;CAGA,IAAI1B,EAAM,YAAY,QAAQ;EAG5B,AAFA,EAAI,OAAO1B,EAAKC,CAAK,GACrB,EAAI,YAAY,QAChB,EAAI,eAAe;EACnB,IAAM4D,IAAY/B,EAAM7B,EAAM,MAAM,GAAI,GAClC8C,IAASD,EACbpB,EAAM,aACNhB,IACC,MAAMkB,EAAI,YAAYkC,CAAC,CAAC,CAAC,OAC1BL,IAAc,GACdH,CACF;EACA,KAAK,IAAM,EAAE,UAAO,YAASP,GAC3B,EAASnB,GAAKoB,EAAM,MAAMI,EAAI,GAAGA,EAAI,IAAIA,EAAI,SAAS,GAAGS,GAAWjB,CAAI;CAE5E;CACA,EAAI,QAAQ;AACd"}
1
+ {"version":3,"file":"overlay.js","names":["font","theme","weight","size","crisp","v","textBox","s","px","a","plot","py","x","width","y","height","rectOf","xa","xb","ya","yb","left","right","top","bottom","drawBackground","input","scales","ctx","r","toCss","yTicks","xTicks","line","base","lastRight","order","i","b","w","text","overlaps","inside","haloText","halo","color","placeLabels","placed","label","labels","measure","gap","above","below","box","c","occupied","o","drawForeground","labelHeight","pos","tx","ty","textColor","t"],"sources":["../../../../charts/src/engine/overlay.ts"],"sourcesContent":["// Canvas2D layers around the data: background (areas, grid, axes, tick\n// labels) and foreground (reference lines, annotation and point labels).\n\nimport { toCss, type Rgba } from \"./color\";\nimport type { AxisTicks } from \"./axis\";\nimport type { Rect, Scales } from \"./layout\";\nimport type { AxisModel } from \"./model\";\nimport type { ChartTheme } from \"./theme\";\nimport type { ChartLabelPosition } from \"./types\";\n\nexport interface ResolvedRect {\n type: \"rect\";\n x0?: number;\n x1?: number;\n y0?: number;\n y1?: number;\n color: Rgba;\n opacity: number;\n label?: string;\n labelPosition: ChartLabelPosition;\n labelColor: Rgba;\n}\n\nexport interface ResolvedLine {\n type: \"line\";\n axis: \"x\" | \"y\";\n value: number;\n color: Rgba;\n width: number;\n dash: number[];\n label?: string;\n}\n\nexport interface ResolvedText {\n type: \"text\";\n x?: number;\n y?: number;\n text: string;\n anchor: \"center\" | \"top\" | \"bottom\" | \"left\" | \"right\";\n color: Rgba;\n weight: number;\n}\n\nexport type ResolvedAnnotation = ResolvedRect | ResolvedLine | ResolvedText;\n\nexport interface PointLabel {\n x: number;\n y: number;\n /** Radius of the dot */\n r: number;\n text: string;\n /** Fixed side (bar values); any free side around the dot otherwise */\n placement?: \"above\" | \"below\";\n}\n\nexport const font = (theme: ChartTheme, size = theme.fontSize, weight = 400) =>\n `${weight} ${size}px ${theme.fontFamily}`;\n\nconst crisp = (v: number) => Math.round(v) + 0.5;\n\n/** Box of a text annotation, kept inside the plot */\nexport const textBox = (\n a: ResolvedText,\n s: Scales,\n width: number,\n height: number,\n): Rect => {\n const { plot } = s;\n const px = a.x === undefined ? plot.x + plot.width / 2 : s.xToPx(a.x);\n const py = a.y === undefined ? plot.y + plot.height / 2 : s.yToPx(a.y);\n const gap = 6;\n let x = px - width / 2;\n let y = py - height / 2;\n if (a.anchor === \"top\") y = py + gap;\n else if (a.anchor === \"bottom\") y = py - gap - height;\n else if (a.anchor === \"left\") x = px + gap;\n else if (a.anchor === \"right\") x = px - gap - width;\n x = Math.max(plot.x + gap, Math.min(x, plot.x + plot.width - gap - width));\n y = Math.max(plot.y + 2, Math.min(y, plot.y + plot.height - 2 - height));\n return { x, y, width, height };\n};\n\nconst rectOf = (a: ResolvedRect, s: Scales): Rect => {\n const { plot } = s;\n const xa = a.x0 === undefined ? -Infinity : s.xToPx(a.x0);\n const xb = a.x1 === undefined ? Infinity : s.xToPx(a.x1);\n const ya = a.y0 === undefined ? Infinity : s.yToPx(a.y0);\n const yb = a.y1 === undefined ? -Infinity : s.yToPx(a.y1);\n const left = Math.max(plot.x, Math.min(xa, xb));\n const right = Math.min(plot.x + plot.width, Math.max(xa, xb));\n const top = Math.max(plot.y, Math.min(ya, yb));\n const bottom = Math.min(plot.y + plot.height, Math.max(ya, yb));\n return { x: left, y: top, width: right - left, height: bottom - top };\n};\n\nexport interface BackgroundInput {\n width: number;\n height: number;\n scales: Scales;\n x: AxisModel;\n y: AxisModel;\n xTicks: AxisTicks;\n yTicks: AxisTicks;\n theme: ChartTheme;\n annotations: readonly ResolvedAnnotation[];\n}\n\nexport const drawBackground = (\n ctx: CanvasRenderingContext2D,\n input: BackgroundInput,\n) => {\n const { scales, theme, x, y, xTicks, yTicks } = input;\n const { plot } = scales;\n ctx.clearRect(0, 0, input.width, input.height);\n\n // areas\n ctx.save();\n ctx.beginPath();\n ctx.rect(plot.x, plot.y, plot.width, plot.height);\n ctx.clip();\n for (const a of input.annotations) {\n if (a.type !== \"rect\") continue;\n const r = rectOf(a, scales);\n if (r.width <= 0 || r.height <= 0) continue;\n ctx.fillStyle = toCss(a.color, a.opacity);\n ctx.fillRect(r.x, r.y, r.width, r.height);\n }\n ctx.restore();\n\n // grid\n ctx.lineWidth = 1;\n ctx.strokeStyle = toCss(theme.grid);\n ctx.beginPath();\n if (y.grid) {\n for (const v of yTicks.values) {\n const py = crisp(scales.yToPx(v));\n if (py < plot.y - 1 || py > plot.y + plot.height + 1) continue;\n ctx.moveTo(plot.x, py);\n ctx.lineTo(plot.x + plot.width, py);\n }\n }\n if (x.grid) {\n for (const v of xTicks.values) {\n const px = crisp(scales.xToPx(v));\n if (px < plot.x - 1 || px > plot.x + plot.width + 1) continue;\n ctx.moveTo(px, plot.y);\n ctx.lineTo(px, plot.y + plot.height);\n }\n }\n ctx.stroke();\n\n const line = Math.ceil(theme.fontSize * 1.4);\n ctx.font = font(theme);\n ctx.fillStyle = toCss(theme.textMuted);\n\n // x axis\n if (x.visible) {\n ctx.strokeStyle = toCss(theme.axis);\n ctx.beginPath();\n const base = crisp(plot.y + plot.height);\n ctx.moveTo(plot.x, base);\n ctx.lineTo(plot.x + plot.width, base);\n ctx.stroke();\n ctx.textBaseline = \"top\";\n ctx.textAlign = \"center\";\n let lastRight = -Infinity;\n // left to right (reversed axes list their ticks right to left)\n const order = xTicks.values\n .map((v, i) => ({ px: scales.xToPx(v), text: xTicks.labels[i] }))\n .sort((a, b) => a.px - b.px);\n for (const { px, text } of order) {\n if (px < plot.x - 0.5 || px > plot.x + plot.width + 0.5) continue;\n const w = ctx.measureText(text).width;\n const left = Math.max(0, Math.min(input.width - w, px - w / 2));\n if (left < lastRight + 6) continue;\n lastRight = left + w;\n ctx.fillText(text, left + w / 2, plot.y + plot.height + 7);\n }\n if (x.title) {\n ctx.font = font(theme, theme.fontSize + 1, 500);\n ctx.fillStyle = toCss(theme.text, 0.8);\n ctx.fillText(\n x.title,\n plot.x + plot.width / 2,\n plot.y + plot.height + line + 10,\n );\n }\n }\n\n // y axis\n if (y.visible) {\n ctx.font = font(theme);\n ctx.fillStyle = toCss(theme.textMuted);\n ctx.textAlign = \"right\";\n ctx.textBaseline = \"middle\";\n yTicks.values.forEach((v, i) => {\n const py = scales.yToPx(v);\n if (py < plot.y - 0.5 || py > plot.y + plot.height + 0.5) return;\n ctx.fillText(yTicks.labels[i], plot.x - 8, py);\n });\n if (y.title) {\n ctx.save();\n ctx.font = font(theme, theme.fontSize + 1, 500);\n ctx.fillStyle = toCss(theme.text, 0.8);\n ctx.translate(line / 2 + 4, plot.y + plot.height / 2);\n ctx.rotate(-Math.PI / 2);\n ctx.textAlign = \"center\";\n ctx.fillText(y.title, 0, 0);\n ctx.restore();\n }\n }\n};\n\nconst overlaps = (a: Rect, b: Rect) =>\n a.x < b.x + b.width &&\n b.x < a.x + a.width &&\n a.y < b.y + b.height &&\n b.y < a.y + a.height;\n\nconst inside = (r: Rect, plot: Rect) =>\n r.x >= plot.x &&\n r.y >= plot.y &&\n r.x + r.width <= plot.x + plot.width &&\n r.y + r.height <= plot.y + plot.height;\n\n/** Text with a halo in the background color (readable over data) */\nconst haloText = (\n ctx: CanvasRenderingContext2D,\n text: string,\n x: number,\n y: number,\n color: string,\n halo: string,\n) => {\n ctx.lineWidth = 3;\n ctx.lineJoin = \"round\";\n ctx.strokeStyle = halo;\n ctx.strokeText(text, x, y);\n ctx.fillStyle = color;\n ctx.fillText(text, x, y);\n};\n\n/** Greedy placement: right, left, above, below the dot; skipped when no slot is free */\nexport const placeLabels = (\n labels: readonly PointLabel[],\n plot: Rect,\n measure: (text: string) => number,\n height: number,\n occupied: Rect[] = [],\n): { label: PointLabel; box: Rect }[] => {\n const placed: { label: PointLabel; box: Rect }[] = [];\n for (const label of labels) {\n const w = measure(label.text);\n const gap = label.r + 4;\n const above = {\n x: label.x - w / 2,\n y: label.y - gap - height,\n width: w,\n height,\n };\n const below = { x: label.x - w / 2, y: label.y + gap, width: w, height };\n const candidates: Rect[] =\n label.placement === \"above\"\n ? [above]\n : label.placement === \"below\"\n ? [below]\n : [\n { x: label.x + gap, y: label.y - height / 2, width: w, height },\n {\n x: label.x - gap - w,\n y: label.y - height / 2,\n width: w,\n height,\n },\n above,\n below,\n ];\n const box = candidates.find(\n (c) => inside(c, plot) && !occupied.some((o) => overlaps(o, c)),\n );\n if (!box) continue;\n occupied.push(box);\n placed.push({ label, box });\n }\n return placed;\n};\n\nexport interface ForegroundInput {\n width: number;\n height: number;\n scales: Scales;\n theme: ChartTheme;\n annotations: readonly ResolvedAnnotation[];\n pointLabels: readonly PointLabel[];\n /**\n * Clears the canvas first (off when the layers share one canvas)\n * @default true\n */\n clear?: boolean;\n}\n\nexport const drawForeground = (\n ctx: CanvasRenderingContext2D,\n input: ForegroundInput,\n) => {\n const { scales, theme } = input;\n const { plot } = scales;\n if (input.clear !== false) ctx.clearRect(0, 0, input.width, input.height);\n ctx.save();\n ctx.beginPath();\n ctx.rect(plot.x, plot.y, plot.width, plot.height);\n ctx.clip();\n\n const halo = toCss(theme.background, 0.9);\n const occupied: Rect[] = [];\n const labelHeight = theme.fontSize + 4;\n\n for (const a of input.annotations) {\n if (a.type !== \"line\") continue;\n const color = toCss(a.color);\n ctx.strokeStyle = color;\n ctx.lineWidth = a.width;\n ctx.setLineDash(a.dash);\n ctx.beginPath();\n if (a.axis === \"y\") {\n const py = crisp(scales.yToPx(a.value));\n ctx.moveTo(plot.x, py);\n ctx.lineTo(plot.x + plot.width, py);\n ctx.stroke();\n if (a.label) {\n ctx.setLineDash([]);\n ctx.font = font(theme, theme.fontSize, 500);\n ctx.textAlign = \"right\";\n ctx.textBaseline = \"bottom\";\n haloText(ctx, a.label, plot.x + plot.width - 6, py - 3, color, halo);\n }\n } else {\n const px = crisp(scales.xToPx(a.value));\n ctx.moveTo(px, plot.y);\n ctx.lineTo(px, plot.y + plot.height);\n ctx.stroke();\n if (a.label) {\n ctx.setLineDash([]);\n ctx.font = font(theme, theme.fontSize, 500);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"top\";\n haloText(ctx, a.label, px + 5, plot.y + 5, color, halo);\n }\n }\n }\n ctx.setLineDash([]);\n\n // labels of areas\n ctx.font = font(theme, theme.fontSize + 1, 600);\n for (const a of input.annotations) {\n if (a.type !== \"rect\" || !a.label) continue;\n const r = rectOf(a, scales);\n if (r.width <= 0 || r.height <= 0) continue;\n const pad = 10;\n const w = ctx.measureText(a.label).width;\n const pos = a.labelPosition;\n const tx = pos.endsWith(\"left\")\n ? r.x + pad\n : pos.endsWith(\"right\")\n ? r.x + r.width - pad - w\n : r.x + (r.width - w) / 2;\n const ty = pos.startsWith(\"top\")\n ? r.y + pad\n : pos.startsWith(\"bottom\")\n ? r.y + r.height - pad - labelHeight\n : r.y + (r.height - labelHeight) / 2;\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"top\";\n ctx.fillStyle = toCss(a.labelColor);\n ctx.fillText(a.label, tx, ty);\n occupied.push({ x: tx, y: ty, width: w, height: labelHeight });\n }\n\n // free texts\n for (const a of input.annotations) {\n if (a.type !== \"text\" || !a.text) continue;\n ctx.font = font(theme, theme.fontSize, a.weight);\n const box = textBox(a, scales, ctx.measureText(a.text).width, labelHeight);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"middle\";\n haloText(ctx, a.text, box.x, box.y + box.height / 2, toCss(a.color), halo);\n occupied.push(box);\n }\n\n // point labels\n if (input.pointLabels.length) {\n ctx.font = font(theme);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"middle\";\n const textColor = toCss(theme.text, 0.85);\n const placed = placeLabels(\n input.pointLabels,\n plot,\n (t) => ctx.measureText(t).width,\n labelHeight - 2,\n occupied,\n );\n for (const { label, box } of placed) {\n haloText(ctx, label.text, box.x, box.y + box.height / 2, textColor, halo);\n }\n }\n ctx.restore();\n};\n"],"mappings":";;AAuDA,IAAaA,KAAQ,GAAmB,IAAOC,EAAM,UAAU,IAAS,QACtE,GAAGC,EAAO,GAAGC,EAAK,KAAKF,EAAM,cAEzBG,KAAS,MAAc,KAAK,MAAMC,CAAC,IAAI,IAGhCC,KACX,GACA,GACA,GACA,MACS;CACT,IAAM,EAAE,YAASC,GACXC,IAAKC,EAAE,MAAM,KAAA,IAAYC,EAAK,IAAIA,EAAK,QAAQ,IAAIH,EAAE,MAAME,EAAE,CAAC,GAC9DE,IAAKF,EAAE,MAAM,KAAA,IAAYC,EAAK,IAAIA,EAAK,SAAS,IAAIH,EAAE,M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E,IAAI,CAAC,CAAC,OAAOkD,CAAW;EAIzE,AAHA,EAAI,YAAY,QAChB,EAAI,eAAe,UACnBhB,EAASf,GAAKnB,EAAE,MAAM6C,EAAI,GAAGA,EAAI,IAAIA,EAAI,SAAS,GAAGxB,EAAMrB,EAAE,KAAK,GAAGmC,CAAI,GACzEY,EAAS,KAAKF,CAAG;CACnB;CAGA,IAAI5B,EAAM,YAAY,QAAQ;EAG5B,AAFA,EAAI,OAAO1B,EAAKC,CAAK,GACrB,EAAI,YAAY,QAChB,EAAI,eAAe;EACnB,IAAM8D,IAAYjC,EAAM7B,EAAM,MAAM,GAAI,GAClC8C,IAASD,EACbpB,EAAM,aACNhB,IACC,MAAMkB,EAAI,YAAYoC,CAAC,CAAC,CAAC,OAC1BL,IAAc,GACdH,CACF;EACA,KAAK,IAAM,EAAE,UAAO,YAAST,GAC3B,EAASnB,GAAKoB,EAAM,MAAMM,EAAI,GAAGA,EAAI,IAAIA,EAAI,SAAS,GAAGS,GAAWnB,CAAI;CAE5E;CACA,EAAI,QAAQ;AACd"}
@@ -1,3 +1,3 @@
1
- var e=(e,t,n)=>e.map(e=>({...e,type:e.type??t,...n!==void 0&&(e.type??t)===`bar`?{stack:e.stack??n}:{}})),t=(t,n=!1)=>e(t,n?`area`:`line`),n=(t,n=!1)=>e(t,`bar`,n?`stack`:void 0),r=t=>e(t,`scatter`),i={topLeft:`var(--danger-color, #ef4444)`,topRight:`var(--primary-color, #4f46e5)`,bottomLeft:`var(--warning-color, #f59e0b)`,bottomRight:`var(--text-secondary-color, #64748b)`},a=`var(--border-strong-color, var(--border-color, #cbd5e1))`,o=e=>{let[t,n]=e.xDomain??[0,10],[r,i]=e.yDomain??[0,10];return{x0:t,x1:n,y0:r,y1:i,xs:e.xSplit??(t+n)/2,ys:e.ySplit??(r+i)/2}},s=(e,t,n)=>{let{xs:r,ys:i}=o(e),a=e.reverseX?t<r:t>=r;return n>=i?a?`topRight`:`topLeft`:a?`bottomRight`:`bottomLeft`},c=(e,t)=>{let{x0:n,x1:r,y0:i,y1:a,xs:s,ys:c}=o(e),l=t.endsWith(`Right`);return{x:(e.reverseX?!l:l)?(s+r)/2:(n+s)/2,y:t.startsWith(`top`)?(c+a)/2:(i+c)/2}},l=(e,t={})=>{let{x0:n,x1:r,y0:c,y1:l,xs:u,ys:d}=o(e),f=!!e.reverseX,p=t=>e.quadrants?.[t]?.color??i[t],m=[{type:`scatter`,name:e.name??``,pointSize:e.pointSize??12,showLabels:e.showLabels??!0,opacity:.9,data:e.points.map(t=>({x:t.x,y:t.y,label:t.label,size:t.size,color:t.color??p(s(e,t.x,t.y))}))}],h=f?[u,r]:[n,u],g=f?[n,u]:[u,r],_=(t,[n,r],[i,a],o)=>({type:`rect`,x0:n,x1:r,y0:i,y1:a,color:p(t),opacity:.07,label:e.quadrants?.[t]?.label,labelPosition:o}),v=e.axisLabels??{},y=f?r:n,b=f?n:r,x=[...v.top?[{type:`text`,x:u,y:l,text:v.top,anchor:`top`}]:[],...v.bottom?[{type:`text`,x:u,y:c,text:v.bottom,anchor:`bottom`}]:[],...v.left?[{type:`text`,x:y,y:d,text:v.left,anchor:`left`}]:[],...v.right?[{type:`text`,x:b,y:d,text:v.right,anchor:`right`}]:[]],S=[_(`topLeft`,h,[d,l],`top-left`),_(`topRight`,g,[d,l],`top-right`),_(`bottomLeft`,h,[c,d],`bottom-left`),_(`bottomRight`,g,[c,d],`bottom-right`),{type:`line`,axis:`x`,value:u,dash:[],color:a},{type:`line`,axis:`y`,value:d,dash:[],color:a},...x,...t.annotations??[]],C=e.showTicks??!0,w=t.interaction!==!1&&{zoom:!1,...typeof t.interaction==`object`?t.interaction:{},...e.draggable?{dragPoints:!0}:{}};return{...t,series:m,annotations:S,tooltip:t.tooltip??(C?void 0:{render:t=>{let n=t.items[0];if(!n)return null;let r=e.quadrants?.[s(e,n.x,n.y)]?.label;return[n.label??e.name??``,r??``].filter(Boolean).join(`
2
- `)}}),xAxis:{min:n,max:r,title:e.xLabel,reverse:f,nice:!1,grid:!1,tickCount:4,visible:C||!!e.xLabel,...C?{}:{format:()=>``}},yAxis:{min:c,max:l,title:e.yLabel,nice:!1,grid:!1,tickCount:4,visible:C||!!e.yLabel,...C?{}:{format:()=>``}},legend:t.legend??!1,padding:t.padding??(C?void 0:{top:4,right:4,bottom:4,left:4}),interaction:w}};exports.DEFAULT_QUADRANT_COLORS=i,exports.barSeries=n,exports.lineSeries=t,exports.quadrantCenter=c,exports.quadrantChartOptions=l,exports.quadrantOf=s,exports.scatterSeries=r,exports.withSeriesType=e;
1
+ var e=(e,t,n,r)=>e.map(e=>{let i=e.type??t;return{...e,type:i,...n!==void 0&&i===t?{stack:e.stack??n}:{},...r!==void 0&&(i===`line`||i===`area`)?{curve:e.curve??r}:{}}}),t=(t,n=!1,r={})=>e(t,n?`area`:`line`,r.stacked?`stack`:void 0,r.curve),n=(e,n={})=>t(e,!0,n),r=(t,n=!1,r=!1)=>e(t,`bar`,n?`stack`:void 0).map(e=>r&&e.type===`bar`?{...e,showLabels:e.showLabels??!0}:e),i=t=>e(t,`scatter`),a=t=>e(t,`candlestick`),o=(e,t={})=>{let n=e.data.some(e=>typeof e.x==`number`),r=e.data.some(e=>typeof e.y==`number`);return{...t,series:[{id:`heatmap`,name:e.name??`Value`,type:`heatmap`,data:e.data.map(e=>({x:e.x,y:e.y,value:e.value})),colorScale:e.colorScale,valueRange:e.valueRange,radius:e.radius,format:e.format}],xAxis:{...n?{}:{type:`category`,categories:e.xCategories},grid:!1,...t.xAxis},yAxis:{...r?{}:{type:`category`,categories:e.yCategories},grid:!1,...t.yAxis},legend:t.legend??!1,interaction:t.interaction??{zoom:!1},tooltip:t.tooltip??{mode:`nearest`}}},s=(e,t={})=>{let n=e.type??`line`;return{...t,series:[{id:`sparkline`,name:e.name??`Value`,type:n,data:e.data,color:e.color,curve:n===`bar`?void 0:e.curve??`smooth`,lineWidth:1.5,opacity:n===`area`?.22:void 0,radius:n===`bar`?1.5:void 0,format:e.format}],xAxis:{visible:!1,grid:!1,...t.xAxis},yAxis:{visible:!1,grid:!1,nice:!1,...t.yAxis},legend:!1,padding:t.padding??{top:4,right:4,bottom:4,left:4},interaction:t.interaction??{zoom:!1},annotations:e.reference===void 0?t.annotations:[...t.annotations??[],{type:`line`,axis:`y`,value:e.reference,dash:[2,3]}]}},c={topLeft:`var(--danger-color, #ef4444)`,topRight:`var(--primary-color, #4f46e5)`,bottomLeft:`var(--warning-color, #f59e0b)`,bottomRight:`var(--text-secondary-color, #64748b)`},l=`var(--border-strong-color, var(--border-color, #cbd5e1))`,u=e=>{let[t,n]=e.xDomain??[0,10],[r,i]=e.yDomain??[0,10];return{x0:t,x1:n,y0:r,y1:i,xs:e.xSplit??(t+n)/2,ys:e.ySplit??(r+i)/2}},d=(e,t,n)=>{let{xs:r,ys:i}=u(e),a=e.reverseX?t<r:t>=r;return n>=i?a?`topRight`:`topLeft`:a?`bottomRight`:`bottomLeft`},f=(e,t)=>{let{x0:n,x1:r,y0:i,y1:a,xs:o,ys:s}=u(e),c=t.endsWith(`Right`);return{x:(e.reverseX?!c:c)?(o+r)/2:(n+o)/2,y:t.startsWith(`top`)?(s+a)/2:(i+s)/2}},p=(e,t={})=>{let{x0:n,x1:r,y0:i,y1:a,xs:o,ys:s}=u(e),f=!!e.reverseX,p=t=>e.quadrants?.[t]?.color??c[t],m=[{type:`scatter`,name:e.name??``,pointSize:e.pointSize??12,showLabels:e.showLabels??!0,opacity:.9,data:e.points.map(t=>({x:t.x,y:t.y,label:t.label,size:t.size,color:t.color??p(d(e,t.x,t.y))}))}],h=f?[o,r]:[n,o],g=f?[n,o]:[o,r],_=(t,[n,r],[i,a],o)=>({type:`rect`,x0:n,x1:r,y0:i,y1:a,color:p(t),opacity:.07,label:e.quadrants?.[t]?.label,labelPosition:o}),v=e.axisLabels??{},y=f?r:n,b=f?n:r,x=[...v.top?[{type:`text`,x:o,y:a,text:v.top,anchor:`top`}]:[],...v.bottom?[{type:`text`,x:o,y:i,text:v.bottom,anchor:`bottom`}]:[],...v.left?[{type:`text`,x:y,y:s,text:v.left,anchor:`left`}]:[],...v.right?[{type:`text`,x:b,y:s,text:v.right,anchor:`right`}]:[]],S=[_(`topLeft`,h,[s,a],`top-left`),_(`topRight`,g,[s,a],`top-right`),_(`bottomLeft`,h,[i,s],`bottom-left`),_(`bottomRight`,g,[i,s],`bottom-right`),{type:`line`,axis:`x`,value:o,dash:[],color:l},{type:`line`,axis:`y`,value:s,dash:[],color:l},...x,...t.annotations??[]],C=e.showTicks??!0,w=t.interaction!==!1&&{zoom:!1,...typeof t.interaction==`object`?t.interaction:{},...e.draggable?{dragPoints:!0}:{}};return{...t,series:m,annotations:S,tooltip:t.tooltip??(C?void 0:{render:t=>{let n=t.items[0];if(!n)return null;let r=e.quadrants?.[d(e,n.x,n.y)]?.label;return[n.label??e.name??``,r??``].filter(Boolean).join(`
2
+ `)}}),xAxis:{min:n,max:r,title:e.xLabel,reverse:f,nice:!1,grid:!1,tickCount:4,visible:C||!!e.xLabel,...C?{}:{format:()=>``}},yAxis:{min:i,max:a,title:e.yLabel,nice:!1,grid:!1,tickCount:4,visible:C||!!e.yLabel,...C?{}:{format:()=>``}},legend:t.legend??!1,padding:t.padding??(C?void 0:{top:4,right:4,bottom:4,left:4}),interaction:w}};exports.DEFAULT_QUADRANT_COLORS=c,exports.areaSeries=n,exports.barSeries=r,exports.candlestickSeries=a,exports.heatmapChartOptions=o,exports.lineSeries=t,exports.quadrantCenter=f,exports.quadrantChartOptions=p,exports.quadrantOf=d,exports.scatterSeries=i,exports.sparklineOptions=s,exports.withSeriesType=e;
3
3
  //# sourceMappingURL=presets.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"presets.cjs","names":["withSeriesType","series","s","type","stack","lineSeries","area","barSeries","stacked","scatterSeries","DEFAULT_QUADRANT_COLORS","DIVIDER","splits","x0","x1","config","y0","y1","quadrantOf","right","x","xs","y","ys","quadrantCenter","visualRight","corner","quadrantChartOptions","reverseX","color","p","left","rect","xa","xb","ya","yb","position","ends","visualLeft","texts","annotations","base","showTicks","interaction","item","event","region"],"sources":["../../../../charts/src/engine/presets.ts"],"sourcesContent":["// Option presets of the chart components, shared by every platform (React,\n// mini-programs, React Native): they turn component props into engine\n// options.\n\nimport type {\n ChartAnnotation,\n ChartInteractionOptions,\n ChartOptions,\n ChartSeries,\n ChartSeriesType,\n} from \"./types\";\n\n/** Gives the series without a `type` the type of the component */\nexport const withSeriesType = (\n series: readonly ChartSeries[],\n type: ChartSeriesType,\n stack?: string,\n): ChartSeries[] =>\n series.map((s) => ({\n ...s,\n type: s.type ?? type,\n ...(stack !== undefined && (s.type ?? type) === \"bar\"\n ? { stack: s.stack ?? stack }\n : {}),\n }));\n\n/** Series of a LineChart (`area` fills them) */\nexport const lineSeries = (series: readonly ChartSeries[], area = false) =>\n withSeriesType(series, area ? \"area\" : \"line\");\n\n/** Series of a BarChart (`stacked` stacks them) */\nexport const barSeries = (series: readonly ChartSeries[], stacked = false) =>\n withSeriesType(series, \"bar\", stacked ? \"stack\" : undefined);\n\n/** Series of a ScatterChart */\nexport const scatterSeries = (series: readonly ChartSeries[]) =>\n withSeriesType(series, \"scatter\");\n\n/** A point of a QuadrantChart */\nexport interface QuadrantPoint {\n /** Position on the horizontal axis */\n x: number;\n /** Position on the vertical axis */\n y: number;\n /** Text drawn next to the dot and shown in the tooltip */\n label?: string;\n /** Dot color (any CSS color); the color of its quadrant by default */\n color?: string;\n /** Dot diameter in pixels */\n size?: number;\n}\n\n/** Title and color of a quadrant */\nexport interface QuadrantRegion {\n /** Title drawn in the outer corner of the quadrant */\n label?: string;\n /** Background tint and default dot color (any CSS color) */\n color?: string;\n}\n\n/** The four quadrants of a QuadrantChart */\nexport interface QuadrantRegions {\n topLeft?: QuadrantRegion;\n topRight?: QuadrantRegion;\n bottomLeft?: QuadrantRegion;\n bottomRight?: QuadrantRegion;\n}\n\n/** A quadrant, as seen on screen */\nexport type QuadrantCorner = keyof QuadrantRegions;\n\n/** Texts at the four ends of the dividers, inside the plot */\nexport interface QuadrantAxisLabels {\n top?: string;\n bottom?: string;\n left?: string;\n right?: string;\n}\n\n/** Settings of a quadrant matrix (the props of QuadrantChart) */\nexport interface QuadrantConfig {\n /** Points to place */\n points: readonly QuadrantPoint[];\n /**\n * Range of the horizontal axis\n * @default [0, 10]\n */\n xDomain?: [number, number];\n /**\n * Range of the vertical axis\n * @default [0, 10]\n */\n yDomain?: [number, number];\n /** X value of the vertical divider (the middle of `xDomain` by default) */\n xSplit?: number;\n /** Y value of the horizontal divider (the middle of `yDomain` by default) */\n ySplit?: number;\n /** Titles and colors of the quadrants */\n quadrants?: QuadrantRegions;\n /** Title of the horizontal axis */\n xLabel?: string;\n /** Title of the vertical axis */\n yLabel?: string;\n /** Texts at the ends of the dividers, drawn inside the plot (e.g. \"Important\" at the top) */\n axisLabels?: QuadrantAxisLabels;\n /**\n * Shows the numeric ticks of the axes; `false` keeps only the matrix\n * @default true\n */\n showTicks?: boolean;\n /** Reverses the horizontal axis (e.g. \"urgent\" on the left) */\n reverseX?: boolean;\n /**\n * Draws the labels next to the dots (overlapping labels are skipped)\n * @default true\n */\n showLabels?: boolean;\n /**\n * Dot diameter in pixels\n * @default 12\n */\n pointSize?: number;\n /** Name of the points in the tooltip */\n name?: string;\n /** Lets the user drag the dots (`drag` / `drop` events) */\n draggable?: boolean;\n}\n\nexport const DEFAULT_QUADRANT_COLORS: Required<Record<QuadrantCorner, string>> =\n {\n topLeft: \"var(--danger-color, #ef4444)\",\n topRight: \"var(--primary-color, #4f46e5)\",\n bottomLeft: \"var(--warning-color, #f59e0b)\",\n bottomRight: \"var(--text-secondary-color, #64748b)\",\n };\n\nconst DIVIDER = \"var(--border-strong-color, var(--border-color, #cbd5e1))\";\n\nconst splits = (config: QuadrantConfig) => {\n const [x0, x1] = config.xDomain ?? [0, 10];\n const [y0, y1] = config.yDomain ?? [0, 10];\n return {\n x0,\n x1,\n y0,\n y1,\n xs: config.xSplit ?? (x0 + x1) / 2,\n ys: config.ySplit ?? (y0 + y1) / 2,\n };\n};\n\n/** Quadrant of a data position, as seen on screen */\nexport const quadrantOf = (\n config: Pick<\n QuadrantConfig,\n \"xDomain\" | \"yDomain\" | \"xSplit\" | \"ySplit\" | \"reverseX\"\n >,\n x: number,\n y: number,\n): QuadrantCorner => {\n const { xs, ys } = splits(config as QuadrantConfig);\n const right = config.reverseX ? x < xs : x >= xs;\n const top = y >= ys;\n return top\n ? right\n ? \"topRight\"\n : \"topLeft\"\n : right\n ? \"bottomRight\"\n : \"bottomLeft\";\n};\n\n/** Center of a quadrant in data coordinates */\nexport const quadrantCenter = (\n config: Pick<\n QuadrantConfig,\n \"xDomain\" | \"yDomain\" | \"xSplit\" | \"ySplit\" | \"reverseX\"\n >,\n corner: QuadrantCorner,\n): { x: number; y: number } => {\n const { x0, x1, y0, y1, xs, ys } = splits(config as QuadrantConfig);\n const visualRight = corner.endsWith(\"Right\");\n const dataHigh = config.reverseX ? !visualRight : visualRight;\n return {\n x: dataHigh ? (xs + x1) / 2 : (x0 + xs) / 2,\n y: corner.startsWith(\"top\") ? (ys + y1) / 2 : (y0 + ys) / 2,\n };\n};\n\n/** Engine options of a quadrant matrix */\nexport const quadrantChartOptions = (\n config: QuadrantConfig,\n base: Omit<ChartOptions, \"series\"> = {},\n): ChartOptions => {\n const { x0, x1, y0, y1, xs, ys } = splits(config);\n const reverseX = !!config.reverseX;\n const color = (corner: QuadrantCorner) =>\n config.quadrants?.[corner]?.color ?? DEFAULT_QUADRANT_COLORS[corner];\n\n const series: ChartSeries[] = [\n {\n type: \"scatter\",\n name: config.name ?? \"\",\n pointSize: config.pointSize ?? 12,\n showLabels: config.showLabels ?? true,\n opacity: 0.9,\n data: config.points.map((p) => ({\n x: p.x,\n y: p.y,\n label: p.label,\n size: p.size,\n color: p.color ?? color(quadrantOf(config, p.x, p.y)),\n })),\n },\n ];\n\n // visual left / right -> data ranges\n const left: [number, number] = reverseX ? [xs, x1] : [x0, xs];\n const right: [number, number] = reverseX ? [x0, xs] : [xs, x1];\n const rect = (\n corner: QuadrantCorner,\n [xa, xb]: [number, number],\n [ya, yb]: [number, number],\n position: \"top-left\" | \"top-right\" | \"bottom-left\" | \"bottom-right\",\n ): ChartAnnotation => ({\n type: \"rect\",\n x0: xa,\n x1: xb,\n y0: ya,\n y1: yb,\n color: color(corner),\n opacity: 0.07,\n label: config.quadrants?.[corner]?.label,\n labelPosition: position,\n });\n const ends = config.axisLabels ?? {};\n const visualLeft = reverseX ? x1 : x0;\n const visualRight = reverseX ? x0 : x1;\n const texts: ChartAnnotation[] = [\n ...(ends.top\n ? [{ type: \"text\", x: xs, y: y1, text: ends.top, anchor: \"top\" } as const]\n : []),\n ...(ends.bottom\n ? [\n {\n type: \"text\",\n x: xs,\n y: y0,\n text: ends.bottom,\n anchor: \"bottom\",\n } as const,\n ]\n : []),\n ...(ends.left\n ? [\n {\n type: \"text\",\n x: visualLeft,\n y: ys,\n text: ends.left,\n anchor: \"left\",\n } as const,\n ]\n : []),\n ...(ends.right\n ? [\n {\n type: \"text\",\n x: visualRight,\n y: ys,\n text: ends.right,\n anchor: \"right\",\n } as const,\n ]\n : []),\n ];\n\n const annotations: ChartAnnotation[] = [\n rect(\"topLeft\", left, [ys, y1], \"top-left\"),\n rect(\"topRight\", right, [ys, y1], \"top-right\"),\n rect(\"bottomLeft\", left, [y0, ys], \"bottom-left\"),\n rect(\"bottomRight\", right, [y0, ys], \"bottom-right\"),\n { type: \"line\", axis: \"x\", value: xs, dash: [], color: DIVIDER },\n { type: \"line\", axis: \"y\", value: ys, dash: [], color: DIVIDER },\n ...texts,\n ...(base.annotations ?? []),\n ];\n\n const showTicks = config.showTicks ?? true;\n const interaction: boolean | ChartInteractionOptions =\n base.interaction === false\n ? false\n : {\n zoom: false,\n ...(typeof base.interaction === \"object\" ? base.interaction : {}),\n ...(config.draggable ? { dragPoints: true } : {}),\n };\n\n return {\n ...base,\n series,\n annotations,\n tooltip:\n base.tooltip ??\n (showTicks\n ? undefined\n : {\n render: (event) => {\n const item = event.items[0];\n if (!item) return null;\n const region =\n config.quadrants?.[quadrantOf(config, item.x, item.y)]?.label;\n return [item.label ?? config.name ?? \"\", region ?? \"\"]\n .filter(Boolean)\n .join(\"\\n\");\n },\n }),\n xAxis: {\n min: x0,\n max: x1,\n title: config.xLabel,\n reverse: reverseX,\n nice: false,\n grid: false,\n tickCount: 4,\n visible: showTicks || !!config.xLabel,\n ...(showTicks ? {} : { format: () => \"\" }),\n },\n yAxis: {\n min: y0,\n max: y1,\n title: config.yLabel,\n nice: false,\n grid: false,\n tickCount: 4,\n visible: showTicks || !!config.yLabel,\n ...(showTicks ? {} : { format: () => \"\" }),\n },\n legend: base.legend ?? false,\n padding:\n base.padding ??\n (showTicks ? undefined : { top: 4, right: 4, bottom: 4, left: 4 }),\n interaction,\n };\n};\n"],"mappings":"AAaA,IAAaA,GACX,EACA,EACA,IAEAC,EAAO,IAAK,IAAO,CACjB,GAAGC,EACH,KAAMA,EAAE,MAAQC,EAChB,GAAIC,IAAU,IAAA,KAAcF,EAAE,MAAQC,KAAU,MAC5C,CAAE,MAAOD,EAAE,OAASE,CAAM,EAC1B,CAAC,CACP,EAAE,EAGSC,GAAc,EAAgC,EAAO,KAChEL,EAAeC,EAAQK,EAAO,OAAS,MAAM,EAGlCC,GAAa,EAAgC,EAAU,KAClEP,EAAeC,EAAQ,MAAOO,EAAU,QAAU,IAAA,EAAS,EAGhDC,EAAiB,GAC5BT,EAAeC,EAAQ,SAAS,EA4FrBS,EACX,CACE,QAAS,+BACT,SAAU,gCACV,WAAY,gCACZ,YAAa,sCACf,EAEIC,EAAU,2DAEVC,EAAU,GAA2B,CACzC,GAAM,CAACC,EAAIC,GAAMC,EAAO,SAAW,CAAC,EAAG,EAAE,EACnC,CAACC,EAAIC,GAAMF,EAAO,SAAW,CAAC,EAAG,EAAE,EACzC,MAAO,CACL,KACA,KACA,KACA,KACA,GAAIA,EAAO,SAAWF,EAAKC,GAAM,EACjC,GAAIC,EAAO,SAAW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,CAC3B,EAEMC,EAAY5B,EAAO,WAAa,GAChC6B,EACJF,EAAK,cAAgB,IAEjB,CACE,KAAM,GACN,GAAI,OAAOA,EAAK,aAAgB,SAAWA,EAAK,YAAc,CAAC,EAC/D,GAAI3B,EAAO,UAAY,CAAE,WAAY,EAAK,EAAI,CAAC,CACjD,EAEN,MAAO,CACL,GAAG2B,EACH,SACA,cACA,QACEA,EAAK,UACJC,EACG,IAAA,GACA,CACE,OAAS,GAAU,CACjB,IAAME,EAAOC,EAAM,MAAM,GACzB,GAAI,CAACD,EAAM,OAAO,KAClB,IAAME,EACJhC,EAAO,YAAYG,EAAWH,EAAQ8B,EAAK,EAAGA,EAAK,CAAC,EAAE,EAAE,MAC1D,MAAO,CAACA,EAAK,OAAS9B,EAAO,MAAQ,GAAIgC,GAAU,EAAE,CAAC,CACnD,OAAO,OAAO,CAAC,CACf,KAAK;CAAI,CACd,CACF,GACN,MAAO,CACL,IAAKlC,EACL,IAAKC,EACL,MAAOC,EAAO,OACd,QAASa,EACT,KAAM,GACN,KAAM,GACN,UAAW,EACX,QAASe,GAAa,CAAC,CAAC5B,EAAO,OAC/B,GAAI4B,EAAY,CAAC,EAAI,CAAE,WAAc,EAAG,CAC1C,EACA,MAAO,CACL,IAAK3B,EACL,IAAKC,EACL,MAAOF,EAAO,OACd,KAAM,GACN,KAAM,GACN,UAAW,EACX,QAAS4B,GAAa,CAAC,CAAC5B,EAAO,OAC/B,GAAI4B,EAAY,CAAC,EAAI,CAAE,WAAc,EAAG,CAC1C,EACA,OAAQD,EAAK,QAAU,GACvB,QACEA,EAAK,UACJC,EAAY,IAAA,GAAY,CAAE,IAAK,EAAG,MAAO,EAAG,OAAQ,EAAG,KAAM,CAAE,GAClE,aACF,CACF"}
1
+ {"version":3,"file":"presets.cjs","names":["withSeriesType","series","t","s","type","stack","curve","lineSeries","area","extra","areaSeries","barSeries","stacked","labels","scatterSeries","candlestickSeries","heatmapChartOptions","numericX","config","c","numericY","base","sparklineOptions","DEFAULT_QUADRANT_COLORS","DIVIDER","splits","x0","x1","y0","y1","quadrantOf","right","x","xs","y","ys","quadrantCenter","visualRight","corner","quadrantChartOptions","reverseX","color","p","left","rect","xa","xb","ya","yb","position","ends","visualLeft","texts","annotations","showTicks","interaction","item","event","region"],"sources":["../../../../charts/src/engine/presets.ts"],"sourcesContent":["// Option presets of the chart components, shared by every platform (React,\n// mini-programs, React Native): they turn component props into engine\n// options.\n\nimport type {\n ChartAnnotation,\n ChartCurve,\n ChartInteractionOptions,\n ChartOptions,\n ChartSeries,\n ChartSeriesType,\n} from \"./types\";\n\n/** Gives the series without a `type` the type of the component */\nexport const withSeriesType = (\n series: readonly ChartSeries[],\n type: ChartSeriesType,\n stack?: string,\n curve?: ChartCurve,\n): ChartSeries[] =>\n series.map((s) => {\n const t = s.type ?? type;\n return {\n ...s,\n type: t,\n ...(stack !== undefined && t === type ? { stack: s.stack ?? stack } : {}),\n ...(curve !== undefined && (t === \"line\" || t === \"area\")\n ? { curve: s.curve ?? curve }\n : {}),\n };\n });\n\n/** Options of the line-like components */\nexport interface LineSeriesOptions {\n /** Stacks the series on top of each other */\n stacked?: boolean;\n /** Shape of the lines */\n curve?: ChartCurve;\n}\n\n/** Series of a LineChart (`area` fills them) */\nexport const lineSeries = (\n series: readonly ChartSeries[],\n area = false,\n extra: LineSeriesOptions = {},\n) =>\n withSeriesType(\n series,\n area ? \"area\" : \"line\",\n extra.stacked ? \"stack\" : undefined,\n extra.curve,\n );\n\n/** Series of an AreaChart */\nexport const areaSeries = (\n series: readonly ChartSeries[],\n extra: LineSeriesOptions = {},\n) => lineSeries(series, true, extra);\n\n/** Series of a BarChart (`stacked` stacks them, `labels` shows the values) */\nexport const barSeries = (\n series: readonly ChartSeries[],\n stacked = false,\n labels = false,\n) =>\n withSeriesType(series, \"bar\", stacked ? \"stack\" : undefined).map((s) =>\n labels && s.type === \"bar\" ? { ...s, showLabels: s.showLabels ?? true } : s,\n );\n\n/** Series of a ScatterChart */\nexport const scatterSeries = (series: readonly ChartSeries[]) =>\n withSeriesType(series, \"scatter\");\n\n/** Series of a CandlestickChart */\nexport const candlestickSeries = (series: readonly ChartSeries[]) =>\n withSeriesType(series, \"candlestick\");\n\n/** A cell of a HeatmapChart */\nexport interface HeatmapCell {\n /** Column: a category name (or a number on a numeric axis) */\n x: string | number;\n /** Row: a category name (or a number on a numeric axis) */\n y: string | number;\n /** Value mapped to the color scale; `null` leaves the cell empty */\n value: number | null;\n}\n\n/** Settings of a heatmap (the props of HeatmapChart) */\nexport interface HeatmapConfig {\n /** Cells */\n data: readonly HeatmapCell[];\n /** Column names in order (collected from the data when omitted) */\n xCategories?: readonly string[];\n /** Row names from bottom to top (collected from the data when omitted) */\n yCategories?: readonly string[];\n /** Colors from the lowest to the highest value; a ramp of the first palette color by default */\n colorScale?: readonly string[];\n /** Values at the ends of the color scale; the data range by default */\n valueRange?: readonly [number, number];\n /** Name of the value in the tooltip */\n name?: string;\n /** Corner radius of the cells, in pixels */\n radius?: number;\n /** Formats the values in the tooltip */\n format?: (value: number) => string;\n}\n\n/** Engine options of a heatmap */\nexport const heatmapChartOptions = (\n config: HeatmapConfig,\n base: Partial<ChartOptions> = {},\n): ChartOptions => {\n const numericX = config.data.some((c) => typeof c.x === \"number\");\n const numericY = config.data.some((c) => typeof c.y === \"number\");\n return {\n ...base,\n series: [\n {\n id: \"heatmap\",\n name: config.name ?? \"Value\",\n type: \"heatmap\",\n data: config.data.map((c) => ({ x: c.x, y: c.y, value: c.value })),\n colorScale: config.colorScale,\n valueRange: config.valueRange,\n radius: config.radius,\n format: config.format,\n },\n ],\n xAxis: {\n ...(numericX\n ? {}\n : { type: \"category\" as const, categories: config.xCategories }),\n grid: false,\n ...base.xAxis,\n },\n yAxis: {\n ...(numericY\n ? {}\n : { type: \"category\" as const, categories: config.yCategories }),\n grid: false,\n ...base.yAxis,\n },\n legend: base.legend ?? false,\n interaction: base.interaction ?? { zoom: false },\n tooltip: base.tooltip ?? { mode: \"nearest\" },\n };\n};\n\n/** Settings of a sparkline (the props of Sparkline) */\nexport interface SparklineConfig {\n /** Values (or `[x, y]` pairs, typed arrays, ...) */\n data: ChartSeries[\"data\"];\n /**\n * How the values are drawn\n * @default \"line\"\n */\n type?: \"line\" | \"area\" | \"bar\";\n /** Color (any CSS color); the first palette color by default */\n color?: string;\n /**\n * Shape of the line\n * @default \"smooth\"\n */\n curve?: ChartCurve;\n /** Name shown in the tooltip */\n name?: string;\n /** Draws a reference line at this value (e.g. a target or the average) */\n reference?: number;\n /** Formats the value in the tooltip */\n format?: (value: number) => string;\n}\n\n/** Engine options of a sparkline: no axes, no legend, a tooltip only */\nexport const sparklineOptions = (\n config: SparklineConfig,\n base: Partial<ChartOptions> = {},\n): ChartOptions => {\n const type = config.type ?? \"line\";\n return {\n ...base,\n series: [\n {\n id: \"sparkline\",\n name: config.name ?? \"Value\",\n type,\n data: config.data,\n color: config.color,\n curve: type === \"bar\" ? undefined : (config.curve ?? \"smooth\"),\n lineWidth: 1.5,\n opacity: type === \"area\" ? 0.22 : undefined,\n radius: type === \"bar\" ? 1.5 : undefined,\n format: config.format,\n },\n ],\n xAxis: { visible: false, grid: false, ...base.xAxis },\n yAxis: { visible: false, grid: false, nice: false, ...base.yAxis },\n legend: false,\n padding: base.padding ?? { top: 4, right: 4, bottom: 4, left: 4 },\n interaction: base.interaction ?? { zoom: false },\n annotations:\n config.reference !== undefined\n ? [\n ...(base.annotations ?? []),\n {\n type: \"line\",\n axis: \"y\",\n value: config.reference,\n dash: [2, 3],\n },\n ]\n : base.annotations,\n };\n};\n\n/** A point of a QuadrantChart */\nexport interface QuadrantPoint {\n /** Position on the horizontal axis */\n x: number;\n /** Position on the vertical axis */\n y: number;\n /** Text drawn next to the dot and shown in the tooltip */\n label?: string;\n /** Dot color (any CSS color); the color of its quadrant by default */\n color?: string;\n /** Dot diameter in pixels */\n size?: number;\n}\n\n/** Title and color of a quadrant */\nexport interface QuadrantRegion {\n /** Title drawn in the outer corner of the quadrant */\n label?: string;\n /** Background tint and default dot color (any CSS color) */\n color?: string;\n}\n\n/** The four quadrants of a QuadrantChart */\nexport interface QuadrantRegions {\n topLeft?: QuadrantRegion;\n topRight?: QuadrantRegion;\n bottomLeft?: QuadrantRegion;\n bottomRight?: QuadrantRegion;\n}\n\n/** A quadrant, as seen on screen */\nexport type QuadrantCorner = keyof QuadrantRegions;\n\n/** Texts at the four ends of the dividers, inside the plot */\nexport interface QuadrantAxisLabels {\n top?: string;\n bottom?: string;\n left?: string;\n right?: string;\n}\n\n/** Settings of a quadrant matrix (the props of QuadrantChart) */\nexport interface QuadrantConfig {\n /** Points to place */\n points: readonly QuadrantPoint[];\n /**\n * Range of the horizontal axis\n * @default [0, 10]\n */\n xDomain?: [number, number];\n /**\n * Range of the vertical axis\n * @default [0, 10]\n */\n yDomain?: [number, number];\n /** X value of the vertical divider (the middle of `xDomain` by default) */\n xSplit?: number;\n /** Y value of the horizontal divider (the middle of `yDomain` by default) */\n ySplit?: number;\n /** Titles and colors of the quadrants */\n quadrants?: QuadrantRegions;\n /** Title of the horizontal axis */\n xLabel?: string;\n /** Title of the vertical axis */\n yLabel?: string;\n /** Texts at the ends of the dividers, drawn inside the plot (e.g. \"Important\" at the top) */\n axisLabels?: QuadrantAxisLabels;\n /**\n * Shows the numeric ticks of the axes; `false` keeps only the matrix\n * @default true\n */\n showTicks?: boolean;\n /** Reverses the horizontal axis (e.g. \"urgent\" on the left) */\n reverseX?: boolean;\n /**\n * Draws the labels next to the dots (overlapping labels are skipped)\n * @default true\n */\n showLabels?: boolean;\n /**\n * Dot diameter in pixels\n * @default 12\n */\n pointSize?: number;\n /** Name of the points in the tooltip */\n name?: string;\n /** Lets the user drag the dots (`drag` / `drop` events) */\n draggable?: boolean;\n}\n\nexport const DEFAULT_QUADRANT_COLORS: Required<Record<QuadrantCorner, string>> =\n {\n topLeft: \"var(--danger-color, #ef4444)\",\n topRight: \"var(--primary-color, #4f46e5)\",\n bottomLeft: \"var(--warning-color, #f59e0b)\",\n bottomRight: \"var(--text-secondary-color, #64748b)\",\n };\n\nconst DIVIDER = \"var(--border-strong-color, var(--border-color, #cbd5e1))\";\n\nconst splits = (config: QuadrantConfig) => {\n const [x0, x1] = config.xDomain ?? [0, 10];\n const [y0, y1] = config.yDomain ?? [0, 10];\n return {\n x0,\n x1,\n y0,\n y1,\n xs: config.xSplit ?? (x0 + x1) / 2,\n ys: config.ySplit ?? (y0 + y1) / 2,\n };\n};\n\n/** Quadrant of a data position, as seen on screen */\nexport const quadrantOf = (\n config: Pick<\n QuadrantConfig,\n \"xDomain\" | \"yDomain\" | \"xSplit\" | \"ySplit\" | \"reverseX\"\n >,\n x: number,\n y: number,\n): QuadrantCorner => {\n const { xs, ys } = splits(config as QuadrantConfig);\n const right = config.reverseX ? x < xs : x >= xs;\n const top = y >= ys;\n return top\n ? right\n ? \"topRight\"\n : \"topLeft\"\n : right\n ? \"bottomRight\"\n : \"bottomLeft\";\n};\n\n/** Center of a quadrant in data coordinates */\nexport const quadrantCenter = (\n config: Pick<\n QuadrantConfig,\n \"xDomain\" | \"yDomain\" | \"xSplit\" | \"ySplit\" | \"reverseX\"\n >,\n corner: QuadrantCorner,\n): { x: number; y: number } => {\n const { x0, x1, y0, y1, xs, ys } = splits(config as QuadrantConfig);\n const visualRight = corner.endsWith(\"Right\");\n const dataHigh = config.reverseX ? !visualRight : visualRight;\n return {\n x: dataHigh ? (xs + x1) / 2 : (x0 + xs) / 2,\n y: corner.startsWith(\"top\") ? (ys + y1) / 2 : (y0 + ys) / 2,\n };\n};\n\n/** Engine options of a quadrant matrix */\nexport const quadrantChartOptions = (\n config: QuadrantConfig,\n base: Omit<ChartOptions, \"series\"> = {},\n): ChartOptions => {\n const { x0, x1, y0, y1, xs, ys } = splits(config);\n const reverseX = !!config.reverseX;\n const color = (corner: QuadrantCorner) =>\n config.quadrants?.[corner]?.color ?? DEFAULT_QUADRANT_COLORS[corner];\n\n const series: ChartSeries[] = [\n {\n type: \"scatter\",\n name: config.name ?? \"\",\n pointSize: config.pointSize ?? 12,\n showLabels: config.showLabels ?? true,\n opacity: 0.9,\n data: config.points.map((p) => ({\n x: p.x,\n y: p.y,\n label: p.label,\n size: p.size,\n color: p.color ?? color(quadrantOf(config, p.x, p.y)),\n })),\n },\n ];\n\n // visual left / right -> data ranges\n const left: [number, number] = reverseX ? [xs, x1] : [x0, xs];\n const right: [number, number] = reverseX ? [x0, xs] : [xs, x1];\n const rect = (\n corner: QuadrantCorner,\n [xa, xb]: [number, number],\n [ya, yb]: [number, number],\n position: \"top-left\" | \"top-right\" | \"bottom-left\" | \"bottom-right\",\n ): ChartAnnotation => ({\n type: \"rect\",\n x0: xa,\n x1: xb,\n y0: ya,\n y1: yb,\n color: color(corner),\n opacity: 0.07,\n label: config.quadrants?.[corner]?.label,\n labelPosition: position,\n });\n const ends = config.axisLabels ?? {};\n const visualLeft = reverseX ? x1 : x0;\n const visualRight = reverseX ? x0 : x1;\n const texts: ChartAnnotation[] = [\n ...(ends.top\n ? [{ type: \"text\", x: xs, y: y1, text: ends.top, anchor: \"top\" } as const]\n : []),\n ...(ends.bottom\n ? [\n {\n type: \"text\",\n x: xs,\n y: y0,\n text: ends.bottom,\n anchor: \"bottom\",\n } as const,\n ]\n : []),\n ...(ends.left\n ? [\n {\n type: \"text\",\n x: visualLeft,\n y: ys,\n text: ends.left,\n anchor: \"left\",\n } as const,\n ]\n : []),\n ...(ends.right\n ? [\n {\n type: \"text\",\n x: visualRight,\n y: ys,\n text: ends.right,\n anchor: \"right\",\n } as const,\n ]\n : []),\n ];\n\n const annotations: ChartAnnotation[] = [\n rect(\"topLeft\", left, [ys, y1], \"top-left\"),\n rect(\"topRight\", right, [ys, y1], \"top-right\"),\n rect(\"bottomLeft\", left, [y0, ys], \"bottom-left\"),\n rect(\"bottomRight\", right, [y0, ys], \"bottom-right\"),\n { type: \"line\", axis: \"x\", value: xs, dash: [], color: DIVIDER },\n { type: \"line\", axis: \"y\", value: ys, dash: [], color: DIVIDER },\n ...texts,\n ...(base.annotations ?? []),\n ];\n\n const showTicks = config.showTicks ?? true;\n const interaction: boolean | ChartInteractionOptions =\n base.interaction === false\n ? false\n : {\n zoom: false,\n ...(typeof base.interaction === \"object\" ? base.interaction : {}),\n ...(config.draggable ? { dragPoints: true } : {}),\n };\n\n return {\n ...base,\n series,\n annotations,\n tooltip:\n base.tooltip ??\n (showTicks\n ? undefined\n : {\n render: (event) => {\n const item = event.items[0];\n if (!item) return null;\n const region =\n config.quadrants?.[quadrantOf(config, item.x, item.y)]?.label;\n return [item.label ?? config.name ?? \"\", region ?? \"\"]\n .filter(Boolean)\n .join(\"\\n\");\n },\n }),\n xAxis: {\n min: x0,\n max: x1,\n title: config.xLabel,\n reverse: reverseX,\n nice: false,\n grid: false,\n tickCount: 4,\n visible: showTicks || !!config.xLabel,\n ...(showTicks ? {} : { format: () => \"\" }),\n },\n yAxis: {\n min: y0,\n max: y1,\n title: config.yLabel,\n nice: false,\n grid: false,\n tickCount: 4,\n visible: showTicks || !!config.yLabel,\n ...(showTicks ? {} : { format: () => \"\" }),\n },\n legend: base.legend ?? false,\n padding:\n base.padding ??\n (showTicks ? undefined : { top: 4, right: 4, bottom: 4, left: 4 }),\n interaction,\n };\n};\n"],"mappings":"AAcA,IAAaA,GACX,EACA,EACA,EACA,IAEAC,EAAO,IAAK,GAAM,CAChB,IAAMC,EAAIC,EAAE,MAAQC,EACpB,MAAO,CACL,GAAGD,EACH,KAAMD,EACN,GAAIG,IAAU,IAAA,IAAaH,IAAME,EAAO,CAAE,MAAOD,EAAE,OAASE,CAAM,EAAI,CAAC,EACvE,GAAIC,IAAU,IAAA,KAAcJ,IAAM,QAAUA,IAAM,QAC9C,CAAE,MAAOC,EAAE,OAASG,CAAM,EAC1B,CAAC,CACP,CACF,CAAC,EAWUC,GACX,EACA,EAAO,GACP,EAA2B,CAAC,IAE5BP,EACEC,EACAO,EAAO,OAAS,OAChBC,EAAM,QAAU,QAAU,IAAA,GAC1BA,EAAM,KACR,EAGWC,GAC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C,CACjD,EAEN,MAAO,CACL,GAAGG,EACH,SACA,cACA,QACEA,EAAK,UACJiC,EACG,IAAA,GACA,CACE,OAAS,GAAU,CACjB,IAAME,EAAOC,EAAM,MAAM,GACzB,GAAI,CAACD,EAAM,OAAO,KAClB,IAAME,EACJxC,EAAO,YAAYY,EAAWZ,EAAQsC,EAAK,EAAGA,EAAK,CAAC,EAAE,EAAE,MAC1D,MAAO,CAACA,EAAK,OAAStC,EAAO,MAAQ,GAAIwC,GAAU,EAAE,CAAC,CACnD,OAAO,OAAO,CAAC,CACf,KAAK;CAAI,CACd,CACF,GACN,MAAO,CACL,IAAKhC,EACL,IAAKC,EACL,MAAOT,EAAO,OACd,QAASsB,EACT,KAAM,GACN,KAAM,GACN,UAAW,EACX,QAASc,GAAa,CAAC,CAACpC,EAAO,OAC/B,GAAIoC,EAAY,CAAC,EAAI,CAAE,WAAc,EAAG,CAC1C,EACA,MAAO,CACL,IAAK1B,EACL,IAAKC,EACL,MAAOX,EAAO,OACd,KAAM,GACN,KAAM,GACN,UAAW,EACX,QAASoC,GAAa,CAAC,CAACpC,EAAO,OAC/B,GAAIoC,EAAY,CAAC,EAAI,CAAE,WAAc,EAAG,CAC1C,EACA,OAAQjC,EAAK,QAAU,GACvB,QACEA,EAAK,UACJiC,EAAY,IAAA,GAAY,CAAE,IAAK,EAAG,MAAO,EAAG,OAAQ,EAAG,KAAM,CAAE,GAClE,aACF,CACF"}
@@ -1,12 +1,78 @@
1
- import { ChartOptions, ChartSeries, ChartSeriesType } from './types.cjs';
1
+ import { ChartCurve, ChartOptions, ChartSeries, ChartSeriesType } from './types.cjs';
2
2
  /** Gives the series without a `type` the type of the component */
3
- export declare const withSeriesType: (series: readonly ChartSeries[], type: ChartSeriesType, stack?: string) => ChartSeries[];
3
+ export declare const withSeriesType: (series: readonly ChartSeries[], type: ChartSeriesType, stack?: string, curve?: ChartCurve) => ChartSeries[];
4
+ /** Options of the line-like components */
5
+ export interface LineSeriesOptions {
6
+ /** Stacks the series on top of each other */
7
+ stacked?: boolean;
8
+ /** Shape of the lines */
9
+ curve?: ChartCurve;
10
+ }
4
11
  /** Series of a LineChart (`area` fills them) */
5
- export declare const lineSeries: (series: readonly ChartSeries[], area?: boolean) => ChartSeries[];
6
- /** Series of a BarChart (`stacked` stacks them) */
7
- export declare const barSeries: (series: readonly ChartSeries[], stacked?: boolean) => ChartSeries[];
12
+ export declare const lineSeries: (series: readonly ChartSeries[], area?: boolean, extra?: LineSeriesOptions) => ChartSeries[];
13
+ /** Series of an AreaChart */
14
+ export declare const areaSeries: (series: readonly ChartSeries[], extra?: LineSeriesOptions) => ChartSeries[];
15
+ /** Series of a BarChart (`stacked` stacks them, `labels` shows the values) */
16
+ export declare const barSeries: (series: readonly ChartSeries[], stacked?: boolean, labels?: boolean) => ChartSeries[];
8
17
  /** Series of a ScatterChart */
9
18
  export declare const scatterSeries: (series: readonly ChartSeries[]) => ChartSeries[];
19
+ /** Series of a CandlestickChart */
20
+ export declare const candlestickSeries: (series: readonly ChartSeries[]) => ChartSeries[];
21
+ /** A cell of a HeatmapChart */
22
+ export interface HeatmapCell {
23
+ /** Column: a category name (or a number on a numeric axis) */
24
+ x: string | number;
25
+ /** Row: a category name (or a number on a numeric axis) */
26
+ y: string | number;
27
+ /** Value mapped to the color scale; `null` leaves the cell empty */
28
+ value: number | null;
29
+ }
30
+ /** Settings of a heatmap (the props of HeatmapChart) */
31
+ export interface HeatmapConfig {
32
+ /** Cells */
33
+ data: readonly HeatmapCell[];
34
+ /** Column names in order (collected from the data when omitted) */
35
+ xCategories?: readonly string[];
36
+ /** Row names from bottom to top (collected from the data when omitted) */
37
+ yCategories?: readonly string[];
38
+ /** Colors from the lowest to the highest value; a ramp of the first palette color by default */
39
+ colorScale?: readonly string[];
40
+ /** Values at the ends of the color scale; the data range by default */
41
+ valueRange?: readonly [number, number];
42
+ /** Name of the value in the tooltip */
43
+ name?: string;
44
+ /** Corner radius of the cells, in pixels */
45
+ radius?: number;
46
+ /** Formats the values in the tooltip */
47
+ format?: (value: number) => string;
48
+ }
49
+ /** Engine options of a heatmap */
50
+ export declare const heatmapChartOptions: (config: HeatmapConfig, base?: Partial<ChartOptions>) => ChartOptions;
51
+ /** Settings of a sparkline (the props of Sparkline) */
52
+ export interface SparklineConfig {
53
+ /** Values (or `[x, y]` pairs, typed arrays, ...) */
54
+ data: ChartSeries["data"];
55
+ /**
56
+ * How the values are drawn
57
+ * @default "line"
58
+ */
59
+ type?: "line" | "area" | "bar";
60
+ /** Color (any CSS color); the first palette color by default */
61
+ color?: string;
62
+ /**
63
+ * Shape of the line
64
+ * @default "smooth"
65
+ */
66
+ curve?: ChartCurve;
67
+ /** Name shown in the tooltip */
68
+ name?: string;
69
+ /** Draws a reference line at this value (e.g. a target or the average) */
70
+ reference?: number;
71
+ /** Formats the value in the tooltip */
72
+ format?: (value: number) => string;
73
+ }
74
+ /** Engine options of a sparkline: no axes, no legend, a tooltip only */
75
+ export declare const sparklineOptions: (config: SparklineConfig, base?: Partial<ChartOptions>) => ChartOptions;
10
76
  /** A point of a QuadrantChart */
11
77
  export interface QuadrantPoint {
12
78
  /** Position on the horizontal axis */
@@ -1,12 +1,78 @@
1
- import { ChartOptions, ChartSeries, ChartSeriesType } from './types.js';
1
+ import { ChartCurve, ChartOptions, ChartSeries, ChartSeriesType } from './types.js';
2
2
  /** Gives the series without a `type` the type of the component */
3
- export declare const withSeriesType: (series: readonly ChartSeries[], type: ChartSeriesType, stack?: string) => ChartSeries[];
3
+ export declare const withSeriesType: (series: readonly ChartSeries[], type: ChartSeriesType, stack?: string, curve?: ChartCurve) => ChartSeries[];
4
+ /** Options of the line-like components */
5
+ export interface LineSeriesOptions {
6
+ /** Stacks the series on top of each other */
7
+ stacked?: boolean;
8
+ /** Shape of the lines */
9
+ curve?: ChartCurve;
10
+ }
4
11
  /** Series of a LineChart (`area` fills them) */
5
- export declare const lineSeries: (series: readonly ChartSeries[], area?: boolean) => ChartSeries[];
6
- /** Series of a BarChart (`stacked` stacks them) */
7
- export declare const barSeries: (series: readonly ChartSeries[], stacked?: boolean) => ChartSeries[];
12
+ export declare const lineSeries: (series: readonly ChartSeries[], area?: boolean, extra?: LineSeriesOptions) => ChartSeries[];
13
+ /** Series of an AreaChart */
14
+ export declare const areaSeries: (series: readonly ChartSeries[], extra?: LineSeriesOptions) => ChartSeries[];
15
+ /** Series of a BarChart (`stacked` stacks them, `labels` shows the values) */
16
+ export declare const barSeries: (series: readonly ChartSeries[], stacked?: boolean, labels?: boolean) => ChartSeries[];
8
17
  /** Series of a ScatterChart */
9
18
  export declare const scatterSeries: (series: readonly ChartSeries[]) => ChartSeries[];
19
+ /** Series of a CandlestickChart */
20
+ export declare const candlestickSeries: (series: readonly ChartSeries[]) => ChartSeries[];
21
+ /** A cell of a HeatmapChart */
22
+ export interface HeatmapCell {
23
+ /** Column: a category name (or a number on a numeric axis) */
24
+ x: string | number;
25
+ /** Row: a category name (or a number on a numeric axis) */
26
+ y: string | number;
27
+ /** Value mapped to the color scale; `null` leaves the cell empty */
28
+ value: number | null;
29
+ }
30
+ /** Settings of a heatmap (the props of HeatmapChart) */
31
+ export interface HeatmapConfig {
32
+ /** Cells */
33
+ data: readonly HeatmapCell[];
34
+ /** Column names in order (collected from the data when omitted) */
35
+ xCategories?: readonly string[];
36
+ /** Row names from bottom to top (collected from the data when omitted) */
37
+ yCategories?: readonly string[];
38
+ /** Colors from the lowest to the highest value; a ramp of the first palette color by default */
39
+ colorScale?: readonly string[];
40
+ /** Values at the ends of the color scale; the data range by default */
41
+ valueRange?: readonly [number, number];
42
+ /** Name of the value in the tooltip */
43
+ name?: string;
44
+ /** Corner radius of the cells, in pixels */
45
+ radius?: number;
46
+ /** Formats the values in the tooltip */
47
+ format?: (value: number) => string;
48
+ }
49
+ /** Engine options of a heatmap */
50
+ export declare const heatmapChartOptions: (config: HeatmapConfig, base?: Partial<ChartOptions>) => ChartOptions;
51
+ /** Settings of a sparkline (the props of Sparkline) */
52
+ export interface SparklineConfig {
53
+ /** Values (or `[x, y]` pairs, typed arrays, ...) */
54
+ data: ChartSeries["data"];
55
+ /**
56
+ * How the values are drawn
57
+ * @default "line"
58
+ */
59
+ type?: "line" | "area" | "bar";
60
+ /** Color (any CSS color); the first palette color by default */
61
+ color?: string;
62
+ /**
63
+ * Shape of the line
64
+ * @default "smooth"
65
+ */
66
+ curve?: ChartCurve;
67
+ /** Name shown in the tooltip */
68
+ name?: string;
69
+ /** Draws a reference line at this value (e.g. a target or the average) */
70
+ reference?: number;
71
+ /** Formats the value in the tooltip */
72
+ format?: (value: number) => string;
73
+ }
74
+ /** Engine options of a sparkline: no axes, no legend, a tooltip only */
75
+ export declare const sparklineOptions: (config: SparklineConfig, base?: Partial<ChartOptions>) => ChartOptions;
10
76
  /** A point of a QuadrantChart */
11
77
  export interface QuadrantPoint {
12
78
  /** Position on the horizontal axis */