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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # minerva-design
2
2
 
3
+ ## 1.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - docs(charts): document the new chart types, the gallery and a performance guide
8
+ feat(charts): add area, candlestick, heatmap, sparkline, pie, radar, gauge, funnel and treemap
9
+
3
10
  ## 1.2.0
4
11
 
5
12
  ### Minor Changes
@@ -1,7 +1,10 @@
1
1
  export { createCanvasChart, drawScene, type CanvasChartConfig, type CanvasChartInstance, type ChartCanvas, type ChartTouch, } from './engine/canvas.cjs';
2
2
  export { createChartController, scenePrimitives, type ChartAreaPrimitive, type ChartBarPrimitive, type ChartController, type ChartControllerConfig, type ChartControllerEventMap, type ChartDotPrimitive, type ChartHoverLayout, type ChartLegendEntry, type ChartLegendLayout, type ChartLinePrimitive, type ChartPointerOptions, type ChartPrimitive, type ChartPrimitiveOptions, type ChartScene, type ChartTooltipLayout, } from './engine/controller.cjs';
3
3
  export { formatCompact } from './engine/format.cjs';
4
- export { barSeries, DEFAULT_QUADRANT_COLORS, lineSeries, quadrantCenter, quadrantChartOptions, quadrantOf, scatterSeries, type QuadrantAxisLabels, type QuadrantConfig, type QuadrantCorner, type QuadrantPoint, type QuadrantRegion, type QuadrantRegions, } from './engine/presets.cjs';
4
+ export { areaSeries, barSeries, candlestickSeries, DEFAULT_QUADRANT_COLORS, heatmapChartOptions, lineSeries, quadrantCenter, quadrantChartOptions, quadrantOf, scatterSeries, sparklineOptions, type HeatmapCell, type HeatmapConfig, type QuadrantAxisLabels, type QuadrantConfig, type QuadrantCorner, type QuadrantPoint, type QuadrantRegion, type QuadrantRegions, type SparklineConfig, } from './engine/presets.cjs';
5
5
  export { toCss } from './engine/color.cjs';
6
6
  export type { ChartThemeInput } from './engine/theme.cjs';
7
7
  export type * from './engine/types.cjs';
8
+ export { createCanvasShapeChart, type CanvasShapeChartConfig, type CanvasShapeChartInstance, } from './engine/shapes/canvas.cjs';
9
+ export { drawShapeScene } from './engine/shapes/draw.cjs';
10
+ export type * from './engine/shapes/types.cjs';
@@ -1,7 +1,10 @@
1
1
  export { createCanvasChart, drawScene, type CanvasChartConfig, type CanvasChartInstance, type ChartCanvas, type ChartTouch, } from './engine/canvas.js';
2
2
  export { createChartController, scenePrimitives, type ChartAreaPrimitive, type ChartBarPrimitive, type ChartController, type ChartControllerConfig, type ChartControllerEventMap, type ChartDotPrimitive, type ChartHoverLayout, type ChartLegendEntry, type ChartLegendLayout, type ChartLinePrimitive, type ChartPointerOptions, type ChartPrimitive, type ChartPrimitiveOptions, type ChartScene, type ChartTooltipLayout, } from './engine/controller.js';
3
3
  export { formatCompact } from './engine/format.js';
4
- export { barSeries, DEFAULT_QUADRANT_COLORS, lineSeries, quadrantCenter, quadrantChartOptions, quadrantOf, scatterSeries, type QuadrantAxisLabels, type QuadrantConfig, type QuadrantCorner, type QuadrantPoint, type QuadrantRegion, type QuadrantRegions, } from './engine/presets.js';
4
+ export { areaSeries, barSeries, candlestickSeries, DEFAULT_QUADRANT_COLORS, heatmapChartOptions, lineSeries, quadrantCenter, quadrantChartOptions, quadrantOf, scatterSeries, sparklineOptions, type HeatmapCell, type HeatmapConfig, type QuadrantAxisLabels, type QuadrantConfig, type QuadrantCorner, type QuadrantPoint, type QuadrantRegion, type QuadrantRegions, type SparklineConfig, } from './engine/presets.js';
5
5
  export { toCss } from './engine/color.js';
6
6
  export type { ChartThemeInput } from './engine/theme.js';
7
7
  export type * from './engine/types.js';
8
+ export { createCanvasShapeChart, type CanvasShapeChartConfig, type CanvasShapeChartInstance, } from './engine/shapes/canvas.js';
9
+ export { drawShapeScene } from './engine/shapes/draw.js';
10
+ export type * from './engine/shapes/types.js';
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./engine/format.cjs"),t=require("./engine/chart.cjs"),n=require("./engine/presets.cjs"),r=require("./engine/controller.cjs"),i=require("./engine/canvas.cjs");exports.createCanvasChart=i.createCanvasChart,exports.createChart=t.createChart,exports.createChartController=r.createChartController,exports.formatCompact=e.formatCompact,exports.quadrantCenter=n.quadrantCenter,exports.quadrantChartOptions=n.quadrantChartOptions,exports.quadrantOf=n.quadrantOf,exports.scenePrimitives=r.scenePrimitives;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./engine/format.cjs"),t=require("./engine/chart.cjs"),n=require("./engine/presets.cjs"),r=require("./engine/shapes/chart.cjs"),i=require("./engine/shapes/canvas.cjs"),a=require("./engine/controller.cjs"),o=require("./engine/canvas.cjs");exports.createCanvasChart=o.createCanvasChart,exports.createCanvasShapeChart=i.createCanvasShapeChart,exports.createChart=t.createChart,exports.createChartController=a.createChartController,exports.createShapeChart=r.createShapeChart,exports.formatCompact=e.formatCompact,exports.heatmapChartOptions=n.heatmapChartOptions,exports.quadrantCenter=n.quadrantCenter,exports.quadrantChartOptions=n.quadrantChartOptions,exports.quadrantOf=n.quadrantOf,exports.scenePrimitives=a.scenePrimitives,exports.sparklineOptions=n.sparklineOptions;
@@ -1,7 +1,10 @@
1
1
  export { createChart } from './engine/chart.cjs';
2
+ export { createShapeChart } from './engine/shapes/chart.cjs';
3
+ export { createCanvasShapeChart, type CanvasShapeChartConfig, type CanvasShapeChartInstance, } from './engine/shapes/canvas.cjs';
4
+ export type { FunnelChartOptions, GaugeBand, GaugeChartOptions, PieChartOptions, RadarChartOptions, RadarIndicator, RadarSeries, ShapeChartCommonOptions, ShapeChartEventMap, ShapeChartInstance, ShapeChartOptions, ShapeChartType, ShapeDatum, ShapeHoverEvent, ShapeLegendOptions, ShapeTooltipOptions, ShapeToggleEvent, TreemapChartOptions, TreemapNode, } from './engine/shapes/types.cjs';
2
5
  export { createCanvasChart, type CanvasChartConfig, type CanvasChartInstance, type ChartCanvas, type ChartTouch, } from './engine/canvas.cjs';
3
6
  export { createChartController, scenePrimitives, type ChartAreaPrimitive, type ChartBarPrimitive, type ChartController, type ChartControllerConfig, type ChartControllerEventMap, type ChartDotPrimitive, type ChartHoverLayout, type ChartLegendEntry, type ChartLegendLayout, type ChartLinePrimitive, type ChartPointerOptions, type ChartPrimitive, type ChartPrimitiveOptions, type ChartScene, type ChartTooltipLayout, } from './engine/controller.cjs';
4
7
  export { formatCompact } from './engine/format.cjs';
5
- export { quadrantCenter, quadrantChartOptions, quadrantOf, type QuadrantAxisLabels, type QuadrantConfig, type QuadrantCorner, type QuadrantPoint, type QuadrantRegion, type QuadrantRegions, } from './engine/presets.cjs';
8
+ export { heatmapChartOptions, quadrantCenter, quadrantChartOptions, quadrantOf, sparklineOptions, type HeatmapCell, type HeatmapConfig, type QuadrantAxisLabels, type QuadrantConfig, type QuadrantCorner, type QuadrantPoint, type QuadrantRegion, type QuadrantRegions, type SparklineConfig, } from './engine/presets.cjs';
6
9
  export type { ChartThemeInput } from './engine/theme.cjs';
7
- export type { ChartAnnotation, ChartAxisOptions, ChartAxisType, ChartColumnData, ChartDragEvent, ChartEventMap, ChartHoverEvent, ChartHoverItem, ChartInstance, ChartInteractionOptions, ChartLabelPosition, ChartLegendOptions, ChartLineAnnotation, ChartOptions, ChartPadding, ChartPlotClickEvent, ChartPointDatum, ChartRect, ChartRectAnnotation, ChartRendererKind, ChartRendererPreference, ChartSeries, ChartSeriesData, ChartSeriesType, ChartTextAnnotation, ChartTooltipOptions, ChartView, ChartXValue, } from './engine/types.cjs';
10
+ export type { ChartAnnotation, ChartAxisOptions, ChartAxisType, ChartColumnData, ChartCurve, ChartDragEvent, ChartEventMap, ChartHoverEvent, ChartHoverItem, ChartInstance, ChartInteractionOptions, ChartLabelPosition, ChartLegendOptions, ChartLineAnnotation, ChartOptions, ChartPadding, ChartPlotClickEvent, ChartPointDatum, ChartRect, ChartRectAnnotation, ChartRendererKind, ChartRendererPreference, ChartSeries, ChartSeriesData, ChartSeriesType, ChartTextAnnotation, ChartTooltipOptions, ChartView, ChartXValue, } from './engine/types.cjs';
@@ -1,7 +1,10 @@
1
1
  export { createChart } from './engine/chart.js';
2
+ export { createShapeChart } from './engine/shapes/chart.js';
3
+ export { createCanvasShapeChart, type CanvasShapeChartConfig, type CanvasShapeChartInstance, } from './engine/shapes/canvas.js';
4
+ export type { FunnelChartOptions, GaugeBand, GaugeChartOptions, PieChartOptions, RadarChartOptions, RadarIndicator, RadarSeries, ShapeChartCommonOptions, ShapeChartEventMap, ShapeChartInstance, ShapeChartOptions, ShapeChartType, ShapeDatum, ShapeHoverEvent, ShapeLegendOptions, ShapeTooltipOptions, ShapeToggleEvent, TreemapChartOptions, TreemapNode, } from './engine/shapes/types.js';
2
5
  export { createCanvasChart, type CanvasChartConfig, type CanvasChartInstance, type ChartCanvas, type ChartTouch, } from './engine/canvas.js';
3
6
  export { createChartController, scenePrimitives, type ChartAreaPrimitive, type ChartBarPrimitive, type ChartController, type ChartControllerConfig, type ChartControllerEventMap, type ChartDotPrimitive, type ChartHoverLayout, type ChartLegendEntry, type ChartLegendLayout, type ChartLinePrimitive, type ChartPointerOptions, type ChartPrimitive, type ChartPrimitiveOptions, type ChartScene, type ChartTooltipLayout, } from './engine/controller.js';
4
7
  export { formatCompact } from './engine/format.js';
5
- export { quadrantCenter, quadrantChartOptions, quadrantOf, type QuadrantAxisLabels, type QuadrantConfig, type QuadrantCorner, type QuadrantPoint, type QuadrantRegion, type QuadrantRegions, } from './engine/presets.js';
8
+ export { heatmapChartOptions, quadrantCenter, quadrantChartOptions, quadrantOf, sparklineOptions, type HeatmapCell, type HeatmapConfig, type QuadrantAxisLabels, type QuadrantConfig, type QuadrantCorner, type QuadrantPoint, type QuadrantRegion, type QuadrantRegions, type SparklineConfig, } from './engine/presets.js';
6
9
  export type { ChartThemeInput } from './engine/theme.js';
7
- export type { ChartAnnotation, ChartAxisOptions, ChartAxisType, ChartColumnData, ChartDragEvent, ChartEventMap, ChartHoverEvent, ChartHoverItem, ChartInstance, ChartInteractionOptions, ChartLabelPosition, ChartLegendOptions, ChartLineAnnotation, ChartOptions, ChartPadding, ChartPlotClickEvent, ChartPointDatum, ChartRect, ChartRectAnnotation, ChartRendererKind, ChartRendererPreference, ChartSeries, ChartSeriesData, ChartSeriesType, ChartTextAnnotation, ChartTooltipOptions, ChartView, ChartXValue, } from './engine/types.js';
10
+ export type { ChartAnnotation, ChartAxisOptions, ChartAxisType, ChartColumnData, ChartCurve, ChartDragEvent, ChartEventMap, ChartHoverEvent, ChartHoverItem, ChartInstance, ChartInteractionOptions, ChartLabelPosition, ChartLegendOptions, ChartLineAnnotation, ChartOptions, ChartPadding, ChartPlotClickEvent, ChartPointDatum, ChartRect, ChartRectAnnotation, ChartRendererKind, ChartRendererPreference, ChartSeries, ChartSeriesData, ChartSeriesType, ChartTextAnnotation, ChartTooltipOptions, ChartView, ChartXValue, } from './engine/types.js';
@@ -1,6 +1,8 @@
1
1
  import { formatCompact as e } from "./engine/format.js";
2
2
  import { createChart as t } from "./engine/chart.js";
3
- import { quadrantCenter as n, quadrantChartOptions as r, quadrantOf as i } from "./engine/presets.js";
4
- import { createChartController as a, scenePrimitives as o } from "./engine/controller.js";
5
- import { createCanvasChart as s } from "./engine/canvas.js";
6
- export { s as createCanvasChart, t as createChart, a as createChartController, e as formatCompact, n as quadrantCenter, r as quadrantChartOptions, i as quadrantOf, o as scenePrimitives };
3
+ import { heatmapChartOptions as n, quadrantCenter as r, quadrantChartOptions as i, quadrantOf as a, sparklineOptions as o } from "./engine/presets.js";
4
+ import { createShapeChart as s } from "./engine/shapes/chart.js";
5
+ import { createCanvasShapeChart as c } from "./engine/shapes/canvas.js";
6
+ import { createChartController as l, scenePrimitives as u } from "./engine/controller.js";
7
+ import { createCanvasChart as d } from "./engine/canvas.js";
8
+ export { d as createCanvasChart, c as createCanvasShapeChart, t as createChart, l as createChartController, s as createShapeChart, e as formatCompact, n as heatmapChartOptions, r as quadrantCenter, i as quadrantChartOptions, a as quadrantOf, u as scenePrimitives, o as sparklineOptions };
@@ -1,2 +1,2 @@
1
- const e=require("./color.cjs"),t=require("./items.cjs"),n=require("./overlay.cjs"),r=require("./renderers/canvas2d.cjs"),i=require("./controller.cjs");var a=e=>(e[0]+e[1])/2,o=(e,t,n,r,i,a)=>{e.beginPath(),e.moveTo(t+a,n),e.lineTo(t+r-a,n),e.arcTo(t+r,n,t+r,n+a,a),e.lineTo(t+r,n+i-a),e.arcTo(t+r,n+i,t+r-a,n+i,a),e.lineTo(t+a,n+i),e.arcTo(t,n+i,t,n+i-a,a),e.lineTo(t,n+a),e.arcTo(t,n,t+a,n,a),e.closePath()},s=(t,i,a,s,c,l=r.createCanvas2dPainter(t))=>{let{width:u,height:d,theme:f,model:p,view:m,layout:h}=i,{plot:g,scales:_}=h,v=c;if(t.setTransform(1,0,0,1,0,0),t.clearRect(0,0,Math.ceil(u*v),Math.ceil(d*v)),t.setTransform(v,0,0,v,0,0),n.drawBackground(t,{width:u,height:d,scales:_,x:p.x,y:p.y,xTicks:h.xTicks,yTicks:h.yTicks,theme:f,annotations:i.annotations}),i.legend){t.font=n.font(f,12),t.textBaseline=`middle`,t.textAlign=`left`;for(let n of i.legend.entries){let r=n.box.y+n.box.height/2;if(t.globalAlpha=n.hidden?.45:1,t.fillStyle=n.color,n.shape===`dot`?(t.beginPath(),t.arc(n.box.x+5,r,4,0,Math.PI*2),t.fill()):n.shape===`line`?t.fillRect(n.box.x,r-1,10,2):t.fillRect(n.box.x+1,r-4,8,8),t.fillStyle=e.toCss(f.textMuted),t.fillText(n.name,n.box.x+14,r),n.hidden){let e=n.box.width-22;t.fillRect(n.box.x+14,r,e,1)}}t.globalAlpha=1}let y=(e,t,n)=>{let r=2/(e[1]-e[0]),i=(t-e[0])*r-1;return n?[-r,-i]:[r,i]},[b,x]=y(m.x,s.x,p.x.reverse),[S,C]=y(m.y,s.y,p.y.reverse);if(l.paint(a,{transform:{xScale:b,xOffset:x,yScale:S,yOffset:C},width:Math.max(1,Math.round(g.width*v)),height:Math.max(1,Math.round(g.height*v)),dpr:v},Math.round(g.x*v),Math.round(g.y*v)),t.setTransform(v,0,0,v,0,0),n.drawForeground(t,{width:u,height:d,scales:_,theme:f,annotations:i.annotations,pointLabels:[],clear:!1}),i.pointLabels.length){t.save(),t.font=n.font(f),t.textAlign=`left`,t.textBaseline=`middle`,t.lineWidth=3,t.lineJoin=`round`,t.strokeStyle=e.toCss(f.background,.9),t.fillStyle=e.toCss(f.text,.85);for(let{label:e,box:n}of i.pointLabels)t.strokeText(e.text,n.x,n.y+n.height/2),t.fillText(e.text,n.x,n.y+n.height/2);t.restore()}let w=i.hover;if(w){if(w.crosshairX!==null){t.save(),t.strokeStyle=e.toCss(f.textMuted,.55),t.lineWidth=1,t.setLineDash([3,3]),t.beginPath();let n=Math.round(w.crosshairX)+.5;t.moveTo(n,g.y),t.lineTo(n,g.y+g.height),t.stroke(),t.restore()}for(let n of w.marks){if(n.kind===`bar`){t.fillStyle=e.toCss(f.text,.08),t.fillRect(n.x-2,n.y-2,n.width+4,n.height+2);continue}t.beginPath(),t.arc(n.x,n.y,n.size/2,0,Math.PI*2),t.fillStyle=n.color,t.fill(),t.lineWidth=2,t.strokeStyle=e.toCss(f.background),t.stroke()}}if(i.dragging){let n=i.dragging;t.beginPath(),t.arc(n.x,n.y,n.size/2,0,Math.PI*2),t.fillStyle=n.color,t.globalAlpha=.85,t.fill(),t.globalAlpha=1,t.lineWidth=2,t.strokeStyle=e.toCss(f.background),t.stroke()}let T=w?.tooltip;if(T){let{box:r,lineHeight:i,padding:a}=T;t.save(),t.shadowColor=`rgba(15, 23, 42, 0.18)`,t.shadowBlur=16,t.shadowOffsetY=6,o(t,r.x,r.y,r.width,r.height,8),t.fillStyle=e.toCss(f.background),t.fill(),t.restore(),o(t,r.x+.5,r.y+.5,r.width-1,r.height-1,8),t.strokeStyle=e.toCss(f.axis),t.lineWidth=1,t.stroke(),t.textBaseline=`middle`;let s=r.y+a+i/2,c=r.x+a+2,l=r.x+r.width-a-2;if(T.text){t.font=n.font(f,12),t.fillStyle=e.toCss(f.text),t.textAlign=`left`;for(let e of T.text)t.fillText(e,c,s),s+=i}else{let{content:r}=T,a=c;r.titleColor&&(t.fillStyle=r.titleColor,t.beginPath(),t.arc(a+4,s,4,0,Math.PI*2),t.fill(),a+=14),t.font=n.font(f,12,600),t.fillStyle=e.toCss(f.text),t.textAlign=`left`,t.fillText(r.title,a,s),s+=i;for(let o of r.rows)a=c,o.color&&(t.fillStyle=o.color,t.beginPath(),t.arc(a+4,s,4,0,Math.PI*2),t.fill(),a+=14),t.font=n.font(f,12),t.textAlign=`left`,t.fillStyle=e.toCss(f.textMuted),t.fillText(o.name,a,s),t.font=n.font(f,12,600),t.textAlign=`right`,t.fillStyle=e.toCss(f.text),t.fillText(o.value,l,s),s+=i}}},c=e=>{let{canvas:n}=e,o=n.getContext(`2d`),c=e.width,l=e.height,u=e.pixelRatio??1,d=!1,f=null,p=[],m=null,h={x:0,y:0},g=0,_=``,v=(e,t)=>o?(t!==_&&(o.font=t,_=t),o.measureText(e).width):e.length*6.5,y=o?r.createCanvas2dPainter(o):null,b=globalThis,x=()=>{if(f=null,d||!o||!y)return;let e=C.getScene();if(!e)return;let r=Math.max(1,Math.round(c*u)),i=Math.max(1,Math.round(l*u));n.width!==r&&(n.width=r),n.height!==i&&(n.height=i),_=``,m!==e.model&&(m=e.model,h={x:a(e.model.base.x),y:a(e.model.base.y)},p=t.buildItems(e.model,h,++g)),s(o,e,p,h,u,y),_=``},S=()=>{d||f!==null||(f=n.requestAnimationFrame?n.requestAnimationFrame(x):b.requestAnimationFrame?b.requestAnimationFrame(x):setTimeout(x,16))},C=i.createChartController({options:e.options,theme:e.theme,measureText:v,onInvalidate:S});C.setSize(c,l);let w=(e,t)=>({id:e.identifier??t,touch:!0});return{setOptions:e=>C.setOptions(e),setTheme:e=>C.setTheme(e),resize(e,t,n){c=e,l=t,n&&(u=n),C.setSize(e,t),S()},render(){f!==null&&(n.cancelAnimationFrame?n.cancelAnimationFrame(f):b.cancelAnimationFrame?b.cancelAnimationFrame(f):clearTimeout(f)),x()},touchStart(e){e.forEach((e,t)=>C.pointerDown(e.x,e.y,w(e,t)))},touchMove(e){e.forEach((e,t)=>C.pointerMove(e.x,e.y,w(e,t)))},touchEnd(e){e.forEach((e,t)=>C.pointerUp(e.x,e.y,w(e,t)))},touchCancel(e=[{x:0,y:0}]){e.forEach((e,t)=>C.pointerCancel(w(e,t)))},pointerDown:(e,t,n)=>C.pointerDown(e,t,n),pointerMove:(e,t,n)=>C.pointerMove(e,t,n),pointerUp:(e,t,n)=>C.pointerUp(e,t,n),pointerLeave:()=>C.pointerLeave(),zoomAt:(e,t,n)=>C.zoomAt(e,t,n),resetZoom:()=>C.resetZoom(),getView:()=>C.getView(),setView:e=>C.setView(e),toggleSeries:e=>C.toggleSeries(e),clearHover:()=>C.clearHover(),getPlotRect:()=>C.getPlotRect(),toPixel:(e,t)=>C.toPixel(e,t),fromPixel:(e,t)=>C.fromPixel(e,t),getController:()=>C,on:(e,t)=>C.on(e,t),destroy(){d||(d=!0,f!==null&&(n.cancelAnimationFrame?n.cancelAnimationFrame(f):b.cancelAnimationFrame?b.cancelAnimationFrame(f):clearTimeout(f)),y?.destroy(),C.destroy())}}};exports.createCanvasChart=c,exports.drawScene=s;
1
+ const e=require("./color.cjs"),t=require("./items.cjs"),n=require("./overlay.cjs"),r=require("./renderers/canvas2d.cjs"),i=require("./signature.cjs"),a=require("./controller.cjs");var o=e=>(e[0]+e[1])/2,s=(e,t,n,r,i,a)=>{e.beginPath(),e.moveTo(t+a,n),e.lineTo(t+r-a,n),e.arcTo(t+r,n,t+r,n+a,a),e.lineTo(t+r,n+i-a),e.arcTo(t+r,n+i,t+r-a,n+i,a),e.lineTo(t+a,n+i),e.arcTo(t,n+i,t,n+i-a,a),e.lineTo(t,n+a),e.arcTo(t,n,t+a,n,a),e.closePath()},c=(t,i,a,o,c,l=r.createCanvas2dPainter(t))=>{let{width:u,height:d,theme:f,model:p,view:m,layout:h}=i,{plot:g,scales:_}=h,v=c;if(t.setTransform(1,0,0,1,0,0),t.clearRect(0,0,Math.ceil(u*v),Math.ceil(d*v)),t.setTransform(v,0,0,v,0,0),n.drawBackground(t,{width:u,height:d,scales:_,x:p.x,y:p.y,xTicks:h.xTicks,yTicks:h.yTicks,theme:f,annotations:i.annotations}),i.legend){t.font=n.font(f,12),t.textBaseline=`middle`,t.textAlign=`left`;for(let n of i.legend.entries){let r=n.box.y+n.box.height/2;if(t.globalAlpha=n.hidden?.45:1,t.fillStyle=n.color,n.shape===`dot`?(t.beginPath(),t.arc(n.box.x+5,r,4,0,Math.PI*2),t.fill()):n.shape===`line`?t.fillRect(n.box.x,r-1,10,2):t.fillRect(n.box.x+1,r-4,8,8),t.fillStyle=e.toCss(f.textMuted),t.fillText(n.name,n.box.x+14,r),n.hidden){let e=n.box.width-22;t.fillRect(n.box.x+14,r,e,1)}}t.globalAlpha=1}for(let n of i.hover?.marks??[])n.kind===`band`&&(s(t,n.x,n.y,n.width,n.height,6),t.fillStyle=e.toCss(f.text,.06),t.fill());let y=(e,t,n)=>{let r=2/(e[1]-e[0]),i=(t-e[0])*r-1;return n?[-r,-i]:[r,i]},[b,x]=y(m.x,o.x,p.x.reverse),[S,C]=y(m.y,o.y,p.y.reverse);if(l.paint(a,{transform:{xScale:b,xOffset:x,yScale:S,yOffset:C},width:Math.max(1,Math.round(g.width*v)),height:Math.max(1,Math.round(g.height*v)),dpr:v},Math.round(g.x*v),Math.round(g.y*v)),t.setTransform(v,0,0,v,0,0),n.drawForeground(t,{width:u,height:d,scales:_,theme:f,annotations:i.annotations,pointLabels:[],clear:!1}),i.pointLabels.length){t.save(),t.font=n.font(f),t.textAlign=`left`,t.textBaseline=`middle`,t.lineWidth=3,t.lineJoin=`round`,t.strokeStyle=e.toCss(f.background,.9),t.fillStyle=e.toCss(f.text,.85);for(let{label:e,box:n}of i.pointLabels)t.strokeText(e.text,n.x,n.y+n.height/2),t.fillText(e.text,n.x,n.y+n.height/2);t.restore()}let w=i.hover;if(w){if(w.crosshairX!==null){t.save(),t.strokeStyle=e.toCss(f.textMuted,.55),t.lineWidth=1,t.setLineDash([3,3]),t.beginPath();let n=Math.round(w.crosshairX)+.5;t.moveTo(n,g.y),t.lineTo(n,g.y+g.height),t.stroke(),t.restore()}for(let n of w.marks)if(n.kind!==`band`){if(n.kind===`cell`){s(t,n.x,n.y,n.width,n.height,3),t.lineWidth=3,t.strokeStyle=e.toCss(f.background),t.stroke(),t.lineWidth=1.5,t.strokeStyle=e.toCss(f.text,.55),t.stroke();continue}t.beginPath(),t.arc(n.x,n.y,n.size/2+4,0,Math.PI*2),t.fillStyle=n.halo,t.fill(),t.beginPath(),t.arc(n.x,n.y,n.size/2-1,0,Math.PI*2),t.fillStyle=n.color,t.fill(),t.lineWidth=2,t.strokeStyle=e.toCss(f.background),t.stroke()}}if(i.dragging){let n=i.dragging;t.beginPath(),t.arc(n.x,n.y,n.size/2,0,Math.PI*2),t.fillStyle=n.color,t.globalAlpha=.85,t.fill(),t.globalAlpha=1,t.lineWidth=2,t.strokeStyle=e.toCss(f.background),t.stroke()}let T=w?.tooltip;if(T){let{box:r,lineHeight:i,padding:a}=T;t.save(),t.shadowColor=`rgba(15, 23, 42, 0.18)`,t.shadowBlur=16,t.shadowOffsetY=6,s(t,r.x,r.y,r.width,r.height,8),t.fillStyle=e.toCss(f.background),t.fill(),t.restore(),s(t,r.x+.5,r.y+.5,r.width-1,r.height-1,8),t.strokeStyle=e.toCss(f.axis,.6),t.lineWidth=1,t.stroke(),t.textBaseline=`middle`;let o=r.y+a+i/2,c=r.x+a+2,l=r.x+r.width-a-2;if(T.text){t.font=n.font(f,12),t.fillStyle=e.toCss(f.text),t.textAlign=`left`;for(let e of T.text)t.fillText(e,c,o),o+=i}else{let{content:r}=T,a=c;r.titleColor&&(t.fillStyle=r.titleColor,t.beginPath(),t.arc(a+4,o,4,0,Math.PI*2),t.fill(),a+=14),t.font=n.font(f,12,600),t.fillStyle=e.toCss(f.text),t.textAlign=`left`,t.fillText(r.title,a,o),o+=i;for(let s of r.rows)a=c,s.color&&(t.fillStyle=s.color,t.beginPath(),t.arc(a+4,o,4,0,Math.PI*2),t.fill(),a+=14),t.font=n.font(f,12),t.textAlign=`left`,t.fillStyle=e.toCss(f.textMuted),t.fillText(s.name,a,o),t.font=n.font(f,12,600),t.textAlign=`right`,t.fillStyle=e.toCss(f.text),t.fillText(s.value,l,o),o+=i}}},l=e=>{let{canvas:n}=e,s=n.getContext(`2d`),l=e.width,u=e.height,d=e.pixelRatio??1,f=!1,p=null,m=[],h=null,g=``,_=e.options,v=new WeakMap,y=0,b=e=>{let t=v.get(e);return t===void 0&&v.set(e,t=++y),t},x={x:0,y:0},S=0,C=``,w=(e,t)=>s?(t!==C&&(s.font=t,C=t),s.measureText(e).width):e.length*6.5,T=s?r.createCanvas2dPainter(s):null,E=globalThis,D=()=>{if(p=null,f||!s||!T)return;let e=k.getScene();if(!e)return;let r=Math.max(1,Math.round(l*d)),a=Math.max(1,Math.round(u*d));if(n.width!==r&&(n.width=r),n.height!==a&&(n.height=a),C=``,h!==e.model){h=e.model;let n=i.itemsSignature(e.model,b(e.theme),e=>_.series[e]?.stack);n!==g&&(g=n,x={x:o(e.model.base.x),y:o(e.model.base.y)},m=t.buildItems(e.model,x,++S))}c(s,e,m,x,d,T),C=``},O=()=>{f||p!==null||(p=n.requestAnimationFrame?n.requestAnimationFrame(D):E.requestAnimationFrame?E.requestAnimationFrame(D):setTimeout(D,16))},k=a.createChartController({options:e.options,theme:e.theme,measureText:w,onInvalidate:O});k.setSize(l,u);let A=(e,t)=>({id:e.identifier??t,touch:!0});return{setOptions:e=>{_=e,k.setOptions(e)},setTheme:e=>k.setTheme(e),resize(e,t,n){l=e,u=t,n&&(d=n),k.setSize(e,t),O()},render(){p!==null&&(n.cancelAnimationFrame?n.cancelAnimationFrame(p):E.cancelAnimationFrame?E.cancelAnimationFrame(p):clearTimeout(p)),D()},touchStart(e){e.forEach((e,t)=>k.pointerDown(e.x,e.y,A(e,t)))},touchMove(e){e.forEach((e,t)=>k.pointerMove(e.x,e.y,A(e,t)))},touchEnd(e){e.forEach((e,t)=>k.pointerUp(e.x,e.y,A(e,t)))},touchCancel(e=[{x:0,y:0}]){e.forEach((e,t)=>k.pointerCancel(A(e,t)))},pointerDown:(e,t,n)=>k.pointerDown(e,t,n),pointerMove:(e,t,n)=>k.pointerMove(e,t,n),pointerUp:(e,t,n)=>k.pointerUp(e,t,n),pointerLeave:()=>k.pointerLeave(),zoomAt:(e,t,n)=>k.zoomAt(e,t,n),resetZoom:()=>k.resetZoom(),getView:()=>k.getView(),setView:e=>k.setView(e),toggleSeries:e=>k.toggleSeries(e),clearHover:()=>k.clearHover(),getPlotRect:()=>k.getPlotRect(),toPixel:(e,t)=>k.toPixel(e,t),fromPixel:(e,t)=>k.fromPixel(e,t),getController:()=>k,on:(e,t)=>k.on(e,t),destroy(){f||(f=!0,p!==null&&(n.cancelAnimationFrame?n.cancelAnimationFrame(p):E.cancelAnimationFrame?E.cancelAnimationFrame(p):clearTimeout(p)),T?.destroy(),k.destroy())}}};exports.createCanvasChart=l,exports.drawScene=c;
2
2
  //# sourceMappingURL=canvas.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"canvas.cjs","names":["createCanvas2dPainter","font","toCss","buildItems","createChartController","require_color","require_items","require_overlay","require_canvas2d","require_controller","mid","r","roundedRect","ctx","x","y","w","h","drawScene","scene","layout","dpr","pixelRatio","width","height","model","theme","e","cy","scale","s","range","offset","o","reverse","xScale","xOffset","view","origin","yScale","yOffset","painter","items","plot","label","box","hover","cx","mark","d","tip","padding","lineHeight","left","right","line","content","row","createCanvasChart","config","canvas","destroyed","frameId","itemsModel","version","fontSet","measureText","f","text","g","render","controller","pw","ph","schedule","touchOptions","t","i","ratio","touches","v","id","type","listener"],"sources":["../../../../charts/src/engine/canvas.ts"],"sourcesContent":["// createCanvasChart: a whole chart drawn on one 2D canvas without any DOM:\n// WeChat / Alipay / ByteDance mini-programs (`<canvas type=\"2d\">`), Taro,\n// uni-app, OffscreenCanvas, or a plain browser canvas. The host forwards\n// touches / pointer events; everything else is handled here.\n\nimport { toCss } from \"./color\";\nimport {\n createChartController,\n type ChartController,\n type ChartControllerEventMap,\n type ChartPointerOptions,\n type ChartScene,\n} from \"./controller\";\nimport { buildItems, type Origin } from \"./items\";\nimport { drawBackground, drawForeground, font } from \"./overlay\";\nimport { createCanvas2dPainter } from \"./renderers/canvas2d\";\nimport type { RenderItem } from \"./renderers/types\";\nimport type { ChartThemeInput } from \"./theme\";\nimport type { ChartOptions, ChartRect, ChartView } from \"./types\";\n\n/**\n * The canvas a chart draws on: a browser `HTMLCanvasElement`, an\n * `OffscreenCanvas` or the node of a mini-program `<canvas type=\"2d\">`\n * (`SelectorQuery.fields({ node: true })`)\n */\nexport interface ChartCanvas {\n width: number;\n height: number;\n getContext(type: \"2d\"): unknown;\n /** Mini-program canvases schedule their frames themselves */\n requestAnimationFrame?: (callback: () => void) => number;\n cancelAnimationFrame?: (id: number) => void;\n}\n\n/** A touch point relative to the canvas (`x` / `y`) with its identifier */\nexport interface ChartTouch {\n x: number;\n y: number;\n identifier?: number;\n}\n\nexport interface CanvasChartConfig {\n canvas: ChartCanvas;\n /** Size of the canvas in CSS pixels (rpx converted by the host) */\n width: number;\n height: number;\n /**\n * Device pixel ratio (`wx.getWindowInfo().pixelRatio` in mini-programs)\n * @default 1\n */\n pixelRatio?: number;\n options: ChartOptions;\n /** Colors and fonts: values of the Minerva CSS variables */\n theme?: ChartThemeInput;\n}\n\nexport interface CanvasChartInstance {\n setOptions(options: ChartOptions): void;\n setTheme(theme: ChartThemeInput | undefined): void;\n /** New CSS size (and pixel ratio) of the canvas */\n resize(width: number, height: number, pixelRatio?: number): void;\n /** Draws now (frames are otherwise scheduled automatically) */\n render(): void;\n /** Touch handlers: pass the `touches` / `changedTouches` of the event */\n touchStart(touches: readonly ChartTouch[]): void;\n touchMove(touches: readonly ChartTouch[]): void;\n touchEnd(changedTouches: readonly ChartTouch[]): void;\n touchCancel(changedTouches?: readonly ChartTouch[]): void;\n /** Mouse / pen handlers (H5, desktop mini-programs) */\n pointerDown(x: number, y: number, options?: ChartPointerOptions): void;\n pointerMove(x: number, y: number, options?: ChartPointerOptions): void;\n pointerUp(x: number, y: number, options?: ChartPointerOptions): void;\n pointerLeave(): void;\n /** Zooms around a pixel (factor < 1 zooms in) */\n zoomAt(x: number, y: number, factor: number): void;\n resetZoom(): void;\n getView(): ChartView;\n setView(view: Partial<ChartView>): void;\n toggleSeries(id: string): void;\n clearHover(): void;\n getPlotRect(): ChartRect | null;\n toPixel(x: number, y: number): { x: number; y: number } | null;\n fromPixel(x: number, y: number): { x: number; y: number } | null;\n /** The platform-free controller (scene, gestures) */\n getController(): ChartController;\n on<K extends keyof ChartControllerEventMap>(\n type: K,\n listener: (event: ChartControllerEventMap[K]) => void,\n ): () => void;\n destroy(): void;\n}\n\nconst mid = (r: [number, number]) => (r[0] + r[1]) / 2;\n\nconst roundedRect = (\n ctx: CanvasRenderingContext2D,\n x: number,\n y: number,\n w: number,\n h: number,\n r: number,\n) => {\n ctx.beginPath();\n ctx.moveTo(x + r, y);\n ctx.lineTo(x + w - r, y);\n ctx.arcTo(x + w, y, x + w, y + r, r);\n ctx.lineTo(x + w, y + h - r);\n ctx.arcTo(x + w, y + h, x + w - r, y + h, r);\n ctx.lineTo(x + r, y + h);\n ctx.arcTo(x, y + h, x, y + h - r, r);\n ctx.lineTo(x, y + r);\n ctx.arcTo(x, y, x + r, y, r);\n ctx.closePath();\n};\n\n/** Draws a scene (legend, axes, data, labels, hover) on a 2D context */\nexport const drawScene = (\n ctx: CanvasRenderingContext2D,\n scene: ChartScene,\n items: readonly RenderItem[],\n origin: Origin,\n pixelRatio: number,\n painter = createCanvas2dPainter(ctx),\n) => {\n const { width, height, theme, model, view, layout } = scene;\n const { plot, scales } = layout;\n const dpr = pixelRatio;\n ctx.setTransform(1, 0, 0, 1, 0, 0);\n ctx.clearRect(0, 0, Math.ceil(width * dpr), Math.ceil(height * dpr));\n ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n drawBackground(ctx, {\n width,\n height,\n scales,\n x: model.x,\n y: model.y,\n xTicks: layout.xTicks,\n yTicks: layout.yTicks,\n theme,\n annotations: scene.annotations,\n });\n\n // legend\n if (scene.legend) {\n ctx.font = font(theme, 12);\n ctx.textBaseline = \"middle\";\n ctx.textAlign = \"left\";\n for (const e of scene.legend.entries) {\n const cy = e.box.y + e.box.height / 2;\n ctx.globalAlpha = e.hidden ? 0.45 : 1;\n ctx.fillStyle = e.color;\n if (e.shape === \"dot\") {\n ctx.beginPath();\n ctx.arc(e.box.x + 5, cy, 4, 0, Math.PI * 2);\n ctx.fill();\n } else if (e.shape === \"line\") {\n ctx.fillRect(e.box.x, cy - 1, 10, 2);\n } else {\n ctx.fillRect(e.box.x + 1, cy - 4, 8, 8);\n }\n ctx.fillStyle = toCss(theme.textMuted);\n ctx.fillText(e.name, e.box.x + 14, cy);\n if (e.hidden) {\n const w = e.box.width - 22;\n ctx.fillRect(e.box.x + 14, cy, w, 1);\n }\n }\n ctx.globalAlpha = 1;\n }\n\n // data\n const scale = (range: [number, number], o: number, reverse: boolean) => {\n const s = 2 / (range[1] - range[0]);\n const offset = (o - range[0]) * s - 1;\n return reverse ? [-s, -offset] : [s, offset];\n };\n const [xScale, xOffset] = scale(view.x, origin.x, model.x.reverse);\n const [yScale, yOffset] = scale(view.y, origin.y, model.y.reverse);\n painter.paint(\n items,\n {\n transform: { xScale, xOffset, yScale, yOffset },\n width: Math.max(1, Math.round(plot.width * dpr)),\n height: Math.max(1, Math.round(plot.height * dpr)),\n dpr,\n },\n Math.round(plot.x * dpr),\n Math.round(plot.y * dpr),\n );\n\n ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n drawForeground(ctx, {\n width,\n height,\n scales,\n theme,\n annotations: scene.annotations,\n pointLabels: [],\n clear: false,\n });\n // dot labels placed by the scene\n if (scene.pointLabels.length) {\n ctx.save();\n ctx.font = font(theme);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"middle\";\n ctx.lineWidth = 3;\n ctx.lineJoin = \"round\";\n ctx.strokeStyle = toCss(theme.background, 0.9);\n ctx.fillStyle = toCss(theme.text, 0.85);\n for (const { label, box } of scene.pointLabels) {\n ctx.strokeText(label.text, box.x, box.y + box.height / 2);\n ctx.fillText(label.text, box.x, box.y + box.height / 2);\n }\n ctx.restore();\n }\n\n // hover\n const hover = scene.hover;\n if (hover) {\n if (hover.crosshairX !== null) {\n ctx.save();\n ctx.strokeStyle = toCss(theme.textMuted, 0.55);\n ctx.lineWidth = 1;\n ctx.setLineDash([3, 3]);\n ctx.beginPath();\n const cx = Math.round(hover.crosshairX) + 0.5;\n ctx.moveTo(cx, plot.y);\n ctx.lineTo(cx, plot.y + plot.height);\n ctx.stroke();\n ctx.restore();\n }\n for (const mark of hover.marks) {\n if (mark.kind === \"bar\") {\n ctx.fillStyle = toCss(theme.text, 0.08);\n ctx.fillRect(mark.x - 2, mark.y - 2, mark.width + 4, mark.height + 2);\n continue;\n }\n ctx.beginPath();\n ctx.arc(mark.x, mark.y, mark.size / 2, 0, Math.PI * 2);\n ctx.fillStyle = mark.color;\n ctx.fill();\n ctx.lineWidth = 2;\n ctx.strokeStyle = toCss(theme.background);\n ctx.stroke();\n }\n }\n if (scene.dragging) {\n const d = scene.dragging;\n ctx.beginPath();\n ctx.arc(d.x, d.y, d.size / 2, 0, Math.PI * 2);\n ctx.fillStyle = d.color;\n ctx.globalAlpha = 0.85;\n ctx.fill();\n ctx.globalAlpha = 1;\n ctx.lineWidth = 2;\n ctx.strokeStyle = toCss(theme.background);\n ctx.stroke();\n }\n const tip = hover?.tooltip;\n if (tip) {\n const { box, lineHeight, padding } = tip;\n ctx.save();\n ctx.shadowColor = \"rgba(15, 23, 42, 0.18)\";\n ctx.shadowBlur = 16;\n ctx.shadowOffsetY = 6;\n roundedRect(ctx, box.x, box.y, box.width, box.height, 8);\n ctx.fillStyle = toCss(theme.background);\n ctx.fill();\n ctx.restore();\n roundedRect(\n ctx,\n box.x + 0.5,\n box.y + 0.5,\n box.width - 1,\n box.height - 1,\n 8,\n );\n ctx.strokeStyle = toCss(theme.axis);\n ctx.lineWidth = 1;\n ctx.stroke();\n ctx.textBaseline = \"middle\";\n let y = box.y + padding + lineHeight / 2;\n const left = box.x + padding + 2;\n const right = box.x + box.width - padding - 2;\n if (tip.text) {\n ctx.font = font(theme, 12);\n ctx.fillStyle = toCss(theme.text);\n ctx.textAlign = \"left\";\n for (const line of tip.text) {\n ctx.fillText(line, left, y);\n y += lineHeight;\n }\n } else {\n const { content } = tip;\n let x = left;\n if (content.titleColor) {\n ctx.fillStyle = content.titleColor;\n ctx.beginPath();\n ctx.arc(x + 4, y, 4, 0, Math.PI * 2);\n ctx.fill();\n x += 14;\n }\n ctx.font = font(theme, 12, 600);\n ctx.fillStyle = toCss(theme.text);\n ctx.textAlign = \"left\";\n ctx.fillText(content.title, x, y);\n y += lineHeight;\n for (const row of content.rows) {\n x = left;\n if (row.color) {\n ctx.fillStyle = row.color;\n ctx.beginPath();\n ctx.arc(x + 4, y, 4, 0, Math.PI * 2);\n ctx.fill();\n x += 14;\n }\n ctx.font = font(theme, 12);\n ctx.textAlign = \"left\";\n ctx.fillStyle = toCss(theme.textMuted);\n ctx.fillText(row.name, x, y);\n ctx.font = font(theme, 12, 600);\n ctx.textAlign = \"right\";\n ctx.fillStyle = toCss(theme.text);\n ctx.fillText(row.value, right, y);\n y += lineHeight;\n }\n }\n }\n};\n\n/**\n * Creates a chart drawn on a 2D canvas: line, area, bar and scatter series,\n * annotations, legend and tooltip, tap / drag / pinch gestures. Works\n * without a DOM (mini-programs); see `createChart` for the GPU version of\n * the web.\n */\nexport const createCanvasChart = (\n config: CanvasChartConfig,\n): CanvasChartInstance => {\n const { canvas } = config;\n const ctx = canvas.getContext(\"2d\") as CanvasRenderingContext2D | null;\n let width = config.width;\n let height = config.height;\n let dpr = config.pixelRatio ?? 1;\n let destroyed = false;\n let frameId: number | null = null;\n let items: RenderItem[] = [];\n let itemsModel: unknown = null;\n let origin: Origin = { x: 0, y: 0 };\n let version = 0;\n let fontSet = \"\";\n\n const measureText = (text: string, f: string) => {\n if (!ctx) return text.length * 6.5;\n if (f !== fontSet) {\n ctx.font = f;\n fontSet = f;\n }\n return ctx.measureText(text).width;\n };\n\n const painter = ctx ? createCanvas2dPainter(ctx) : null;\n\n const g = globalThis as {\n requestAnimationFrame?: (cb: () => void) => number;\n cancelAnimationFrame?: (id: number) => void;\n };\n\n const render = () => {\n frameId = null;\n if (destroyed || !ctx || !painter) return;\n const scene = controller.getScene();\n if (!scene) return;\n const pw = Math.max(1, Math.round(width * dpr));\n const ph = Math.max(1, Math.round(height * dpr));\n if (canvas.width !== pw) canvas.width = pw;\n if (canvas.height !== ph) canvas.height = ph;\n fontSet = \"\";\n if (itemsModel !== scene.model) {\n itemsModel = scene.model;\n origin = { x: mid(scene.model.base.x), y: mid(scene.model.base.y) };\n items = buildItems(scene.model, origin, ++version);\n }\n drawScene(ctx, scene, items, origin, dpr, painter);\n fontSet = \"\";\n };\n\n const schedule = () => {\n if (destroyed || frameId !== null) return;\n if (canvas.requestAnimationFrame)\n frameId = canvas.requestAnimationFrame(render);\n else if (g.requestAnimationFrame) frameId = g.requestAnimationFrame(render);\n else frameId = setTimeout(render, 16) as unknown as number;\n };\n\n const controller = createChartController({\n options: config.options,\n theme: config.theme,\n measureText,\n onInvalidate: schedule,\n });\n controller.setSize(width, height);\n\n const touchOptions = (t: ChartTouch, i: number): ChartPointerOptions => ({\n id: t.identifier ?? i,\n touch: true,\n });\n\n return {\n setOptions: (o) => controller.setOptions(o),\n setTheme: (t) => controller.setTheme(t),\n resize(w, h, ratio) {\n width = w;\n height = h;\n if (ratio) dpr = ratio;\n controller.setSize(w, h);\n schedule();\n },\n render() {\n if (frameId !== null) {\n if (canvas.cancelAnimationFrame) canvas.cancelAnimationFrame(frameId);\n else if (g.cancelAnimationFrame) g.cancelAnimationFrame(frameId);\n else clearTimeout(frameId);\n }\n render();\n },\n touchStart(touches) {\n touches.forEach((t, i) =>\n controller.pointerDown(t.x, t.y, touchOptions(t, i)),\n );\n },\n touchMove(touches) {\n touches.forEach((t, i) =>\n controller.pointerMove(t.x, t.y, touchOptions(t, i)),\n );\n },\n touchEnd(touches) {\n touches.forEach((t, i) =>\n controller.pointerUp(t.x, t.y, touchOptions(t, i)),\n );\n },\n touchCancel(touches = [{ x: 0, y: 0 }]) {\n touches.forEach((t, i) => controller.pointerCancel(touchOptions(t, i)));\n },\n pointerDown: (x, y, o) => controller.pointerDown(x, y, o),\n pointerMove: (x, y, o) => controller.pointerMove(x, y, o),\n pointerUp: (x, y, o) => controller.pointerUp(x, y, o),\n pointerLeave: () => controller.pointerLeave(),\n zoomAt: (x, y, f) => controller.zoomAt(x, y, f),\n resetZoom: () => controller.resetZoom(),\n getView: () => controller.getView(),\n setView: (v) => controller.setView(v),\n toggleSeries: (id) => controller.toggleSeries(id),\n clearHover: () => controller.clearHover(),\n getPlotRect: () => controller.getPlotRect(),\n toPixel: (x, y) => controller.toPixel(x, y),\n fromPixel: (x, y) => controller.fromPixel(x, y),\n getController: () => controller,\n on: (type, listener) => controller.on(type, listener),\n destroy() {\n if (destroyed) return;\n destroyed = true;\n if (frameId !== null) {\n if (canvas.cancelAnimationFrame) canvas.cancelAnimationFrame(frameId);\n else if (g.cancelAnimationFrame) g.cancelAnimationFrame(frameId);\n else clearTimeout(frameId);\n }\n painter?.destroy();\n controller.destroy();\n },\n };\n};\n"],"mappings":"uJA4FA,IAAMU,EAAO,IAAyBC,EAAE,GAAKA,EAAE,IAAM,EAE/CC,GACJ,EACA,EACA,EACA,EACA,EACA,IACG,CACHC,EAAI,UAAU,EACdA,EAAI,OAAOC,EAAIH,EAAGI,CAAC,EACnBF,EAAI,OAA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AU,CAAC,CAAE,EAAG,EAAG,EAAG,CAAE,CAAC,EAAG,CACtCE,EAAQ,SAAS,EAAG,IAAMR,EAAW,cAAcI,EAAaC,EAAGC,CAAC,CAAC,CAAC,CACxE,EACA,aAAc,EAAG,EAAG,IAAMN,EAAW,YAAYzD,EAAGC,EAAGkB,CAAC,EACxD,aAAc,EAAG,EAAG,IAAMsC,EAAW,YAAYzD,EAAGC,EAAGkB,CAAC,EACxD,WAAY,EAAG,EAAG,IAAMsC,EAAW,UAAUzD,EAAGC,EAAGkB,CAAC,EACpD,iBAAoBsC,EAAW,aAAa,EAC5C,QAAS,EAAG,EAAG,IAAMA,EAAW,OAAOzD,EAAGC,EAAGoD,CAAC,EAC9C,cAAiBI,EAAW,UAAU,EACtC,YAAeA,EAAW,QAAQ,EAClC,QAAU,GAAMA,EAAW,QAAQS,CAAC,EACpC,aAAe,GAAOT,EAAW,aAAaU,CAAE,EAChD,eAAkBV,EAAW,WAAW,EACxC,gBAAmBA,EAAW,YAAY,EAC1C,SAAU,EAAG,IAAMA,EAAW,QAAQzD,EAAGC,CAAC,EAC1C,WAAY,EAAG,IAAMwD,EAAW,UAAUzD,EAAGC,CAAC,EAC9C,kBAAqBwD,EACrB,IAAK,EAAM,IAAaA,EAAW,GAAGW,EAAMC,CAAQ,EACpD,SAAU,CACJtB,IACJ,EAAY,GACRC,IAAY,OACVF,EAAO,qBAAsBA,EAAO,qBAAqBE,CAAO,EAC3DO,EAAE,qBAAsBA,EAAE,qBAAqBP,CAAO,EAC1D,aAAaA,CAAO,GAE3BrB,GAAS,QAAQ,EACjB8B,EAAW,QAAQ,EACrB,CACF,CACF"}
1
+ {"version":3,"file":"canvas.cjs","names":["createCanvas2dPainter","font","toCss","itemsSignature","buildItems","createChartController","require_color","require_items","require_overlay","require_canvas2d","require_signature","require_controller","mid","r","roundedRect","ctx","x","y","w","h","drawScene","scene","layout","dpr","pixelRatio","width","height","model","theme","e","cy","mark","scale","s","range","offset","o","reverse","xScale","xOffset","view","origin","yScale","yOffset","painter","items","plot","label","box","hover","cx","d","tip","padding","lineHeight","left","right","line","content","row","createCanvasChart","config","canvas","destroyed","frameId","itemsModel","itemsKey","options","themeIds","themeCount","themeId","id","version","fontSet","measureText","f","text","g","render","controller","pw","ph","key","index","schedule","touchOptions","t","i","ratio","touches","v","type","listener"],"sources":["../../../../charts/src/engine/canvas.ts"],"sourcesContent":["// createCanvasChart: a whole chart drawn on one 2D canvas without any DOM:\n// WeChat / Alipay / ByteDance mini-programs (`<canvas type=\"2d\">`), Taro,\n// uni-app, OffscreenCanvas, or a plain browser canvas. The host forwards\n// touches / pointer events; everything else is handled here.\n\nimport { toCss } from \"./color\";\nimport {\n createChartController,\n type ChartController,\n type ChartControllerEventMap,\n type ChartPointerOptions,\n type ChartScene,\n} from \"./controller\";\nimport { buildItems, type Origin } from \"./items\";\nimport { drawBackground, drawForeground, font } from \"./overlay\";\nimport { createCanvas2dPainter } from \"./renderers/canvas2d\";\nimport type { RenderItem } from \"./renderers/types\";\nimport { itemsSignature } from \"./signature\";\nimport type { ChartThemeInput } from \"./theme\";\nimport type { ChartOptions, ChartRect, ChartView } from \"./types\";\n\n/**\n * The canvas a chart draws on: a browser `HTMLCanvasElement`, an\n * `OffscreenCanvas` or the node of a mini-program `<canvas type=\"2d\">`\n * (`SelectorQuery.fields({ node: true })`)\n */\nexport interface ChartCanvas {\n width: number;\n height: number;\n getContext(type: \"2d\"): unknown;\n /** Mini-program canvases schedule their frames themselves */\n requestAnimationFrame?: (callback: () => void) => number;\n cancelAnimationFrame?: (id: number) => void;\n}\n\n/** A touch point relative to the canvas (`x` / `y`) with its identifier */\nexport interface ChartTouch {\n x: number;\n y: number;\n identifier?: number;\n}\n\nexport interface CanvasChartConfig {\n canvas: ChartCanvas;\n /** Size of the canvas in CSS pixels (rpx converted by the host) */\n width: number;\n height: number;\n /**\n * Device pixel ratio (`wx.getWindowInfo().pixelRatio` in mini-programs)\n * @default 1\n */\n pixelRatio?: number;\n options: ChartOptions;\n /** Colors and fonts: values of the Minerva CSS variables */\n theme?: ChartThemeInput;\n}\n\nexport interface CanvasChartInstance {\n setOptions(options: ChartOptions): void;\n setTheme(theme: ChartThemeInput | undefined): void;\n /** New CSS size (and pixel ratio) of the canvas */\n resize(width: number, height: number, pixelRatio?: number): void;\n /** Draws now (frames are otherwise scheduled automatically) */\n render(): void;\n /** Touch handlers: pass the `touches` / `changedTouches` of the event */\n touchStart(touches: readonly ChartTouch[]): void;\n touchMove(touches: readonly ChartTouch[]): void;\n touchEnd(changedTouches: readonly ChartTouch[]): void;\n touchCancel(changedTouches?: readonly ChartTouch[]): void;\n /** Mouse / pen handlers (H5, desktop mini-programs) */\n pointerDown(x: number, y: number, options?: ChartPointerOptions): void;\n pointerMove(x: number, y: number, options?: ChartPointerOptions): void;\n pointerUp(x: number, y: number, options?: ChartPointerOptions): void;\n pointerLeave(): void;\n /** Zooms around a pixel (factor < 1 zooms in) */\n zoomAt(x: number, y: number, factor: number): void;\n resetZoom(): void;\n getView(): ChartView;\n setView(view: Partial<ChartView>): void;\n toggleSeries(id: string): void;\n clearHover(): void;\n getPlotRect(): ChartRect | null;\n toPixel(x: number, y: number): { x: number; y: number } | null;\n fromPixel(x: number, y: number): { x: number; y: number } | null;\n /** The platform-free controller (scene, gestures) */\n getController(): ChartController;\n on<K extends keyof ChartControllerEventMap>(\n type: K,\n listener: (event: ChartControllerEventMap[K]) => void,\n ): () => void;\n destroy(): void;\n}\n\nconst mid = (r: [number, number]) => (r[0] + r[1]) / 2;\n\nconst roundedRect = (\n ctx: CanvasRenderingContext2D,\n x: number,\n y: number,\n w: number,\n h: number,\n r: number,\n) => {\n ctx.beginPath();\n ctx.moveTo(x + r, y);\n ctx.lineTo(x + w - r, y);\n ctx.arcTo(x + w, y, x + w, y + r, r);\n ctx.lineTo(x + w, y + h - r);\n ctx.arcTo(x + w, y + h, x + w - r, y + h, r);\n ctx.lineTo(x + r, y + h);\n ctx.arcTo(x, y + h, x, y + h - r, r);\n ctx.lineTo(x, y + r);\n ctx.arcTo(x, y, x + r, y, r);\n ctx.closePath();\n};\n\n/** Draws a scene (legend, axes, data, labels, hover) on a 2D context */\nexport const drawScene = (\n ctx: CanvasRenderingContext2D,\n scene: ChartScene,\n items: readonly RenderItem[],\n origin: Origin,\n pixelRatio: number,\n painter = createCanvas2dPainter(ctx),\n) => {\n const { width, height, theme, model, view, layout } = scene;\n const { plot, scales } = layout;\n const dpr = pixelRatio;\n ctx.setTransform(1, 0, 0, 1, 0, 0);\n ctx.clearRect(0, 0, Math.ceil(width * dpr), Math.ceil(height * dpr));\n ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n drawBackground(ctx, {\n width,\n height,\n scales,\n x: model.x,\n y: model.y,\n xTicks: layout.xTicks,\n yTicks: layout.yTicks,\n theme,\n annotations: scene.annotations,\n });\n\n // legend\n if (scene.legend) {\n ctx.font = font(theme, 12);\n ctx.textBaseline = \"middle\";\n ctx.textAlign = \"left\";\n for (const e of scene.legend.entries) {\n const cy = e.box.y + e.box.height / 2;\n ctx.globalAlpha = e.hidden ? 0.45 : 1;\n ctx.fillStyle = e.color;\n if (e.shape === \"dot\") {\n ctx.beginPath();\n ctx.arc(e.box.x + 5, cy, 4, 0, Math.PI * 2);\n ctx.fill();\n } else if (e.shape === \"line\") {\n ctx.fillRect(e.box.x, cy - 1, 10, 2);\n } else {\n ctx.fillRect(e.box.x + 1, cy - 4, 8, 8);\n }\n ctx.fillStyle = toCss(theme.textMuted);\n ctx.fillText(e.name, e.box.x + 14, cy);\n if (e.hidden) {\n const w = e.box.width - 22;\n ctx.fillRect(e.box.x + 14, cy, w, 1);\n }\n }\n ctx.globalAlpha = 1;\n }\n\n // hover band of bars, below the data\n for (const mark of scene.hover?.marks ?? []) {\n if (mark.kind !== \"band\") continue;\n roundedRect(ctx, mark.x, mark.y, mark.width, mark.height, 6);\n ctx.fillStyle = toCss(theme.text, 0.06);\n ctx.fill();\n }\n\n // data\n const scale = (range: [number, number], o: number, reverse: boolean) => {\n const s = 2 / (range[1] - range[0]);\n const offset = (o - range[0]) * s - 1;\n return reverse ? [-s, -offset] : [s, offset];\n };\n const [xScale, xOffset] = scale(view.x, origin.x, model.x.reverse);\n const [yScale, yOffset] = scale(view.y, origin.y, model.y.reverse);\n painter.paint(\n items,\n {\n transform: { xScale, xOffset, yScale, yOffset },\n width: Math.max(1, Math.round(plot.width * dpr)),\n height: Math.max(1, Math.round(plot.height * dpr)),\n dpr,\n },\n Math.round(plot.x * dpr),\n Math.round(plot.y * dpr),\n );\n\n ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n drawForeground(ctx, {\n width,\n height,\n scales,\n theme,\n annotations: scene.annotations,\n pointLabels: [],\n clear: false,\n });\n // dot labels placed by the scene\n if (scene.pointLabels.length) {\n ctx.save();\n ctx.font = font(theme);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"middle\";\n ctx.lineWidth = 3;\n ctx.lineJoin = \"round\";\n ctx.strokeStyle = toCss(theme.background, 0.9);\n ctx.fillStyle = toCss(theme.text, 0.85);\n for (const { label, box } of scene.pointLabels) {\n ctx.strokeText(label.text, box.x, box.y + box.height / 2);\n ctx.fillText(label.text, box.x, box.y + box.height / 2);\n }\n ctx.restore();\n }\n\n // hover\n const hover = scene.hover;\n if (hover) {\n if (hover.crosshairX !== null) {\n ctx.save();\n ctx.strokeStyle = toCss(theme.textMuted, 0.55);\n ctx.lineWidth = 1;\n ctx.setLineDash([3, 3]);\n ctx.beginPath();\n const cx = Math.round(hover.crosshairX) + 0.5;\n ctx.moveTo(cx, plot.y);\n ctx.lineTo(cx, plot.y + plot.height);\n ctx.stroke();\n ctx.restore();\n }\n for (const mark of hover.marks) {\n if (mark.kind === \"band\") continue;\n if (mark.kind === \"cell\") {\n roundedRect(ctx, mark.x, mark.y, mark.width, mark.height, 3);\n ctx.lineWidth = 3;\n ctx.strokeStyle = toCss(theme.background);\n ctx.stroke();\n ctx.lineWidth = 1.5;\n ctx.strokeStyle = toCss(theme.text, 0.55);\n ctx.stroke();\n continue;\n }\n ctx.beginPath();\n ctx.arc(mark.x, mark.y, mark.size / 2 + 4, 0, Math.PI * 2);\n ctx.fillStyle = mark.halo;\n ctx.fill();\n ctx.beginPath();\n ctx.arc(mark.x, mark.y, mark.size / 2 - 1, 0, Math.PI * 2);\n ctx.fillStyle = mark.color;\n ctx.fill();\n ctx.lineWidth = 2;\n ctx.strokeStyle = toCss(theme.background);\n ctx.stroke();\n }\n }\n if (scene.dragging) {\n const d = scene.dragging;\n ctx.beginPath();\n ctx.arc(d.x, d.y, d.size / 2, 0, Math.PI * 2);\n ctx.fillStyle = d.color;\n ctx.globalAlpha = 0.85;\n ctx.fill();\n ctx.globalAlpha = 1;\n ctx.lineWidth = 2;\n ctx.strokeStyle = toCss(theme.background);\n ctx.stroke();\n }\n const tip = hover?.tooltip;\n if (tip) {\n const { box, lineHeight, padding } = tip;\n ctx.save();\n ctx.shadowColor = \"rgba(15, 23, 42, 0.18)\";\n ctx.shadowBlur = 16;\n ctx.shadowOffsetY = 6;\n roundedRect(ctx, box.x, box.y, box.width, box.height, 8);\n ctx.fillStyle = toCss(theme.background);\n ctx.fill();\n ctx.restore();\n roundedRect(\n ctx,\n box.x + 0.5,\n box.y + 0.5,\n box.width - 1,\n box.height - 1,\n 8,\n );\n ctx.strokeStyle = toCss(theme.axis, 0.6);\n ctx.lineWidth = 1;\n ctx.stroke();\n ctx.textBaseline = \"middle\";\n let y = box.y + padding + lineHeight / 2;\n const left = box.x + padding + 2;\n const right = box.x + box.width - padding - 2;\n if (tip.text) {\n ctx.font = font(theme, 12);\n ctx.fillStyle = toCss(theme.text);\n ctx.textAlign = \"left\";\n for (const line of tip.text) {\n ctx.fillText(line, left, y);\n y += lineHeight;\n }\n } else {\n const { content } = tip;\n let x = left;\n if (content.titleColor) {\n ctx.fillStyle = content.titleColor;\n ctx.beginPath();\n ctx.arc(x + 4, y, 4, 0, Math.PI * 2);\n ctx.fill();\n x += 14;\n }\n ctx.font = font(theme, 12, 600);\n ctx.fillStyle = toCss(theme.text);\n ctx.textAlign = \"left\";\n ctx.fillText(content.title, x, y);\n y += lineHeight;\n for (const row of content.rows) {\n x = left;\n if (row.color) {\n ctx.fillStyle = row.color;\n ctx.beginPath();\n ctx.arc(x + 4, y, 4, 0, Math.PI * 2);\n ctx.fill();\n x += 14;\n }\n ctx.font = font(theme, 12);\n ctx.textAlign = \"left\";\n ctx.fillStyle = toCss(theme.textMuted);\n ctx.fillText(row.name, x, y);\n ctx.font = font(theme, 12, 600);\n ctx.textAlign = \"right\";\n ctx.fillStyle = toCss(theme.text);\n ctx.fillText(row.value, right, y);\n y += lineHeight;\n }\n }\n }\n};\n\n/**\n * Creates a chart drawn on a 2D canvas: line, area, bar and scatter series,\n * annotations, legend and tooltip, tap / drag / pinch gestures. Works\n * without a DOM (mini-programs); see `createChart` for the GPU version of\n * the web.\n */\nexport const createCanvasChart = (\n config: CanvasChartConfig,\n): CanvasChartInstance => {\n const { canvas } = config;\n const ctx = canvas.getContext(\"2d\") as CanvasRenderingContext2D | null;\n let width = config.width;\n let height = config.height;\n let dpr = config.pixelRatio ?? 1;\n let destroyed = false;\n let frameId: number | null = null;\n let items: RenderItem[] = [];\n let itemsModel: unknown = null;\n let itemsKey = \"\";\n let options = config.options;\n /** Ids of the themes seen (the controller replaces its theme on changes) */\n const themeIds = new WeakMap<object, number>();\n let themeCount = 0;\n const themeId = (theme: object) => {\n let id = themeIds.get(theme);\n if (id === undefined) themeIds.set(theme, (id = ++themeCount));\n return id;\n };\n let origin: Origin = { x: 0, y: 0 };\n let version = 0;\n let fontSet = \"\";\n\n const measureText = (text: string, f: string) => {\n if (!ctx) return text.length * 6.5;\n if (f !== fontSet) {\n ctx.font = f;\n fontSet = f;\n }\n return ctx.measureText(text).width;\n };\n\n const painter = ctx ? createCanvas2dPainter(ctx) : null;\n\n const g = globalThis as {\n requestAnimationFrame?: (cb: () => void) => number;\n cancelAnimationFrame?: (id: number) => void;\n };\n\n const render = () => {\n frameId = null;\n if (destroyed || !ctx || !painter) return;\n const scene = controller.getScene();\n if (!scene) return;\n const pw = Math.max(1, Math.round(width * dpr));\n const ph = Math.max(1, Math.round(height * dpr));\n if (canvas.width !== pw) canvas.width = pw;\n if (canvas.height !== ph) canvas.height = ph;\n fontSet = \"\";\n if (itemsModel !== scene.model) {\n itemsModel = scene.model;\n // a new model (any setOptions) keeps the items when nothing they\n // depend on changed\n const key = itemsSignature(\n scene.model,\n themeId(scene.theme),\n (index) => options.series[index]?.stack,\n );\n if (key !== itemsKey) {\n itemsKey = key;\n origin = { x: mid(scene.model.base.x), y: mid(scene.model.base.y) };\n items = buildItems(scene.model, origin, ++version);\n }\n }\n drawScene(ctx, scene, items, origin, dpr, painter);\n fontSet = \"\";\n };\n\n const schedule = () => {\n if (destroyed || frameId !== null) return;\n if (canvas.requestAnimationFrame)\n frameId = canvas.requestAnimationFrame(render);\n else if (g.requestAnimationFrame) frameId = g.requestAnimationFrame(render);\n else frameId = setTimeout(render, 16) as unknown as number;\n };\n\n const controller = createChartController({\n options: config.options,\n theme: config.theme,\n measureText,\n onInvalidate: schedule,\n });\n controller.setSize(width, height);\n\n const touchOptions = (t: ChartTouch, i: number): ChartPointerOptions => ({\n id: t.identifier ?? i,\n touch: true,\n });\n\n return {\n setOptions: (o) => {\n options = o;\n controller.setOptions(o);\n },\n setTheme: (t) => controller.setTheme(t),\n resize(w, h, ratio) {\n width = w;\n height = h;\n if (ratio) dpr = ratio;\n controller.setSize(w, h);\n schedule();\n },\n render() {\n if (frameId !== null) {\n if (canvas.cancelAnimationFrame) canvas.cancelAnimationFrame(frameId);\n else if (g.cancelAnimationFrame) g.cancelAnimationFrame(frameId);\n else clearTimeout(frameId);\n }\n render();\n },\n touchStart(touches) {\n touches.forEach((t, i) =>\n controller.pointerDown(t.x, t.y, touchOptions(t, i)),\n );\n },\n touchMove(touches) {\n touches.forEach((t, i) =>\n controller.pointerMove(t.x, t.y, touchOptions(t, i)),\n );\n },\n touchEnd(touches) {\n touches.forEach((t, i) =>\n controller.pointerUp(t.x, t.y, touchOptions(t, i)),\n );\n },\n touchCancel(touches = [{ x: 0, y: 0 }]) {\n touches.forEach((t, i) => controller.pointerCancel(touchOptions(t, i)));\n },\n pointerDown: (x, y, o) => controller.pointerDown(x, y, o),\n pointerMove: (x, y, o) => controller.pointerMove(x, y, o),\n pointerUp: (x, y, o) => controller.pointerUp(x, y, o),\n pointerLeave: () => controller.pointerLeave(),\n zoomAt: (x, y, f) => controller.zoomAt(x, y, f),\n resetZoom: () => controller.resetZoom(),\n getView: () => controller.getView(),\n setView: (v) => controller.setView(v),\n toggleSeries: (id) => controller.toggleSeries(id),\n clearHover: () => controller.clearHover(),\n getPlotRect: () => controller.getPlotRect(),\n toPixel: (x, y) => controller.toPixel(x, y),\n fromPixel: (x, y) => controller.fromPixel(x, y),\n getController: () => controller,\n on: (type, listener) => controller.on(type, listener),\n destroy() {\n if (destroyed) return;\n destroyed = true;\n if (frameId !== null) {\n if (canvas.cancelAnimationFrame) canvas.cancelAnimationFrame(frameId);\n else if (g.cancelAnimationFrame) g.cancelAnimationFrame(frameId);\n else clearTimeout(frameId);\n }\n painter?.destroy();\n controller.destroy();\n },\n };\n};\n"],"mappings":"oLA6FA,IAAMY,EAAO,IAAyBC,EAAE,GAAKA,EAAE,IAAM,EAE/CC,GACJ,EACA,EACA,EACA,EACA,EACA,IACG,CACHC,EAAI,UAAU,EACdA,EAAI,OAAOC,EAAIH,EAAGI,CAAC,EACnBF,EAAI,OAAOC,EAAIE,EAAIL,EAAGI,CAAC,EACvBF,EAAI,MAAMC,EAAIE,EAAGD,EAAGD,EAAIE,EAAGD,EAAIJ,EAAGA,CAAC,EACnCE,EAAI,OAAOC,EAAIE,EAAGD,EAAIE,EAAIN,CAAC,EAC3BE,EAAI,MAAMC,EAAIE,EAAGD,EAAIE,EAAGH,EAAIE,EAAIL,EAAGI,EAAIE,EAAGN,CAAC,EAC3CE,EAAI,OAAOC,EAAIH,EAAGI,EAAIE,CA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W,EACxC,gBAAmBA,EAAW,YAAY,EAC1C,SAAU,EAAG,IAAMA,EAAW,QAAQ/D,EAAGC,CAAC,EAC1C,WAAY,EAAG,IAAM8D,EAAW,UAAU/D,EAAGC,CAAC,EAC9C,kBAAqB8D,EACrB,IAAK,EAAM,IAAaA,EAAW,GAAGY,EAAMC,CAAQ,EACpD,SAAU,CACJ7B,IACJ,EAAY,GACRC,IAAY,OACVF,EAAO,qBAAsBA,EAAO,qBAAqBE,CAAO,EAC3Da,EAAE,qBAAsBA,EAAE,qBAAqBb,CAAO,EAC1D,aAAaA,CAAO,GAE3BpB,GAAS,QAAQ,EACjBmC,EAAW,QAAQ,EACrB,CACF,CACF"}
@@ -2,11 +2,12 @@ import { toCss as e } from "./color.js";
2
2
  import { buildItems as t } from "./items.js";
3
3
  import { drawBackground as n, drawForeground as r, font as i } from "./overlay.js";
4
4
  import { createCanvas2dPainter as a } from "./renderers/canvas2d.js";
5
- import { createChartController as o } from "./controller.js";
5
+ import { itemsSignature as o } from "./signature.js";
6
+ import { createChartController as s } from "./controller.js";
6
7
  //#region src/engine/canvas.ts
7
- var s = (e) => (e[0] + e[1]) / 2, c = (e, t, n, r, i, a) => {
8
+ var c = (e) => (e[0] + e[1]) / 2, l = (e, t, n, r, i, a) => {
8
9
  e.beginPath(), e.moveTo(t + a, n), e.lineTo(t + r - a, n), e.arcTo(t + r, n, t + r, n + a, a), e.lineTo(t + r, n + i - a), e.arcTo(t + r, n + i, t + r - a, n + i, a), e.lineTo(t + a, n + i), e.arcTo(t, n + i, t, n + i - a, a), e.lineTo(t, n + a), e.arcTo(t, n, t + a, n, a), e.closePath();
9
- }, l = (t, o, s, l, u, d = a(t)) => {
10
+ }, u = (t, o, s, c, u, d = a(t)) => {
10
11
  let { width: f, height: p, theme: m, model: h, view: g, layout: _ } = o, { plot: v, scales: y } = _, b = u;
11
12
  if (t.setTransform(1, 0, 0, 1, 0, 0), t.clearRect(0, 0, Math.ceil(f * b), Math.ceil(p * b)), t.setTransform(b, 0, 0, b, 0, 0), n(t, {
12
13
  width: f,
@@ -29,10 +30,11 @@ var s = (e) => (e[0] + e[1]) / 2, c = (e, t, n, r, i, a) => {
29
30
  }
30
31
  t.globalAlpha = 1;
31
32
  }
33
+ for (let n of o.hover?.marks ?? []) n.kind === "band" && (l(t, n.x, n.y, n.width, n.height, 6), t.fillStyle = e(m.text, .06), t.fill());
32
34
  let x = (e, t, n) => {
33
35
  let r = 2 / (e[1] - e[0]), i = (t - e[0]) * r - 1;
34
36
  return n ? [-r, -i] : [r, i];
35
- }, [S, C] = x(g.x, l.x, h.x.reverse), [w, T] = x(g.y, l.y, h.y.reverse);
37
+ }, [S, C] = x(g.x, c.x, h.x.reverse), [w, T] = x(g.y, c.y, h.y.reverse);
36
38
  if (d.paint(s, {
37
39
  transform: {
38
40
  xScale: S,
@@ -63,12 +65,12 @@ var s = (e) => (e[0] + e[1]) / 2, c = (e, t, n, r, i, a) => {
63
65
  let n = Math.round(E.crosshairX) + .5;
64
66
  t.moveTo(n, v.y), t.lineTo(n, v.y + v.height), t.stroke(), t.restore();
65
67
  }
66
- for (let n of E.marks) {
67
- if (n.kind === "bar") {
68
- t.fillStyle = e(m.text, .08), t.fillRect(n.x - 2, n.y - 2, n.width + 4, n.height + 2);
68
+ for (let n of E.marks) if (n.kind !== "band") {
69
+ if (n.kind === "cell") {
70
+ l(t, n.x, n.y, n.width, n.height, 3), t.lineWidth = 3, t.strokeStyle = e(m.background), t.stroke(), t.lineWidth = 1.5, t.strokeStyle = e(m.text, .55), t.stroke();
69
71
  continue;
70
72
  }
71
- t.beginPath(), t.arc(n.x, n.y, n.size / 2, 0, Math.PI * 2), t.fillStyle = n.color, t.fill(), t.lineWidth = 2, t.strokeStyle = e(m.background), t.stroke();
73
+ t.beginPath(), t.arc(n.x, n.y, n.size / 2 + 4, 0, Math.PI * 2), t.fillStyle = n.halo, t.fill(), t.beginPath(), t.arc(n.x, n.y, n.size / 2 - 1, 0, Math.PI * 2), t.fillStyle = n.color, t.fill(), t.lineWidth = 2, t.strokeStyle = e(m.background), t.stroke();
72
74
  }
73
75
  }
74
76
  if (o.dragging) {
@@ -78,88 +80,98 @@ var s = (e) => (e[0] + e[1]) / 2, c = (e, t, n, r, i, a) => {
78
80
  let D = E?.tooltip;
79
81
  if (D) {
80
82
  let { box: n, lineHeight: r, padding: a } = D;
81
- t.save(), t.shadowColor = "rgba(15, 23, 42, 0.18)", t.shadowBlur = 16, t.shadowOffsetY = 6, c(t, n.x, n.y, n.width, n.height, 8), t.fillStyle = e(m.background), t.fill(), t.restore(), c(t, n.x + .5, n.y + .5, n.width - 1, n.height - 1, 8), t.strokeStyle = e(m.axis), t.lineWidth = 1, t.stroke(), t.textBaseline = "middle";
82
- let o = n.y + a + r / 2, s = n.x + a + 2, l = n.x + n.width - a - 2;
83
+ t.save(), t.shadowColor = "rgba(15, 23, 42, 0.18)", t.shadowBlur = 16, t.shadowOffsetY = 6, l(t, n.x, n.y, n.width, n.height, 8), t.fillStyle = e(m.background), t.fill(), t.restore(), l(t, n.x + .5, n.y + .5, n.width - 1, n.height - 1, 8), t.strokeStyle = e(m.axis, .6), t.lineWidth = 1, t.stroke(), t.textBaseline = "middle";
84
+ let o = n.y + a + r / 2, s = n.x + a + 2, c = n.x + n.width - a - 2;
83
85
  if (D.text) {
84
86
  t.font = i(m, 12), t.fillStyle = e(m.text), t.textAlign = "left";
85
87
  for (let e of D.text) t.fillText(e, s, o), o += r;
86
88
  } else {
87
89
  let { content: n } = D, a = s;
88
90
  n.titleColor && (t.fillStyle = n.titleColor, t.beginPath(), t.arc(a + 4, o, 4, 0, Math.PI * 2), t.fill(), a += 14), t.font = i(m, 12, 600), t.fillStyle = e(m.text), t.textAlign = "left", t.fillText(n.title, a, o), o += r;
89
- for (let c of n.rows) a = s, c.color && (t.fillStyle = c.color, t.beginPath(), t.arc(a + 4, o, 4, 0, Math.PI * 2), t.fill(), a += 14), t.font = i(m, 12), t.textAlign = "left", t.fillStyle = e(m.textMuted), t.fillText(c.name, a, o), t.font = i(m, 12, 600), t.textAlign = "right", t.fillStyle = e(m.text), t.fillText(c.value, l, o), o += r;
91
+ for (let l of n.rows) a = s, l.color && (t.fillStyle = l.color, t.beginPath(), t.arc(a + 4, o, 4, 0, Math.PI * 2), t.fill(), a += 14), t.font = i(m, 12), t.textAlign = "left", t.fillStyle = e(m.textMuted), t.fillText(l.name, a, o), t.font = i(m, 12, 600), t.textAlign = "right", t.fillStyle = e(m.text), t.fillText(l.value, c, o), o += r;
90
92
  }
91
93
  }
92
- }, u = (e) => {
93
- let { canvas: n } = e, r = n.getContext("2d"), i = e.width, c = e.height, u = e.pixelRatio ?? 1, d = !1, f = null, p = [], m = null, h = {
94
+ }, d = (e) => {
95
+ let { canvas: n } = e, r = n.getContext("2d"), i = e.width, l = e.height, d = e.pixelRatio ?? 1, f = !1, p = null, m = [], h = null, g = "", _ = e.options, v = /* @__PURE__ */ new WeakMap(), y = 0, b = (e) => {
96
+ let t = v.get(e);
97
+ return t === void 0 && v.set(e, t = ++y), t;
98
+ }, x = {
94
99
  x: 0,
95
100
  y: 0
96
- }, g = 0, _ = "", v = (e, t) => r ? (t !== _ && (r.font = t, _ = t), r.measureText(e).width) : e.length * 6.5, y = r ? a(r) : null, b = globalThis, x = () => {
97
- if (f = null, d || !r || !y) return;
98
- let e = C.getScene();
101
+ }, S = 0, C = "", w = (e, t) => r ? (t !== C && (r.font = t, C = t), r.measureText(e).width) : e.length * 6.5, T = r ? a(r) : null, E = globalThis, D = () => {
102
+ if (p = null, f || !r || !T) return;
103
+ let e = k.getScene();
99
104
  if (!e) return;
100
- let a = Math.max(1, Math.round(i * u)), o = Math.max(1, Math.round(c * u));
101
- n.width !== a && (n.width = a), n.height !== o && (n.height = o), _ = "", m !== e.model && (m = e.model, h = {
102
- x: s(e.model.base.x),
103
- y: s(e.model.base.y)
104
- }, p = t(e.model, h, ++g)), l(r, e, p, h, u, y), _ = "";
105
- }, S = () => {
106
- d || f !== null || (f = n.requestAnimationFrame ? n.requestAnimationFrame(x) : b.requestAnimationFrame ? b.requestAnimationFrame(x) : setTimeout(x, 16));
107
- }, C = o({
105
+ let a = Math.max(1, Math.round(i * d)), s = Math.max(1, Math.round(l * d));
106
+ if (n.width !== a && (n.width = a), n.height !== s && (n.height = s), C = "", h !== e.model) {
107
+ h = e.model;
108
+ let n = o(e.model, b(e.theme), (e) => _.series[e]?.stack);
109
+ n !== g && (g = n, x = {
110
+ x: c(e.model.base.x),
111
+ y: c(e.model.base.y)
112
+ }, m = t(e.model, x, ++S));
113
+ }
114
+ u(r, e, m, x, d, T), C = "";
115
+ }, O = () => {
116
+ f || p !== null || (p = n.requestAnimationFrame ? n.requestAnimationFrame(D) : E.requestAnimationFrame ? E.requestAnimationFrame(D) : setTimeout(D, 16));
117
+ }, k = s({
108
118
  options: e.options,
109
119
  theme: e.theme,
110
- measureText: v,
111
- onInvalidate: S
120
+ measureText: w,
121
+ onInvalidate: O
112
122
  });
113
- C.setSize(i, c);
114
- let w = (e, t) => ({
123
+ k.setSize(i, l);
124
+ let A = (e, t) => ({
115
125
  id: e.identifier ?? t,
116
126
  touch: !0
117
127
  });
118
128
  return {
119
- setOptions: (e) => C.setOptions(e),
120
- setTheme: (e) => C.setTheme(e),
129
+ setOptions: (e) => {
130
+ _ = e, k.setOptions(e);
131
+ },
132
+ setTheme: (e) => k.setTheme(e),
121
133
  resize(e, t, n) {
122
- i = e, c = t, n && (u = n), C.setSize(e, t), S();
134
+ i = e, l = t, n && (d = n), k.setSize(e, t), O();
123
135
  },
124
136
  render() {
125
- f !== null && (n.cancelAnimationFrame ? n.cancelAnimationFrame(f) : b.cancelAnimationFrame ? b.cancelAnimationFrame(f) : clearTimeout(f)), x();
137
+ p !== null && (n.cancelAnimationFrame ? n.cancelAnimationFrame(p) : E.cancelAnimationFrame ? E.cancelAnimationFrame(p) : clearTimeout(p)), D();
126
138
  },
127
139
  touchStart(e) {
128
- e.forEach((e, t) => C.pointerDown(e.x, e.y, w(e, t)));
140
+ e.forEach((e, t) => k.pointerDown(e.x, e.y, A(e, t)));
129
141
  },
130
142
  touchMove(e) {
131
- e.forEach((e, t) => C.pointerMove(e.x, e.y, w(e, t)));
143
+ e.forEach((e, t) => k.pointerMove(e.x, e.y, A(e, t)));
132
144
  },
133
145
  touchEnd(e) {
134
- e.forEach((e, t) => C.pointerUp(e.x, e.y, w(e, t)));
146
+ e.forEach((e, t) => k.pointerUp(e.x, e.y, A(e, t)));
135
147
  },
136
148
  touchCancel(e = [{
137
149
  x: 0,
138
150
  y: 0
139
151
  }]) {
140
- e.forEach((e, t) => C.pointerCancel(w(e, t)));
152
+ e.forEach((e, t) => k.pointerCancel(A(e, t)));
141
153
  },
142
- pointerDown: (e, t, n) => C.pointerDown(e, t, n),
143
- pointerMove: (e, t, n) => C.pointerMove(e, t, n),
144
- pointerUp: (e, t, n) => C.pointerUp(e, t, n),
145
- pointerLeave: () => C.pointerLeave(),
146
- zoomAt: (e, t, n) => C.zoomAt(e, t, n),
147
- resetZoom: () => C.resetZoom(),
148
- getView: () => C.getView(),
149
- setView: (e) => C.setView(e),
150
- toggleSeries: (e) => C.toggleSeries(e),
151
- clearHover: () => C.clearHover(),
152
- getPlotRect: () => C.getPlotRect(),
153
- toPixel: (e, t) => C.toPixel(e, t),
154
- fromPixel: (e, t) => C.fromPixel(e, t),
155
- getController: () => C,
156
- on: (e, t) => C.on(e, t),
154
+ pointerDown: (e, t, n) => k.pointerDown(e, t, n),
155
+ pointerMove: (e, t, n) => k.pointerMove(e, t, n),
156
+ pointerUp: (e, t, n) => k.pointerUp(e, t, n),
157
+ pointerLeave: () => k.pointerLeave(),
158
+ zoomAt: (e, t, n) => k.zoomAt(e, t, n),
159
+ resetZoom: () => k.resetZoom(),
160
+ getView: () => k.getView(),
161
+ setView: (e) => k.setView(e),
162
+ toggleSeries: (e) => k.toggleSeries(e),
163
+ clearHover: () => k.clearHover(),
164
+ getPlotRect: () => k.getPlotRect(),
165
+ toPixel: (e, t) => k.toPixel(e, t),
166
+ fromPixel: (e, t) => k.fromPixel(e, t),
167
+ getController: () => k,
168
+ on: (e, t) => k.on(e, t),
157
169
  destroy() {
158
- d || (d = !0, f !== null && (n.cancelAnimationFrame ? n.cancelAnimationFrame(f) : b.cancelAnimationFrame ? b.cancelAnimationFrame(f) : clearTimeout(f)), y?.destroy(), C.destroy());
170
+ f || (f = !0, p !== null && (n.cancelAnimationFrame ? n.cancelAnimationFrame(p) : E.cancelAnimationFrame ? E.cancelAnimationFrame(p) : clearTimeout(p)), T?.destroy(), k.destroy());
159
171
  }
160
172
  };
161
173
  };
162
174
  //#endregion
163
- export { u as createCanvasChart, l as drawScene };
175
+ export { d as createCanvasChart, u as drawScene };
164
176
 
165
177
  //# sourceMappingURL=canvas.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"canvas.js","names":["mid","r","roundedRect","ctx","x","y","w","h","drawScene","createCanvas2dPainter","scene","layout","dpr","pixelRatio","width","height","drawBackground","model","font","theme","e","cy","toCss","scale","s","range","offset","o","reverse","xScale","xOffset","view","origin","yScale","yOffset","painter","items","plot","drawForeground","label","box","hover","cx","mark","d","tip","padding","lineHeight","left","right","line","content","row","createCanvasChart","config","canvas","destroyed","frameId","itemsModel","version","fontSet","measureText","f","text","g","render","controller","pw","ph","buildItems","schedule","createChartController","touchOptions","t","i","ratio","v","id","type","listener"],"sources":["../../../../charts/src/engine/canvas.ts"],"sourcesContent":["// createCanvasChart: a whole chart drawn on one 2D canvas without any DOM:\n// WeChat / Alipay / ByteDance mini-programs (`<canvas type=\"2d\">`), Taro,\n// uni-app, OffscreenCanvas, or a plain browser canvas. The host forwards\n// touches / pointer events; everything else is handled here.\n\nimport { toCss } from \"./color\";\nimport {\n createChartController,\n type ChartController,\n type ChartControllerEventMap,\n type ChartPointerOptions,\n type ChartScene,\n} from \"./controller\";\nimport { buildItems, type Origin } from \"./items\";\nimport { drawBackground, drawForeground, font } from \"./overlay\";\nimport { createCanvas2dPainter } from \"./renderers/canvas2d\";\nimport type { RenderItem } from \"./renderers/types\";\nimport type { ChartThemeInput } from \"./theme\";\nimport type { ChartOptions, ChartRect, ChartView } from \"./types\";\n\n/**\n * The canvas a chart draws on: a browser `HTMLCanvasElement`, an\n * `OffscreenCanvas` or the node of a mini-program `<canvas type=\"2d\">`\n * (`SelectorQuery.fields({ node: true })`)\n */\nexport interface ChartCanvas {\n width: number;\n height: number;\n getContext(type: \"2d\"): unknown;\n /** Mini-program canvases schedule their frames themselves */\n requestAnimationFrame?: (callback: () => void) => number;\n cancelAnimationFrame?: (id: number) => void;\n}\n\n/** A touch point relative to the canvas (`x` / `y`) with its identifier */\nexport interface ChartTouch {\n x: number;\n y: number;\n identifier?: number;\n}\n\nexport interface CanvasChartConfig {\n canvas: ChartCanvas;\n /** Size of the canvas in CSS pixels (rpx converted by the host) */\n width: number;\n height: number;\n /**\n * Device pixel ratio (`wx.getWindowInfo().pixelRatio` in mini-programs)\n * @default 1\n */\n pixelRatio?: number;\n options: ChartOptions;\n /** Colors and fonts: values of the Minerva CSS variables */\n theme?: ChartThemeInput;\n}\n\nexport interface CanvasChartInstance {\n setOptions(options: ChartOptions): void;\n setTheme(theme: ChartThemeInput | undefined): void;\n /** New CSS size (and pixel ratio) of the canvas */\n resize(width: number, height: number, pixelRatio?: number): void;\n /** Draws now (frames are otherwise scheduled automatically) */\n render(): void;\n /** Touch handlers: pass the `touches` / `changedTouches` of the event */\n touchStart(touches: readonly ChartTouch[]): void;\n touchMove(touches: readonly ChartTouch[]): void;\n touchEnd(changedTouches: readonly ChartTouch[]): void;\n touchCancel(changedTouches?: readonly ChartTouch[]): void;\n /** Mouse / pen handlers (H5, desktop mini-programs) */\n pointerDown(x: number, y: number, options?: ChartPointerOptions): void;\n pointerMove(x: number, y: number, options?: ChartPointerOptions): void;\n pointerUp(x: number, y: number, options?: ChartPointerOptions): void;\n pointerLeave(): void;\n /** Zooms around a pixel (factor < 1 zooms in) */\n zoomAt(x: number, y: number, factor: number): void;\n resetZoom(): void;\n getView(): ChartView;\n setView(view: Partial<ChartView>): void;\n toggleSeries(id: string): void;\n clearHover(): void;\n getPlotRect(): ChartRect | null;\n toPixel(x: number, y: number): { x: number; y: number } | null;\n fromPixel(x: number, y: number): { x: number; y: number } | null;\n /** The platform-free controller (scene, gestures) */\n getController(): ChartController;\n on<K extends keyof ChartControllerEventMap>(\n type: K,\n listener: (event: ChartControllerEventMap[K]) => void,\n ): () => void;\n destroy(): void;\n}\n\nconst mid = (r: [number, number]) => (r[0] + r[1]) / 2;\n\nconst roundedRect = (\n ctx: CanvasRenderingContext2D,\n x: number,\n y: number,\n w: number,\n h: number,\n r: number,\n) => {\n ctx.beginPath();\n ctx.moveTo(x + r, y);\n ctx.lineTo(x + w - r, y);\n ctx.arcTo(x + w, y, x + w, y + r, r);\n ctx.lineTo(x + w, y + h - r);\n ctx.arcTo(x + w, y + h, x + w - r, y + h, r);\n ctx.lineTo(x + r, y + h);\n ctx.arcTo(x, y + h, x, y + h - r, r);\n ctx.lineTo(x, y + r);\n ctx.arcTo(x, y, x + r, y, r);\n ctx.closePath();\n};\n\n/** Draws a scene (legend, axes, data, labels, hover) on a 2D context */\nexport const drawScene = (\n ctx: CanvasRenderingContext2D,\n scene: ChartScene,\n items: readonly RenderItem[],\n origin: Origin,\n pixelRatio: number,\n painter = createCanvas2dPainter(ctx),\n) => {\n const { width, height, theme, model, view, layout } = scene;\n const { plot, scales } = layout;\n const dpr = pixelRatio;\n ctx.setTransform(1, 0, 0, 1, 0, 0);\n ctx.clearRect(0, 0, Math.ceil(width * dpr), Math.ceil(height * dpr));\n ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n drawBackground(ctx, {\n width,\n height,\n scales,\n x: model.x,\n y: model.y,\n xTicks: layout.xTicks,\n yTicks: layout.yTicks,\n theme,\n annotations: scene.annotations,\n });\n\n // legend\n if (scene.legend) {\n ctx.font = font(theme, 12);\n ctx.textBaseline = \"middle\";\n ctx.textAlign = \"left\";\n for (const e of scene.legend.entries) {\n const cy = e.box.y + e.box.height / 2;\n ctx.globalAlpha = e.hidden ? 0.45 : 1;\n ctx.fillStyle = e.color;\n if (e.shape === \"dot\") {\n ctx.beginPath();\n ctx.arc(e.box.x + 5, cy, 4, 0, Math.PI * 2);\n ctx.fill();\n } else if (e.shape === \"line\") {\n ctx.fillRect(e.box.x, cy - 1, 10, 2);\n } else {\n ctx.fillRect(e.box.x + 1, cy - 4, 8, 8);\n }\n ctx.fillStyle = toCss(theme.textMuted);\n ctx.fillText(e.name, e.box.x + 14, cy);\n if (e.hidden) {\n const w = e.box.width - 22;\n ctx.fillRect(e.box.x + 14, cy, w, 1);\n }\n }\n ctx.globalAlpha = 1;\n }\n\n // data\n const scale = (range: [number, number], o: number, reverse: boolean) => {\n const s = 2 / (range[1] - range[0]);\n const offset = (o - range[0]) * s - 1;\n return reverse ? [-s, -offset] : [s, offset];\n };\n const [xScale, xOffset] = scale(view.x, origin.x, model.x.reverse);\n const [yScale, yOffset] = scale(view.y, origin.y, model.y.reverse);\n painter.paint(\n items,\n {\n transform: { xScale, xOffset, yScale, yOffset },\n width: Math.max(1, Math.round(plot.width * dpr)),\n height: Math.max(1, Math.round(plot.height * dpr)),\n dpr,\n },\n Math.round(plot.x * dpr),\n Math.round(plot.y * dpr),\n );\n\n ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n drawForeground(ctx, {\n width,\n height,\n scales,\n theme,\n annotations: scene.annotations,\n pointLabels: [],\n clear: false,\n });\n // dot labels placed by the scene\n if (scene.pointLabels.length) {\n ctx.save();\n ctx.font = font(theme);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"middle\";\n ctx.lineWidth = 3;\n ctx.lineJoin = \"round\";\n ctx.strokeStyle = toCss(theme.background, 0.9);\n ctx.fillStyle = toCss(theme.text, 0.85);\n for (const { label, box } of scene.pointLabels) {\n ctx.strokeText(label.text, box.x, box.y + box.height / 2);\n ctx.fillText(label.text, box.x, box.y + box.height / 2);\n }\n ctx.restore();\n }\n\n // hover\n const hover = scene.hover;\n if (hover) {\n if (hover.crosshairX !== null) {\n ctx.save();\n ctx.strokeStyle = toCss(theme.textMuted, 0.55);\n ctx.lineWidth = 1;\n ctx.setLineDash([3, 3]);\n ctx.beginPath();\n const cx = Math.round(hover.crosshairX) + 0.5;\n ctx.moveTo(cx, plot.y);\n ctx.lineTo(cx, plot.y + plot.height);\n ctx.stroke();\n ctx.restore();\n }\n for (const mark of hover.marks) {\n if (mark.kind === \"bar\") {\n ctx.fillStyle = toCss(theme.text, 0.08);\n ctx.fillRect(mark.x - 2, mark.y - 2, mark.width + 4, mark.height + 2);\n continue;\n }\n ctx.beginPath();\n ctx.arc(mark.x, mark.y, mark.size / 2, 0, Math.PI * 2);\n ctx.fillStyle = mark.color;\n ctx.fill();\n ctx.lineWidth = 2;\n ctx.strokeStyle = toCss(theme.background);\n ctx.stroke();\n }\n }\n if (scene.dragging) {\n const d = scene.dragging;\n ctx.beginPath();\n ctx.arc(d.x, d.y, d.size / 2, 0, Math.PI * 2);\n ctx.fillStyle = d.color;\n ctx.globalAlpha = 0.85;\n ctx.fill();\n ctx.globalAlpha = 1;\n ctx.lineWidth = 2;\n ctx.strokeStyle = toCss(theme.background);\n ctx.stroke();\n }\n const tip = hover?.tooltip;\n if (tip) {\n const { box, lineHeight, padding } = tip;\n ctx.save();\n ctx.shadowColor = \"rgba(15, 23, 42, 0.18)\";\n ctx.shadowBlur = 16;\n ctx.shadowOffsetY = 6;\n roundedRect(ctx, box.x, box.y, box.width, box.height, 8);\n ctx.fillStyle = toCss(theme.background);\n ctx.fill();\n ctx.restore();\n roundedRect(\n ctx,\n box.x + 0.5,\n box.y + 0.5,\n box.width - 1,\n box.height - 1,\n 8,\n );\n ctx.strokeStyle = toCss(theme.axis);\n ctx.lineWidth = 1;\n ctx.stroke();\n ctx.textBaseline = \"middle\";\n let y = box.y + padding + lineHeight / 2;\n const left = box.x + padding + 2;\n const right = box.x + box.width - padding - 2;\n if (tip.text) {\n ctx.font = font(theme, 12);\n ctx.fillStyle = toCss(theme.text);\n ctx.textAlign = \"left\";\n for (const line of tip.text) {\n ctx.fillText(line, left, y);\n y += lineHeight;\n }\n } else {\n const { content } = tip;\n let x = left;\n if (content.titleColor) {\n ctx.fillStyle = content.titleColor;\n ctx.beginPath();\n ctx.arc(x + 4, y, 4, 0, Math.PI * 2);\n ctx.fill();\n x += 14;\n }\n ctx.font = font(theme, 12, 600);\n ctx.fillStyle = toCss(theme.text);\n ctx.textAlign = \"left\";\n ctx.fillText(content.title, x, y);\n y += lineHeight;\n for (const row of content.rows) {\n x = left;\n if (row.color) {\n ctx.fillStyle = row.color;\n ctx.beginPath();\n ctx.arc(x + 4, y, 4, 0, Math.PI * 2);\n ctx.fill();\n x += 14;\n }\n ctx.font = font(theme, 12);\n ctx.textAlign = \"left\";\n ctx.fillStyle = toCss(theme.textMuted);\n ctx.fillText(row.name, x, y);\n ctx.font = font(theme, 12, 600);\n ctx.textAlign = \"right\";\n ctx.fillStyle = toCss(theme.text);\n ctx.fillText(row.value, right, y);\n y += lineHeight;\n }\n }\n }\n};\n\n/**\n * Creates a chart drawn on a 2D canvas: line, area, bar and scatter series,\n * annotations, legend and tooltip, tap / drag / pinch gestures. Works\n * without a DOM (mini-programs); see `createChart` for the GPU version of\n * the web.\n */\nexport const createCanvasChart = (\n config: CanvasChartConfig,\n): CanvasChartInstance => {\n const { canvas } = config;\n const ctx = canvas.getContext(\"2d\") as CanvasRenderingContext2D | null;\n let width = config.width;\n let height = config.height;\n let dpr = config.pixelRatio ?? 1;\n let destroyed = false;\n let frameId: number | null = null;\n let items: RenderItem[] = [];\n let itemsModel: unknown = null;\n let origin: Origin = { x: 0, y: 0 };\n let version = 0;\n let fontSet = \"\";\n\n const measureText = (text: string, f: string) => {\n if (!ctx) return text.length * 6.5;\n if (f !== fontSet) {\n ctx.font = f;\n fontSet = f;\n }\n return ctx.measureText(text).width;\n };\n\n const painter = ctx ? createCanvas2dPainter(ctx) : null;\n\n const g = globalThis as {\n requestAnimationFrame?: (cb: () => void) => number;\n cancelAnimationFrame?: (id: number) => void;\n };\n\n const render = () => {\n frameId = null;\n if (destroyed || !ctx || !painter) return;\n const scene = controller.getScene();\n if (!scene) return;\n const pw = Math.max(1, Math.round(width * dpr));\n const ph = Math.max(1, Math.round(height * dpr));\n if (canvas.width !== pw) canvas.width = pw;\n if (canvas.height !== ph) canvas.height = ph;\n fontSet = \"\";\n if (itemsModel !== scene.model) {\n itemsModel = scene.model;\n origin = { x: mid(scene.model.base.x), y: mid(scene.model.base.y) };\n items = buildItems(scene.model, origin, ++version);\n }\n drawScene(ctx, scene, items, origin, dpr, painter);\n fontSet = \"\";\n };\n\n const schedule = () => {\n if (destroyed || frameId !== null) return;\n if (canvas.requestAnimationFrame)\n frameId = canvas.requestAnimationFrame(render);\n else if (g.requestAnimationFrame) frameId = g.requestAnimationFrame(render);\n else frameId = setTimeout(render, 16) as unknown as number;\n };\n\n const controller = createChartController({\n options: config.options,\n theme: config.theme,\n measureText,\n onInvalidate: schedule,\n });\n controller.setSize(width, height);\n\n const touchOptions = (t: ChartTouch, i: number): ChartPointerOptions => ({\n id: t.identifier ?? i,\n touch: true,\n });\n\n return {\n setOptions: (o) => controller.setOptions(o),\n setTheme: (t) => controller.setTheme(t),\n resize(w, h, ratio) {\n width = w;\n height = h;\n if (ratio) dpr = ratio;\n controller.setSize(w, h);\n schedule();\n },\n render() {\n if (frameId !== null) {\n if (canvas.cancelAnimationFrame) canvas.cancelAnimationFrame(frameId);\n else if (g.cancelAnimationFrame) g.cancelAnimationFrame(frameId);\n else clearTimeout(frameId);\n }\n render();\n },\n touchStart(touches) {\n touches.forEach((t, i) =>\n controller.pointerDown(t.x, t.y, touchOptions(t, i)),\n );\n },\n touchMove(touches) {\n touches.forEach((t, i) =>\n controller.pointerMove(t.x, t.y, touchOptions(t, i)),\n );\n },\n touchEnd(touches) {\n touches.forEach((t, i) =>\n controller.pointerUp(t.x, t.y, touchOptions(t, i)),\n );\n },\n touchCancel(touches = [{ x: 0, y: 0 }]) {\n touches.forEach((t, i) => controller.pointerCancel(touchOptions(t, i)));\n },\n pointerDown: (x, y, o) => controller.pointerDown(x, y, o),\n pointerMove: (x, y, o) => controller.pointerMove(x, y, o),\n pointerUp: (x, y, o) => controller.pointerUp(x, y, o),\n pointerLeave: () => controller.pointerLeave(),\n zoomAt: (x, y, f) => controller.zoomAt(x, y, f),\n resetZoom: () => controller.resetZoom(),\n getView: () => controller.getView(),\n setView: (v) => controller.setView(v),\n toggleSeries: (id) => controller.toggleSeries(id),\n clearHover: () => controller.clearHover(),\n getPlotRect: () => controller.getPlotRect(),\n toPixel: (x, y) => controller.toPixel(x, y),\n fromPixel: (x, y) => controller.fromPixel(x, y),\n getController: () => controller,\n on: (type, listener) => controller.on(type, listener),\n destroy() {\n if (destroyed) return;\n destroyed = true;\n if (frameId !== null) {\n if (canvas.cancelAnimationFrame) canvas.cancelAnimationFrame(frameId);\n else if (g.cancelAnimationFrame) g.cancelAnimationFrame(frameId);\n else clearTimeout(frameId);\n }\n painter?.destroy();\n controller.destroy();\n },\n };\n};\n"],"mappings":";;;;;;AA4FA,IAAMA,KAAO,OAAyBC,EAAE,KAAKA,EAAE,MAAM,GAE/CC,KACJ,GACA,GACA,GACA,GACA,GACA,MACG;CAWH,AAVAC,EAAI,UAAU,GACdA,EAAI,OAAOC,IAAIH,GAAGI,CAAC,GACnBF,EAAI,OAAOC,IAAIE,IAAIL,GAAGI,CAAC,GACvBF,EAAI,MAAMC,IAAIE,GAAGD,GAAGD,IAAIE,GAAGD,IAAIJ,GAAGA,CAAC,GACnCE,EAAI,OAAOC,IAAIE,GAAGD,IAAIE,IAAIN,CAAC,GAC3BE,EAAI,MAAMC,IAAIE,GAAGD,IAAIE,GAAGH,IAAIE,IAAIL,GAAGI,IAAIE,GAAGN,CAAC,GAC3CE,EAAI,OAAOC,IAAIH,GAAGI,IAAIE,CAAC,GACvBJ,EAAI,MAAMC,GAAGC,IAAIE,GAAGH,GAAGC,IAAIE,IAAIN,GAAGA,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,QAAQ;EAClC,UAAU,MAAMA,EAAW,QAAQU,CAAC;EACpC,eAAe,MAAOV,EAAW,aAAaW,CAAE;EAChD,kBAAkBX,EAAW,WAAW;EACxC,mBAAmBA,EAAW,YAAY;EAC1C,UAAU,GAAG,MAAMA,EAAW,QAAQ9D,GAAGC,CAAC;EAC1C,YAAY,GAAG,MAAM6D,EAAW,UAAU9D,GAAGC,CAAC;EAC9C,qBAAqB6D;EACrB,KAAK,GAAM,MAAaA,EAAW,GAAGY,GAAMC,CAAQ;EACpD,UAAU;GACR,AAAIvB,MACJ,IAAY,IACRC,MAAY,SACVF,EAAO,uBAAsBA,EAAO,qBAAqBE,CAAO,IAC3DO,EAAE,uBAAsBA,EAAE,qBAAqBP,CAAO,IAC1D,aAAaA,CAAO,IAE3BtB,GAAS,QAAQ,GACjB+B,EAAW,QAAQ;EACrB;CACF;AACF"}
1
+ {"version":3,"file":"canvas.js","names":["mid","r","roundedRect","ctx","x","y","w","h","drawScene","createCanvas2dPainter","scene","layout","dpr","pixelRatio","width","height","drawBackground","model","font","theme","e","cy","toCss","mark","scale","s","range","offset","o","reverse","xScale","xOffset","view","origin","yScale","yOffset","painter","items","plot","drawForeground","label","box","hover","cx","d","tip","padding","lineHeight","left","right","line","content","row","createCanvasChart","config","canvas","destroyed","frameId","itemsModel","itemsKey","options","themeIds","themeCount","themeId","id","version","fontSet","measureText","f","text","g","render","controller","pw","ph","key","itemsSignature","index","buildItems","schedule","createChartController","touchOptions","t","i","ratio","v","type","listener"],"sources":["../../../../charts/src/engine/canvas.ts"],"sourcesContent":["// createCanvasChart: a whole chart drawn on one 2D canvas without any DOM:\n// WeChat / Alipay / ByteDance mini-programs (`<canvas type=\"2d\">`), Taro,\n// uni-app, OffscreenCanvas, or a plain browser canvas. The host forwards\n// touches / pointer events; everything else is handled here.\n\nimport { toCss } from \"./color\";\nimport {\n createChartController,\n type ChartController,\n type ChartControllerEventMap,\n type ChartPointerOptions,\n type ChartScene,\n} from \"./controller\";\nimport { buildItems, type Origin } from \"./items\";\nimport { drawBackground, drawForeground, font } from \"./overlay\";\nimport { createCanvas2dPainter } from \"./renderers/canvas2d\";\nimport type { RenderItem } from \"./renderers/types\";\nimport { itemsSignature } from \"./signature\";\nimport type { ChartThemeInput } from \"./theme\";\nimport type { ChartOptions, ChartRect, ChartView } from \"./types\";\n\n/**\n * The canvas a chart draws on: a browser `HTMLCanvasElement`, an\n * `OffscreenCanvas` or the node of a mini-program `<canvas type=\"2d\">`\n * (`SelectorQuery.fields({ node: true })`)\n */\nexport interface ChartCanvas {\n width: number;\n height: number;\n getContext(type: \"2d\"): unknown;\n /** Mini-program canvases schedule their frames themselves */\n requestAnimationFrame?: (callback: () => void) => number;\n cancelAnimationFrame?: (id: number) => void;\n}\n\n/** A touch point relative to the canvas (`x` / `y`) with its identifier */\nexport interface ChartTouch {\n x: number;\n y: number;\n identifier?: number;\n}\n\nexport interface CanvasChartConfig {\n canvas: ChartCanvas;\n /** Size of the canvas in CSS pixels (rpx converted by the host) */\n width: number;\n height: number;\n /**\n * Device pixel ratio (`wx.getWindowInfo().pixelRatio` in mini-programs)\n * @default 1\n */\n pixelRatio?: number;\n options: ChartOptions;\n /** Colors and fonts: values of the Minerva CSS variables */\n theme?: ChartThemeInput;\n}\n\nexport interface CanvasChartInstance {\n setOptions(options: ChartOptions): void;\n setTheme(theme: ChartThemeInput | undefined): void;\n /** New CSS size (and pixel ratio) of the canvas */\n resize(width: number, height: number, pixelRatio?: number): void;\n /** Draws now (frames are otherwise scheduled automatically) */\n render(): void;\n /** Touch handlers: pass the `touches` / `changedTouches` of the event */\n touchStart(touches: readonly ChartTouch[]): void;\n touchMove(touches: readonly ChartTouch[]): void;\n touchEnd(changedTouches: readonly ChartTouch[]): void;\n touchCancel(changedTouches?: readonly ChartTouch[]): void;\n /** Mouse / pen handlers (H5, desktop mini-programs) */\n pointerDown(x: number, y: number, options?: ChartPointerOptions): void;\n pointerMove(x: number, y: number, options?: ChartPointerOptions): void;\n pointerUp(x: number, y: number, options?: ChartPointerOptions): void;\n pointerLeave(): void;\n /** Zooms around a pixel (factor < 1 zooms in) */\n zoomAt(x: number, y: number, factor: number): void;\n resetZoom(): void;\n getView(): ChartView;\n setView(view: Partial<ChartView>): void;\n toggleSeries(id: string): void;\n clearHover(): void;\n getPlotRect(): ChartRect | null;\n toPixel(x: number, y: number): { x: number; y: number } | null;\n fromPixel(x: number, y: number): { x: number; y: number } | null;\n /** The platform-free controller (scene, gestures) */\n getController(): ChartController;\n on<K extends keyof ChartControllerEventMap>(\n type: K,\n listener: (event: ChartControllerEventMap[K]) => void,\n ): () => void;\n destroy(): void;\n}\n\nconst mid = (r: [number, number]) => (r[0] + r[1]) / 2;\n\nconst roundedRect = (\n ctx: CanvasRenderingContext2D,\n x: number,\n y: number,\n w: number,\n h: number,\n r: number,\n) => {\n ctx.beginPath();\n ctx.moveTo(x + r, y);\n ctx.lineTo(x + w - r, y);\n ctx.arcTo(x + w, y, x + w, y + r, r);\n ctx.lineTo(x + w, y + h - r);\n ctx.arcTo(x + w, y + h, x + w - r, y + h, r);\n ctx.lineTo(x + r, y + h);\n ctx.arcTo(x, y + h, x, y + h - r, r);\n ctx.lineTo(x, y + r);\n ctx.arcTo(x, y, x + r, y, r);\n ctx.closePath();\n};\n\n/** Draws a scene (legend, axes, data, labels, hover) on a 2D context */\nexport const drawScene = (\n ctx: CanvasRenderingContext2D,\n scene: ChartScene,\n items: readonly RenderItem[],\n origin: Origin,\n pixelRatio: number,\n painter = createCanvas2dPainter(ctx),\n) => {\n const { width, height, theme, model, view, layout } = scene;\n const { plot, scales } = layout;\n const dpr = pixelRatio;\n ctx.setTransform(1, 0, 0, 1, 0, 0);\n ctx.clearRect(0, 0, Math.ceil(width * dpr), Math.ceil(height * dpr));\n ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n drawBackground(ctx, {\n width,\n height,\n scales,\n x: model.x,\n y: model.y,\n xTicks: layout.xTicks,\n yTicks: layout.yTicks,\n theme,\n annotations: scene.annotations,\n });\n\n // legend\n if (scene.legend) {\n ctx.font = font(theme, 12);\n ctx.textBaseline = \"middle\";\n ctx.textAlign = \"left\";\n for (const e of scene.legend.entries) {\n const cy = e.box.y + e.box.height / 2;\n ctx.globalAlpha = e.hidden ? 0.45 : 1;\n ctx.fillStyle = e.color;\n if (e.shape === \"dot\") {\n ctx.beginPath();\n ctx.arc(e.box.x + 5, cy, 4, 0, Math.PI * 2);\n ctx.fill();\n } else if (e.shape === \"line\") {\n ctx.fillRect(e.box.x, cy - 1, 10, 2);\n } else {\n ctx.fillRect(e.box.x + 1, cy - 4, 8, 8);\n }\n ctx.fillStyle = toCss(theme.textMuted);\n ctx.fillText(e.name, e.box.x + 14, cy);\n if (e.hidden) {\n const w = e.box.width - 22;\n ctx.fillRect(e.box.x + 14, cy, w, 1);\n }\n }\n ctx.globalAlpha = 1;\n }\n\n // hover band of bars, below the data\n for (const mark of scene.hover?.marks ?? []) {\n if (mark.kind !== \"band\") continue;\n roundedRect(ctx, mark.x, mark.y, mark.width, mark.height, 6);\n ctx.fillStyle = toCss(theme.text, 0.06);\n ctx.fill();\n }\n\n // data\n const scale = (range: [number, number], o: number, reverse: boolean) => {\n const s = 2 / (range[1] - range[0]);\n const offset = (o - range[0]) * s - 1;\n return reverse ? [-s, -offset] : [s, offset];\n };\n const [xScale, xOffset] = scale(view.x, origin.x, model.x.reverse);\n const [yScale, yOffset] = scale(view.y, origin.y, model.y.reverse);\n painter.paint(\n items,\n {\n transform: { xScale, xOffset, yScale, yOffset },\n width: Math.max(1, Math.round(plot.width * dpr)),\n height: Math.max(1, Math.round(plot.height * dpr)),\n dpr,\n },\n Math.round(plot.x * dpr),\n Math.round(plot.y * dpr),\n );\n\n ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n drawForeground(ctx, {\n width,\n height,\n scales,\n theme,\n annotations: scene.annotations,\n pointLabels: [],\n clear: false,\n });\n // dot labels placed by the scene\n if (scene.pointLabels.length) {\n ctx.save();\n ctx.font = font(theme);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"middle\";\n ctx.lineWidth = 3;\n ctx.lineJoin = \"round\";\n ctx.strokeStyle = toCss(theme.background, 0.9);\n ctx.fillStyle = toCss(theme.text, 0.85);\n for (const { label, box } of scene.pointLabels) {\n ctx.strokeText(label.text, box.x, box.y + box.height / 2);\n ctx.fillText(label.text, box.x, box.y + box.height / 2);\n }\n ctx.restore();\n }\n\n // hover\n const hover = scene.hover;\n if (hover) {\n if (hover.crosshairX !== null) {\n ctx.save();\n ctx.strokeStyle = toCss(theme.textMuted, 0.55);\n ctx.lineWidth = 1;\n ctx.setLineDash([3, 3]);\n ctx.beginPath();\n const cx = Math.round(hover.crosshairX) + 0.5;\n ctx.moveTo(cx, plot.y);\n ctx.lineTo(cx, plot.y + plot.height);\n ctx.stroke();\n ctx.restore();\n }\n for (const mark of hover.marks) {\n if (mark.kind === \"band\") continue;\n if (mark.kind === \"cell\") {\n roundedRect(ctx, mark.x, mark.y, mark.width, mark.height, 3);\n ctx.lineWidth = 3;\n ctx.strokeStyle = toCss(theme.background);\n ctx.stroke();\n ctx.lineWidth = 1.5;\n ctx.strokeStyle = toCss(theme.text, 0.55);\n ctx.stroke();\n continue;\n }\n ctx.beginPath();\n ctx.arc(mark.x, mark.y, mark.size / 2 + 4, 0, Math.PI * 2);\n ctx.fillStyle = mark.halo;\n ctx.fill();\n ctx.beginPath();\n ctx.arc(mark.x, mark.y, mark.size / 2 - 1, 0, Math.PI * 2);\n ctx.fillStyle = mark.color;\n ctx.fill();\n ctx.lineWidth = 2;\n ctx.strokeStyle = toCss(theme.background);\n ctx.stroke();\n }\n }\n if (scene.dragging) {\n const d = scene.dragging;\n ctx.beginPath();\n ctx.arc(d.x, d.y, d.size / 2, 0, Math.PI * 2);\n ctx.fillStyle = d.color;\n ctx.globalAlpha = 0.85;\n ctx.fill();\n ctx.globalAlpha = 1;\n ctx.lineWidth = 2;\n ctx.strokeStyle = toCss(theme.background);\n ctx.stroke();\n }\n const tip = hover?.tooltip;\n if (tip) {\n const { box, lineHeight, padding } = tip;\n ctx.save();\n ctx.shadowColor = \"rgba(15, 23, 42, 0.18)\";\n ctx.shadowBlur = 16;\n ctx.shadowOffsetY = 6;\n roundedRect(ctx, box.x, box.y, box.width, box.height, 8);\n ctx.fillStyle = toCss(theme.background);\n ctx.fill();\n ctx.restore();\n roundedRect(\n ctx,\n box.x + 0.5,\n box.y + 0.5,\n box.width - 1,\n box.height - 1,\n 8,\n );\n ctx.strokeStyle = toCss(theme.axis, 0.6);\n ctx.lineWidth = 1;\n ctx.stroke();\n ctx.textBaseline = \"middle\";\n let y = box.y + padding + lineHeight / 2;\n const left = box.x + padding + 2;\n const right = box.x + box.width - padding - 2;\n if (tip.text) {\n ctx.font = font(theme, 12);\n ctx.fillStyle = toCss(theme.text);\n ctx.textAlign = \"left\";\n for (const line of tip.text) {\n ctx.fillText(line, left, y);\n y += lineHeight;\n }\n } else {\n const { content } = tip;\n let x = left;\n if (content.titleColor) {\n ctx.fillStyle = content.titleColor;\n ctx.beginPath();\n ctx.arc(x + 4, y, 4, 0, Math.PI * 2);\n ctx.fill();\n x += 14;\n }\n ctx.font = font(theme, 12, 600);\n ctx.fillStyle = toCss(theme.text);\n ctx.textAlign = \"left\";\n ctx.fillText(content.title, x, y);\n y += lineHeight;\n for (const row of content.rows) {\n x = left;\n if (row.color) {\n ctx.fillStyle = row.color;\n ctx.beginPath();\n ctx.arc(x + 4, y, 4, 0, Math.PI * 2);\n ctx.fill();\n x += 14;\n }\n ctx.font = font(theme, 12);\n ctx.textAlign = \"left\";\n ctx.fillStyle = toCss(theme.textMuted);\n ctx.fillText(row.name, x, y);\n ctx.font = font(theme, 12, 600);\n ctx.textAlign = \"right\";\n ctx.fillStyle = toCss(theme.text);\n ctx.fillText(row.value, right, y);\n y += lineHeight;\n }\n }\n }\n};\n\n/**\n * Creates a chart drawn on a 2D canvas: line, area, bar and scatter series,\n * annotations, legend and tooltip, tap / drag / pinch gestures. Works\n * without a DOM (mini-programs); see `createChart` for the GPU version of\n * the web.\n */\nexport const createCanvasChart = (\n config: CanvasChartConfig,\n): CanvasChartInstance => {\n const { canvas } = config;\n const ctx = canvas.getContext(\"2d\") as CanvasRenderingContext2D | null;\n let width = config.width;\n let height = config.height;\n let dpr = config.pixelRatio ?? 1;\n let destroyed = false;\n let frameId: number | null = null;\n let items: RenderItem[] = [];\n let itemsModel: unknown = null;\n let itemsKey = \"\";\n let options = config.options;\n /** Ids of the themes seen (the controller replaces its theme on changes) */\n const themeIds = new WeakMap<object, number>();\n let themeCount = 0;\n const themeId = (theme: object) => {\n let id = themeIds.get(theme);\n if (id === undefined) themeIds.set(theme, (id = ++themeCount));\n return id;\n };\n let origin: Origin = { x: 0, y: 0 };\n let version = 0;\n let fontSet = \"\";\n\n const measureText = (text: string, f: string) => {\n if (!ctx) return text.length * 6.5;\n if (f !== fontSet) {\n ctx.font = f;\n fontSet = f;\n }\n return ctx.measureText(text).width;\n };\n\n const painter = ctx ? createCanvas2dPainter(ctx) : null;\n\n const g = globalThis as {\n requestAnimationFrame?: (cb: () => void) => number;\n cancelAnimationFrame?: (id: number) => void;\n };\n\n const render = () => {\n frameId = null;\n if (destroyed || !ctx || !painter) return;\n const scene = controller.getScene();\n if (!scene) return;\n const pw = Math.max(1, Math.round(width * dpr));\n const ph = Math.max(1, Math.round(height * dpr));\n if (canvas.width !== pw) canvas.width = pw;\n if (canvas.height !== ph) canvas.height = ph;\n fontSet = \"\";\n if (itemsModel !== scene.model) {\n itemsModel = scene.model;\n // a new model (any setOptions) keeps the items when nothing they\n // depend on changed\n const key = itemsSignature(\n scene.model,\n themeId(scene.theme),\n (index) => options.series[index]?.stack,\n );\n if (key !== itemsKey) {\n itemsKey = key;\n origin = { x: mid(scene.model.base.x), y: mid(scene.model.base.y) };\n items = buildItems(scene.model, origin, ++version);\n }\n }\n drawScene(ctx, scene, items, origin, dpr, painter);\n fontSet = \"\";\n };\n\n const schedule = () => {\n if (destroyed || frameId !== null) return;\n if (canvas.requestAnimationFrame)\n frameId = canvas.requestAnimationFrame(render);\n else if (g.requestAnimationFrame) frameId = g.requestAnimationFrame(render);\n else frameId = setTimeout(render, 16) as unknown as number;\n };\n\n const controller = createChartController({\n options: config.options,\n theme: config.theme,\n measureText,\n onInvalidate: schedule,\n });\n controller.setSize(width, height);\n\n const touchOptions = (t: ChartTouch, i: number): ChartPointerOptions => ({\n id: t.identifier ?? i,\n touch: true,\n });\n\n return {\n setOptions: (o) => {\n options = o;\n controller.setOptions(o);\n },\n setTheme: (t) => controller.setTheme(t),\n resize(w, h, ratio) {\n width = w;\n height = h;\n if (ratio) dpr = ratio;\n controller.setSize(w, h);\n schedule();\n },\n render() {\n if (frameId !== null) {\n if (canvas.cancelAnimationFrame) canvas.cancelAnimationFrame(frameId);\n else if (g.cancelAnimationFrame) g.cancelAnimationFrame(frameId);\n else clearTimeout(frameId);\n }\n render();\n },\n touchStart(touches) {\n touches.forEach((t, i) =>\n controller.pointerDown(t.x, t.y, touchOptions(t, i)),\n );\n },\n touchMove(touches) {\n touches.forEach((t, i) =>\n controller.pointerMove(t.x, t.y, touchOptions(t, i)),\n );\n },\n touchEnd(touches) {\n touches.forEach((t, i) =>\n controller.pointerUp(t.x, t.y, touchOptions(t, i)),\n );\n },\n touchCancel(touches = [{ x: 0, y: 0 }]) {\n touches.forEach((t, i) => controller.pointerCancel(touchOptions(t, i)));\n },\n pointerDown: (x, y, o) => controller.pointerDown(x, y, o),\n pointerMove: (x, y, o) => controller.pointerMove(x, y, o),\n pointerUp: (x, y, o) => controller.pointerUp(x, y, o),\n pointerLeave: () => controller.pointerLeave(),\n zoomAt: (x, y, f) => controller.zoomAt(x, y, f),\n resetZoom: () => controller.resetZoom(),\n getView: () => controller.getView(),\n setView: (v) => controller.setView(v),\n toggleSeries: (id) => controller.toggleSeries(id),\n clearHover: () => controller.clearHover(),\n getPlotRect: () => controller.getPlotRect(),\n toPixel: (x, y) => controller.toPixel(x, y),\n fromPixel: (x, y) => controller.fromPixel(x, y),\n getController: () => controller,\n on: (type, listener) => controller.on(type, listener),\n destroy() {\n if (destroyed) return;\n destroyed = true;\n if (frameId !== null) {\n if (canvas.cancelAnimationFrame) canvas.cancelAnimationFrame(frameId);\n else if (g.cancelAnimationFrame) g.cancelAnimationFrame(frameId);\n else clearTimeout(frameId);\n }\n painter?.destroy();\n controller.destroy();\n },\n };\n};\n"],"mappings":";;;;;;;AA6FA,IAAMA,KAAO,OAAyBC,EAAE,KAAKA,EAAE,MAAM,GAE/CC,KACJ,GACA,GACA,GACA,GACA,GACA,MACG;CAWH,AAVAC,EAAI,UAAU,GACdA,EAAI,OAAOC,IAAIH,GAAGI,CAAC,GACnBF,EAAI,OAAOC,IAAIE,IAAIL,GAAGI,CAAC,GACvBF,EAAI,MAAMC,IAAIE,GAAGD,GAAGD,IAAIE,GAAGD,IAAIJ,GAAGA,CAAC,GACnCE,EAAI,OAAOC,IAAIE,GAAGD,IAAIE,IAAIN,CAAC,GAC3BE,EAAI,MAAMC,IAAIE,GAAGD,IAAIE,GAAGH,IAAIE,IAAIL,GAAGI,IAAIE,GAAGN,CAAC,GAC3CE,EAAI,OAAOC,IAAIH,GAAGI,IAAIE,CAAC,GACvBJ,EAAI,MAAMC,GAAGC,IAAIE,GAAGH,GAAGC,IAAIE,IAAIN,GAAGA,CAAC,GACnCE,EAAI,OAAOC,GAAGC,IAAIJ,CAAC,GACnBE,EAAI,MAAMC,GAAGC,GAAGD,IAAIH,GAAGI,GAAGJ,CAAC,GAC3BE,EAAI,UAAU;AAChB,GAGaK,KACX,GACA,GACA,GACA,GACA,GACA,IAAUC,EAAsBN,CAAG,MAChC;CACH,IAAM,EAAE,UAAO,WAAQ,UAAO,UAAO,SAAM,cAAWO,GAChD,EAAE,SAAM,cAAWC,GACnBC,IAAMC;CAiBZ,IAhBAV,EAAI,aAAa,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC,GACjCA,EAAI,UAAU,GAAG,GAAG,KAAK,KAAKW,IAAQF,CA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