@vielzeug/prism 26.10.0 → 26.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/README.md +2 -2
  2. package/dist/_dev.cjs +1 -1
  3. package/dist/_dev.cjs.map +1 -1
  4. package/dist/_dev.js +1 -1
  5. package/dist/_dev.js.map +1 -1
  6. package/dist/animation/easing.cjs.map +1 -1
  7. package/dist/animation/easing.js.map +1 -1
  8. package/dist/axes/axis.cjs +1 -1
  9. package/dist/axes/axis.cjs.map +1 -1
  10. package/dist/axes/axis.d.ts +2 -2
  11. package/dist/axes/axis.d.ts.map +1 -1
  12. package/dist/axes/axis.js +1 -1
  13. package/dist/axes/axis.js.map +1 -1
  14. package/dist/axes/scale-utils.cjs.map +1 -1
  15. package/dist/axes/scale-utils.d.ts +1 -1
  16. package/dist/axes/scale-utils.js.map +1 -1
  17. package/dist/charts/area/area-chart.cjs +1 -1
  18. package/dist/charts/area/area-chart.cjs.map +1 -1
  19. package/dist/charts/area/area-chart.d.ts.map +1 -1
  20. package/dist/charts/area/area-chart.js +1 -1
  21. package/dist/charts/area/area-chart.js.map +1 -1
  22. package/dist/charts/area/area-renderer.cjs +1 -1
  23. package/dist/charts/area/area-renderer.cjs.map +1 -1
  24. package/dist/charts/area/area-renderer.d.ts +7 -2
  25. package/dist/charts/area/area-renderer.d.ts.map +1 -1
  26. package/dist/charts/area/area-renderer.js +1 -1
  27. package/dist/charts/area/area-renderer.js.map +1 -1
  28. package/dist/charts/bar/bar-chart.cjs +1 -1
  29. package/dist/charts/bar/bar-chart.cjs.map +1 -1
  30. package/dist/charts/bar/bar-chart.d.ts.map +1 -1
  31. package/dist/charts/bar/bar-chart.js +1 -1
  32. package/dist/charts/bar/bar-chart.js.map +1 -1
  33. package/dist/charts/bar/bar-hit-test.cjs +1 -1
  34. package/dist/charts/bar/bar-hit-test.cjs.map +1 -1
  35. package/dist/charts/bar/bar-hit-test.d.ts +0 -5
  36. package/dist/charts/bar/bar-hit-test.d.ts.map +1 -1
  37. package/dist/charts/bar/bar-hit-test.js +1 -1
  38. package/dist/charts/bar/bar-hit-test.js.map +1 -1
  39. package/dist/charts/bar/bar-renderer.cjs +1 -1
  40. package/dist/charts/bar/bar-renderer.cjs.map +1 -1
  41. package/dist/charts/bar/bar-renderer.d.ts +3 -1
  42. package/dist/charts/bar/bar-renderer.d.ts.map +1 -1
  43. package/dist/charts/bar/bar-renderer.js +1 -1
  44. package/dist/charts/bar/bar-renderer.js.map +1 -1
  45. package/dist/charts/line/line-chart.cjs +1 -1
  46. package/dist/charts/line/line-chart.cjs.map +1 -1
  47. package/dist/charts/line/line-chart.d.ts.map +1 -1
  48. package/dist/charts/line/line-chart.js +1 -1
  49. package/dist/charts/line/line-chart.js.map +1 -1
  50. package/dist/charts/line/line-renderer.cjs +1 -1
  51. package/dist/charts/line/line-renderer.cjs.map +1 -1
  52. package/dist/charts/line/line-renderer.d.ts +6 -2
  53. package/dist/charts/line/line-renderer.d.ts.map +1 -1
  54. package/dist/charts/line/line-renderer.js +1 -1
  55. package/dist/charts/line/line-renderer.js.map +1 -1
  56. package/dist/charts/pie/pie-chart.cjs +1 -1
  57. package/dist/charts/pie/pie-chart.cjs.map +1 -1
  58. package/dist/charts/pie/pie-chart.d.ts.map +1 -1
  59. package/dist/charts/pie/pie-chart.js +1 -1
  60. package/dist/charts/pie/pie-chart.js.map +1 -1
  61. package/dist/charts/pie/pie-renderer.cjs +1 -1
  62. package/dist/charts/pie/pie-renderer.cjs.map +1 -1
  63. package/dist/charts/pie/pie-renderer.d.ts.map +1 -1
  64. package/dist/charts/pie/pie-renderer.js +1 -1
  65. package/dist/charts/pie/pie-renderer.js.map +1 -1
  66. package/dist/charts/radar/index.d.ts +2 -0
  67. package/dist/charts/radar/index.d.ts.map +1 -0
  68. package/dist/charts/radar/radar-chart.cjs +2 -0
  69. package/dist/charts/radar/radar-chart.cjs.map +1 -0
  70. package/dist/charts/radar/radar-chart.d.ts +3 -0
  71. package/dist/charts/radar/radar-chart.d.ts.map +1 -0
  72. package/dist/charts/radar/radar-chart.js +2 -0
  73. package/dist/charts/radar/radar-chart.js.map +1 -0
  74. package/dist/charts/radar/radar-geometry.cjs +2 -0
  75. package/dist/charts/radar/radar-geometry.cjs.map +1 -0
  76. package/dist/charts/radar/radar-geometry.d.ts +22 -0
  77. package/dist/charts/radar/radar-geometry.d.ts.map +1 -0
  78. package/dist/charts/radar/radar-geometry.js +2 -0
  79. package/dist/charts/radar/radar-geometry.js.map +1 -0
  80. package/dist/charts/sparkline/sparkline.cjs +1 -1
  81. package/dist/charts/sparkline/sparkline.cjs.map +1 -1
  82. package/dist/charts/sparkline/sparkline.d.ts.map +1 -1
  83. package/dist/charts/sparkline/sparkline.js +1 -1
  84. package/dist/charts/sparkline/sparkline.js.map +1 -1
  85. package/dist/core/cartesian-scales.cjs +1 -1
  86. package/dist/core/cartesian-scales.cjs.map +1 -1
  87. package/dist/core/cartesian-scales.js +1 -1
  88. package/dist/core/cartesian-scales.js.map +1 -1
  89. package/dist/core/chart-base.cjs +1 -1
  90. package/dist/core/chart-base.cjs.map +1 -1
  91. package/dist/core/chart-base.d.ts +9 -0
  92. package/dist/core/chart-base.d.ts.map +1 -1
  93. package/dist/core/chart-base.js +1 -1
  94. package/dist/core/chart-base.js.map +1 -1
  95. package/dist/core/chart-scaffold.cjs +1 -1
  96. package/dist/core/chart-scaffold.cjs.map +1 -1
  97. package/dist/core/chart-scaffold.d.ts +7 -3
  98. package/dist/core/chart-scaffold.d.ts.map +1 -1
  99. package/dist/core/chart-scaffold.js +1 -1
  100. package/dist/core/chart-scaffold.js.map +1 -1
  101. package/dist/core/datum-style.cjs +2 -0
  102. package/dist/core/datum-style.cjs.map +1 -0
  103. package/dist/core/datum-style.d.ts +18 -0
  104. package/dist/core/datum-style.d.ts.map +1 -0
  105. package/dist/core/datum-style.js +2 -0
  106. package/dist/core/datum-style.js.map +1 -0
  107. package/dist/core/ids.cjs +2 -0
  108. package/dist/core/ids.cjs.map +1 -0
  109. package/dist/core/ids.d.ts +3 -0
  110. package/dist/core/ids.d.ts.map +1 -0
  111. package/dist/core/ids.js +2 -0
  112. package/dist/core/ids.js.map +1 -0
  113. package/dist/core/polar.cjs +2 -0
  114. package/dist/core/polar.cjs.map +1 -0
  115. package/dist/core/polar.d.ts +5 -0
  116. package/dist/core/polar.d.ts.map +1 -0
  117. package/dist/core/polar.js +2 -0
  118. package/dist/core/polar.js.map +1 -0
  119. package/dist/core/series-id.cjs +2 -0
  120. package/dist/core/series-id.cjs.map +1 -0
  121. package/dist/core/series-id.d.ts +8 -0
  122. package/dist/core/series-id.d.ts.map +1 -0
  123. package/dist/core/series-id.js +2 -0
  124. package/dist/core/series-id.js.map +1 -0
  125. package/dist/devtools/index.d.ts +1 -1
  126. package/dist/devtools.cjs.map +1 -1
  127. package/dist/devtools.js.map +1 -1
  128. package/dist/errors.cjs.map +1 -1
  129. package/dist/errors.d.ts +1 -1
  130. package/dist/errors.d.ts.map +1 -1
  131. package/dist/errors.js.map +1 -1
  132. package/dist/index.cjs +1 -1
  133. package/dist/index.d.ts +2 -1
  134. package/dist/index.d.ts.map +1 -1
  135. package/dist/index.js +1 -1
  136. package/dist/interaction/announcer.cjs +2 -0
  137. package/dist/interaction/announcer.cjs.map +1 -0
  138. package/dist/interaction/announcer.d.ts +13 -0
  139. package/dist/interaction/announcer.d.ts.map +1 -0
  140. package/dist/interaction/announcer.js +2 -0
  141. package/dist/interaction/announcer.js.map +1 -0
  142. package/dist/interaction/crosshair.cjs +1 -1
  143. package/dist/interaction/crosshair.cjs.map +1 -1
  144. package/dist/interaction/crosshair.d.ts +1 -5
  145. package/dist/interaction/crosshair.d.ts.map +1 -1
  146. package/dist/interaction/crosshair.js +1 -1
  147. package/dist/interaction/crosshair.js.map +1 -1
  148. package/dist/interaction/series-interaction.cjs +1 -1
  149. package/dist/interaction/series-interaction.cjs.map +1 -1
  150. package/dist/interaction/series-interaction.d.ts +11 -1
  151. package/dist/interaction/series-interaction.d.ts.map +1 -1
  152. package/dist/interaction/series-interaction.js +1 -1
  153. package/dist/interaction/series-interaction.js.map +1 -1
  154. package/dist/interaction/tooltip.cjs +1 -1
  155. package/dist/interaction/tooltip.cjs.map +1 -1
  156. package/dist/interaction/tooltip.d.ts +12 -1
  157. package/dist/interaction/tooltip.d.ts.map +1 -1
  158. package/dist/interaction/tooltip.js +1 -1
  159. package/dist/interaction/tooltip.js.map +1 -1
  160. package/dist/prism.cjs +1 -1
  161. package/dist/prism.cjs.map +1 -1
  162. package/dist/prism.iife.js +1 -1
  163. package/dist/prism.iife.js.map +1 -1
  164. package/dist/prism.js +1 -1
  165. package/dist/prism.js.map +1 -1
  166. package/dist/scales/band.cjs.map +1 -1
  167. package/dist/scales/band.js.map +1 -1
  168. package/dist/scales/linear.cjs.map +1 -1
  169. package/dist/scales/linear.js.map +1 -1
  170. package/dist/scales/time.cjs.map +1 -1
  171. package/dist/scales/time.js.map +1 -1
  172. package/dist/svg/element.cjs.map +1 -1
  173. package/dist/svg/element.js.map +1 -1
  174. package/dist/svg/text.cjs +1 -1
  175. package/dist/svg/text.cjs.map +1 -1
  176. package/dist/svg/text.d.ts +1 -0
  177. package/dist/svg/text.d.ts.map +1 -1
  178. package/dist/svg/text.js +1 -1
  179. package/dist/svg/text.js.map +1 -1
  180. package/dist/theme/index.cjs.map +1 -1
  181. package/dist/theme/index.js.map +1 -1
  182. package/dist/theme/prism.css +214 -7
  183. package/dist/types.d.ts +102 -5
  184. package/dist/types.d.ts.map +1 -1
  185. package/package.json +4 -3
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @vielzeug/prism
2
2
 
3
- > Responsive SVG charts with explicit updates — line, bar, area, pie, sparkline
3
+ > Responsive SVG charts with explicit updates: line, bar, area, pie, radar, sparkline
4
4
 
5
5
  ## Installation
6
6
 
@@ -60,4 +60,4 @@ chart.dispose();
60
60
 
61
61
  ## License
62
62
 
63
- MIT © [Helmuth Saatkamp](https://github.com/helmuthdu) — part of the [Vielzeug](https://github.com/helmuthdu/vielzeug) monorepo.
63
+ MIT © [Helmuth Saatkamp](https://github.com/helmuthdu): part of the [Vielzeug](https://github.com/helmuthdu/vielzeug) monorepo.
package/dist/_dev.cjs CHANGED
@@ -1,2 +1,2 @@
1
- function warn(e){}exports.warn=warn;
1
+ function warn(e){}function devOnly(e){}exports.devOnly=devOnly,exports.warn=warn;
2
2
  //# sourceMappingURL=_dev.cjs.map
package/dist/_dev.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"_dev.cjs","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["/** @internal */\nconst isDev = !(globalThis as { __PRISM_PROD__?: boolean }).__PRISM_PROD__;\n\n/**\n * Emits a `console.warn` in development builds only.\n * @internal\n * @security Messages may include user-supplied data (e.g. category names, x-values).\n * Never pass PII, tokens, or secrets as chart data labels.\n */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/prism] ${msg}`);\n}\n\n/**\n * Emits a `console.error` in development builds only.\n * @internal\n */\nexport function error(msg: string, ...args: unknown[]): void {\n if (isDev) console.error(`[@vielzeug/prism] ${msg}`, ...args);\n}\n\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n"],"mappings":"AASA,SAAgB,KAAK,EAAmB,CAExC"}
1
+ {"version":3,"file":"_dev.cjs","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["/** @internal */\nconst isDev = !(globalThis as { __PRISM_PROD__?: boolean }).__PRISM_PROD__;\n\n/**\n * Emits a `console.warn` in development builds only.\n * @internal\n * @security Messages may include user-supplied data (e.g. category names, x-values).\n * Never pass PII, tokens, or secrets as chart data labels.\n */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/prism] ${msg}`);\n}\n\n/**\n * Emits a `console.error` in development builds only.\n * @internal\n */\nexport function error(msg: string, ...args: unknown[]): void {\n if (isDev) console.error(`[@vielzeug/prism] ${msg}`, ...args);\n}\n\n/** @internal: Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n"],"mappings":"AASA,SAAgB,KAAK,EAAmB,CAExC,CAWA,SAAgB,QAAQ,EAAsB,CAE9C"}
package/dist/_dev.js CHANGED
@@ -1,2 +1,2 @@
1
- function warn(e){}export{warn};
1
+ function warn(e){}function devOnly(e){}export{devOnly,warn};
2
2
  //# sourceMappingURL=_dev.js.map
package/dist/_dev.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"_dev.js","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["/** @internal */\nconst isDev = !(globalThis as { __PRISM_PROD__?: boolean }).__PRISM_PROD__;\n\n/**\n * Emits a `console.warn` in development builds only.\n * @internal\n * @security Messages may include user-supplied data (e.g. category names, x-values).\n * Never pass PII, tokens, or secrets as chart data labels.\n */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/prism] ${msg}`);\n}\n\n/**\n * Emits a `console.error` in development builds only.\n * @internal\n */\nexport function error(msg: string, ...args: unknown[]): void {\n if (isDev) console.error(`[@vielzeug/prism] ${msg}`, ...args);\n}\n\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n"],"mappings":"AASA,SAAgB,KAAK,EAAmB,CAExC"}
1
+ {"version":3,"file":"_dev.js","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["/** @internal */\nconst isDev = !(globalThis as { __PRISM_PROD__?: boolean }).__PRISM_PROD__;\n\n/**\n * Emits a `console.warn` in development builds only.\n * @internal\n * @security Messages may include user-supplied data (e.g. category names, x-values).\n * Never pass PII, tokens, or secrets as chart data labels.\n */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/prism] ${msg}`);\n}\n\n/**\n * Emits a `console.error` in development builds only.\n * @internal\n */\nexport function error(msg: string, ...args: unknown[]): void {\n if (isDev) console.error(`[@vielzeug/prism] ${msg}`, ...args);\n}\n\n/** @internal: Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n"],"mappings":"AASA,SAAgB,KAAK,EAAmB,CAExC,CAWA,SAAgB,QAAQ,EAAsB,CAE9C"}
@@ -1 +1 @@
1
- {"version":3,"file":"easing.cjs","names":[],"sources":["../../src/animation/easing.ts"],"sourcesContent":["export type EasingFn = (t: number) => number;\n\nexport const easings: Record<string, EasingFn> = {\n 'ease-in': (t) => t * t,\n 'ease-in-out': (t) => (t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2),\n 'ease-out': (t) => 1 - (1 - t) * (1 - t),\n linear: (t) => t,\n};\n\nexport function resolveEasing(easing: string | ((t: number) => number) | undefined): EasingFn {\n if (typeof easing === 'function') return easing;\n\n // `Object.hasOwn` guards against `easing` being a prototype-chain key (e.g. `'__proto__'`,\n // `'constructor'`) — a plain bracket lookup on those would silently resolve to an\n // `Object.prototype` value instead of `undefined`, which is either not callable (throws)\n // or callable but not an easing function (produces garbage interpolation).\n if (easing !== undefined && Object.hasOwn(easings, easing)) return easings[easing];\n\n return easings['ease-out'];\n}\n"],"mappings":"AAEA,IAAa,EAAoC,CAC/C,UAAY,GAAM,EAAI,EACtB,cAAgB,GAAO,EAAI,GAAM,EAAI,EAAI,EAAI,GAAK,GAAK,EAAI,IAAM,EAAI,EACrE,WAAa,GAAM,GAAK,EAAI,IAAM,EAAI,GACtC,OAAS,GAAM,CACjB,EAEA,SAAgB,cAAc,EAAgE,CAS5F,OARI,OAAO,GAAW,WAAmB,EAMrC,IAAW,IAAA,IAAa,OAAO,OAAO,EAAS,CAAM,EAAU,EAAQ,GAEpE,EAAQ,WACjB"}
1
+ {"version":3,"file":"easing.cjs","names":[],"sources":["../../src/animation/easing.ts"],"sourcesContent":["export type EasingFn = (t: number) => number;\n\nexport const easings: Record<string, EasingFn> = {\n 'ease-in': (t) => t * t,\n 'ease-in-out': (t) => (t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2),\n 'ease-out': (t) => 1 - (1 - t) * (1 - t),\n linear: (t) => t,\n};\n\nexport function resolveEasing(easing: string | ((t: number) => number) | undefined): EasingFn {\n if (typeof easing === 'function') return easing;\n\n // `Object.hasOwn` guards against `easing` being a prototype-chain key (e.g. `'__proto__'`,\n // `'constructor'`): a plain bracket lookup on those would silently resolve to an\n // `Object.prototype` value instead of `undefined`, which is either not callable (throws)\n // or callable but not an easing function (produces garbage interpolation).\n if (easing !== undefined && Object.hasOwn(easings, easing)) return easings[easing];\n\n return easings['ease-out'];\n}\n"],"mappings":"AAEA,IAAa,EAAoC,CAC/C,UAAY,GAAM,EAAI,EACtB,cAAgB,GAAO,EAAI,GAAM,EAAI,EAAI,EAAI,GAAK,GAAK,EAAI,IAAM,EAAI,EACrE,WAAa,GAAM,GAAK,EAAI,IAAM,EAAI,GACtC,OAAS,GAAM,CACjB,EAEA,SAAgB,cAAc,EAAgE,CAS5F,OARI,OAAO,GAAW,WAAmB,EAMrC,IAAW,IAAA,IAAa,OAAO,OAAO,EAAS,CAAM,EAAU,EAAQ,GAEpE,EAAQ,WACjB"}
@@ -1 +1 @@
1
- {"version":3,"file":"easing.js","names":[],"sources":["../../src/animation/easing.ts"],"sourcesContent":["export type EasingFn = (t: number) => number;\n\nexport const easings: Record<string, EasingFn> = {\n 'ease-in': (t) => t * t,\n 'ease-in-out': (t) => (t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2),\n 'ease-out': (t) => 1 - (1 - t) * (1 - t),\n linear: (t) => t,\n};\n\nexport function resolveEasing(easing: string | ((t: number) => number) | undefined): EasingFn {\n if (typeof easing === 'function') return easing;\n\n // `Object.hasOwn` guards against `easing` being a prototype-chain key (e.g. `'__proto__'`,\n // `'constructor'`) — a plain bracket lookup on those would silently resolve to an\n // `Object.prototype` value instead of `undefined`, which is either not callable (throws)\n // or callable but not an easing function (produces garbage interpolation).\n if (easing !== undefined && Object.hasOwn(easings, easing)) return easings[easing];\n\n return easings['ease-out'];\n}\n"],"mappings":"AAEA,IAAa,EAAoC,CAC/C,UAAY,GAAM,EAAI,EACtB,cAAgB,GAAO,EAAI,GAAM,EAAI,EAAI,EAAI,GAAK,GAAK,EAAI,IAAM,EAAI,EACrE,WAAa,GAAM,GAAK,EAAI,IAAM,EAAI,GACtC,OAAS,GAAM,CACjB,EAEA,SAAgB,cAAc,EAAgE,CAS5F,OARI,OAAO,GAAW,WAAmB,EAMrC,IAAW,IAAA,IAAa,OAAO,OAAO,EAAS,CAAM,EAAU,EAAQ,GAEpE,EAAQ,WACjB"}
1
+ {"version":3,"file":"easing.js","names":[],"sources":["../../src/animation/easing.ts"],"sourcesContent":["export type EasingFn = (t: number) => number;\n\nexport const easings: Record<string, EasingFn> = {\n 'ease-in': (t) => t * t,\n 'ease-in-out': (t) => (t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2),\n 'ease-out': (t) => 1 - (1 - t) * (1 - t),\n linear: (t) => t,\n};\n\nexport function resolveEasing(easing: string | ((t: number) => number) | undefined): EasingFn {\n if (typeof easing === 'function') return easing;\n\n // `Object.hasOwn` guards against `easing` being a prototype-chain key (e.g. `'__proto__'`,\n // `'constructor'`): a plain bracket lookup on those would silently resolve to an\n // `Object.prototype` value instead of `undefined`, which is either not callable (throws)\n // or callable but not an easing function (produces garbage interpolation).\n if (easing !== undefined && Object.hasOwn(easings, easing)) return easings[easing];\n\n return easings['ease-out'];\n}\n"],"mappings":"AAEA,IAAa,EAAoC,CAC/C,UAAY,GAAM,EAAI,EACtB,cAAgB,GAAO,EAAI,GAAM,EAAI,EAAI,EAAI,GAAK,GAAK,EAAI,IAAM,EAAI,EACrE,WAAa,GAAM,GAAK,EAAI,IAAM,EAAI,GACtC,OAAS,GAAM,CACjB,EAEA,SAAgB,cAAc,EAAgE,CAS5F,OARI,OAAO,GAAW,WAAmB,EAMrC,IAAW,IAAA,IAAa,OAAO,OAAO,EAAS,CAAM,EAAU,EAAQ,GAEpE,EAAQ,WACjB"}
@@ -1,2 +1,2 @@
1
- const e=require("../svg/element.cjs"),t=require("../svg/text.cjs"),n=require("./scale-utils.cjs");var defaultTickFormat=e=>e instanceof Date?e.toLocaleDateString(void 0,{month:`short`,year:`numeric`}):String(e);function positionAxis(e,t,n,r){let i=t===`bottom`?`translate(0,${r})`:t===`right`?`translate(${n},0)`:void 0;i?e.setAttribute(`transform`,i):e.removeAttribute(`transform`)}function resolveTickCount(e,t,n){let r=e.position??n,i=r===`bottom`||r===`top`?Math.max(2,Math.floor(t/80)):Math.max(2,Math.floor(t/50));return e.tickCount??i}function renderAxis(r,i,a,o,s=`bottom`){e.removeChildren(r);let c=a.position??s,l=c===`bottom`||c===`top`,u=c===`top`||c===`left`,d=u?-1:1,f=e.createSvgElement(`line`,{"aria-hidden":`true`,class:`prism-axis-line`,x1:0,x2:l?o:0,y1:0,y2:l?0:o});r.appendChild(f);let p=i.ticks(resolveTickCount(a,o,s)),m=a.tickFormat??defaultTickFormat;for(let a of p){let o=n.mapTick(i,a),s=e.createSvgElement(`line`,{"aria-hidden":`true`,class:`prism-axis-tick`,x1:l?o:0,x2:l?o:6*d,y1:l?0:o,y2:l?6*d:o});r.appendChild(s);let c=t.createTextElement(m(a),{"aria-hidden":`true`,class:`prism-axis-label`,"dominant-baseline":l?u?`auto`:`hanging`:`middle`,"text-anchor":l?`middle`:u?`end`:`start`,x:l?o:6*d*1.5,y:l?6*d*1.5:o});r.appendChild(c)}if(a.label){let n=t.createTextElement(a.label,{class:`prism-axis-title`,"dominant-baseline":`middle`,"text-anchor":`middle`});l?e.setAttributes(n,{x:o/2,y:6*d*6}):e.setAttributes(n,{transform:`translate(${6*d*7}, ${o/2}) rotate(-90)`}),r.appendChild(n)}}exports.positionAxis=positionAxis,exports.renderAxis=renderAxis,exports.resolveTickCount=resolveTickCount;
1
+ const e=require("../svg/element.cjs"),t=require("../svg/text.cjs"),n=require("./scale-utils.cjs");var r=11,i=8,defaultTickFormat=e=>e instanceof Date?e.toLocaleDateString(void 0,{month:`short`,year:`numeric`}):String(e);function positionAxis(e,t,n,r){let i=t===`bottom`?`translate(0,${r})`:t===`right`?`translate(${n},0)`:void 0;i?e.setAttribute(`transform`,i):e.removeAttribute(`transform`)}function resolveTickCount(e,t,n){let r=e.position??n,i=r===`bottom`||r===`top`?Math.max(2,Math.floor(t/80)):Math.max(2,Math.floor(t/50));return e.tickCount??i}function categoryTickCount(e,n,a,o){if(e.length===0)return 0;let s=o?Math.max(...e.map(e=>t.estimateTextWidth(n(e),r))):r*1.3;return Math.max(1,Math.min(e.length,Math.floor(a/(s+i))))}function renderAxis(r,i,a,o,s=`bottom`){e.removeChildren(r);let c=a.position??s,l=c===`bottom`||c===`top`,u=c===`top`||c===`left`,d=u?-1:1,f=e.createSvgElement(`line`,{"aria-hidden":`true`,class:`prism-axis-line`,x1:0,x2:l?o:0,y1:0,y2:l?0:o});r.appendChild(f);let p=a.tickFormat??defaultTickFormat,m=a.tickCount===void 0&&`bandwidth`in i?categoryTickCount(i.domain,p,o,l):resolveTickCount(a,o,s),h=i.ticks(m);for(let a of h){let o=n.mapTick(i,a),s=e.createSvgElement(`line`,{"aria-hidden":`true`,class:`prism-axis-tick`,x1:l?o:0,x2:l?o:6*d,y1:l?0:o,y2:l?6*d:o});r.appendChild(s);let c=t.createTextElement(p(a),{"aria-hidden":`true`,class:`prism-axis-label`,"dominant-baseline":l?u?`auto`:`hanging`:`middle`,"text-anchor":l?`middle`:u?`end`:`start`,x:l?o:6*d*1.5,y:l?6*d*1.5:o});r.appendChild(c)}if(a.label){let n=t.createTextElement(a.label,{class:`prism-axis-title`,"dominant-baseline":`middle`,"text-anchor":`middle`});l?e.setAttributes(n,{x:o/2,y:6*d*6}):e.setAttributes(n,{transform:`translate(${6*d*7}, ${o/2}) rotate(-90)`}),r.appendChild(n)}}exports.positionAxis=positionAxis,exports.renderAxis=renderAxis,exports.resolveTickCount=resolveTickCount;
2
2
  //# sourceMappingURL=axis.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"axis.cjs","names":[],"sources":["../../src/axes/axis.ts"],"sourcesContent":["import { createSvgElement, removeChildren, setAttributes } from '../svg/element';\nimport { createTextElement } from '../svg/text';\nimport type { AxisConfig, AxisPosition } from '../types';\nimport { type AnyScale, mapTick } from './scale-utils';\n\nconst defaultTickFormat = (v: Date | number | string): string =>\n v instanceof Date ? v.toLocaleDateString(undefined, { month: 'short', year: 'numeric' }) : String(v);\n\n/**\n * Resolves the tick count an axis will render for a given scale/length — shared with\n * `renderGrid` so gridlines line up with axis ticks. `defaultPosition` must match the\n * one passed to the corresponding `renderAxis` call ('bottom' for xAxis, 'left' for yAxis).\n */\nexport function positionAxis(parent: SVGGElement, position: AxisPosition, width: number, height: number): void {\n const transform =\n position === 'bottom' ? `translate(0,${height})` : position === 'right' ? `translate(${width},0)` : undefined;\n\n if (transform) parent.setAttribute('transform', transform);\n else parent.removeAttribute('transform');\n}\n\nexport function resolveTickCount(config: AxisConfig, length: number, defaultPosition: AxisPosition): number {\n const position = config.position ?? defaultPosition;\n const isHorizontal = position === 'bottom' || position === 'top';\n const defaultTickCount = isHorizontal ? Math.max(2, Math.floor(length / 80)) : Math.max(2, Math.floor(length / 50));\n\n return config.tickCount ?? defaultTickCount;\n}\n\n/**\n * `defaultPosition` is applied when `config.position` is unset — pass `'bottom'` for an\n * xAxis call and `'left'` for a yAxis call so an unconfigured axis renders on its\n * conventional side instead of always defaulting to a horizontal bottom axis.\n */\nexport function renderAxis(\n parent: SVGGElement,\n scale: AnyScale,\n config: AxisConfig,\n length: number,\n defaultPosition: AxisPosition = 'bottom',\n): void {\n removeChildren(parent);\n\n const position = config.position ?? defaultPosition;\n const isHorizontal = position === 'bottom' || position === 'top';\n const isInverted = position === 'top' || position === 'left';\n const tickSize = 6;\n const tickDirection = isInverted ? -1 : 1;\n\n const axisLine = createSvgElement('line', {\n 'aria-hidden': 'true',\n class: 'prism-axis-line',\n x1: isHorizontal ? 0 : 0,\n x2: isHorizontal ? length : 0,\n y1: isHorizontal ? 0 : 0,\n y2: isHorizontal ? 0 : length,\n });\n\n parent.appendChild(axisLine);\n\n const ticks = scale.ticks(resolveTickCount(config, length, defaultPosition));\n const format = config.tickFormat ?? defaultTickFormat;\n\n for (const tick of ticks) {\n const pos = mapTick(scale, tick);\n const tickLine = createSvgElement('line', {\n 'aria-hidden': 'true',\n class: 'prism-axis-tick',\n x1: isHorizontal ? pos : 0,\n x2: isHorizontal ? pos : tickSize * tickDirection,\n y1: isHorizontal ? 0 : pos,\n y2: isHorizontal ? tickSize * tickDirection : pos,\n });\n\n parent.appendChild(tickLine);\n\n const label = createTextElement(format(tick), {\n 'aria-hidden': 'true',\n class: 'prism-axis-label',\n 'dominant-baseline': isHorizontal ? (isInverted ? 'auto' : 'hanging') : 'middle',\n 'text-anchor': isHorizontal ? 'middle' : isInverted ? 'end' : 'start',\n x: isHorizontal ? pos : tickSize * tickDirection * 1.5,\n y: isHorizontal ? tickSize * tickDirection * 1.5 : pos,\n });\n\n parent.appendChild(label);\n }\n\n if (config.label) {\n const labelEl = createTextElement(config.label, {\n class: 'prism-axis-title',\n 'dominant-baseline': 'middle',\n 'text-anchor': 'middle',\n });\n\n if (isHorizontal) {\n setAttributes(labelEl, { x: length / 2, y: tickSize * tickDirection * 6 });\n } else {\n setAttributes(labelEl, {\n transform: `translate(${tickSize * tickDirection * 7}, ${length / 2}) rotate(-90)`,\n });\n }\n\n parent.appendChild(labelEl);\n }\n}\n"],"mappings":"kGAKA,IAAM,kBAAqB,GACzB,aAAa,KAAO,EAAE,mBAAmB,IAAA,GAAW,CAAE,MAAO,QAAS,KAAM,SAAU,CAAC,EAAI,OAAO,CAAC,EAOrG,SAAgB,aAAa,EAAqB,EAAwB,EAAe,EAAsB,CAC7G,IAAM,EACJ,IAAa,SAAW,eAAe,EAAO,GAAK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Q,QAC9D,EAAG,EAAe,EAAM,EAAW,EAAgB,IACnD,EAAG,EAAe,EAAW,EAAgB,IAAM,CACrD,CAAC,EAED,EAAO,YAAY,CAAK,CAC1B,CAEA,GAAI,EAAO,MAAO,CAChB,IAAM,EAAU,EAAA,kBAAkB,EAAO,MAAO,CAC9C,MAAO,mBACP,oBAAqB,SACrB,cAAe,QACjB,CAAC,EAEG,EACF,EAAA,cAAc,EAAS,CAAE,EAAG,EAAS,EAAG,EAAG,EAAW,EAAgB,CAAE,CAAC,EAEzE,EAAA,cAAc,EAAS,CACrB,UAAW,aAAa,EAAW,EAAgB,EAAE,IAAI,EAAS,EAAE,cACtE,CAAC,EAGH,EAAO,YAAY,CAAO,CAC5B,CACF"}
1
+ {"version":3,"file":"axis.cjs","names":[],"sources":["../../src/axes/axis.ts"],"sourcesContent":["import { createSvgElement, removeChildren, setAttributes } from '../svg/element';\nimport { createTextElement, estimateTextWidth } from '../svg/text';\nimport type { AxisConfig, AxisPosition } from '../types';\nimport { type AnyScale, mapTick } from './scale-utils';\n\n/** Default `--prism-font-size-label` in px, used to estimate category label size. */\nconst LABEL_FONT_SIZE = 11;\nconst LABEL_GAP = 8;\n\nconst defaultTickFormat = (v: Date | number | string): string =>\n v instanceof Date ? v.toLocaleDateString(undefined, { month: 'short', year: 'numeric' }) : String(v);\n\n/**\n * Resolves the tick count an axis will render for a given scale/length: shared with\n * `renderGrid` so gridlines line up with axis ticks. `defaultPosition` must match the\n * one passed to the corresponding `renderAxis` call ('bottom' for xAxis, 'left' for yAxis).\n */\nexport function positionAxis(parent: SVGGElement, position: AxisPosition, width: number, height: number): void {\n const transform =\n position === 'bottom' ? `translate(0,${height})` : position === 'right' ? `translate(${width},0)` : undefined;\n\n if (transform) parent.setAttribute('transform', transform);\n else parent.removeAttribute('transform');\n}\n\nexport function resolveTickCount(config: AxisConfig, length: number, defaultPosition: AxisPosition): number {\n const position = config.position ?? defaultPosition;\n const isHorizontal = position === 'bottom' || position === 'top';\n const defaultTickCount = isHorizontal ? Math.max(2, Math.floor(length / 80)) : Math.max(2, Math.floor(length / 50));\n\n return config.tickCount ?? defaultTickCount;\n}\n\n/** How many category labels fit along the axis without their estimated boxes overlapping. */\nfunction categoryTickCount(\n domain: readonly string[],\n format: (value: string) => string,\n length: number,\n isHorizontal: boolean,\n): number {\n if (domain.length === 0) return 0;\n\n const size = isHorizontal\n ? Math.max(...domain.map((value) => estimateTextWidth(format(value), LABEL_FONT_SIZE)))\n : LABEL_FONT_SIZE * 1.3;\n\n return Math.max(1, Math.min(domain.length, Math.floor(length / (size + LABEL_GAP))));\n}\n\n/**\n * `defaultPosition` is applied when `config.position` is unset: pass `'bottom'` for an\n * xAxis call and `'left'` for a yAxis call so an unconfigured axis renders on its\n * conventional side instead of always defaulting to a horizontal bottom axis.\n */\nexport function renderAxis(\n parent: SVGGElement,\n scale: AnyScale,\n config: AxisConfig,\n length: number,\n defaultPosition: AxisPosition = 'bottom',\n): void {\n removeChildren(parent);\n\n const position = config.position ?? defaultPosition;\n const isHorizontal = position === 'bottom' || position === 'top';\n const isInverted = position === 'top' || position === 'left';\n const tickSize = 6;\n const tickDirection = isInverted ? -1 : 1;\n\n const axisLine = createSvgElement('line', {\n 'aria-hidden': 'true',\n class: 'prism-axis-line',\n x1: isHorizontal ? 0 : 0,\n x2: isHorizontal ? length : 0,\n y1: isHorizontal ? 0 : 0,\n y2: isHorizontal ? 0 : length,\n });\n\n parent.appendChild(axisLine);\n\n const format = config.tickFormat ?? defaultTickFormat;\n const tickCount =\n config.tickCount === undefined && 'bandwidth' in scale\n ? categoryTickCount(scale.domain, format, length, isHorizontal)\n : resolveTickCount(config, length, defaultPosition);\n const ticks = scale.ticks(tickCount);\n\n for (const tick of ticks) {\n const pos = mapTick(scale, tick);\n const tickLine = createSvgElement('line', {\n 'aria-hidden': 'true',\n class: 'prism-axis-tick',\n x1: isHorizontal ? pos : 0,\n x2: isHorizontal ? pos : tickSize * tickDirection,\n y1: isHorizontal ? 0 : pos,\n y2: isHorizontal ? tickSize * tickDirection : pos,\n });\n\n parent.appendChild(tickLine);\n\n const label = createTextElement(format(tick), {\n 'aria-hidden': 'true',\n class: 'prism-axis-label',\n 'dominant-baseline': isHorizontal ? (isInverted ? 'auto' : 'hanging') : 'middle',\n 'text-anchor': isHorizontal ? 'middle' : isInverted ? 'end' : 'start',\n x: isHorizontal ? pos : tickSize * tickDirection * 1.5,\n y: isHorizontal ? tickSize * tickDirection * 1.5 : pos,\n });\n\n parent.appendChild(label);\n }\n\n if (config.label) {\n const labelEl = createTextElement(config.label, {\n class: 'prism-axis-title',\n 'dominant-baseline': 'middle',\n 'text-anchor': 'middle',\n });\n\n if (isHorizontal) {\n setAttributes(labelEl, { x: length / 2, y: tickSize * tickDirection * 6 });\n } else {\n setAttributes(labelEl, {\n transform: `translate(${tickSize * tickDirection * 7}, ${length / 2}) rotate(-90)`,\n });\n }\n\n parent.appendChild(labelEl);\n }\n}\n"],"mappings":"kGAMA,IAAM,EAAkB,GAClB,EAAY,EAEZ,kBAAqB,GACzB,aAAa,KAAO,EAAE,mBAAmB,IAAA,GAAW,CAAE,MAAO,QAAS,KAAM,SAAU,CAAC,EAAI,OAAO,CAAC,EAOrG,SAAgB,aAAa,EAAqB,EAAwB,EAAe,EAAsB,CAC7G,IAAM,EACJ,IAAa,SAAW,eAAe,EAAO,GAAK,IAAa,QAAU,aAAa,EAAM,KAAO,IAAA,GAElG,EAAW,EAAO,aAAa,YAAa,CAAS,EACpD,EAAO,gBAAgB,WAAW,CACzC,CAEA,SAAgB,iBAAiB,EAAoB,EAAgB,EAAuC,CAC1G,IAAM,EAAW,EAAO,UAAY,EAE9B,EADe,IAAa,UAAY,IAAa,MACnB,KAAK,IAAI,EAAG,KAAK,MAAM,EAAS,EAAE,CAAC,EAAI,KAAK,IAAI,EAAG,KAAK,MAAM,EAAS,EAAE,CAAC,EAElH,OAAO,EAAO,WAAa,CAC7B,CAGA,SAAS,kBACP,EACA,EACA,EACA,EACQ,CACR,G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Aa,MAAQ,QAC9D,EAAG,EAAe,EAAM,EAAW,EAAgB,IACnD,EAAG,EAAe,EAAW,EAAgB,IAAM,CACrD,CAAC,EAED,EAAO,YAAY,CAAK,CAC1B,CAEA,GAAI,EAAO,MAAO,CAChB,IAAM,EAAU,EAAA,kBAAkB,EAAO,MAAO,CAC9C,MAAO,mBACP,oBAAqB,SACrB,cAAe,QACjB,CAAC,EAEG,EACF,EAAA,cAAc,EAAS,CAAE,EAAG,EAAS,EAAG,EAAG,EAAW,EAAgB,CAAE,CAAC,EAEzE,EAAA,cAAc,EAAS,CACrB,UAAW,aAAa,EAAW,EAAgB,EAAE,IAAI,EAAS,EAAE,cACtE,CAAC,EAGH,EAAO,YAAY,CAAO,CAC5B,CACF"}
@@ -1,14 +1,14 @@
1
1
  import type { AxisConfig, AxisPosition } from '../types';
2
2
  import { type AnyScale } from './scale-utils';
3
3
  /**
4
- * Resolves the tick count an axis will render for a given scale/length — shared with
4
+ * Resolves the tick count an axis will render for a given scale/length: shared with
5
5
  * `renderGrid` so gridlines line up with axis ticks. `defaultPosition` must match the
6
6
  * one passed to the corresponding `renderAxis` call ('bottom' for xAxis, 'left' for yAxis).
7
7
  */
8
8
  export declare function positionAxis(parent: SVGGElement, position: AxisPosition, width: number, height: number): void;
9
9
  export declare function resolveTickCount(config: AxisConfig, length: number, defaultPosition: AxisPosition): number;
10
10
  /**
11
- * `defaultPosition` is applied when `config.position` is unset — pass `'bottom'` for an
11
+ * `defaultPosition` is applied when `config.position` is unset: pass `'bottom'` for an
12
12
  * xAxis call and `'left'` for a yAxis call so an unconfigured axis renders on its
13
13
  * conventional side instead of always defaulting to a horizontal bottom axis.
14
14
  */
@@ -1 +1 @@
1
- {"version":3,"file":"axis.d.ts","sourceRoot":"","sources":["../../src/axes/axis.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,KAAK,QAAQ,EAAW,MAAM,eAAe,CAAC;AAKvD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAM7G;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,YAAY,GAAG,MAAM,CAM1G;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,MAAM,EACd,eAAe,GAAE,YAAuB,GACvC,IAAI,CAiEN"}
1
+ {"version":3,"file":"axis.d.ts","sourceRoot":"","sources":["../../src/axes/axis.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,KAAK,QAAQ,EAAW,MAAM,eAAe,CAAC;AASvD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAM7G;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,YAAY,GAAG,MAAM,CAM1G;AAkBD;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,MAAM,EACd,eAAe,GAAE,YAAuB,GACvC,IAAI,CAqEN"}
package/dist/axes/axis.js CHANGED
@@ -1,2 +1,2 @@
1
- import{createSvgElement as e,removeChildren as t,setAttributes as n}from"../svg/element.js";import{createTextElement as r}from"../svg/text.js";import{mapTick as i}from"./scale-utils.js";var defaultTickFormat=e=>e instanceof Date?e.toLocaleDateString(void 0,{month:`short`,year:`numeric`}):String(e);function positionAxis(e,t,n,r){let i=t===`bottom`?`translate(0,${r})`:t===`right`?`translate(${n},0)`:void 0;i?e.setAttribute(`transform`,i):e.removeAttribute(`transform`)}function resolveTickCount(e,t,n){let r=e.position??n,i=r===`bottom`||r===`top`?Math.max(2,Math.floor(t/80)):Math.max(2,Math.floor(t/50));return e.tickCount??i}function renderAxis(a,o,s,c,l=`bottom`){t(a);let u=s.position??l,d=u===`bottom`||u===`top`,f=u===`top`||u===`left`,p=f?-1:1,m=e(`line`,{"aria-hidden":`true`,class:`prism-axis-line`,x1:0,x2:d?c:0,y1:0,y2:d?0:c});a.appendChild(m);let h=o.ticks(resolveTickCount(s,c,l)),g=s.tickFormat??defaultTickFormat;for(let t of h){let n=i(o,t),s=e(`line`,{"aria-hidden":`true`,class:`prism-axis-tick`,x1:d?n:0,x2:d?n:6*p,y1:d?0:n,y2:d?6*p:n});a.appendChild(s);let c=r(g(t),{"aria-hidden":`true`,class:`prism-axis-label`,"dominant-baseline":d?f?`auto`:`hanging`:`middle`,"text-anchor":d?`middle`:f?`end`:`start`,x:d?n:6*p*1.5,y:d?6*p*1.5:n});a.appendChild(c)}if(s.label){let e=r(s.label,{class:`prism-axis-title`,"dominant-baseline":`middle`,"text-anchor":`middle`});d?n(e,{x:c/2,y:6*p*6}):n(e,{transform:`translate(${6*p*7}, ${c/2}) rotate(-90)`}),a.appendChild(e)}}export{positionAxis,renderAxis,resolveTickCount};
1
+ import{createSvgElement as e,removeChildren as t,setAttributes as n}from"../svg/element.js";import{createTextElement as r,estimateTextWidth as i}from"../svg/text.js";import{mapTick as a}from"./scale-utils.js";var o=11,s=8,defaultTickFormat=e=>e instanceof Date?e.toLocaleDateString(void 0,{month:`short`,year:`numeric`}):String(e);function positionAxis(e,t,n,r){let i=t===`bottom`?`translate(0,${r})`:t===`right`?`translate(${n},0)`:void 0;i?e.setAttribute(`transform`,i):e.removeAttribute(`transform`)}function resolveTickCount(e,t,n){let r=e.position??n,i=r===`bottom`||r===`top`?Math.max(2,Math.floor(t/80)):Math.max(2,Math.floor(t/50));return e.tickCount??i}function categoryTickCount(e,t,n,r){if(e.length===0)return 0;let a=r?Math.max(...e.map(e=>i(t(e),o))):o*1.3;return Math.max(1,Math.min(e.length,Math.floor(n/(a+s))))}function renderAxis(i,o,s,c,l=`bottom`){t(i);let u=s.position??l,d=u===`bottom`||u===`top`,f=u===`top`||u===`left`,p=f?-1:1,m=e(`line`,{"aria-hidden":`true`,class:`prism-axis-line`,x1:0,x2:d?c:0,y1:0,y2:d?0:c});i.appendChild(m);let h=s.tickFormat??defaultTickFormat,g=s.tickCount===void 0&&`bandwidth`in o?categoryTickCount(o.domain,h,c,d):resolveTickCount(s,c,l),_=o.ticks(g);for(let t of _){let n=a(o,t),s=e(`line`,{"aria-hidden":`true`,class:`prism-axis-tick`,x1:d?n:0,x2:d?n:6*p,y1:d?0:n,y2:d?6*p:n});i.appendChild(s);let c=r(h(t),{"aria-hidden":`true`,class:`prism-axis-label`,"dominant-baseline":d?f?`auto`:`hanging`:`middle`,"text-anchor":d?`middle`:f?`end`:`start`,x:d?n:6*p*1.5,y:d?6*p*1.5:n});i.appendChild(c)}if(s.label){let e=r(s.label,{class:`prism-axis-title`,"dominant-baseline":`middle`,"text-anchor":`middle`});d?n(e,{x:c/2,y:6*p*6}):n(e,{transform:`translate(${6*p*7}, ${c/2}) rotate(-90)`}),i.appendChild(e)}}export{positionAxis,renderAxis,resolveTickCount};
2
2
  //# sourceMappingURL=axis.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"axis.js","names":[],"sources":["../../src/axes/axis.ts"],"sourcesContent":["import { createSvgElement, removeChildren, setAttributes } from '../svg/element';\nimport { createTextElement } from '../svg/text';\nimport type { AxisConfig, AxisPosition } from '../types';\nimport { type AnyScale, mapTick } from './scale-utils';\n\nconst defaultTickFormat = (v: Date | number | string): string =>\n v instanceof Date ? v.toLocaleDateString(undefined, { month: 'short', year: 'numeric' }) : String(v);\n\n/**\n * Resolves the tick count an axis will render for a given scale/length — shared with\n * `renderGrid` so gridlines line up with axis ticks. `defaultPosition` must match the\n * one passed to the corresponding `renderAxis` call ('bottom' for xAxis, 'left' for yAxis).\n */\nexport function positionAxis(parent: SVGGElement, position: AxisPosition, width: number, height: number): void {\n const transform =\n position === 'bottom' ? `translate(0,${height})` : position === 'right' ? `translate(${width},0)` : undefined;\n\n if (transform) parent.setAttribute('transform', transform);\n else parent.removeAttribute('transform');\n}\n\nexport function resolveTickCount(config: AxisConfig, length: number, defaultPosition: AxisPosition): number {\n const position = config.position ?? defaultPosition;\n const isHorizontal = position === 'bottom' || position === 'top';\n const defaultTickCount = isHorizontal ? Math.max(2, Math.floor(length / 80)) : Math.max(2, Math.floor(length / 50));\n\n return config.tickCount ?? defaultTickCount;\n}\n\n/**\n * `defaultPosition` is applied when `config.position` is unset — pass `'bottom'` for an\n * xAxis call and `'left'` for a yAxis call so an unconfigured axis renders on its\n * conventional side instead of always defaulting to a horizontal bottom axis.\n */\nexport function renderAxis(\n parent: SVGGElement,\n scale: AnyScale,\n config: AxisConfig,\n length: number,\n defaultPosition: AxisPosition = 'bottom',\n): void {\n removeChildren(parent);\n\n const position = config.position ?? defaultPosition;\n const isHorizontal = position === 'bottom' || position === 'top';\n const isInverted = position === 'top' || position === 'left';\n const tickSize = 6;\n const tickDirection = isInverted ? -1 : 1;\n\n const axisLine = createSvgElement('line', {\n 'aria-hidden': 'true',\n class: 'prism-axis-line',\n x1: isHorizontal ? 0 : 0,\n x2: isHorizontal ? length : 0,\n y1: isHorizontal ? 0 : 0,\n y2: isHorizontal ? 0 : length,\n });\n\n parent.appendChild(axisLine);\n\n const ticks = scale.ticks(resolveTickCount(config, length, defaultPosition));\n const format = config.tickFormat ?? defaultTickFormat;\n\n for (const tick of ticks) {\n const pos = mapTick(scale, tick);\n const tickLine = createSvgElement('line', {\n 'aria-hidden': 'true',\n class: 'prism-axis-tick',\n x1: isHorizontal ? pos : 0,\n x2: isHorizontal ? pos : tickSize * tickDirection,\n y1: isHorizontal ? 0 : pos,\n y2: isHorizontal ? tickSize * tickDirection : pos,\n });\n\n parent.appendChild(tickLine);\n\n const label = createTextElement(format(tick), {\n 'aria-hidden': 'true',\n class: 'prism-axis-label',\n 'dominant-baseline': isHorizontal ? (isInverted ? 'auto' : 'hanging') : 'middle',\n 'text-anchor': isHorizontal ? 'middle' : isInverted ? 'end' : 'start',\n x: isHorizontal ? pos : tickSize * tickDirection * 1.5,\n y: isHorizontal ? tickSize * tickDirection * 1.5 : pos,\n });\n\n parent.appendChild(label);\n }\n\n if (config.label) {\n const labelEl = createTextElement(config.label, {\n class: 'prism-axis-title',\n 'dominant-baseline': 'middle',\n 'text-anchor': 'middle',\n });\n\n if (isHorizontal) {\n setAttributes(labelEl, { x: length / 2, y: tickSize * tickDirection * 6 });\n } else {\n setAttributes(labelEl, {\n transform: `translate(${tickSize * tickDirection * 7}, ${length / 2}) rotate(-90)`,\n });\n }\n\n parent.appendChild(labelEl);\n }\n}\n"],"mappings":"0LAKA,IAAM,kBAAqB,GACzB,aAAa,KAAO,EAAE,mBAAmB,IAAA,GAAW,CAAE,MAAO,QAAS,KAAM,SAAU,CAAC,EAAI,OAAO,CAAC,EAOrG,SAAgB,aAAa,EAAqB,EAAwB,EAAe,EAAsB,CAC7G,IAAM,EACJ,IAAa,SAAW,eAAe,EAAO,GAAK,IAAa,QAAU,aAAa,EAAM,KAAO,IAAA,GAElG,EAAW,EAAO,aAAa,YAAa,CAAS,EACpD,EAAO,gBAAgB,WAAW,CACzC,CAEA,SAAgB,iBAAiB,EAAoB,EAAgB,EAAuC,CAC1G,IAAM,EAAW,EAAO,UAAY,EAE9B,EADe,IAAa,UAAY,IAAa,MACnB,KAAK,IAAI,EAAG,KAAK,MAAM,EAAS,EAAE,CAAC,EAAI,KAAK,IAAI,EAAG,KAAK,MAAM,EAAS,EAAE,CAAC,EAElH,OAAO,EAAO,WAAa,CAC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,EAAE,cACtE,CAAC,EAGH,EAAO,YAAY,CAAO,CAC5B,CACF"}
1
+ {"version":3,"file":"axis.js","names":[],"sources":["../../src/axes/axis.ts"],"sourcesContent":["import { createSvgElement, removeChildren, setAttributes } from '../svg/element';\nimport { createTextElement, estimateTextWidth } from '../svg/text';\nimport type { AxisConfig, AxisPosition } from '../types';\nimport { type AnyScale, mapTick } from './scale-utils';\n\n/** Default `--prism-font-size-label` in px, used to estimate category label size. */\nconst LABEL_FONT_SIZE = 11;\nconst LABEL_GAP = 8;\n\nconst defaultTickFormat = (v: Date | number | string): string =>\n v instanceof Date ? v.toLocaleDateString(undefined, { month: 'short', year: 'numeric' }) : String(v);\n\n/**\n * Resolves the tick count an axis will render for a given scale/length: shared with\n * `renderGrid` so gridlines line up with axis ticks. `defaultPosition` must match the\n * one passed to the corresponding `renderAxis` call ('bottom' for xAxis, 'left' for yAxis).\n */\nexport function positionAxis(parent: SVGGElement, position: AxisPosition, width: number, height: number): void {\n const transform =\n position === 'bottom' ? `translate(0,${height})` : position === 'right' ? `translate(${width},0)` : undefined;\n\n if (transform) parent.setAttribute('transform', transform);\n else parent.removeAttribute('transform');\n}\n\nexport function resolveTickCount(config: AxisConfig, length: number, defaultPosition: AxisPosition): number {\n const position = config.position ?? defaultPosition;\n const isHorizontal = position === 'bottom' || position === 'top';\n const defaultTickCount = isHorizontal ? Math.max(2, Math.floor(length / 80)) : Math.max(2, Math.floor(length / 50));\n\n return config.tickCount ?? defaultTickCount;\n}\n\n/** How many category labels fit along the axis without their estimated boxes overlapping. */\nfunction categoryTickCount(\n domain: readonly string[],\n format: (value: string) => string,\n length: number,\n isHorizontal: boolean,\n): number {\n if (domain.length === 0) return 0;\n\n const size = isHorizontal\n ? Math.max(...domain.map((value) => estimateTextWidth(format(value), LABEL_FONT_SIZE)))\n : LABEL_FONT_SIZE * 1.3;\n\n return Math.max(1, Math.min(domain.length, Math.floor(length / (size + LABEL_GAP))));\n}\n\n/**\n * `defaultPosition` is applied when `config.position` is unset: pass `'bottom'` for an\n * xAxis call and `'left'` for a yAxis call so an unconfigured axis renders on its\n * conventional side instead of always defaulting to a horizontal bottom axis.\n */\nexport function renderAxis(\n parent: SVGGElement,\n scale: AnyScale,\n config: AxisConfig,\n length: number,\n defaultPosition: AxisPosition = 'bottom',\n): void {\n removeChildren(parent);\n\n const position = config.position ?? defaultPosition;\n const isHorizontal = position === 'bottom' || position === 'top';\n const isInverted = position === 'top' || position === 'left';\n const tickSize = 6;\n const tickDirection = isInverted ? -1 : 1;\n\n const axisLine = createSvgElement('line', {\n 'aria-hidden': 'true',\n class: 'prism-axis-line',\n x1: isHorizontal ? 0 : 0,\n x2: isHorizontal ? length : 0,\n y1: isHorizontal ? 0 : 0,\n y2: isHorizontal ? 0 : length,\n });\n\n parent.appendChild(axisLine);\n\n const format = config.tickFormat ?? defaultTickFormat;\n const tickCount =\n config.tickCount === undefined && 'bandwidth' in scale\n ? categoryTickCount(scale.domain, format, length, isHorizontal)\n : resolveTickCount(config, length, defaultPosition);\n const ticks = scale.ticks(tickCount);\n\n for (const tick of ticks) {\n const pos = mapTick(scale, tick);\n const tickLine = createSvgElement('line', {\n 'aria-hidden': 'true',\n class: 'prism-axis-tick',\n x1: isHorizontal ? pos : 0,\n x2: isHorizontal ? pos : tickSize * tickDirection,\n y1: isHorizontal ? 0 : pos,\n y2: isHorizontal ? tickSize * tickDirection : pos,\n });\n\n parent.appendChild(tickLine);\n\n const label = createTextElement(format(tick), {\n 'aria-hidden': 'true',\n class: 'prism-axis-label',\n 'dominant-baseline': isHorizontal ? (isInverted ? 'auto' : 'hanging') : 'middle',\n 'text-anchor': isHorizontal ? 'middle' : isInverted ? 'end' : 'start',\n x: isHorizontal ? pos : tickSize * tickDirection * 1.5,\n y: isHorizontal ? tickSize * tickDirection * 1.5 : pos,\n });\n\n parent.appendChild(label);\n }\n\n if (config.label) {\n const labelEl = createTextElement(config.label, {\n class: 'prism-axis-title',\n 'dominant-baseline': 'middle',\n 'text-anchor': 'middle',\n });\n\n if (isHorizontal) {\n setAttributes(labelEl, { x: length / 2, y: tickSize * tickDirection * 6 });\n } else {\n setAttributes(labelEl, {\n transform: `translate(${tickSize * tickDirection * 7}, ${length / 2}) rotate(-90)`,\n });\n }\n\n parent.appendChild(labelEl);\n }\n}\n"],"mappings":"iNAMA,IAAM,EAAkB,GAClB,EAAY,EAEZ,kBAAqB,GACzB,aAAa,KAAO,EAAE,mBAAmB,IAAA,GAAW,CAAE,MAAO,QAAS,KAAM,SAAU,CAAC,EAAI,OAAO,CAAC,EAOrG,SAAgB,aAAa,EAAqB,EAAwB,EAAe,EAAsB,CAC7G,IAAM,EACJ,IAAa,SAAW,eAAe,EAAO,GAAK,IAAa,QAAU,aAAa,EAAM,KAAO,IAAA,GAElG,EAAW,EAAO,aAAa,YAAa,CAAS,EACpD,EAAO,gBAAgB,WAAW,CACzC,CAEA,SAAgB,iBAAiB,EAAoB,EAAgB,EAAuC,CAC1G,IAAM,EAAW,EAAO,UAAY,EAE9B,EADe,IAAa,UAAY,IAAa,MACnB,KAAK,IAAI,EAAG,KAAK,MAAM,EAAS,EAAE,CAAC,EAAI,KAAK,IAAI,EAAG,KAAK,MAAM,EAAS,EAAE,CAAC,EAElH,OAAO,EAAO,WAAa,CAC7B,CAGA,SAAS,kBACP,EACA,EACA,EACA,EACQ,CACR,GAAI,EAAO,SAAW,EAAG,MAAO,GAEhC,IAAM,EAAO,EACT,KAAK,IAAI,GAAG,EAAO,IAAK,GAAU,EAAkB,EAAO,CAAK,EAAG,CAAe,CAAC,CAAC,EACpF,EAAkB,IAEtB,OAAO,KAAK,IAAI,EAAG,KAAK,IAAI,EAAO,OAAQ,KAAK,MAAM,GAAU,EAAO,EAAU,CAAC,CAAC,CACrF,CAOA,SAAgB,WACd,EACA,EACA,EACA,EACA,EAAgC,SAC1B,CACN,EAAe,CAAM,EAErB,IAAM,EAAW,EAAO,UAAY,EAC9B,EAAe,IAAa,UAAY,IAAa,MACrD,EAAa,IAAa,OAA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}
@@ -1 +1 @@
1
- {"version":3,"file":"scale-utils.cjs","names":[],"sources":["../../src/axes/scale-utils.ts"],"sourcesContent":["import type { BandScale, Scale } from '../types';\n\nexport type AnyScale = BandScale | Scale<Date> | Scale<number>;\n\nfunction isBandScale(scale: AnyScale): scale is BandScale {\n return typeof (scale as BandScale).bandwidth === 'function';\n}\n\n/**\n * Maps a tick value through any of prism's three scale kinds, centering band-scale\n * ticks on their band (bandScale.map() returns a band's left edge by design).\n *\n * Overloaded so a caller's `tick` type must match the scale kind it's paired with —\n * `AxisConfig`/`GridConfig` accept any scale kind, so the runtime discrimination\n * inside the implementation is unavoidable, but the overload set keeps that a single\n * isolated cast here instead of an unchecked `Date | number | string` accepted at\n * every call site.\n */\nexport function mapTick(scale: BandScale, tick: string): number;\nexport function mapTick(scale: Scale<Date>, tick: Date): number;\nexport function mapTick(scale: Scale<number>, tick: number): number;\n// Fallback overload for callers (axis.ts/grid.ts) holding an already-erased `AnyScale`\n// union — the type-correlated overloads above are what protect a caller with a\n// narrower, known scale type from mismatching it with the wrong tick type.\nexport function mapTick(scale: AnyScale, tick: Date | number | string): number;\nexport function mapTick(scale: AnyScale, tick: Date | number | string): number {\n if (isBandScale(scale)) return scale.map(tick as string) + scale.bandwidth() / 2;\n\n return (scale as Scale<Date | number>).map(tick as Date | number);\n}\n"],"mappings":"AAIA,SAAS,YAAY,EAAqC,CACxD,OAAO,OAAQ,EAAoB,WAAc,UACnD,CAmBA,SAAgB,QAAQ,EAAiB,EAAsC,CAG7E,OAFI,YAAY,CAAK,EAAU,EAAM,IAAI,CAAc,EAAI,EAAM,UAAU,EAAI,EAEvE,EAA+B,IAAI,CAAqB,CAClE"}
1
+ {"version":3,"file":"scale-utils.cjs","names":[],"sources":["../../src/axes/scale-utils.ts"],"sourcesContent":["import type { BandScale, Scale } from '../types';\n\nexport type AnyScale = BandScale | Scale<Date> | Scale<number>;\n\nfunction isBandScale(scale: AnyScale): scale is BandScale {\n return typeof (scale as BandScale).bandwidth === 'function';\n}\n\n/**\n * Maps a tick value through any of prism's three scale kinds, centering band-scale\n * ticks on their band (bandScale.map() returns a band's left edge by design).\n *\n * Overloaded so a caller's `tick` type must match the scale kind it's paired with :\n * `AxisConfig`/`GridConfig` accept any scale kind, so the runtime discrimination\n * inside the implementation is unavoidable, but the overload set keeps that a single\n * isolated cast here instead of an unchecked `Date | number | string` accepted at\n * every call site.\n */\nexport function mapTick(scale: BandScale, tick: string): number;\nexport function mapTick(scale: Scale<Date>, tick: Date): number;\nexport function mapTick(scale: Scale<number>, tick: number): number;\n// Fallback overload for callers (axis.ts/grid.ts) holding an already-erased `AnyScale`\n// union: the type-correlated overloads above are what protect a caller with a\n// narrower, known scale type from mismatching it with the wrong tick type.\nexport function mapTick(scale: AnyScale, tick: Date | number | string): number;\nexport function mapTick(scale: AnyScale, tick: Date | number | string): number {\n if (isBandScale(scale)) return scale.map(tick as string) + scale.bandwidth() / 2;\n\n return (scale as Scale<Date | number>).map(tick as Date | number);\n}\n"],"mappings":"AAIA,SAAS,YAAY,EAAqC,CACxD,OAAO,OAAQ,EAAoB,WAAc,UACnD,CAmBA,SAAgB,QAAQ,EAAiB,EAAsC,CAG7E,OAFI,YAAY,CAAK,EAAU,EAAM,IAAI,CAAc,EAAI,EAAM,UAAU,EAAI,EAEvE,EAA+B,IAAI,CAAqB,CAClE"}
@@ -4,7 +4,7 @@ export type AnyScale = BandScale | Scale<Date> | Scale<number>;
4
4
  * Maps a tick value through any of prism's three scale kinds, centering band-scale
5
5
  * ticks on their band (bandScale.map() returns a band's left edge by design).
6
6
  *
7
- * Overloaded so a caller's `tick` type must match the scale kind it's paired with —
7
+ * Overloaded so a caller's `tick` type must match the scale kind it's paired with :
8
8
  * `AxisConfig`/`GridConfig` accept any scale kind, so the runtime discrimination
9
9
  * inside the implementation is unavoidable, but the overload set keeps that a single
10
10
  * isolated cast here instead of an unchecked `Date | number | string` accepted at
@@ -1 +1 @@
1
- {"version":3,"file":"scale-utils.js","names":[],"sources":["../../src/axes/scale-utils.ts"],"sourcesContent":["import type { BandScale, Scale } from '../types';\n\nexport type AnyScale = BandScale | Scale<Date> | Scale<number>;\n\nfunction isBandScale(scale: AnyScale): scale is BandScale {\n return typeof (scale as BandScale).bandwidth === 'function';\n}\n\n/**\n * Maps a tick value through any of prism's three scale kinds, centering band-scale\n * ticks on their band (bandScale.map() returns a band's left edge by design).\n *\n * Overloaded so a caller's `tick` type must match the scale kind it's paired with —\n * `AxisConfig`/`GridConfig` accept any scale kind, so the runtime discrimination\n * inside the implementation is unavoidable, but the overload set keeps that a single\n * isolated cast here instead of an unchecked `Date | number | string` accepted at\n * every call site.\n */\nexport function mapTick(scale: BandScale, tick: string): number;\nexport function mapTick(scale: Scale<Date>, tick: Date): number;\nexport function mapTick(scale: Scale<number>, tick: number): number;\n// Fallback overload for callers (axis.ts/grid.ts) holding an already-erased `AnyScale`\n// union — the type-correlated overloads above are what protect a caller with a\n// narrower, known scale type from mismatching it with the wrong tick type.\nexport function mapTick(scale: AnyScale, tick: Date | number | string): number;\nexport function mapTick(scale: AnyScale, tick: Date | number | string): number {\n if (isBandScale(scale)) return scale.map(tick as string) + scale.bandwidth() / 2;\n\n return (scale as Scale<Date | number>).map(tick as Date | number);\n}\n"],"mappings":"AAIA,SAAS,YAAY,EAAqC,CACxD,OAAO,OAAQ,EAAoB,WAAc,UACnD,CAmBA,SAAgB,QAAQ,EAAiB,EAAsC,CAG7E,OAFI,YAAY,CAAK,EAAU,EAAM,IAAI,CAAc,EAAI,EAAM,UAAU,EAAI,EAEvE,EAA+B,IAAI,CAAqB,CAClE"}
1
+ {"version":3,"file":"scale-utils.js","names":[],"sources":["../../src/axes/scale-utils.ts"],"sourcesContent":["import type { BandScale, Scale } from '../types';\n\nexport type AnyScale = BandScale | Scale<Date> | Scale<number>;\n\nfunction isBandScale(scale: AnyScale): scale is BandScale {\n return typeof (scale as BandScale).bandwidth === 'function';\n}\n\n/**\n * Maps a tick value through any of prism's three scale kinds, centering band-scale\n * ticks on their band (bandScale.map() returns a band's left edge by design).\n *\n * Overloaded so a caller's `tick` type must match the scale kind it's paired with :\n * `AxisConfig`/`GridConfig` accept any scale kind, so the runtime discrimination\n * inside the implementation is unavoidable, but the overload set keeps that a single\n * isolated cast here instead of an unchecked `Date | number | string` accepted at\n * every call site.\n */\nexport function mapTick(scale: BandScale, tick: string): number;\nexport function mapTick(scale: Scale<Date>, tick: Date): number;\nexport function mapTick(scale: Scale<number>, tick: number): number;\n// Fallback overload for callers (axis.ts/grid.ts) holding an already-erased `AnyScale`\n// union: the type-correlated overloads above are what protect a caller with a\n// narrower, known scale type from mismatching it with the wrong tick type.\nexport function mapTick(scale: AnyScale, tick: Date | number | string): number;\nexport function mapTick(scale: AnyScale, tick: Date | number | string): number {\n if (isBandScale(scale)) return scale.map(tick as string) + scale.bandwidth() / 2;\n\n return (scale as Scale<Date | number>).map(tick as Date | number);\n}\n"],"mappings":"AAIA,SAAS,YAAY,EAAqC,CACxD,OAAO,OAAQ,EAAoB,WAAc,UACnD,CAmBA,SAAgB,QAAQ,EAAiB,EAAsC,CAG7E,OAFI,YAAY,CAAK,EAAU,EAAM,IAAI,CAAc,EAAI,EAAM,UAAU,EAAI,EAEvE,EAA+B,IAAI,CAAqB,CAClE"}
@@ -1,2 +1,2 @@
1
- const e=require("../../svg/element.cjs"),t=require("../../axes/axis.cjs"),n=require("../../axes/grid.cjs"),r=require("../../core/cartesian-scales.cjs"),i=require("../../core/layout.cjs"),a=require("../../core/chart-scaffold.cjs"),o=require("../../interaction/crosshair.cjs"),s=require("../../interaction/series-interaction.cjs"),c=require("../../theme/index.cjs"),l=require("./area-renderer.cjs");function createAreaChart(u,d){let f=null,p=d.series;return a.createChartScaffold(u,d,u=>{let{groups:m,legend:h,tooltip:g}=u,_=u.dimensions,v=i.chartArea(_.width,_.height,_.margin),y=p.map(e=>e.data),b=y.flat().map(e=>e.key),x=y.flat().map(e=>e.value);if(b.length===0){a.clearCartesianDom(m,h,g,f);return}d.crosshair&&!f&&(f=o.createCrosshair(u.chartArea,d.crosshair));let S=r.buildXScale(b,v.width),C=r.buildYScale(x,v.height),w=C.map(0);for(d.yAxis?.grid&&n.renderGrid(m.grid,C,d.yAxis.grid,v.width,`horizontal`,t.resolveTickCount(d.yAxis,v.height,`left`)),d.xAxis?.grid&&n.renderGrid(m.grid,S,d.xAxis.grid,v.height,`vertical`,t.resolveTickCount(d.xAxis,v.width,`bottom`)),d.xAxis&&(t.positionAxis(m.xAxis,d.xAxis.position??`bottom`,v.width,v.height),t.renderAxis(m.xAxis,S,d.xAxis,v.width,`bottom`)),d.yAxis&&(t.positionAxis(m.yAxis,d.yAxis.position??`left`,v.width,v.height),t.renderAxis(m.yAxis,C,d.yAxis,v.height,`left`));m.series.children.length>p.length;)m.series.removeChild(m.series.lastChild);let T=[];for(let t=0;t<p.length;t++){let n=p[t],r=m.series.children[t];r||(r=e.createSvgElement(`g`,{class:`prism-area-series`}),m.series.appendChild(r));let i=l.computeAreaPoints(y[t],S,C);T.push(i),l.renderArea(r,i,w,{color:c.seriesColor(t,n.color),curve:n.curve??`linear`,disposalSignal:u.disposalSignal,fillOpacity:n.fillOpacity??.3,showLine:n.showLine!==!1,transition:d.transition})}return h?.update(p.map((e,t)=>({color:c.seriesColor(t,e.color),name:e.name}))),g?.hide(),s.createSeriesInteraction({crosshair:f,dims:()=>u.dimensions,getData:()=>y,getPoints:()=>T,getSeriesList:()=>p,onClick:d.onClick,onHover:d.onHover,svg:u.svg,tooltip:g})},e=>{p=e})}exports.createAreaChart=createAreaChart;
1
+ const e=require("../../svg/element.cjs"),t=require("../../axes/axis.cjs"),n=require("../../axes/grid.cjs"),r=require("../../core/cartesian-scales.cjs"),i=require("../../core/layout.cjs"),a=require("../../core/chart-scaffold.cjs"),o=require("../../core/series-id.cjs"),s=require("../../interaction/crosshair.cjs"),c=require("../../interaction/series-interaction.cjs"),l=require("../../theme/index.cjs"),u=require("./area-renderer.cjs");function createAreaChart(d,f){let p=null,m=null,h=f.series;return a.createChartScaffold(d,f,d=>{let{groups:g,legend:_,tooltip:v}=d,y=d.dimensions,b=i.chartArea(y.width,y.height,y.margin),x=h.map(e=>e.data),S=x.flat().map(e=>e.key),C=x.flat().map(e=>e.value);if(S.length===0){a.clearCartesianDom(g,_,v,p),m?.replaceChildren();return}f.crosshair&&!p&&(p=s.createCrosshair(d.chartArea,f.crosshair));let w=r.buildXScale(S,b.width),T=r.buildYScale(C,b.height),E=T.map(0);for(f.yAxis?.grid&&n.renderGrid(g.grid,T,f.yAxis.grid,b.width,`horizontal`,t.resolveTickCount(f.yAxis,b.height,`left`)),f.xAxis?.grid&&n.renderGrid(g.grid,w,f.xAxis.grid,b.height,`vertical`,t.resolveTickCount(f.xAxis,b.width,`bottom`)),f.xAxis&&(t.positionAxis(g.xAxis,f.xAxis.position??`bottom`,b.width,b.height),t.renderAxis(g.xAxis,w,f.xAxis,b.width,`bottom`)),f.yAxis&&(t.positionAxis(g.yAxis,f.yAxis.position??`left`,b.width,b.height),t.renderAxis(g.yAxis,T,f.yAxis,b.height,`left`));g.series.children.length>h.length;)g.series.removeChild(g.series.lastChild);let D=[];for(let t=0;t<h.length;t++){let n=h[t],r=g.series.children[t];r||(r=e.createSvgElement(`g`,{class:`prism-area-series`}),g.series.appendChild(r)),r.setAttribute(`data-series-id`,o.seriesDomId(n,t));let i=u.computeAreaPoints(x[t],w,T);D.push(i),u.renderArea(r,i,E,{color:l.seriesColor(t,n.color),curve:n.curve??`linear`,disposalSignal:d.disposalSignal,fill:n.fill??`gradient`,fillOpacity:n.fillOpacity,marks:n.data,showLine:n.showLine!==!1,transition:f.transition})}return _?.update(h.map((e,t)=>({color:l.seriesColor(t,e.color),name:e.name}))),v?.hide(),m=c.ensureMarkerGroup(d.chartArea,m),c.createSeriesInteraction({announcer:d.announcer,colors:()=>h.map((e,t)=>l.seriesColor(t,e.color)),crosshair:p,dims:()=>d.dimensions,getData:()=>x,getPoints:()=>D,getSeriesList:()=>h,markers:m,onClick:f.onClick,onHover:f.onHover,seriesGroup:g.series,svg:d.svg,tooltip:v})},e=>{h=e})}exports.createAreaChart=createAreaChart;
2
2
  //# sourceMappingURL=area-chart.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"area-chart.cjs","names":[],"sources":["../../../src/charts/area/area-chart.ts"],"sourcesContent":["import { positionAxis, renderAxis, resolveTickCount } from '../../axes/axis';\nimport { renderGrid } from '../../axes/grid';\nimport { buildXScale, buildYScale } from '../../core/cartesian-scales';\nimport { clearCartesianDom, createChartScaffold } from '../../core/chart-scaffold';\nimport { chartArea } from '../../core/layout';\nimport { createCrosshair } from '../../interaction/crosshair';\nimport { createSeriesInteraction } from '../../interaction/series-interaction';\nimport { createSvgElement } from '../../svg/element';\nimport type { Point } from '../../svg/path';\nimport { seriesColor } from '../../theme';\nimport type { AreaChartConfig, AreaSeriesConfig, ChartHandle } from '../../types';\nimport { computeAreaPoints, renderArea } from './area-renderer';\n\nexport function createAreaChart(container: HTMLElement, config: AreaChartConfig): ChartHandle<AreaSeriesConfig[]> {\n let crosshair: ReturnType<typeof createCrosshair> | null = null;\n let seriesList = config.series;\n\n return createChartScaffold(\n container,\n config,\n (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const allData = seriesList.map((series) => series.data);\n const allX = allData.flat().map((datum) => datum.key);\n const allY = allData.flat().map((d) => d.value);\n\n if (allX.length === 0) {\n clearCartesianDom(groups, legend, tooltip, crosshair);\n\n return;\n }\n\n if (config.crosshair && !crosshair) {\n crosshair = createCrosshair(ctx.chartArea, config.crosshair);\n }\n\n const xScale = buildXScale(allX, area.width);\n const yScale = buildYScale(allY, area.height);\n const baselineY = yScale.map(0);\n\n if (config.yAxis?.grid) {\n renderGrid(\n groups.grid,\n yScale,\n config.yAxis.grid,\n area.width,\n 'horizontal',\n resolveTickCount(config.yAxis, area.height, 'left'),\n );\n }\n\n if (config.xAxis?.grid) {\n renderGrid(\n groups.grid,\n xScale,\n config.xAxis.grid,\n area.height,\n 'vertical',\n resolveTickCount(config.xAxis, area.width, 'bottom'),\n );\n }\n\n if (config.xAxis) {\n positionAxis(groups.xAxis, config.xAxis.position ?? 'bottom', area.width, area.height);\n renderAxis(groups.xAxis, xScale, config.xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) {\n positionAxis(groups.yAxis, config.yAxis.position ?? 'left', area.width, area.height);\n renderAxis(groups.yAxis, yScale, config.yAxis, area.height, 'left');\n }\n\n while (groups.series.children.length > seriesList.length) {\n groups.series.removeChild(groups.series.lastChild!);\n }\n\n const allPoints: Point[][] = [];\n\n for (let i = 0; i < seriesList.length; i++) {\n const series = seriesList[i];\n let group = groups.series.children[i] as SVGGElement | undefined;\n\n if (!group) {\n group = createSvgElement('g', { class: 'prism-area-series' });\n groups.series.appendChild(group);\n }\n\n const points = computeAreaPoints(allData[i], xScale, yScale);\n\n allPoints.push(points);\n\n renderArea(group, points, baselineY, {\n color: seriesColor(i, series.color),\n curve: series.curve ?? 'linear',\n disposalSignal: ctx.disposalSignal,\n fillOpacity: series.fillOpacity ?? 0.3,\n showLine: series.showLine !== false,\n transition: config.transition,\n });\n }\n\n legend?.update(seriesList.map((s, i) => ({ color: seriesColor(i, s.color), name: s.name })));\n tooltip?.hide();\n\n return createSeriesInteraction({\n crosshair,\n dims: () => ctx.dimensions,\n getData: () => allData,\n getPoints: () => allPoints,\n getSeriesList: () => seriesList,\n onClick: config.onClick,\n onHover: config.onHover,\n svg: ctx.svg,\n tooltip,\n });\n },\n (data) => {\n seriesList = data;\n },\n );\n}\n"],"mappings":"6YAaA,SAAgB,gBAAgB,EAAwB,EAA0D,CAChH,IAAI,EAAuD,KACvD,EAAa,EAAO,OAExB,OAAO,EAAA,oBACL,EACA,EACC,GAAQ,CACP,GAAM,CAAE,SAAQ,SAAQ,WAAY,EAC9B,EAAO,EAAI,WACX,EAAO,EAAA,UAAU,EAAK,MAAO,EAAK,OAAQ,EAAK,MAAM,EACrD,EAA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,EAAQ,EAAO,OAAO,SAAS,GAE9B,IACH,EAAQ,EAAA,iBAAiB,IAAK,CAAE,MAAO,mBAAoB,CAAC,EAC5D,EAAO,OAAO,YAAY,CAAK,GAGjC,IAAM,EAAS,EAAA,kBAAkB,EAAQ,GAAI,EAAQ,CAAM,EAE3D,EAAU,KAAK,CAAM,EAErB,EAAA,WAAW,EAAO,EAAQ,EAAW,CACnC,MAAO,EAAA,YAAY,EAAG,EAAO,KAAK,EAClC,MAAO,EAAO,OAAS,SACvB,eAAgB,EAAI,eACpB,YAAa,EAAO,aAAe,GACnC,SAAU,EAAO,WAAa,GAC9B,WAAY,EAAO,UACrB,CAAC,CACH,CAKA,OAHA,GAAQ,OAAO,EAAW,KAAK,EAAG,KAAO,CAAE,MAAO,EAAA,YAAY,EAAG,EAAE,KAAK,EAAG,KAAM,EAAE,IAAK,EAAE,CAAC,EAC3F,GAAS,KAAK,EAEP,EAAA,wBAAwB,CAC7B,YACA,SAAY,EAAI,WAChB,YAAe,EACf,cAAiB,EACjB,kBAAqB,EACrB,QAAS,EAAO,QAChB,QAAS,EAAO,QAChB,IAAK,EAAI,IACT,SACF,CAAC,CACH,EACC,GAAS,CACR,EAAa,CACf,CACF,CACF"}
1
+ {"version":3,"file":"area-chart.cjs","names":[],"sources":["../../../src/charts/area/area-chart.ts"],"sourcesContent":["import { positionAxis, renderAxis, resolveTickCount } from '../../axes/axis';\nimport { renderGrid } from '../../axes/grid';\nimport { buildXScale, buildYScale } from '../../core/cartesian-scales';\nimport { clearCartesianDom, createChartScaffold } from '../../core/chart-scaffold';\nimport { chartArea } from '../../core/layout';\nimport { seriesDomId } from '../../core/series-id';\nimport { createCrosshair } from '../../interaction/crosshair';\nimport { createSeriesInteraction, ensureMarkerGroup } from '../../interaction/series-interaction';\nimport { createSvgElement } from '../../svg/element';\nimport type { Point } from '../../svg/path';\nimport { seriesColor } from '../../theme';\nimport type { AreaChartConfig, AreaSeriesConfig, ChartHandle } from '../../types';\nimport { computeAreaPoints, renderArea } from './area-renderer';\n\nexport function createAreaChart(container: HTMLElement, config: AreaChartConfig): ChartHandle<AreaSeriesConfig[]> {\n let crosshair: ReturnType<typeof createCrosshair> | null = null;\n let markers: SVGGElement | null = null;\n let seriesList = config.series;\n\n return createChartScaffold(\n container,\n config,\n (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const allData = seriesList.map((series) => series.data);\n const allX = allData.flat().map((datum) => datum.key);\n const allY = allData.flat().map((d) => d.value);\n\n if (allX.length === 0) {\n clearCartesianDom(groups, legend, tooltip, crosshair);\n markers?.replaceChildren();\n\n return;\n }\n\n if (config.crosshair && !crosshair) {\n crosshair = createCrosshair(ctx.chartArea, config.crosshair);\n }\n\n const xScale = buildXScale(allX, area.width);\n const yScale = buildYScale(allY, area.height);\n const baselineY = yScale.map(0);\n\n if (config.yAxis?.grid) {\n renderGrid(\n groups.grid,\n yScale,\n config.yAxis.grid,\n area.width,\n 'horizontal',\n resolveTickCount(config.yAxis, area.height, 'left'),\n );\n }\n\n if (config.xAxis?.grid) {\n renderGrid(\n groups.grid,\n xScale,\n config.xAxis.grid,\n area.height,\n 'vertical',\n resolveTickCount(config.xAxis, area.width, 'bottom'),\n );\n }\n\n if (config.xAxis) {\n positionAxis(groups.xAxis, config.xAxis.position ?? 'bottom', area.width, area.height);\n renderAxis(groups.xAxis, xScale, config.xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) {\n positionAxis(groups.yAxis, config.yAxis.position ?? 'left', area.width, area.height);\n renderAxis(groups.yAxis, yScale, config.yAxis, area.height, 'left');\n }\n\n while (groups.series.children.length > seriesList.length) {\n groups.series.removeChild(groups.series.lastChild!);\n }\n\n const allPoints: Point[][] = [];\n\n for (let i = 0; i < seriesList.length; i++) {\n const series = seriesList[i];\n let group = groups.series.children[i] as SVGGElement | undefined;\n\n if (!group) {\n group = createSvgElement('g', { class: 'prism-area-series' });\n groups.series.appendChild(group);\n }\n\n group.setAttribute('data-series-id', seriesDomId(series, i));\n\n const points = computeAreaPoints(allData[i], xScale, yScale);\n\n allPoints.push(points);\n\n renderArea(group, points, baselineY, {\n color: seriesColor(i, series.color),\n curve: series.curve ?? 'linear',\n disposalSignal: ctx.disposalSignal,\n fill: series.fill ?? 'gradient',\n fillOpacity: series.fillOpacity,\n marks: series.data,\n showLine: series.showLine !== false,\n transition: config.transition,\n });\n }\n\n legend?.update(seriesList.map((s, i) => ({ color: seriesColor(i, s.color), name: s.name })));\n tooltip?.hide();\n markers = ensureMarkerGroup(ctx.chartArea, markers);\n\n return createSeriesInteraction({\n announcer: ctx.announcer,\n colors: () => seriesList.map((s, i) => seriesColor(i, s.color)),\n crosshair,\n dims: () => ctx.dimensions,\n getData: () => allData,\n getPoints: () => allPoints,\n getSeriesList: () => seriesList,\n markers,\n onClick: config.onClick,\n onHover: config.onHover,\n seriesGroup: groups.series,\n svg: ctx.svg,\n tooltip,\n });\n },\n (data) => {\n seriesList = data;\n },\n );\n}\n"],"mappings":"mbAcA,SAAgB,gBAAgB,EAAwB,EAA0D,CAChH,IAAI,EAAuD,KACvD,EAA8B,KAC9B,EAAa,EAAO,OAExB,OAAO,EAAA,oBACL,EACA,EACC,GAAQ,CACP,GAAM,CAAE,SAAQ,SAAQ,WAAY,EAC9B,EAAO,EAAI,WACX,EAAO,EAAA,UAAU,EAAK,MAAO,EAAK,OAAQ,EAAK,MAAM,EACrD,EAAU,EAAW,IAAK,GAAW,EAAO,IAAI,EAChD,EAAO,EAAQ,KAAK,CAAC,CAAC,IAAK,GAAU,EAAM,GAAG,EAC9C,EAAO,EAAQ,KAAK,CAAC,CAAC,IAAK,GAAM,EAAE,KAAK,EAE9C,GAAI,EAAK,SAAW,EAAG,CACrB,EAAA,kBAAkB,EAAQ,EAAQ,EAAS,CAAS,EACpD,GAAS,gBAAgB,EAEzB,MACF,CAEI,EAAO,WAAa,CAAC,IACvB,EAAY,EAAA,gBAAgB,EAAI,UAAW,EAA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AAO,EAAA,YAAY,EAAG,EAAO,KAAK,EAClC,MAAO,EAAO,OAAS,SACvB,eAAgB,EAAI,eACpB,KAAM,EAAO,MAAQ,WACrB,YAAa,EAAO,YACpB,MAAO,EAAO,KACd,SAAU,EAAO,WAAa,GAC9B,WAAY,EAAO,UACrB,CAAC,CACH,CAMA,OAJA,GAAQ,OAAO,EAAW,KAAK,EAAG,KAAO,CAAE,MAAO,EAAA,YAAY,EAAG,EAAE,KAAK,EAAG,KAAM,EAAE,IAAK,EAAE,CAAC,EAC3F,GAAS,KAAK,EACd,EAAU,EAAA,kBAAkB,EAAI,UAAW,CAAO,EAE3C,EAAA,wBAAwB,CAC7B,UAAW,EAAI,UACf,WAAc,EAAW,KAAK,EAAG,IAAM,EAAA,YAAY,EAAG,EAAE,KAAK,CAAC,EAC9D,YACA,SAAY,EAAI,WAChB,YAAe,EACf,cAAiB,EACjB,kBAAqB,EACrB,UACA,QAAS,EAAO,QAChB,QAAS,EAAO,QAChB,YAAa,EAAO,OACpB,IAAK,EAAI,IACT,SACF,CAAC,CACH,EACC,GAAS,CACR,EAAa,CACf,CACF,CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"area-chart.d.ts","sourceRoot":"","sources":["../../../src/charts/area/area-chart.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAGlF,wBAAgB,eAAe,CAAC,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,eAAe,GAAG,WAAW,CAAC,gBAAgB,EAAE,CAAC,CA6GhH"}
1
+ {"version":3,"file":"area-chart.d.ts","sourceRoot":"","sources":["../../../src/charts/area/area-chart.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAGlF,wBAAgB,eAAe,CAAC,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,eAAe,GAAG,WAAW,CAAC,gBAAgB,EAAE,CAAC,CAwHhH"}
@@ -1,2 +1,2 @@
1
- import{createSvgElement as e}from"../../svg/element.js";import{positionAxis as t,renderAxis as n,resolveTickCount as r}from"../../axes/axis.js";import{renderGrid as i}from"../../axes/grid.js";import{buildXScale as a,buildYScale as o}from"../../core/cartesian-scales.js";import{chartArea as s}from"../../core/layout.js";import{clearCartesianDom as c,createChartScaffold as l}from"../../core/chart-scaffold.js";import{createCrosshair as u}from"../../interaction/crosshair.js";import{createSeriesInteraction as d}from"../../interaction/series-interaction.js";import{seriesColor as f}from"../../theme/index.js";import{computeAreaPoints as p,renderArea as m}from"./area-renderer.js";function createAreaChart(h,g){let _=null,v=g.series;return l(h,g,l=>{let{groups:h,legend:y,tooltip:b}=l,x=l.dimensions,S=s(x.width,x.height,x.margin),C=v.map(e=>e.data),w=C.flat().map(e=>e.key),T=C.flat().map(e=>e.value);if(w.length===0){c(h,y,b,_);return}g.crosshair&&!_&&(_=u(l.chartArea,g.crosshair));let E=a(w,S.width),D=o(T,S.height),O=D.map(0);for(g.yAxis?.grid&&i(h.grid,D,g.yAxis.grid,S.width,`horizontal`,r(g.yAxis,S.height,`left`)),g.xAxis?.grid&&i(h.grid,E,g.xAxis.grid,S.height,`vertical`,r(g.xAxis,S.width,`bottom`)),g.xAxis&&(t(h.xAxis,g.xAxis.position??`bottom`,S.width,S.height),n(h.xAxis,E,g.xAxis,S.width,`bottom`)),g.yAxis&&(t(h.yAxis,g.yAxis.position??`left`,S.width,S.height),n(h.yAxis,D,g.yAxis,S.height,`left`));h.series.children.length>v.length;)h.series.removeChild(h.series.lastChild);let k=[];for(let t=0;t<v.length;t++){let n=v[t],r=h.series.children[t];r||(r=e(`g`,{class:`prism-area-series`}),h.series.appendChild(r));let i=p(C[t],E,D);k.push(i),m(r,i,O,{color:f(t,n.color),curve:n.curve??`linear`,disposalSignal:l.disposalSignal,fillOpacity:n.fillOpacity??.3,showLine:n.showLine!==!1,transition:g.transition})}return y?.update(v.map((e,t)=>({color:f(t,e.color),name:e.name}))),b?.hide(),d({crosshair:_,dims:()=>l.dimensions,getData:()=>C,getPoints:()=>k,getSeriesList:()=>v,onClick:g.onClick,onHover:g.onHover,svg:l.svg,tooltip:b})},e=>{v=e})}export{createAreaChart};
1
+ import{createSvgElement as e}from"../../svg/element.js";import{positionAxis as t,renderAxis as n,resolveTickCount as r}from"../../axes/axis.js";import{renderGrid as i}from"../../axes/grid.js";import{buildXScale as a,buildYScale as o}from"../../core/cartesian-scales.js";import{chartArea as s}from"../../core/layout.js";import{clearCartesianDom as c,createChartScaffold as l}from"../../core/chart-scaffold.js";import{seriesDomId as u}from"../../core/series-id.js";import{createCrosshair as d}from"../../interaction/crosshair.js";import{createSeriesInteraction as f,ensureMarkerGroup as p}from"../../interaction/series-interaction.js";import{seriesColor as m}from"../../theme/index.js";import{computeAreaPoints as h,renderArea as g}from"./area-renderer.js";function createAreaChart(_,v){let y=null,b=null,x=v.series;return l(_,v,l=>{let{groups:_,legend:S,tooltip:C}=l,w=l.dimensions,T=s(w.width,w.height,w.margin),E=x.map(e=>e.data),D=E.flat().map(e=>e.key),O=E.flat().map(e=>e.value);if(D.length===0){c(_,S,C,y),b?.replaceChildren();return}v.crosshair&&!y&&(y=d(l.chartArea,v.crosshair));let k=a(D,T.width),A=o(O,T.height),j=A.map(0);for(v.yAxis?.grid&&i(_.grid,A,v.yAxis.grid,T.width,`horizontal`,r(v.yAxis,T.height,`left`)),v.xAxis?.grid&&i(_.grid,k,v.xAxis.grid,T.height,`vertical`,r(v.xAxis,T.width,`bottom`)),v.xAxis&&(t(_.xAxis,v.xAxis.position??`bottom`,T.width,T.height),n(_.xAxis,k,v.xAxis,T.width,`bottom`)),v.yAxis&&(t(_.yAxis,v.yAxis.position??`left`,T.width,T.height),n(_.yAxis,A,v.yAxis,T.height,`left`));_.series.children.length>x.length;)_.series.removeChild(_.series.lastChild);let M=[];for(let t=0;t<x.length;t++){let n=x[t],r=_.series.children[t];r||(r=e(`g`,{class:`prism-area-series`}),_.series.appendChild(r)),r.setAttribute(`data-series-id`,u(n,t));let i=h(E[t],k,A);M.push(i),g(r,i,j,{color:m(t,n.color),curve:n.curve??`linear`,disposalSignal:l.disposalSignal,fill:n.fill??`gradient`,fillOpacity:n.fillOpacity,marks:n.data,showLine:n.showLine!==!1,transition:v.transition})}return S?.update(x.map((e,t)=>({color:m(t,e.color),name:e.name}))),C?.hide(),b=p(l.chartArea,b),f({announcer:l.announcer,colors:()=>x.map((e,t)=>m(t,e.color)),crosshair:y,dims:()=>l.dimensions,getData:()=>E,getPoints:()=>M,getSeriesList:()=>x,markers:b,onClick:v.onClick,onHover:v.onHover,seriesGroup:_.series,svg:l.svg,tooltip:C})},e=>{x=e})}export{createAreaChart};
2
2
  //# sourceMappingURL=area-chart.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"area-chart.js","names":[],"sources":["../../../src/charts/area/area-chart.ts"],"sourcesContent":["import { positionAxis, renderAxis, resolveTickCount } from '../../axes/axis';\nimport { renderGrid } from '../../axes/grid';\nimport { buildXScale, buildYScale } from '../../core/cartesian-scales';\nimport { clearCartesianDom, createChartScaffold } from '../../core/chart-scaffold';\nimport { chartArea } from '../../core/layout';\nimport { createCrosshair } from '../../interaction/crosshair';\nimport { createSeriesInteraction } from '../../interaction/series-interaction';\nimport { createSvgElement } from '../../svg/element';\nimport type { Point } from '../../svg/path';\nimport { seriesColor } from '../../theme';\nimport type { AreaChartConfig, AreaSeriesConfig, ChartHandle } from '../../types';\nimport { computeAreaPoints, renderArea } from './area-renderer';\n\nexport function createAreaChart(container: HTMLElement, config: AreaChartConfig): ChartHandle<AreaSeriesConfig[]> {\n let crosshair: ReturnType<typeof createCrosshair> | null = null;\n let seriesList = config.series;\n\n return createChartScaffold(\n container,\n config,\n (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const allData = seriesList.map((series) => series.data);\n const allX = allData.flat().map((datum) => datum.key);\n const allY = allData.flat().map((d) => d.value);\n\n if (allX.length === 0) {\n clearCartesianDom(groups, legend, tooltip, crosshair);\n\n return;\n }\n\n if (config.crosshair && !crosshair) {\n crosshair = createCrosshair(ctx.chartArea, config.crosshair);\n }\n\n const xScale = buildXScale(allX, area.width);\n const yScale = buildYScale(allY, area.height);\n const baselineY = yScale.map(0);\n\n if (config.yAxis?.grid) {\n renderGrid(\n groups.grid,\n yScale,\n config.yAxis.grid,\n area.width,\n 'horizontal',\n resolveTickCount(config.yAxis, area.height, 'left'),\n );\n }\n\n if (config.xAxis?.grid) {\n renderGrid(\n groups.grid,\n xScale,\n config.xAxis.grid,\n area.height,\n 'vertical',\n resolveTickCount(config.xAxis, area.width, 'bottom'),\n );\n }\n\n if (config.xAxis) {\n positionAxis(groups.xAxis, config.xAxis.position ?? 'bottom', area.width, area.height);\n renderAxis(groups.xAxis, xScale, config.xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) {\n positionAxis(groups.yAxis, config.yAxis.position ?? 'left', area.width, area.height);\n renderAxis(groups.yAxis, yScale, config.yAxis, area.height, 'left');\n }\n\n while (groups.series.children.length > seriesList.length) {\n groups.series.removeChild(groups.series.lastChild!);\n }\n\n const allPoints: Point[][] = [];\n\n for (let i = 0; i < seriesList.length; i++) {\n const series = seriesList[i];\n let group = groups.series.children[i] as SVGGElement | undefined;\n\n if (!group) {\n group = createSvgElement('g', { class: 'prism-area-series' });\n groups.series.appendChild(group);\n }\n\n const points = computeAreaPoints(allData[i], xScale, yScale);\n\n allPoints.push(points);\n\n renderArea(group, points, baselineY, {\n color: seriesColor(i, series.color),\n curve: series.curve ?? 'linear',\n disposalSignal: ctx.disposalSignal,\n fillOpacity: series.fillOpacity ?? 0.3,\n showLine: series.showLine !== false,\n transition: config.transition,\n });\n }\n\n legend?.update(seriesList.map((s, i) => ({ color: seriesColor(i, s.color), name: s.name })));\n tooltip?.hide();\n\n return createSeriesInteraction({\n crosshair,\n dims: () => ctx.dimensions,\n getData: () => allData,\n getPoints: () => allPoints,\n getSeriesList: () => seriesList,\n onClick: config.onClick,\n onHover: config.onHover,\n svg: ctx.svg,\n tooltip,\n });\n },\n (data) => {\n seriesList = data;\n },\n );\n}\n"],"mappings":"sqBAaA,SAAgB,gBAAgB,EAAwB,EAA0D,CAChH,IAAI,EAAuD,KACvD,EAAa,EAAO,OAExB,OAAO,EACL,EACA,EACC,GAAQ,CACP,GAAM,CAAE,SAAQ,SAAQ,WAAY,EAC9B,EAAO,EAAI,WACX,EAAO,EAAU,EAAK,MAAO,EAAK,OAAQ,EAAK,MAAM,EACrD,EAAU,EAAW,IAAK,GAAW,EAAO,IAAI,EAChD,EAAO,EAAQ,KAAK,CAAC,CAAC,IAAK,GAAU,EAAM,GAAG,EAC9C,EAAO,EAAQ,KAAK,CAAC,CAAC,IAAK,GAAM,EAAE,KAAK,EAE9C,GAAI,EAAK,SAAW,EAAG,CACrB,EAAkB,EAAQ,EAAQ,EAAS,CAAS,EAEpD,MACF,CAEI,EAAO,WAAa,CAAC,IACvB,EAAY,EAAgB,EAAI,UAAW,EAAO,SAAS,GAG7D,IAAM,EAAS,EAAY,EAAM,EAAK,KAAK,EACrC,EAAS,EAAY,EAAM,EAAK,MAAM,EACtC,EAAY,EAAO,IAAI,CAAC,EAkC9B,IAhCI,EAAO,OAAO,MAChB,EACE,EAAO,KACP,EACA,EAAO,MAAM,KACb,EAAK,MACL,aACA,EAAiB,EAAO,MAAO,EAAK,OAAQ,MAAM,CACpD,EAGE,EAAO,OAAO,MAChB,EACE,EAAO,KACP,EACA,EAAO,MAAM,KACb,EAAK,OACL,WACA,EAAiB,EAAO,MAAO,EAAK,MAAO,QAAQ,CACrD,EAGE,EAAO,QACT,EAAa,EAAO,MAAO,EAAO,MAAM,UAAY,SAAU,EAAK,MAAO,EAAK,MAAM,EACrF,EAAW,EAAO,MAAO,EAAQ,EAAO,MAAO,EAAK,MAAO,QAAQ,GAGjE,EAAO,QACT,EAAa,EAAO,MAAO,EAAO,MAAM,UAAY,OAAQ,EAAK,MAAO,EAAK,MAAM,EACnF,EAAW,EAAO,MAAO,EAAQ,EAAO,MAAO,EAAK,OAAQ,MAAM,GAG7D,EAAO,OAAO,SAAS,OAAS,EAAW,QAChD,EAAO,OAAO,YAAY,EAAO,OAAO,SAAU,EAGpD,IAAM,EAAuB,CAAC,EAE9B,IAAK,IAAI,EAAI,EAAG,EAAI,EAAW,OAAQ,IAAK,CAC1C,IAAM,EAAS,EAAW,GACtB,EAAQ,EAAO,OAAO,SAAS,GAE9B,IACH,EAAQ,EAAiB,IAAK,CAAE,MAAO,mBAAoB,CAAC,EAC5D,EAAO,OAAO,YAAY,CAAK,GAGjC,IAAM,EAAS,EAAkB,EAAQ,GAAI,EAAQ,CAAM,EAE3D,EAAU,KAAK,CAAM,EAErB,EAAW,EAAO,EAAQ,EAAW,CACnC,MAAO,EAAY,EAAG,EAAO,KAAK,EAClC,MAAO,EAAO,OAAS,SACvB,eAAgB,EAAI,eACpB,YAAa,EAAO,aAAe,GACnC,SAAU,EAAO,WAAa,GAC9B,WAAY,EAAO,UACrB,CAAC,CACH,CAKA,OAHA,GAAQ,OAAO,EAAW,KAAK,EAAG,KAAO,CAAE,MAAO,EAAY,EAAG,EAAE,KAAK,EAAG,KAAM,EAAE,IAAK,EAAE,CAAC,EAC3F,GAAS,KAAK,EAEP,EAAwB,CAC7B,YACA,SAAY,EAAI,WAChB,YAAe,EACf,cAAiB,EACjB,kBAAqB,EACrB,QAAS,EAAO,QAChB,QAAS,EAAO,QAChB,IAAK,EAAI,IACT,SACF,CAAC,CACH,EACC,GAAS,CACR,EAAa,CACf,CACF,CACF"}
1
+ {"version":3,"file":"area-chart.js","names":[],"sources":["../../../src/charts/area/area-chart.ts"],"sourcesContent":["import { positionAxis, renderAxis, resolveTickCount } from '../../axes/axis';\nimport { renderGrid } from '../../axes/grid';\nimport { buildXScale, buildYScale } from '../../core/cartesian-scales';\nimport { clearCartesianDom, createChartScaffold } from '../../core/chart-scaffold';\nimport { chartArea } from '../../core/layout';\nimport { seriesDomId } from '../../core/series-id';\nimport { createCrosshair } from '../../interaction/crosshair';\nimport { createSeriesInteraction, ensureMarkerGroup } from '../../interaction/series-interaction';\nimport { createSvgElement } from '../../svg/element';\nimport type { Point } from '../../svg/path';\nimport { seriesColor } from '../../theme';\nimport type { AreaChartConfig, AreaSeriesConfig, ChartHandle } from '../../types';\nimport { computeAreaPoints, renderArea } from './area-renderer';\n\nexport function createAreaChart(container: HTMLElement, config: AreaChartConfig): ChartHandle<AreaSeriesConfig[]> {\n let crosshair: ReturnType<typeof createCrosshair> | null = null;\n let markers: SVGGElement | null = null;\n let seriesList = config.series;\n\n return createChartScaffold(\n container,\n config,\n (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const allData = seriesList.map((series) => series.data);\n const allX = allData.flat().map((datum) => datum.key);\n const allY = allData.flat().map((d) => d.value);\n\n if (allX.length === 0) {\n clearCartesianDom(groups, legend, tooltip, crosshair);\n markers?.replaceChildren();\n\n return;\n }\n\n if (config.crosshair && !crosshair) {\n crosshair = createCrosshair(ctx.chartArea, config.crosshair);\n }\n\n const xScale = buildXScale(allX, area.width);\n const yScale = buildYScale(allY, area.height);\n const baselineY = yScale.map(0);\n\n if (config.yAxis?.grid) {\n renderGrid(\n groups.grid,\n yScale,\n config.yAxis.grid,\n area.width,\n 'horizontal',\n resolveTickCount(config.yAxis, area.height, 'left'),\n );\n }\n\n if (config.xAxis?.grid) {\n renderGrid(\n groups.grid,\n xScale,\n config.xAxis.grid,\n area.height,\n 'vertical',\n resolveTickCount(config.xAxis, area.width, 'bottom'),\n );\n }\n\n if (config.xAxis) {\n positionAxis(groups.xAxis, config.xAxis.position ?? 'bottom', area.width, area.height);\n renderAxis(groups.xAxis, xScale, config.xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) {\n positionAxis(groups.yAxis, config.yAxis.position ?? 'left', area.width, area.height);\n renderAxis(groups.yAxis, yScale, config.yAxis, area.height, 'left');\n }\n\n while (groups.series.children.length > seriesList.length) {\n groups.series.removeChild(groups.series.lastChild!);\n }\n\n const allPoints: Point[][] = [];\n\n for (let i = 0; i < seriesList.length; i++) {\n const series = seriesList[i];\n let group = groups.series.children[i] as SVGGElement | undefined;\n\n if (!group) {\n group = createSvgElement('g', { class: 'prism-area-series' });\n groups.series.appendChild(group);\n }\n\n group.setAttribute('data-series-id', seriesDomId(series, i));\n\n const points = computeAreaPoints(allData[i], xScale, yScale);\n\n allPoints.push(points);\n\n renderArea(group, points, baselineY, {\n color: seriesColor(i, series.color),\n curve: series.curve ?? 'linear',\n disposalSignal: ctx.disposalSignal,\n fill: series.fill ?? 'gradient',\n fillOpacity: series.fillOpacity,\n marks: series.data,\n showLine: series.showLine !== false,\n transition: config.transition,\n });\n }\n\n legend?.update(seriesList.map((s, i) => ({ color: seriesColor(i, s.color), name: s.name })));\n tooltip?.hide();\n markers = ensureMarkerGroup(ctx.chartArea, markers);\n\n return createSeriesInteraction({\n announcer: ctx.announcer,\n colors: () => seriesList.map((s, i) => seriesColor(i, s.color)),\n crosshair,\n dims: () => ctx.dimensions,\n getData: () => allData,\n getPoints: () => allPoints,\n getSeriesList: () => seriesList,\n markers,\n onClick: config.onClick,\n onHover: config.onHover,\n seriesGroup: groups.series,\n svg: ctx.svg,\n tooltip,\n });\n },\n (data) => {\n seriesList = data;\n },\n );\n}\n"],"mappings":"mvBAcA,SAAgB,gBAAgB,EAAwB,EAA0D,CAChH,IAAI,EAAuD,KACvD,EAA8B,KAC9B,EAAa,EAAO,OAExB,OAAO,EACL,EACA,EACC,GAAQ,CACP,GAAM,CAAE,SAAQ,SAAQ,WAAY,EAC9B,EAAO,EAAI,WACX,EAAO,EAAU,EAAK,MAAO,EAAK,OAAQ,EAAK,MAAM,EACrD,EAAU,EAAW,IAAK,GAAW,EAAO,IAAI,EAChD,EAAO,EAAQ,KAAK,CAAC,CAAC,IAAK,GAAU,EAAM,GA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AY,EAAQ,CAAC,CAAC,EAE3D,IAAM,EAAS,EAAkB,EAAQ,GAAI,EAAQ,CAAM,EAE3D,EAAU,KAAK,CAAM,EAErB,EAAW,EAAO,EAAQ,EAAW,CACnC,MAAO,EAAY,EAAG,EAAO,KAAK,EAClC,MAAO,EAAO,OAAS,SACvB,eAAgB,EAAI,eACpB,KAAM,EAAO,MAAQ,WACrB,YAAa,EAAO,YACpB,MAAO,EAAO,KACd,SAAU,EAAO,WAAa,GAC9B,WAAY,EAAO,UACrB,CAAC,CACH,CAMA,OAJA,GAAQ,OAAO,EAAW,KAAK,EAAG,KAAO,CAAE,MAAO,EAAY,EAAG,EAAE,KAAK,EAAG,KAAM,EAAE,IAAK,EAAE,CAAC,EAC3F,GAAS,KAAK,EACd,EAAU,EAAkB,EAAI,UAAW,CAAO,EAE3C,EAAwB,CAC7B,UAAW,EAAI,UACf,WAAc,EAAW,KAAK,EAAG,IAAM,EAAY,EAAG,EAAE,KAAK,CAAC,EAC9D,YACA,SAAY,EAAI,WAChB,YAAe,EACf,cAAiB,EACjB,kBAAqB,EACrB,UACA,QAAS,EAAO,QAChB,QAAS,EAAO,QAChB,YAAa,EAAO,OACpB,IAAK,EAAI,IACT,SACF,CAAC,CACH,EACC,GAAS,CACR,EAAa,CACf,CACF,CACF"}
@@ -1,2 +1,2 @@
1
- require("../../_dev.cjs");const e=require("../../svg/element.cjs"),t=require("../../animation/easing.cjs"),n=require("../../animation/motion.cjs"),r=require("../../animation/tween.cjs"),i=require("../../svg/path.cjs");var a=new WeakMap,o=new WeakMap;function buildLinePath(e,t){return t===`monotone`?i.monotonePath(e):t===`step`?i.stepPath(e):i.linePath(e)}function renderArea(s,c,l,u){let d=n.resolveMotion(u.transition,0),f=d.duration,p=t.resolveEasing(d.easing),m=s.querySelector(`.prism-area-fill`);m||(m=e.createSvgElement(`path`,{class:`prism-area-fill`}),s.appendChild(m)),e.setAttributes(m,{fill:u.color,"fill-opacity":u.fillOpacity,stroke:`none`});let h=null;if(u.showLine?(h=s.querySelector(`.prism-area-line`),h||(h=e.createSvgElement(`path`,{class:`prism-area-line`,fill:`none`}),s.appendChild(h)),e.setAttributes(h,{stroke:u.color,"stroke-width":2})):s.querySelector(`.prism-area-line`)?.remove(),f===0){let t=c.map(e=>({x:e.x,y:l}));e.setAttributes(m,{d:i.areaPath(c,t,u.curve)}),h&&e.setAttributes(h,{d:buildLinePath(c,u.curve)});return}if(a.get(s)?.(),!m.hasAttribute(`d`)){let t=c.map(e=>({x:e.x,y:l}));e.setAttributes(m,{d:i.areaPath(c,t,u.curve)}),h&&e.setAttributes(h,{d:buildLinePath(c,u.curve)}),o.set(s,c);return}let g=o.get(s)??c,_=c.map((e,t)=>g[t]??g[g.length-1]??c[t]),v=null;function frame(t){if(u.disposalSignal?.aborted){a.delete(s);return}v===null&&(v=t);let n=Math.min(1,(t-v)/f),d=p(n),g=c.map((e,t)=>({x:r.tweenNumber(_[t].x,e.x,d),y:r.tweenNumber(_[t].y,e.y,d)})),y=g.map(e=>({x:e.x,y:l}));if(e.setAttributes(m,{d:i.areaPath(g,y,u.curve)}),h&&e.setAttributes(h,{d:buildLinePath(g,u.curve)}),n<1){let e=requestAnimationFrame(frame);a.set(s,()=>cancelAnimationFrame(e))}else a.delete(s),o.set(s,c)}o.set(s,_);let y=requestAnimationFrame(frame);a.set(s,()=>cancelAnimationFrame(y))}function computeAreaPoints(e,t,n){return e.some(e=>e.key==null)||e.some(e=>typeof e.key==`string`),e.map(e=>({x:t.map(e.key),y:n.map(e.value)}))}exports.computeAreaPoints=computeAreaPoints,exports.renderArea=renderArea;
1
+ require("../../_dev.cjs");const e=require("../../svg/element.cjs"),t=require("../../animation/easing.cjs"),n=require("../../animation/motion.cjs"),r=require("../../animation/tween.cjs"),i=require("../../core/datum-style.cjs"),a=require("../../core/ids.cjs"),o=require("../../svg/path.cjs");var s=new WeakMap,c=new WeakMap;function buildLinePath(e,t){return t===`monotone`?o.monotonePath(e):t===`step`?o.stepPath(e):o.linePath(e)}function applyAreaFill(t,n,r){let i=t.querySelector(`linearGradient`);if(r.fill===`gradient`){if(!i){let n=e.createSvgElement(`defs`);i=e.createSvgElement(`linearGradient`,{id:a.uniqueId(`prism-area-fill`),x1:0,x2:0,y1:0,y2:1}),i.append(e.createSvgElement(`stop`,{class:`prism-area-stop-top`,offset:0}),e.createSvgElement(`stop`,{class:`prism-area-stop-bottom`,offset:1})),n.appendChild(i),t.insertBefore(n,t.firstChild)}for(let e of i.querySelectorAll(`stop`))e.setAttribute(`stop-color`,r.color),e.style.stopColor=r.color;e.setAttributes(n,{fill:`url(#${i.id})`})}else i?.parentElement?.remove(),e.setAttributes(n,{fill:r.color});e.setAttributes(n,{class:`prism-area-fill prism-area-fill--${r.fill}`,stroke:`none`}),n.style.fillOpacity=r.fillOpacity===void 0?``:String(r.fillOpacity)}function renderArea(a,l,u,d){let f=n.resolveMotion(d.transition,0),p=f.duration,m=t.resolveEasing(f.easing),h=a.querySelector(`.prism-area-fill`);h||(h=e.createSvgElement(`path`,{class:`prism-area-fill`}),a.appendChild(h)),applyAreaFill(a,h,d);let g=null,_=[],v=[],y=i.hasStyledRuns(d.marks),b=d.marks??[];if(d.showLine){if(y){_=i.computeStyleRuns(b,l.length);let t=[...a.querySelectorAll(`.prism-area-line`)];for(let e of t.slice(_.length))e.remove();v=_.map((n,r)=>{let i=t[r];if(i)return i;let o=e.createSvgElement(`path`,{class:`prism-area-line`,fill:`none`});return a.appendChild(o),o});for(let[t,n]of _.entries())e.setAttributes(v[t],{opacity:n.opacity,stroke:d.color,"stroke-dasharray":n.dash,"stroke-width":2});g=null}else{let t=[...a.querySelectorAll(`.prism-area-line`)];for(let e of t.slice(1))e.remove();g=t[0]??null,g||(g=e.createSvgElement(`path`,{class:`prism-area-line`,fill:`none`}),a.appendChild(g)),e.setAttributes(g,{opacity:void 0,stroke:d.color,"stroke-dasharray":void 0,"stroke-width":2})}}else for(let e of a.querySelectorAll(`.prism-area-line`))e.remove();let drawLine=t=>{if(d.showLine){if(y)for(let[n,r]of _.entries())e.setAttributes(v[n],{d:buildLinePath(t.slice(r.start,r.end+1),d.curve)});else g&&e.setAttributes(g,{d:buildLinePath(t,d.curve)})}};if(p===0){let t=l.map(e=>({x:e.x,y:u}));e.setAttributes(h,{d:o.areaPath(l,t,d.curve)}),drawLine(l);return}if(s.get(a)?.(),!h.hasAttribute(`d`)){let t=l.map(e=>({x:e.x,y:u}));e.setAttributes(h,{d:o.areaPath(l,t,d.curve)}),drawLine(l),c.set(a,l);return}let x=c.get(a)??l,S=l.map((e,t)=>x[t]??x[x.length-1]??l[t]),C=null;function frame(t){if(d.disposalSignal?.aborted){s.delete(a);return}C===null&&(C=t);let n=Math.min(1,(t-C)/p),i=m(n),f=l.map((e,t)=>({x:r.tweenNumber(S[t].x,e.x,i),y:r.tweenNumber(S[t].y,e.y,i)})),g=f.map(e=>({x:e.x,y:u}));if(e.setAttributes(h,{d:o.areaPath(f,g,d.curve)}),drawLine(f),n<1){let e=requestAnimationFrame(frame);s.set(a,()=>cancelAnimationFrame(e))}else s.delete(a),c.set(a,l)}c.set(a,S);let w=requestAnimationFrame(frame);s.set(a,()=>cancelAnimationFrame(w))}function computeAreaPoints(e,t,n){return e.some(e=>e.key==null)||e.some(e=>typeof e.key==`string`),e.map(e=>({x:t.map(e.key),y:n.map(e.value)}))}exports.computeAreaPoints=computeAreaPoints,exports.renderArea=renderArea;
2
2
  //# sourceMappingURL=area-renderer.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"area-renderer.cjs","names":[],"sources":["../../../src/charts/area/area-renderer.ts"],"sourcesContent":["import { warn } from '../../_dev';\nimport { resolveEasing } from '../../animation/easing';\nimport { resolveMotion } from '../../animation/motion';\nimport { tweenNumber } from '../../animation/tween';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport type { Point } from '../../svg/path';\nimport { areaPath, linePath, monotonePath, stepPath } from '../../svg/path';\nimport type { ContinuousDatum, Scale, TransitionConfig } from '../../types';\n\nexport interface AreaRenderOptions {\n color: string;\n curve: 'linear' | 'monotone' | 'step';\n /** Aborted when the owning chart is disposed — stops the transition's `requestAnimationFrame` loop from rescheduling. */\n disposalSignal?: AbortSignal;\n fillOpacity: number;\n showLine: boolean;\n transition?: TransitionConfig;\n}\n\nconst activeAreaAnimations = new WeakMap<SVGGElement, () => void>();\nconst previousPoints = new WeakMap<SVGGElement, Point[]>();\n\nfunction buildLinePath(pts: Point[], curve: AreaRenderOptions['curve']): string {\n return curve === 'monotone' ? monotonePath(pts) : curve === 'step' ? stepPath(pts) : linePath(pts);\n}\n\nexport function renderArea(parent: SVGGElement, points: Point[], baselineY: number, options: AreaRenderOptions): void {\n const motion = resolveMotion(options.transition, 0);\n const dur = motion.duration;\n const easing = resolveEasing(motion.easing);\n\n let fill = parent.querySelector<SVGPathElement>('.prism-area-fill');\n\n if (!fill) {\n fill = createSvgElement('path', { class: 'prism-area-fill' });\n parent.appendChild(fill);\n }\n\n setAttributes(fill, { fill: options.color, 'fill-opacity': options.fillOpacity, stroke: 'none' });\n\n let line: SVGPathElement | null = null;\n\n if (options.showLine) {\n line = parent.querySelector<SVGPathElement>('.prism-area-line');\n\n if (!line) {\n line = createSvgElement('path', { class: 'prism-area-line', fill: 'none' });\n parent.appendChild(line);\n }\n\n setAttributes(line, { stroke: options.color, 'stroke-width': 2 });\n } else {\n parent.querySelector('.prism-area-line')?.remove();\n }\n\n if (dur === 0) {\n const bottomPoints = points.map((p) => ({ x: p.x, y: baselineY }));\n\n setAttributes(fill, { d: areaPath(points, bottomPoints, options.curve) });\n\n if (line) setAttributes(line, { d: buildLinePath(points, options.curve) });\n\n return;\n }\n\n activeAreaAnimations.get(parent)?.();\n\n const hasExisting = fill.hasAttribute('d');\n\n if (!hasExisting) {\n const bottomPoints = points.map((p) => ({ x: p.x, y: baselineY }));\n\n setAttributes(fill, { d: areaPath(points, bottomPoints, options.curve) });\n\n if (line) setAttributes(line, { d: buildLinePath(points, options.curve) });\n\n previousPoints.set(parent, points);\n\n return;\n }\n\n const rawFrom = previousPoints.get(parent) ?? points;\n const fromPoints: Point[] = points.map((_, i) => rawFrom[i] ?? rawFrom[rawFrom.length - 1] ?? points[i]);\n\n let startTime: number | null = null;\n\n function frame(ts: number) {\n if (options.disposalSignal?.aborted) {\n activeAreaAnimations.delete(parent);\n\n return;\n }\n\n if (startTime === null) startTime = ts;\n\n const t = Math.min(1, (ts - startTime) / dur);\n const e = easing(t);\n const interpolated: Point[] = points.map((to, i) => ({\n x: tweenNumber(fromPoints[i].x, to.x, e),\n y: tweenNumber(fromPoints[i].y, to.y, e),\n }));\n const interpolatedBottom = interpolated.map((p) => ({ x: p.x, y: baselineY }));\n\n setAttributes(fill!, { d: areaPath(interpolated, interpolatedBottom, options.curve) });\n\n if (line) setAttributes(line, { d: buildLinePath(interpolated, options.curve) });\n\n if (t < 1) {\n const id = requestAnimationFrame(frame);\n\n activeAreaAnimations.set(parent, () => cancelAnimationFrame(id));\n } else {\n activeAreaAnimations.delete(parent);\n previousPoints.set(parent, points);\n }\n }\n\n previousPoints.set(parent, fromPoints);\n\n const id = requestAnimationFrame(frame);\n\n activeAreaAnimations.set(parent, () => cancelAnimationFrame(id));\n}\n\nexport function computeAreaPoints(\n data: ContinuousDatum[],\n xScale: Scale<Date | number>,\n yScale: Scale<number>,\n): Point[] {\n if (data.some((d) => d.key == null)) {\n warn(\n 'computeAreaPoints: datum.key is null or undefined — data must use the Datum shape { key, value }. Did you pass { x, y } instead?',\n );\n } else if (data.some((d) => typeof d.key === 'string')) {\n warn('computeAreaPoints: string keys are not supported for line/area charts — use numeric or Date keys.');\n }\n\n return data.map((d) => ({\n x: xScale.map(d.key as Date | number),\n y: yScale.map(d.value),\n }));\n}\n"],"mappings":"0NAmBA,IAAM,EAAuB,IAAI,QAC3B,EAAiB,IAAI,QAE3B,SAAS,cAAc,EAAc,EAA2C,CAC9E,OAAO,IAAU,WAAa,EAAA,aAAa,CAAG,EAAI,IAAU,OAAS,EAAA,SAAS,CAAG,EAAI,E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,IAAI,GAIvB,EAAK,KAAM,GAAM,OAAO,EAAE,KAAQ,QAAQ,EAI9C,EAAK,IAAK,IAAO,CACtB,EAAG,EAAO,IAAI,EAAE,GAAoB,EACpC,EAAG,EAAO,IAAI,EAAE,KAAK,CACvB,EAAE,CACJ"}
1
+ {"version":3,"file":"area-renderer.cjs","names":[],"sources":["../../../src/charts/area/area-renderer.ts"],"sourcesContent":["import { warn } from '../../_dev';\nimport { resolveEasing } from '../../animation/easing';\nimport { resolveMotion } from '../../animation/motion';\nimport { tweenNumber } from '../../animation/tween';\nimport { computeStyleRuns, type DatumMark, hasStyledRuns, type StyleRun } from '../../core/datum-style';\nimport { uniqueId } from '../../core/ids';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport type { Point } from '../../svg/path';\nimport { areaPath, linePath, monotonePath, stepPath } from '../../svg/path';\nimport type { ContinuousDatum, Scale, TransitionConfig } from '../../types';\n\nexport interface AreaRenderOptions {\n color: string;\n curve: 'linear' | 'monotone' | 'step';\n /** Aborted when the owning chart is disposed: stops the transition's `requestAnimationFrame` loop from rescheduling. */\n disposalSignal?: AbortSignal;\n fill: 'gradient' | 'solid';\n /** Explicit opacity beats the `--prism-area-opacity` theme token. */\n fillOpacity?: number;\n /** Per-datum presentation parallel to `points`; styled runs split the top line into subpaths. */\n marks?: readonly DatumMark[];\n showLine: boolean;\n transition?: TransitionConfig;\n}\n\nconst activeAreaAnimations = new WeakMap<SVGGElement, () => void>();\nconst previousPoints = new WeakMap<SVGGElement, Point[]>();\n\nfunction buildLinePath(pts: Point[], curve: AreaRenderOptions['curve']): string {\n return curve === 'monotone' ? monotonePath(pts) : curve === 'step' ? stepPath(pts) : linePath(pts);\n}\n\n/** A vertical gradient fading to transparent at the baseline, or a flat fill. */\nfunction applyAreaFill(parent: SVGGElement, fill: SVGPathElement, options: AreaRenderOptions): void {\n let gradient = parent.querySelector<SVGLinearGradientElement>('linearGradient');\n\n if (options.fill === 'gradient') {\n if (!gradient) {\n const defs = createSvgElement('defs');\n\n gradient = createSvgElement('linearGradient', { id: uniqueId('prism-area-fill'), x1: 0, x2: 0, y1: 0, y2: 1 });\n gradient.append(\n createSvgElement('stop', { class: 'prism-area-stop-top', offset: 0 }),\n createSvgElement('stop', { class: 'prism-area-stop-bottom', offset: 1 }),\n );\n defs.appendChild(gradient);\n parent.insertBefore(defs, parent.firstChild);\n }\n\n for (const stop of gradient.querySelectorAll('stop')) {\n stop.setAttribute('stop-color', options.color);\n stop.style.stopColor = options.color;\n }\n\n setAttributes(fill, { fill: `url(#${gradient.id})` });\n } else {\n gradient?.parentElement?.remove();\n setAttributes(fill, { fill: options.color });\n }\n\n setAttributes(fill, { class: `prism-area-fill prism-area-fill--${options.fill}`, stroke: 'none' });\n fill.style.fillOpacity = options.fillOpacity === undefined ? '' : String(options.fillOpacity);\n}\n\nexport function renderArea(parent: SVGGElement, points: Point[], baselineY: number, options: AreaRenderOptions): void {\n const motion = resolveMotion(options.transition, 0);\n const dur = motion.duration;\n const easing = resolveEasing(motion.easing);\n\n let fill = parent.querySelector<SVGPathElement>('.prism-area-fill');\n\n if (!fill) {\n fill = createSvgElement('path', { class: 'prism-area-fill' });\n parent.appendChild(fill);\n }\n\n applyAreaFill(parent, fill, options);\n\n let line: SVGPathElement | null = null;\n let runs: readonly StyleRun[] = [];\n let lines: SVGPathElement[] = [];\n const styled = hasStyledRuns(options.marks);\n const marks = options.marks ?? [];\n\n if (options.showLine) {\n if (styled) {\n runs = computeStyleRuns(marks, points.length);\n\n const existing = [...parent.querySelectorAll<SVGPathElement>('.prism-area-line')];\n\n for (const extra of existing.slice(runs.length)) extra.remove();\n\n lines = runs.map((_, r) => {\n const reuse = existing[r];\n\n if (reuse) return reuse;\n\n const created = createSvgElement('path', { class: 'prism-area-line', fill: 'none' });\n\n parent.appendChild(created);\n\n return created;\n });\n\n for (const [r, run] of runs.entries()) {\n setAttributes(lines[r], {\n opacity: run.opacity,\n stroke: options.color,\n 'stroke-dasharray': run.dash,\n 'stroke-width': 2,\n });\n }\n\n line = null;\n } else {\n const existing = [...parent.querySelectorAll<SVGPathElement>('.prism-area-line')];\n\n for (const stale of existing.slice(1)) stale.remove();\n\n line = existing[0] ?? null;\n\n if (!line) {\n line = createSvgElement('path', { class: 'prism-area-line', fill: 'none' });\n parent.appendChild(line);\n }\n\n setAttributes(line, {\n opacity: undefined,\n stroke: options.color,\n 'stroke-dasharray': undefined,\n 'stroke-width': 2,\n });\n }\n } else {\n for (const stale of parent.querySelectorAll('.prism-area-line')) stale.remove();\n }\n\n const drawLine = (pts: Point[]): void => {\n if (!options.showLine) return;\n\n if (styled) {\n for (const [r, run] of runs.entries()) {\n setAttributes(lines[r], { d: buildLinePath(pts.slice(run.start, run.end + 1), options.curve) });\n }\n } else if (line) {\n setAttributes(line, { d: buildLinePath(pts, options.curve) });\n }\n };\n\n if (dur === 0) {\n const bottomPoints = points.map((p) => ({ x: p.x, y: baselineY }));\n\n setAttributes(fill, { d: areaPath(points, bottomPoints, options.curve) });\n\n drawLine(points);\n\n return;\n }\n\n activeAreaAnimations.get(parent)?.();\n\n const hasExisting = fill.hasAttribute('d');\n\n if (!hasExisting) {\n const bottomPoints = points.map((p) => ({ x: p.x, y: baselineY }));\n\n setAttributes(fill, { d: areaPath(points, bottomPoints, options.curve) });\n\n drawLine(points);\n\n previousPoints.set(parent, points);\n\n return;\n }\n\n const rawFrom = previousPoints.get(parent) ?? points;\n const fromPoints: Point[] = points.map((_, i) => rawFrom[i] ?? rawFrom[rawFrom.length - 1] ?? points[i]);\n\n let startTime: number | null = null;\n\n function frame(ts: number) {\n if (options.disposalSignal?.aborted) {\n activeAreaAnimations.delete(parent);\n\n return;\n }\n\n if (startTime === null) startTime = ts;\n\n const t = Math.min(1, (ts - startTime) / dur);\n const e = easing(t);\n const interpolated: Point[] = points.map((to, i) => ({\n x: tweenNumber(fromPoints[i].x, to.x, e),\n y: tweenNumber(fromPoints[i].y, to.y, e),\n }));\n const interpolatedBottom = interpolated.map((p) => ({ x: p.x, y: baselineY }));\n\n setAttributes(fill!, { d: areaPath(interpolated, interpolatedBottom, options.curve) });\n\n drawLine(interpolated);\n\n if (t < 1) {\n const id = requestAnimationFrame(frame);\n\n activeAreaAnimations.set(parent, () => cancelAnimationFrame(id));\n } else {\n activeAreaAnimations.delete(parent);\n previousPoints.set(parent, points);\n }\n }\n\n previousPoints.set(parent, fromPoints);\n\n const id = requestAnimationFrame(frame);\n\n activeAreaAnimations.set(parent, () => cancelAnimationFrame(id));\n}\n\nexport function computeAreaPoints(\n data: ContinuousDatum[],\n xScale: Scale<Date | number>,\n yScale: Scale<number>,\n): Point[] {\n if (data.some((d) => d.key == null)) {\n warn(\n 'computeAreaPoints: datum.key is null or undefined: data must use the Datum shape { key, value }. Did you pass { x, y } instead?',\n );\n } else if (data.some((d) => typeof d.key === 'string')) {\n warn('computeAreaPoints: string keys are not supported for line/area charts: use numeric or Date keys.');\n }\n\n return data.map((d) => ({\n x: xScale.map(d.key as Date | number),\n y: yScale.map(d.value),\n }));\n}\n"],"mappings":"kSAyBA,IAAM,EAAuB,IAAI,QAC3B,EAAiB,IAAI,QAE3B,SAAS,cAAc,EAAc,EAA2C,CAC9E,OAAO,IAAU,WAAa,EAAA,aAAa,CAAG,EAAI,IAAU,OAAS,EAAA,SAAS,CAAG,EAAI,EAAA,SAAS,CAAG,CACnG,CAGA,SAAS,cAAc,EAAqB,EAAsB,EAAkC,CAClG,IAAI,EAAW,EAAO,cAAwC,gBAAgB,EAE9E,GAAI,EAAQ,OAAS,WAAY,CAC/B,GAAI,CAAC,EAAU,CACb,IAAM,EAAO,EAAA,iBAAiB,MAAM,EAEpC,EAAW,EAAA,iBAAiB,iBAAkB,CAAE,GAAI,EAAA,SAAS,iBAAiB,EAAG,GAAI,EAAG,GAAI,EAAG,GAAI,EAAG,GAAI,CAAE,CAAC,EAC7G,EAAS,OACP,EAAA,iBAAiB,OAAQ,CAAE,MAAO,sBAAuB,OAAQ,CAAE,CAAC,EACpE,EAAA,iBAAiB,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,MACE,EAAqB,OAAO,CAAM,EAClC,EAAe,IAAI,EAAQ,CAAM,CAErC,CAEA,EAAe,IAAI,EAAQ,CAAU,EAErC,IAAM,EAAK,sBAAsB,KAAK,EAEtC,EAAqB,IAAI,MAAc,qBAAqB,CAAE,CAAC,CACjE,CAEA,SAAgB,kBACd,EACA,EACA,EACS,CAST,OARI,EAAK,KAAM,GAAM,EAAE,KAAO,IAAI,GAIvB,EAAK,KAAM,GAAM,OAAO,EAAE,KAAQ,QAAQ,EAI9C,EAAK,IAAK,IAAO,CACtB,EAAG,EAAO,IAAI,EAAE,GAAoB,EACpC,EAAG,EAAO,IAAI,EAAE,KAAK,CACvB,EAAE,CACJ"}
@@ -1,11 +1,16 @@
1
+ import { type DatumMark } from '../../core/datum-style';
1
2
  import type { Point } from '../../svg/path';
2
3
  import type { ContinuousDatum, Scale, TransitionConfig } from '../../types';
3
4
  export interface AreaRenderOptions {
4
5
  color: string;
5
6
  curve: 'linear' | 'monotone' | 'step';
6
- /** Aborted when the owning chart is disposed — stops the transition's `requestAnimationFrame` loop from rescheduling. */
7
+ /** Aborted when the owning chart is disposed: stops the transition's `requestAnimationFrame` loop from rescheduling. */
7
8
  disposalSignal?: AbortSignal;
8
- fillOpacity: number;
9
+ fill: 'gradient' | 'solid';
10
+ /** Explicit opacity beats the `--prism-area-opacity` theme token. */
11
+ fillOpacity?: number;
12
+ /** Per-datum presentation parallel to `points`; styled runs split the top line into subpaths. */
13
+ marks?: readonly DatumMark[];
9
14
  showLine: boolean;
10
15
  transition?: TransitionConfig;
11
16
  }
@@ -1 +1 @@
1
- {"version":3,"file":"area-renderer.d.ts","sourceRoot":"","sources":["../../../src/charts/area/area-renderer.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE5E,MAAM,WAAW,iBAAiB;I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AC;CAC/B;AAyCD,wBAAgB,UAAU,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAwJpH;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,eAAe,EAAE,EACvB,MAAM,EAAE,KAAK,CAAC,IAAI,GAAG,MAAM,CAAC,EAC5B,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,GACpB,KAAK,EAAE,CAaT"}
@@ -1,2 +1,2 @@
1
- import"../../_dev.js";import{createSvgElement as e,setAttributes as t}from"../../svg/element.js";import{resolveEasing as n}from"../../animation/easing.js";import{resolveMotion as r}from"../../animation/motion.js";import{tweenNumber as i}from"../../animation/tween.js";import{areaPath as a,linePath as o,monotonePath as s,stepPath as c}from"../../svg/path.js";var l=new WeakMap,u=new WeakMap;function buildLinePath(e,t){return t===`monotone`?s(e):t===`step`?c(e):o(e)}function renderArea(o,s,c,d){let f=r(d.transition,0),p=f.duration,m=n(f.easing),h=o.querySelector(`.prism-area-fill`);h||(h=e(`path`,{class:`prism-area-fill`}),o.appendChild(h)),t(h,{fill:d.color,"fill-opacity":d.fillOpacity,stroke:`none`});let g=null;if(d.showLine?(g=o.querySelector(`.prism-area-line`),g||(g=e(`path`,{class:`prism-area-line`,fill:`none`}),o.appendChild(g)),t(g,{stroke:d.color,"stroke-width":2})):o.querySelector(`.prism-area-line`)?.remove(),p===0){let e=s.map(e=>({x:e.x,y:c}));t(h,{d:a(s,e,d.curve)}),g&&t(g,{d:buildLinePath(s,d.curve)});return}if(l.get(o)?.(),!h.hasAttribute(`d`)){let e=s.map(e=>({x:e.x,y:c}));t(h,{d:a(s,e,d.curve)}),g&&t(g,{d:buildLinePath(s,d.curve)}),u.set(o,s);return}let _=u.get(o)??s,v=s.map((e,t)=>_[t]??_[_.length-1]??s[t]),y=null;function frame(e){if(d.disposalSignal?.aborted){l.delete(o);return}y===null&&(y=e);let n=Math.min(1,(e-y)/p),r=m(n),f=s.map((e,t)=>({x:i(v[t].x,e.x,r),y:i(v[t].y,e.y,r)})),_=f.map(e=>({x:e.x,y:c}));if(t(h,{d:a(f,_,d.curve)}),g&&t(g,{d:buildLinePath(f,d.curve)}),n<1){let e=requestAnimationFrame(frame);l.set(o,()=>cancelAnimationFrame(e))}else l.delete(o),u.set(o,s)}u.set(o,v);let b=requestAnimationFrame(frame);l.set(o,()=>cancelAnimationFrame(b))}function computeAreaPoints(e,t,n){return e.some(e=>e.key==null)||e.some(e=>typeof e.key==`string`),e.map(e=>({x:t.map(e.key),y:n.map(e.value)}))}export{computeAreaPoints,renderArea};
1
+ import"../../_dev.js";import{createSvgElement as e,setAttributes as t}from"../../svg/element.js";import{resolveEasing as n}from"../../animation/easing.js";import{resolveMotion as r}from"../../animation/motion.js";import{tweenNumber as i}from"../../animation/tween.js";import{computeStyleRuns as a,hasStyledRuns as o}from"../../core/datum-style.js";import{uniqueId as s}from"../../core/ids.js";import{areaPath as c,linePath as l,monotonePath as u,stepPath as d}from"../../svg/path.js";var f=new WeakMap,p=new WeakMap;function buildLinePath(e,t){return t===`monotone`?u(e):t===`step`?d(e):l(e)}function applyAreaFill(n,r,i){let a=n.querySelector(`linearGradient`);if(i.fill===`gradient`){if(!a){let t=e(`defs`);a=e(`linearGradient`,{id:s(`prism-area-fill`),x1:0,x2:0,y1:0,y2:1}),a.append(e(`stop`,{class:`prism-area-stop-top`,offset:0}),e(`stop`,{class:`prism-area-stop-bottom`,offset:1})),t.appendChild(a),n.insertBefore(t,n.firstChild)}for(let e of a.querySelectorAll(`stop`))e.setAttribute(`stop-color`,i.color),e.style.stopColor=i.color;t(r,{fill:`url(#${a.id})`})}else a?.parentElement?.remove(),t(r,{fill:i.color});t(r,{class:`prism-area-fill prism-area-fill--${i.fill}`,stroke:`none`}),r.style.fillOpacity=i.fillOpacity===void 0?``:String(i.fillOpacity)}function renderArea(s,l,u,d){let m=r(d.transition,0),h=m.duration,g=n(m.easing),_=s.querySelector(`.prism-area-fill`);_||(_=e(`path`,{class:`prism-area-fill`}),s.appendChild(_)),applyAreaFill(s,_,d);let v=null,y=[],b=[],x=o(d.marks),S=d.marks??[];if(d.showLine){if(x){y=a(S,l.length);let n=[...s.querySelectorAll(`.prism-area-line`)];for(let e of n.slice(y.length))e.remove();b=y.map((t,r)=>{let i=n[r];if(i)return i;let a=e(`path`,{class:`prism-area-line`,fill:`none`});return s.appendChild(a),a});for(let[e,n]of y.entries())t(b[e],{opacity:n.opacity,stroke:d.color,"stroke-dasharray":n.dash,"stroke-width":2});v=null}else{let n=[...s.querySelectorAll(`.prism-area-line`)];for(let e of n.slice(1))e.remove();v=n[0]??null,v||(v=e(`path`,{class:`prism-area-line`,fill:`none`}),s.appendChild(v)),t(v,{opacity:void 0,stroke:d.color,"stroke-dasharray":void 0,"stroke-width":2})}}else for(let e of s.querySelectorAll(`.prism-area-line`))e.remove();let drawLine=e=>{if(d.showLine){if(x)for(let[n,r]of y.entries())t(b[n],{d:buildLinePath(e.slice(r.start,r.end+1),d.curve)});else v&&t(v,{d:buildLinePath(e,d.curve)})}};if(h===0){let e=l.map(e=>({x:e.x,y:u}));t(_,{d:c(l,e,d.curve)}),drawLine(l);return}if(f.get(s)?.(),!_.hasAttribute(`d`)){let e=l.map(e=>({x:e.x,y:u}));t(_,{d:c(l,e,d.curve)}),drawLine(l),p.set(s,l);return}let C=p.get(s)??l,w=l.map((e,t)=>C[t]??C[C.length-1]??l[t]),T=null;function frame(e){if(d.disposalSignal?.aborted){f.delete(s);return}T===null&&(T=e);let n=Math.min(1,(e-T)/h),r=g(n),a=l.map((e,t)=>({x:i(w[t].x,e.x,r),y:i(w[t].y,e.y,r)})),o=a.map(e=>({x:e.x,y:u}));if(t(_,{d:c(a,o,d.curve)}),drawLine(a),n<1){let e=requestAnimationFrame(frame);f.set(s,()=>cancelAnimationFrame(e))}else f.delete(s),p.set(s,l)}p.set(s,w);let E=requestAnimationFrame(frame);f.set(s,()=>cancelAnimationFrame(E))}function computeAreaPoints(e,t,n){return e.some(e=>e.key==null)||e.some(e=>typeof e.key==`string`),e.map(e=>({x:t.map(e.key),y:n.map(e.value)}))}export{computeAreaPoints,renderArea};
2
2
  //# sourceMappingURL=area-renderer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"area-renderer.js","names":[],"sources":["../../../src/charts/area/area-renderer.ts"],"sourcesContent":["import { warn } from '../../_dev';\nimport { resolveEasing } from '../../animation/easing';\nimport { resolveMotion } from '../../animation/motion';\nimport { tweenNumber } from '../../animation/tween';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport type { Point } from '../../svg/path';\nimport { areaPath, linePath, monotonePath, stepPath } from '../../svg/path';\nimport type { ContinuousDatum, Scale, TransitionConfig } from '../../types';\n\nexport interface AreaRenderOptions {\n color: string;\n curve: 'linear' | 'monotone' | 'step';\n /** Aborted when the owning chart is disposed — stops the transition's `requestAnimationFrame` loop from rescheduling. */\n disposalSignal?: AbortSignal;\n fillOpacity: number;\n showLine: boolean;\n transition?: TransitionConfig;\n}\n\nconst activeAreaAnimations = new WeakMap<SVGGElement, () => void>();\nconst previousPoints = new WeakMap<SVGGElement, Point[]>();\n\nfunction buildLinePath(pts: Point[], curve: AreaRenderOptions['curve']): string {\n return curve === 'monotone' ? monotonePath(pts) : curve === 'step' ? stepPath(pts) : linePath(pts);\n}\n\nexport function renderArea(parent: SVGGElement, points: Point[], baselineY: number, options: AreaRenderOptions): void {\n const motion = resolveMotion(options.transition, 0);\n const dur = motion.duration;\n const easing = resolveEasing(motion.easing);\n\n let fill = parent.querySelector<SVGPathElement>('.prism-area-fill');\n\n if (!fill) {\n fill = createSvgElement('path', { class: 'prism-area-fill' });\n parent.appendChild(fill);\n }\n\n setAttributes(fill, { fill: options.color, 'fill-opacity': options.fillOpacity, stroke: 'none' });\n\n let line: SVGPathElement | null = null;\n\n if (options.showLine) {\n line = parent.querySelector<SVGPathElement>('.prism-area-line');\n\n if (!line) {\n line = createSvgElement('path', { class: 'prism-area-line', fill: 'none' });\n parent.appendChild(line);\n }\n\n setAttributes(line, { stroke: options.color, 'stroke-width': 2 });\n } else {\n parent.querySelector('.prism-area-line')?.remove();\n }\n\n if (dur === 0) {\n const bottomPoints = points.map((p) => ({ x: p.x, y: baselineY }));\n\n setAttributes(fill, { d: areaPath(points, bottomPoints, options.curve) });\n\n if (line) setAttributes(line, { d: buildLinePath(points, options.curve) });\n\n return;\n }\n\n activeAreaAnimations.get(parent)?.();\n\n const hasExisting = fill.hasAttribute('d');\n\n if (!hasExisting) {\n const bottomPoints = points.map((p) => ({ x: p.x, y: baselineY }));\n\n setAttributes(fill, { d: areaPath(points, bottomPoints, options.curve) });\n\n if (line) setAttributes(line, { d: buildLinePath(points, options.curve) });\n\n previousPoints.set(parent, points);\n\n return;\n }\n\n const rawFrom = previousPoints.get(parent) ?? points;\n const fromPoints: Point[] = points.map((_, i) => rawFrom[i] ?? rawFrom[rawFrom.length - 1] ?? points[i]);\n\n let startTime: number | null = null;\n\n function frame(ts: number) {\n if (options.disposalSignal?.aborted) {\n activeAreaAnimations.delete(parent);\n\n return;\n }\n\n if (startTime === null) startTime = ts;\n\n const t = Math.min(1, (ts - startTime) / dur);\n const e = easing(t);\n const interpolated: Point[] = points.map((to, i) => ({\n x: tweenNumber(fromPoints[i].x, to.x, e),\n y: tweenNumber(fromPoints[i].y, to.y, e),\n }));\n const interpolatedBottom = interpolated.map((p) => ({ x: p.x, y: baselineY }));\n\n setAttributes(fill!, { d: areaPath(interpolated, interpolatedBottom, options.curve) });\n\n if (line) setAttributes(line, { d: buildLinePath(interpolated, options.curve) });\n\n if (t < 1) {\n const id = requestAnimationFrame(frame);\n\n activeAreaAnimations.set(parent, () => cancelAnimationFrame(id));\n } else {\n activeAreaAnimations.delete(parent);\n previousPoints.set(parent, points);\n }\n }\n\n previousPoints.set(parent, fromPoints);\n\n const id = requestAnimationFrame(frame);\n\n activeAreaAnimations.set(parent, () => cancelAnimationFrame(id));\n}\n\nexport function computeAreaPoints(\n data: ContinuousDatum[],\n xScale: Scale<Date | number>,\n yScale: Scale<number>,\n): Point[] {\n if (data.some((d) => d.key == null)) {\n warn(\n 'computeAreaPoints: datum.key is null or undefined — data must use the Datum shape { key, value }. Did you pass { x, y } instead?',\n );\n } else if (data.some((d) => typeof d.key === 'string')) {\n warn('computeAreaPoints: string keys are not supported for line/area charts — use numeric or Date keys.');\n }\n\n return data.map((d) => ({\n x: xScale.map(d.key as Date | number),\n y: yScale.map(d.value),\n }));\n}\n"],"mappings":"uWAmBA,IAAM,EAAuB,IAAI,QAC3B,EAAiB,IAAI,QAE3B,SAAS,cAAc,EAAc,EAA2C,CAC9E,OAAO,IAAU,WAAa,EAAa,CAAG,EAAI,IAAU,OAAS,EAAS,CAAG,EAAI,EAAS,CAAG,CACnG,CAEA,SAAgB,WAAW,EAAqB,EAAiB,EAAmB,EAAkC,CACpH,IAAM,EAAS,EAAc,EAAQ,WAAY,CAAC,EAC5C,EAAM,EAAO,SACb,EAAS,EAAc,EAAO,MAAM,EAEtC,EAAO,EAAO,cAA8B,kBAAkB,EAE7D,IACH,EAAO,EAAiB,OAAQ,CAAE,MAAO,iBAAkB,CAAC,EAC5D,EAAO,YAAY,CAAI,GAGzB,EAAc,EAAM,CAAE,KAAM,EAAQ,MAAO,eAAgB,EAAQ,YAAa,OAAQ,MAAO,CAAC,EAEhG,IAAI,EAA8B,KAelC,GAbI,EAAQ,UACV,EAAO,EAAO,cAA8B,kBAAkB,EAEzD,IACH,EAAO,EAAiB,OAAQ,CAAE,MAAO,kBAAmB,KAAM,MAAO,CAAC,EAC1E,EAAO,YAAY,CAAI,GAGzB,EAAc,EAAM,CAAE,OAAQ,EAAQ,MAAO,eAAgB,CAAE,CAAC,GAEhE,EAAO,cAAc,kBAAkB,CAAC,EAAE,OAAO,EAG/C,IAAQ,EAAG,CACb,IAAM,EAAe,EAAO,IAAK,IAAO,CAAE,EAAG,EAAE,EAAG,EAAG,CAAU,EAAE,EAEjE,E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AQ,KAAK,CAAE,CAAC,EAE3E,EAAI,EAAG,CACT,IAAM,EAAK,sBAAsB,KAAK,EAEtC,EAAqB,IAAI,MAAc,qBAAqB,CAAE,CAAC,CACjE,MACE,EAAqB,OAAO,CAAM,EAClC,EAAe,IAAI,EAAQ,CAAM,CAErC,CAEA,EAAe,IAAI,EAAQ,CAAU,EAErC,IAAM,EAAK,sBAAsB,KAAK,EAEtC,EAAqB,IAAI,MAAc,qBAAqB,CAAE,CAAC,CACjE,CAEA,SAAgB,kBACd,EACA,EACA,EACS,CAST,OARI,EAAK,KAAM,GAAM,EAAE,KAAO,IAAI,GAIvB,EAAK,KAAM,GAAM,OAAO,EAAE,KAAQ,QAAQ,EAI9C,EAAK,IAAK,IAAO,CACtB,EAAG,EAAO,IAAI,EAAE,GAAoB,EACpC,EAAG,EAAO,IAAI,EAAE,KAAK,CACvB,EAAE,CACJ"}
1
+ {"version":3,"file":"area-renderer.js","names":[],"sources":["../../../src/charts/area/area-renderer.ts"],"sourcesContent":["import { warn } from '../../_dev';\nimport { resolveEasing } from '../../animation/easing';\nimport { resolveMotion } from '../../animation/motion';\nimport { tweenNumber } from '../../animation/tween';\nimport { computeStyleRuns, type DatumMark, hasStyledRuns, type StyleRun } from '../../core/datum-style';\nimport { uniqueId } from '../../core/ids';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport type { Point } from '../../svg/path';\nimport { areaPath, linePath, monotonePath, stepPath } from '../../svg/path';\nimport type { ContinuousDatum, Scale, TransitionConfig } from '../../types';\n\nexport interface AreaRenderOptions {\n color: string;\n curve: 'linear' | 'monotone' | 'step';\n /** Aborted when the owning chart is disposed: stops the transition's `requestAnimationFrame` loop from rescheduling. */\n disposalSignal?: AbortSignal;\n fill: 'gradient' | 'solid';\n /** Explicit opacity beats the `--prism-area-opacity` theme token. */\n fillOpacity?: number;\n /** Per-datum presentation parallel to `points`; styled runs split the top line into subpaths. */\n marks?: readonly DatumMark[];\n showLine: boolean;\n transition?: TransitionConfig;\n}\n\nconst activeAreaAnimations = new WeakMap<SVGGElement, () => void>();\nconst previousPoints = new WeakMap<SVGGElement, Point[]>();\n\nfunction buildLinePath(pts: Point[], curve: AreaRenderOptions['curve']): string {\n return curve === 'monotone' ? monotonePath(pts) : curve === 'step' ? stepPath(pts) : linePath(pts);\n}\n\n/** A vertical gradient fading to transparent at the baseline, or a flat fill. */\nfunction applyAreaFill(parent: SVGGElement, fill: SVGPathElement, options: AreaRenderOptions): void {\n let gradient = parent.querySelector<SVGLinearGradientElement>('linearGradient');\n\n if (options.fill === 'gradient') {\n if (!gradient) {\n const defs = createSvgElement('defs');\n\n gradient = createSvgElement('linearGradient', { id: uniqueId('prism-area-fill'), x1: 0, x2: 0, y1: 0, y2: 1 });\n gradient.append(\n createSvgElement('stop', { class: 'prism-area-stop-top', offset: 0 }),\n createSvgElement('stop', { class: 'prism-area-stop-bottom', offset: 1 }),\n );\n defs.appendChild(gradient);\n parent.insertBefore(defs, parent.firstChild);\n }\n\n for (const stop of gradient.querySelectorAll('stop')) {\n stop.setAttribute('stop-color', options.color);\n stop.style.stopColor = options.color;\n }\n\n setAttributes(fill, { fill: `url(#${gradient.id})` });\n } else {\n gradient?.parentElement?.remove();\n setAttributes(fill, { fill: options.color });\n }\n\n setAttributes(fill, { class: `prism-area-fill prism-area-fill--${options.fill}`, stroke: 'none' });\n fill.style.fillOpacity = options.fillOpacity === undefined ? '' : String(options.fillOpacity);\n}\n\nexport function renderArea(parent: SVGGElement, points: Point[], baselineY: number, options: AreaRenderOptions): void {\n const motion = resolveMotion(options.transition, 0);\n const dur = motion.duration;\n const easing = resolveEasing(motion.easing);\n\n let fill = parent.querySelector<SVGPathElement>('.prism-area-fill');\n\n if (!fill) {\n fill = createSvgElement('path', { class: 'prism-area-fill' });\n parent.appendChild(fill);\n }\n\n applyAreaFill(parent, fill, options);\n\n let line: SVGPathElement | null = null;\n let runs: readonly StyleRun[] = [];\n let lines: SVGPathElement[] = [];\n const styled = hasStyledRuns(options.marks);\n const marks = options.marks ?? [];\n\n if (options.showLine) {\n if (styled) {\n runs = computeStyleRuns(marks, points.length);\n\n const existing = [...parent.querySelectorAll<SVGPathElement>('.prism-area-line')];\n\n for (const extra of existing.slice(runs.length)) extra.remove();\n\n lines = runs.map((_, r) => {\n const reuse = existing[r];\n\n if (reuse) return reuse;\n\n const created = createSvgElement('path', { class: 'prism-area-line', fill: 'none' });\n\n parent.appendChild(created);\n\n return created;\n });\n\n for (const [r, run] of runs.entries()) {\n setAttributes(lines[r], {\n opacity: run.opacity,\n stroke: options.color,\n 'stroke-dasharray': run.dash,\n 'stroke-width': 2,\n });\n }\n\n line = null;\n } else {\n const existing = [...parent.querySelectorAll<SVGPathElement>('.prism-area-line')];\n\n for (const stale of existing.slice(1)) stale.remove();\n\n line = existing[0] ?? null;\n\n if (!line) {\n line = createSvgElement('path', { class: 'prism-area-line', fill: 'none' });\n parent.appendChild(line);\n }\n\n setAttributes(line, {\n opacity: undefined,\n stroke: options.color,\n 'stroke-dasharray': undefined,\n 'stroke-width': 2,\n });\n }\n } else {\n for (const stale of parent.querySelectorAll('.prism-area-line')) stale.remove();\n }\n\n const drawLine = (pts: Point[]): void => {\n if (!options.showLine) return;\n\n if (styled) {\n for (const [r, run] of runs.entries()) {\n setAttributes(lines[r], { d: buildLinePath(pts.slice(run.start, run.end + 1), options.curve) });\n }\n } else if (line) {\n setAttributes(line, { d: buildLinePath(pts, options.curve) });\n }\n };\n\n if (dur === 0) {\n const bottomPoints = points.map((p) => ({ x: p.x, y: baselineY }));\n\n setAttributes(fill, { d: areaPath(points, bottomPoints, options.curve) });\n\n drawLine(points);\n\n return;\n }\n\n activeAreaAnimations.get(parent)?.();\n\n const hasExisting = fill.hasAttribute('d');\n\n if (!hasExisting) {\n const bottomPoints = points.map((p) => ({ x: p.x, y: baselineY }));\n\n setAttributes(fill, { d: areaPath(points, bottomPoints, options.curve) });\n\n drawLine(points);\n\n previousPoints.set(parent, points);\n\n return;\n }\n\n const rawFrom = previousPoints.get(parent) ?? points;\n const fromPoints: Point[] = points.map((_, i) => rawFrom[i] ?? rawFrom[rawFrom.length - 1] ?? points[i]);\n\n let startTime: number | null = null;\n\n function frame(ts: number) {\n if (options.disposalSignal?.aborted) {\n activeAreaAnimations.delete(parent);\n\n return;\n }\n\n if (startTime === null) startTime = ts;\n\n const t = Math.min(1, (ts - startTime) / dur);\n const e = easing(t);\n const interpolated: Point[] = points.map((to, i) => ({\n x: tweenNumber(fromPoints[i].x, to.x, e),\n y: tweenNumber(fromPoints[i].y, to.y, e),\n }));\n const interpolatedBottom = interpolated.map((p) => ({ x: p.x, y: baselineY }));\n\n setAttributes(fill!, { d: areaPath(interpolated, interpolatedBottom, options.curve) });\n\n drawLine(interpolated);\n\n if (t < 1) {\n const id = requestAnimationFrame(frame);\n\n activeAreaAnimations.set(parent, () => cancelAnimationFrame(id));\n } else {\n activeAreaAnimations.delete(parent);\n previousPoints.set(parent, points);\n }\n }\n\n previousPoints.set(parent, fromPoints);\n\n const id = requestAnimationFrame(frame);\n\n activeAreaAnimations.set(parent, () => cancelAnimationFrame(id));\n}\n\nexport function computeAreaPoints(\n data: ContinuousDatum[],\n xScale: Scale<Date | number>,\n yScale: Scale<number>,\n): Point[] {\n if (data.some((d) => d.key == null)) {\n warn(\n 'computeAreaPoints: datum.key is null or undefined: data must use the Datum shape { key, value }. Did you pass { x, y } instead?',\n );\n } else if (data.some((d) => typeof d.key === 'string')) {\n warn('computeAreaPoints: string keys are not supported for line/area charts: use numeric or Date keys.');\n }\n\n return data.map((d) => ({\n x: xScale.map(d.key as Date | number),\n y: yScale.map(d.value),\n }));\n}\n"],"mappings":"oeAyBA,IAAM,EAAuB,IAAI,QAC3B,EAAiB,IAAI,QAE3B,SAAS,cAAc,EAAc,EAA2C,CAC9E,OAAO,IAAU,WAAa,EAAa,CAAG,EAAI,IAAU,OAAS,EAAS,CAAG,EAAI,EAAS,CAAG,CACnG,CAGA,SAAS,cAAc,EAAqB,EAAsB,EAAkC,CAClG,I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,EAAO,CAAE,EAAG,EAAS,EAAc,EAAoB,EAAQ,KAAK,CAAE,CAAC,EAErF,SAAS,CAAY,EAEjB,EAAI,EAAG,CACT,IAAM,EAAK,sBAAsB,KAAK,EAEtC,EAAqB,IAAI,MAAc,qBAAqB,CAAE,CAAC,CACjE,MACE,EAAqB,OAAO,CAAM,EAClC,EAAe,IAAI,EAAQ,CAAM,CAErC,CAEA,EAAe,IAAI,EAAQ,CAAU,EAErC,IAAM,EAAK,sBAAsB,KAAK,EAEtC,EAAqB,IAAI,MAAc,qBAAqB,CAAE,CAAC,CACjE,CAEA,SAAgB,kBACd,EACA,EACA,EACS,CAST,OARI,EAAK,KAAM,GAAM,EAAE,KAAO,IAAI,GAIvB,EAAK,KAAM,GAAM,OAAO,EAAE,KAAQ,QAAQ,EAI9C,EAAK,IAAK,IAAO,CACtB,EAAG,EAAO,IAAI,EAAE,GAAoB,EACpC,EAAG,EAAO,IAAI,EAAE,KAAK,CACvB,EAAE,CACJ"}
@@ -1,2 +1,2 @@
1
- require("../../_dev.cjs");const e=require("../../svg/element.cjs"),t=require("../../axes/axis.cjs"),n=require("../../axes/grid.cjs"),r=require("../../scales/linear.cjs"),i=require("../../core/layout.cjs"),a=require("../../core/chart-scaffold.cjs"),o=require("../../core/cartesian-model.cjs"),s=require("../../interaction/events.cjs"),c=require("../../theme/index.cjs"),l=require("../../scales/band.cjs"),u=require("./bar-hit-test.cjs"),d=require("./bar-renderer.cjs");function variantFlags(e){return{horizontal:e===`grouped-horizontal`||e===`stacked-horizontal`,stacked:e===`stacked`||e===`stacked-horizontal`}}function createBarChart(f,p){let m=p.series;return a.createChartScaffold(f,p,f=>{let{groups:h,legend:g,tooltip:_}=f,v=f.dimensions,y=i.chartArea(v.width,v.height,v.margin),b=m.map(e=>e.data),x=o.normalizeCartesianSeries(m,b),S=x.domain,C=x.series.map(({byKey:e})=>S.map(t=>e.get(t))),categoryAxis=e=>{if(e)return{...e,tickFormat:t=>{let n=String(t),r=x.labels.get(n)??t;return e.tickFormat?e.tickFormat(r):String(r)}}};if(S.length===0){a.clearCartesianDom(h,g,_);return}let{horizontal:w,stacked:T}=variantFlags(p.variant??`grouped`),E,D;if(T){C.some(e=>e.some(e=>(e?.value??0)<0));let e=S.map((e,t)=>C.reduce((e,n)=>e+Math.max(0,n[t]?.value??0),0));E=Math.max(...e),D=0}else{let e=C.flatMap(e=>e.flatMap(e=>e?[e.value]:[]));E=Math.max(...e),D=Math.min(0,...e)}let O=w?l.bandScale({domain:S,range:[0,y.height]}):l.bandScale({domain:S,range:[0,y.width]}),k=w?r.linearScale({domain:[D,E],range:[0,y.width]}):r.linearScale({domain:[D,E],range:[y.height,0]}),A=[],j=Object.create(null);for(let e of S)j[e]=0;let M={bandCenter:e=>O.map(e)+O.bandwidth()/2,bandwidth:O.bandwidth(),baselinePx:k.map(0),horizontal:w,stacked:T,stackedTops:A,valueScale:k};if(w){p.xAxis?.grid&&n.renderGrid(h.grid,k,p.xAxis.grid,y.height,`vertical`,t.resolveTickCount(p.xAxis,y.width,`bottom`));let e=categoryAxis(p.yAxis);e&&(t.positionAxis(h.yAxis,e.position??`left`,y.width,y.height),t.renderAxis(h.yAxis,O,e,y.height,`left`)),p.xAxis&&(t.positionAxis(h.xAxis,p.xAxis.position??`bottom`,y.width,y.height),t.renderAxis(h.xAxis,k,p.xAxis,y.width,`bottom`))}else{p.yAxis?.grid&&n.renderGrid(h.grid,k,p.yAxis.grid,y.width,`horizontal`,t.resolveTickCount(p.yAxis,y.height,`left`));let e=categoryAxis(p.xAxis);e&&(t.positionAxis(h.xAxis,e.position??`bottom`,y.width,y.height),t.renderAxis(h.xAxis,O,e,y.width,`bottom`)),p.yAxis&&(t.positionAxis(h.yAxis,p.yAxis.position??`left`,y.width,y.height),t.renderAxis(h.yAxis,k,p.yAxis,y.height,`left`))}for(;h.series.children.length>m.length;){let e=h.series.lastElementChild;e&&h.series.removeChild(e)}for(let t=0;t<m.length;t++){let n=m[t],r=h.series.children[t];r||(r=e.createSvgElement(`g`,{class:`prism-bar-series`}),h.series.appendChild(r));let i=S.map((e,n)=>{let r=C[t]?.[n];if(T){let t=j[e]??0,n=t+Math.max(0,r?.value??0);return j[e]=n,{base:t,key:e,present:r!==void 0,y:n}}return{base:0,key:e,present:r!==void 0,y:r?.value??0}});A[t]=i.map(e=>e.y);let a=T?i.map(e=>k.map(e.base)):void 0;d.renderBars(r,i,O,k,M.baselinePx,{baselineYs:a,borderRadius:n.borderRadius??0,color:c.seriesColor(t,n.color),disposalSignal:f.disposalSignal,horizontal:w,seriesCount:m.length,seriesIndex:t,stacked:T,transition:p.transition})}g?.update(m.map((e,t)=>({color:c.seriesColor(t,e.color),name:e.name}))),_?.hide();let onMouseMove=e=>{let t=f.dimensions,n=s.getMousePosition(f.svg,e,t.margin.left,t.margin.top),r=i.chartArea(t.width,t.height,t.margin);if(n.x<0||n.x>r.width||n.y<0||n.y>r.height){_?.hide();return}let a=w?n.y:n.x,o=u.findCatIdx(a,S,M);if(o===-1){_?.hide();return}if(u.isOutsideBars(n,o,C,M,m.length)){_?.hide();return}let c=u.findSeriesIdx(n,o,S,M,m.length),l=C[c]?.[o];if(l){let n=M.bandCenter(S[o]),r=T?A[c]?.[o]??l.value:l.value,i=k.map(r),a=w?i+t.margin.left:n+t.margin.left,s=w?n+t.margin.top:i+t.margin.top;_?.show(a,s,l,m[c]),p.onHover?.({datum:l,originalEvent:e,series:m[c]})}},onMouseLeave=()=>{_?.hide(),p.onHover?.(null)},onClick=e=>{if(!p.onClick)return;let t=f.dimensions,n=s.getMousePosition(f.svg,e,t.margin.left,t.margin.top),r=i.chartArea(t.width,t.height,t.margin);if(n.x<0||n.x>r.width||n.y<0||n.y>r.height)return;let a=w?n.y:n.x,o=u.findCatIdx(a,S,M);if(o===-1)return;let c=u.findSeriesIdx(n,o,S,M,m.length),l=C[c]?.[o];l&&p.onClick({datum:l,originalEvent:e,series:m[c]})};return{onClick,onMouseLeave,onMouseMove}},e=>{m=e})}exports.createBarChart=createBarChart;
1
+ require("../../_dev.cjs");const e=require("../../svg/element.cjs"),t=require("../../axes/axis.cjs"),n=require("../../axes/grid.cjs"),r=require("../../scales/linear.cjs"),i=require("../../interaction/announcer.cjs"),a=require("../../interaction/tooltip.cjs"),o=require("../../core/layout.cjs"),s=require("../../core/chart-scaffold.cjs"),c=require("../../core/series-id.cjs"),l=require("../../core/cartesian-model.cjs"),u=require("../../interaction/events.cjs"),d=require("../../theme/index.cjs"),f=require("../../scales/band.cjs"),p=require("./bar-hit-test.cjs"),m=require("./bar-renderer.cjs");function variantFlags(e){return{horizontal:e===`grouped-horizontal`||e===`stacked-horizontal`,stacked:e===`stacked`||e===`stacked-horizontal`}}function createBarChart(h,g){let _=g.series,v=null;return s.createChartScaffold(h,g,h=>{let{groups:y,legend:b,tooltip:x}=h,S=h.dimensions,C=o.chartArea(S.width,S.height,S.margin),w=_.map(e=>e.data),T=l.normalizeCartesianSeries(_,w),E=T.domain,D=T.series.map(({byKey:e})=>E.map(t=>e.get(t))),categoryAxis=e=>{if(e)return{...e,tickFormat:t=>{let n=String(t),r=T.labels.get(n)??t;return e.tickFormat?e.tickFormat(r):String(r)}}};if(E.length===0){s.clearCartesianDom(y,b,x),v?.remove(),v=null;return}let{horizontal:O,stacked:k}=variantFlags(g.variant??`grouped`),A,j;if(k){D.some(e=>e.some(e=>(e?.value??0)<0));let e=E.map((e,t)=>D.reduce((e,n)=>e+Math.max(0,n[t]?.value??0),0));A=Math.max(...e),j=0}else{let e=D.flatMap(e=>e.flatMap(e=>e?[e.value]:[]));A=Math.max(...e),j=Math.min(0,...e)}let M=O?f.bandScale({domain:E,range:[0,C.height]}):f.bandScale({domain:E,range:[0,C.width]}),N=O?r.linearScale({domain:[j,A],range:[0,C.width]}):r.linearScale({domain:[j,A],range:[C.height,0]}),P=[],F=Object.create(null);for(let e of E)F[e]=0;let I={bandCenter:e=>M.map(e)+M.bandwidth()/2,bandwidth:M.bandwidth(),baselinePx:N.map(0),horizontal:O,stacked:k,stackedTops:P,valueScale:N};if(O){g.xAxis?.grid&&n.renderGrid(y.grid,N,g.xAxis.grid,C.height,`vertical`,t.resolveTickCount(g.xAxis,C.width,`bottom`));let e=categoryAxis(g.yAxis);e&&(t.positionAxis(y.yAxis,e.position??`left`,C.width,C.height),t.renderAxis(y.yAxis,M,e,C.height,`left`)),g.xAxis&&(t.positionAxis(y.xAxis,g.xAxis.position??`bottom`,C.width,C.height),t.renderAxis(y.xAxis,N,g.xAxis,C.width,`bottom`))}else{g.yAxis?.grid&&n.renderGrid(y.grid,N,g.yAxis.grid,C.width,`horizontal`,t.resolveTickCount(g.yAxis,C.height,`left`));let e=categoryAxis(g.xAxis);e&&(t.positionAxis(y.xAxis,e.position??`bottom`,C.width,C.height),t.renderAxis(y.xAxis,M,e,C.width,`bottom`)),g.yAxis&&(t.positionAxis(y.yAxis,g.yAxis.position??`left`,C.width,C.height),t.renderAxis(y.yAxis,N,g.yAxis,C.height,`left`))}let L=k?0:Number.parseFloat(getComputedStyle(h.svg).getPropertyValue(`--prism-bar-radius`))||0;for(;y.series.children.length>_.length;){let e=y.series.lastElementChild;e&&y.series.removeChild(e)}for(let t=0;t<_.length;t++){let n=_[t],r=y.series.children[t];r||(r=e.createSvgElement(`g`,{class:`prism-bar-series`}),y.series.appendChild(r)),r.setAttribute(`data-series-id`,c.seriesDomId(n,t));let i=E.map((e,n)=>{let r=D[t]?.[n];if(k){let t=F[e]??0,n=t+Math.max(0,r?.value??0);return F[e]=n,{base:t,dash:r?.dash,key:e,opacity:r?.opacity,present:r!==void 0,y:n}}return{base:0,dash:r?.dash,key:e,opacity:r?.opacity,present:r!==void 0,y:r?.value??0}});P[t]=i.map(e=>e.y);let a=k?i.map(e=>N.map(e.base)):void 0;m.renderBars(r,i,M,N,I.baselinePx,{baselineYs:a,borderRadius:n.borderRadius??L,color:d.seriesColor(t,n.color),disposalSignal:h.disposalSignal,horizontal:O,seriesCount:_.length,seriesIndex:t,stacked:k,transition:g.transition})}b?.update(_.map((e,t)=>({color:d.seriesColor(t,e.color),name:e.name}))),x?.hide(),y.series.classList.toggle(`prism-bars-stacked`,k),(!v||!h.chartArea.contains(v))&&(v=e.createSvgElement(`rect`,{"aria-hidden":`true`,class:`prism-bar-band`,"pointer-events":`none`}),h.chartArea.insertBefore(v,y.series)),v.style.display=`none`;let R=_.map((e,t)=>d.seriesColor(t,e.color)),labelOf=e=>String(T.labels.get(E[e])??E[e]),z=-1,valuesAt=e=>_.map((t,n)=>({datum:D[n]?.[e],series:t})),eventAt=(e,t,n)=>{let r=valuesAt(e),i=r[t]?.datum?t:r.findIndex(e=>e.datum),a=r[i]?.datum;return a?{datum:a,originalEvent:n,series:_[i],values:r}:null},setActive=t=>{z=t,y.series.classList.toggle(`prism-bars-focused`,t>=0);for(let e of y.series.children)for(let[n,r]of[...e.children].entries())r.classList.toggle(`prism-bar--active`,n===t);if(!v||(v.style.display=t<0?`none`:``,t<0))return;let n=I.bandCenter(E[t])-M.bandwidth()/2-M.gap()/2,r=M.bandwidth()+M.gap(),i=o.chartArea(h.dimensions.width,h.dimensions.height,h.dimensions.margin);e.setAttributes(v,O?{height:r,width:i.width,x:0,y:n}:{height:i.height,width:r,x:n,y:0})},activate=(e,t,n)=>{let r=eventAt(e,t,n);if(!r)return;setActive(e);let o=r.values??[],s=i.describeValues(labelOf(e),o);if(x){let t=o.map((t,n)=>k?P[n]?.[e]??0:Math.max(0,t.datum?.value??0)),n=N.map(Math.max(...t)),i=I.bandCenter(E[e]),{margin:c}=h.dimensions,l=o.flatMap((e,t)=>e.datum?[{color:R[t],name:e.series.name,value:String(e.datum.value)}]:[]);x.show((O?n:i)+c.left,(O?i:n)+c.top,r.datum,r.series,a.comparisonContent(h.svg.ownerDocument,labelOf(e),l,s))}else h.announcer.announce(s);g.onHover?.(r)},deactivate=()=>{setActive(-1),x?.hide(),h.announcer.clear(),g.onHover?.(null)},hit=e=>{let t=h.dimensions,n=u.getMousePosition(h.svg,e,t.margin.left,t.margin.top),r=o.chartArea(t.width,t.height,t.margin);if(n.x<0||n.x>r.width||n.y<0||n.y>r.height)return null;let i=p.findCatIdx(O?n.y:n.x,E,I);return i===-1?null:{catIdx:i,seriesIdx:p.findSeriesIdx(n,i,E,I,_.length)}},onMouseMove=e=>{let t=hit(e);t?activate(t.catIdx,t.seriesIdx,e):z>=0&&deactivate()},onClick=e=>{let t=g.onClick&&hit(e),n=t&&eventAt(t.catIdx,t.seriesIdx,e);n&&g.onClick?.(n)},onKeyDown=e=>{let t=E.length-1,n=z<0?t:Math.max(0,z-1),r=z<0?0:Math.min(t,z+1),i={ArrowDown:r,ArrowLeft:n,ArrowRight:r,ArrowUp:n,End:t,Home:0};if(e.key in i)e.preventDefault(),activate(i[e.key],0,e);else if((e.key===`Enter`||e.key===` `)&&z>=0&&g.onClick){e.preventDefault();let t=eventAt(z,0,e);t&&g.onClick(t)}else e.key===`Escape`&&deactivate()};return{onClick,onKeyDown,onMouseLeave:deactivate,onMouseMove}},e=>{_=e})}exports.createBarChart=createBarChart;
2
2
  //# sourceMappingURL=bar-chart.cjs.map