@vielzeug/prism 2.2.6 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/README.md +19 -40
  2. package/dist/_dev.cjs +1 -1
  3. package/dist/_dev.cjs.map +1 -1
  4. package/dist/_dev.js +1 -2
  5. package/dist/_dev.js.map +1 -1
  6. package/dist/axes/axis.cjs +1 -1
  7. package/dist/axes/axis.cjs.map +1 -1
  8. package/dist/axes/axis.d.ts +1 -0
  9. package/dist/axes/axis.d.ts.map +1 -1
  10. package/dist/axes/axis.js +15 -11
  11. package/dist/axes/axis.js.map +1 -1
  12. package/dist/charts/area/area-chart.cjs +1 -1
  13. package/dist/charts/area/area-chart.cjs.map +1 -1
  14. package/dist/charts/area/area-chart.d.ts +2 -2
  15. package/dist/charts/area/area-chart.d.ts.map +1 -1
  16. package/dist/charts/area/area-chart.js +45 -49
  17. package/dist/charts/area/area-chart.js.map +1 -1
  18. package/dist/charts/area/area-renderer.cjs +1 -1
  19. package/dist/charts/area/area-renderer.cjs.map +1 -1
  20. package/dist/charts/area/area-renderer.d.ts +2 -2
  21. package/dist/charts/area/area-renderer.d.ts.map +1 -1
  22. package/dist/charts/area/area-renderer.js +14 -14
  23. package/dist/charts/area/area-renderer.js.map +1 -1
  24. package/dist/charts/bar/bar-chart.cjs +1 -1
  25. package/dist/charts/bar/bar-chart.cjs.map +1 -1
  26. package/dist/charts/bar/bar-chart.d.ts +2 -2
  27. package/dist/charts/bar/bar-chart.d.ts.map +1 -1
  28. package/dist/charts/bar/bar-chart.js +140 -143
  29. package/dist/charts/bar/bar-chart.js.map +1 -1
  30. package/dist/charts/bar/bar-hit-test.cjs +1 -1
  31. package/dist/charts/bar/bar-hit-test.cjs.map +1 -1
  32. package/dist/charts/bar/bar-hit-test.js +5 -4
  33. package/dist/charts/bar/bar-hit-test.js.map +1 -1
  34. package/dist/charts/bar/bar-renderer.cjs +1 -1
  35. package/dist/charts/bar/bar-renderer.js +24 -24
  36. package/dist/charts/line/line-chart.cjs +1 -1
  37. package/dist/charts/line/line-chart.cjs.map +1 -1
  38. package/dist/charts/line/line-chart.d.ts +2 -2
  39. package/dist/charts/line/line-chart.d.ts.map +1 -1
  40. package/dist/charts/line/line-chart.js +46 -50
  41. package/dist/charts/line/line-chart.js.map +1 -1
  42. package/dist/charts/line/line-renderer.cjs +1 -1
  43. package/dist/charts/line/line-renderer.cjs.map +1 -1
  44. package/dist/charts/line/line-renderer.d.ts +2 -2
  45. package/dist/charts/line/line-renderer.d.ts.map +1 -1
  46. package/dist/charts/line/line-renderer.js +34 -34
  47. package/dist/charts/line/line-renderer.js.map +1 -1
  48. package/dist/charts/pie/pie-chart.cjs +1 -1
  49. package/dist/charts/pie/pie-chart.cjs.map +1 -1
  50. package/dist/charts/pie/pie-chart.d.ts +2 -2
  51. package/dist/charts/pie/pie-chart.d.ts.map +1 -1
  52. package/dist/charts/pie/pie-chart.js +84 -79
  53. package/dist/charts/pie/pie-chart.js.map +1 -1
  54. package/dist/charts/sparkline/sparkline.cjs +1 -1
  55. package/dist/charts/sparkline/sparkline.cjs.map +1 -1
  56. package/dist/charts/sparkline/sparkline.d.ts +2 -2
  57. package/dist/charts/sparkline/sparkline.d.ts.map +1 -1
  58. package/dist/charts/sparkline/sparkline.js +100 -101
  59. package/dist/charts/sparkline/sparkline.js.map +1 -1
  60. package/dist/core/chart-base.cjs +1 -1
  61. package/dist/core/chart-base.cjs.map +1 -1
  62. package/dist/core/chart-base.d.ts +2 -4
  63. package/dist/core/chart-base.d.ts.map +1 -1
  64. package/dist/core/chart-base.js +21 -30
  65. package/dist/core/chart-base.js.map +1 -1
  66. package/dist/core/chart-scaffold.cjs +1 -1
  67. package/dist/core/chart-scaffold.cjs.map +1 -1
  68. package/dist/core/chart-scaffold.d.ts +9 -10
  69. package/dist/core/chart-scaffold.d.ts.map +1 -1
  70. package/dist/core/chart-scaffold.js +31 -43
  71. package/dist/core/chart-scaffold.js.map +1 -1
  72. package/dist/core/index.d.ts +0 -1
  73. package/dist/core/index.d.ts.map +1 -1
  74. package/dist/core/layout.cjs +1 -1
  75. package/dist/core/layout.cjs.map +1 -1
  76. package/dist/core/layout.js +1 -1
  77. package/dist/core/layout.js.map +1 -1
  78. package/dist/index.cjs +1 -1
  79. package/dist/index.d.ts +2 -6
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +11 -12
  82. package/dist/interaction/legend.cjs +1 -1
  83. package/dist/interaction/legend.cjs.map +1 -1
  84. package/dist/interaction/legend.js +1 -1
  85. package/dist/interaction/legend.js.map +1 -1
  86. package/dist/interaction/tooltip.cjs +1 -1
  87. package/dist/interaction/tooltip.cjs.map +1 -1
  88. package/dist/interaction/tooltip.d.ts.map +1 -1
  89. package/dist/interaction/tooltip.js +29 -29
  90. package/dist/interaction/tooltip.js.map +1 -1
  91. package/dist/prism.cjs +1 -1
  92. package/dist/prism.cjs.map +1 -1
  93. package/dist/prism.iife.js +1 -1
  94. package/dist/prism.iife.js.map +1 -1
  95. package/dist/prism.js +1 -1
  96. package/dist/prism.js.map +1 -1
  97. package/dist/types.d.ts +24 -48
  98. package/dist/types.d.ts.map +1 -1
  99. package/package.json +8 -9
  100. package/dist/core/resolve.cjs +0 -2
  101. package/dist/core/resolve.cjs.map +0 -1
  102. package/dist/core/resolve.d.ts +0 -9
  103. package/dist/core/resolve.d.ts.map +0 -1
  104. package/dist/core/resolve.js +0 -15
  105. package/dist/core/resolve.js.map +0 -1
package/README.md CHANGED
@@ -1,72 +1,50 @@
1
1
  # @vielzeug/prism
2
2
 
3
- > Reactive SVG charting library — line, bar, area, pie, and sparkline charts with keyed data, accessible interactions, and signal-driven updates.
4
-
5
- [![npm version](https://img.shields.io/npm/v/@vielzeug/prism)](https://www.npmjs.com/package/@vielzeug/prism) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
-
7
- <details>
8
- <summary>Quick Reference</summary>
9
-
10
- **Package:** `@vielzeug/prism` &nbsp;·&nbsp; **Category:** UI / Visualization
11
-
12
- **Key exports:** `createLineChart`, `createBarChart`, `createAreaChart`, `createPieChart`, `createSparkline`, `linearScale`, `timeScale`, `bandScale`, `seriesColor`, `setTheme`
13
-
14
- **When to use:** Data visualization with reactive charts that auto-update when signal-based data sources change. Renders accessible SVG, themeable via CSS custom properties.
15
-
16
- **Related:** [@vielzeug/ripple](https://vielzeug.dev/ripple/) · [@vielzeug/refine](https://vielzeug.dev/refine/) · [@vielzeug/orbit](https://vielzeug.dev/orbit/)
17
-
18
- </details>
19
-
20
- `@vielzeug/prism` is part of Vielzeug. It depends on Orbit for tooltips and Ripple for reactivity, and ships as a TypeScript package with ESM+CJS output.
3
+ > Responsive SVG charts with explicit updates — line, bar, area, pie, sparkline
21
4
 
22
5
  ## Installation
23
6
 
24
7
  ```sh
25
- # pnpm
26
8
  pnpm add @vielzeug/prism
27
- # npm
28
9
  npm install @vielzeug/prism
29
- # yarn
30
10
  yarn add @vielzeug/prism
31
11
  ```
32
12
 
33
- ## Sub-paths
34
-
35
- | Import | Purpose |
36
- | -------------------------- | -------------------------------------------------------------- |
37
- | `@vielzeug/prism` | Chart factories, scales, and types |
38
- | `@vielzeug/prism/theme` | Default CSS custom properties (light + dark mode) |
39
- | `@vielzeug/prism/devtools` | `warn` / `issue` helpers (dev-only, tree-shaken in production) |
40
-
41
13
  ## Quick Start
42
14
 
43
15
  ```ts
44
16
  import { createLineChart, setTheme } from '@vielzeug/prism';
45
- import { signal } from '@vielzeug/ripple';
46
17
  import '@vielzeug/prism/theme';
47
18
 
48
19
  // Optional: apply a custom color palette at startup
49
20
  setTheme({ colors: ['#6366f1', '#22d3ee', '#f59e0b', '#10b981'] });
50
21
 
51
- const data = signal([
52
- { x: 1, y: 10 },
53
- { x: 2, y: 25 },
54
- { x: 3, y: 18 },
55
- { x: 4, y: 32 },
56
- ]);
22
+ let series = [
23
+ {
24
+ color: '#3b82f6',
25
+ data: [
26
+ { key: 1, value: 10 },
27
+ { key: 2, value: 25 },
28
+ { key: 3, value: 18 },
29
+ { key: 4, value: 32 },
30
+ ],
31
+ name: 'Revenue',
32
+ },
33
+ ];
57
34
 
58
35
  const chart = createLineChart(document.getElementById('chart')!, {
59
36
  a11y: { ariaLabel: 'Revenue by month' },
60
- series: [{ name: 'Revenue', data, color: '#3b82f6' }],
37
+ series,
61
38
  xAxis: { position: 'bottom' },
62
39
  yAxis: { position: 'left', grid: true },
63
40
  tooltip: true,
64
41
  crosshair: true,
65
- onHover: (event) => console.log(event?.point),
42
+ onHover: (event) => console.log(event?.datum),
66
43
  });
67
44
 
68
- // Data updates chart re-renders automatically
69
- data.value = [...data.value, { x: 5, y: 28 }];
45
+ // Replace data explicitly when application state changes
46
+ series = [{ ...series[0]!, data: [...series[0]!.data, { key: 5, value: 28 }] }];
47
+ chart.update(series);
70
48
 
71
49
  // Cleanup (also works with TC39 `using` declarations)
72
50
  chart.dispose();
@@ -78,6 +56,7 @@ chart.dispose();
78
56
  - [Usage Guide](https://vielzeug.dev/prism/usage)
79
57
  - [API Reference](https://vielzeug.dev/prism/api)
80
58
  - [Examples](https://vielzeug.dev/prism/examples)
59
+ - [Migration Guide](https://vielzeug.dev/prism/migration)
81
60
 
82
61
  ## License
83
62
 
package/dist/_dev.cjs CHANGED
@@ -1,2 +1,2 @@
1
- function e(e){}function t(e,...t){}exports.error=t,exports.warn=e;
1
+ function e(e){}exports.warn=e;
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,EAAK,EAAmB,CAExC,CAMA,SAAgB,EAAM,EAAa,GAAG,EAAuB,CAE7D"}
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,EAAK,EAAmB,CAExC"}
package/dist/_dev.js CHANGED
@@ -1,7 +1,6 @@
1
1
  //#region src/_dev.ts
2
2
  function e(e) {}
3
- function t(e, ...t) {}
4
3
  //#endregion
5
- export { t as error, e as warn };
4
+ export { e as warn };
6
5
 
7
6
  //# 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,EAAK,GAAmB,CAExC;AAMA,SAAgB,EAAM,GAAa,GAAG,GAAuB,CAE7D"}
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,EAAK,GAAmB,CAExC"}
@@ -1,2 +1,2 @@
1
- const e=require("../svg/element.cjs"),t=require("../svg/text.cjs"),n=require("./scale-utils.cjs");var r=e=>e instanceof Date?e.toLocaleDateString(void 0,{month:`short`,year:`numeric`}):String(e);function i(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 a(a,o,s,c,l=`bottom`){e.removeChildren(a);let u=s.position??l,d=u===`bottom`||u===`top`,f=u===`top`||u===`left`,p=f?-1:1,m=e.createSvgElement(`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(i(s,c,l)),g=s.tickFormat??r;for(let r of h){let i=n.mapTick(o,r),s=e.createSvgElement(`line`,{"aria-hidden":`true`,class:`prism-axis-tick`,x1:d?i:0,x2:d?i:6*p,y1:d?0:i,y2:d?6*p:i});a.appendChild(s);let c=t.createTextElement(g(r),{"aria-hidden":`true`,class:`prism-axis-label`,"dominant-baseline":d?f?`auto`:`hanging`:`middle`,"text-anchor":d?`middle`:f?`end`:`start`,x:d?i:6*p*1.5,y:d?6*p*1.5:i});a.appendChild(c)}if(s.label){let n=t.createTextElement(s.label,{class:`prism-axis-title`,"dominant-baseline":`middle`,"text-anchor":`middle`});d?e.setAttributes(n,{x:c/2,y:6*p*3.5}):e.setAttributes(n,{transform:`translate(${6*p*4}, ${c/2}) rotate(-90)`}),a.appendChild(n)}}exports.renderAxis=a,exports.resolveTickCount=i;
1
+ const e=require("../svg/element.cjs"),t=require("../svg/text.cjs"),n=require("./scale-utils.cjs");var r=e=>e instanceof Date?e.toLocaleDateString(void 0,{month:`short`,year:`numeric`}):String(e);function i(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 a(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 o(i,o,s,c,l=`bottom`){e.removeChildren(i);let u=s.position??l,d=u===`bottom`||u===`top`,f=u===`top`||u===`left`,p=f?-1:1,m=e.createSvgElement(`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=o.ticks(a(s,c,l)),g=s.tickFormat??r;for(let r of h){let a=n.mapTick(o,r),s=e.createSvgElement(`line`,{"aria-hidden":`true`,class:`prism-axis-tick`,x1:d?a:0,x2:d?a:6*p,y1:d?0:a,y2:d?6*p:a});i.appendChild(s);let c=t.createTextElement(g(r),{"aria-hidden":`true`,class:`prism-axis-label`,"dominant-baseline":d?f?`auto`:`hanging`:`middle`,"text-anchor":d?`middle`:f?`end`:`start`,x:d?a:6*p*1.5,y:d?6*p*1.5:a});i.appendChild(c)}if(s.label){let n=t.createTextElement(s.label,{class:`prism-axis-title`,"dominant-baseline":`middle`,"text-anchor":`middle`});d?e.setAttributes(n,{x:c/2,y:6*p*6}):e.setAttributes(n,{transform:`translate(${6*p*7}, ${c/2}) rotate(-90)`}),i.appendChild(n)}}exports.positionAxis=i,exports.renderAxis=o,exports.resolveTickCount=a;
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 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 * 3.5 });\n } else {\n setAttributes(labelEl, {\n transform: `translate(${tickSize * tickDirection * 4}, ${length / 2}) rotate(-90)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,EAAgB,EAAa,OAAS,UAAa,SACxE,cAAe,EAAe,SAAW,EAAa,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,GAAI,CAAC,EAE3E,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 } 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,EAAqB,GACzB,aAAa,KAAO,EAAE,mBAAmB,IAAA,GAAW,CAAE,MAAO,QAAS,KAAM,SAAU,CAAC,EAAI,OAAO,CAAC,EAOrG,SAAgB,EAAa,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,EAAiB,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,CAOA,SAAgB,EACd,EACA,EACA,EACA,EACA,EAAgC,SAC1B,CACN,EAAA,eAAe,CAAM,EAErB,IAAM,EAAW,EAAO,UAAY,EAC9B,EAAe,IAAa,UAAY,IAAa,MACrD,EAAa,IAAa,OAAS,IAAa,OAEhD,EAAgB,EAAa,GAAK,EAElC,EAAW,EAAA,iBAAiB,OAAQ,CACxC,cAAe,OACf,MAAO,kBACP,GAAmB,EACnB,GAAI,EAAe,EAAS,EAC5B,GAAmB,EACnB,GAAI,EAAe,EAAI,CACzB,CAAC,EAED,EAAO,YAAY,CAAQ,EAE3B,IAAM,EAAQ,EAAM,MAAM,EAAiB,EAAQ,EAAQ,CAAe,CAAC,EACrE,EAAS,EAAO,YAAc,EAEpC,IAAK,IAAM,KAAQ,EAAO,CACxB,IAAM,EAAM,EAAA,QAAQ,EAAO,CAAI,EACzB,EAAW,EAAA,iBAAiB,OAAQ,CACxC,cAAe,OACf,MAAO,kBACP,GAAI,EAAe,EAAM,EACzB,GAAI,EAAe,EAAM,EAAW,EACpC,GAAI,EAAe,EAAI,EACvB,GAAI,EAAe,EAAW,EAAgB,CAChD,CAAC,EAED,EAAO,YAAY,CAAQ,EAE3B,IAAM,EAAQ,EAAA,kBAAkB,EAAO,CAAI,EAAG,CAC5C,cAAe,OACf,MAAO,mBACP,oBAAqB,EAAgB,EAAa,OAAS,UAAa,SACxE,cAAe,EAAe,SAAW,EAAa,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"}
@@ -5,6 +5,7 @@ import { type AnyScale } from './scale-utils';
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
+ export declare function positionAxis(parent: SVGGElement, position: AxisPosition, width: number, height: number): void;
8
9
  export declare function resolveTickCount(config: AxisConfig, length: number, defaultPosition: AxisPosition): number;
9
10
  /**
10
11
  * `defaultPosition` is applied when `config.position` is unset — pass `'bottom'` for an
@@ -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,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;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"}
package/dist/axes/axis.js CHANGED
@@ -6,12 +6,16 @@ var a = (e) => e instanceof Date ? e.toLocaleDateString(void 0, {
6
6
  month: "short",
7
7
  year: "numeric"
8
8
  }) : String(e);
9
- function o(e, t, n) {
9
+ function o(e, t, n, r) {
10
+ let i = t === "bottom" ? `translate(0,${r})` : t === "right" ? `translate(${n},0)` : void 0;
11
+ i ? e.setAttribute("transform", i) : e.removeAttribute("transform");
12
+ }
13
+ function s(e, t, n) {
10
14
  let r = e.position ?? n, i = r === "bottom" || r === "top" ? Math.max(2, Math.floor(t / 80)) : Math.max(2, Math.floor(t / 50));
11
15
  return e.tickCount ?? i;
12
16
  }
13
- function s(s, c, l, u, d = "bottom") {
14
- t(s);
17
+ function c(o, c, l, u, d = "bottom") {
18
+ t(o);
15
19
  let f = l.position ?? d, p = f === "bottom" || f === "top", m = f === "top" || f === "left", h = m ? -1 : 1, g = e("line", {
16
20
  "aria-hidden": "true",
17
21
  class: "prism-axis-line",
@@ -20,8 +24,8 @@ function s(s, c, l, u, d = "bottom") {
20
24
  y1: 0,
21
25
  y2: p ? 0 : u
22
26
  });
23
- s.appendChild(g);
24
- let _ = c.ticks(o(l, u, d)), v = l.tickFormat ?? a;
27
+ o.appendChild(g);
28
+ let _ = c.ticks(s(l, u, d)), v = l.tickFormat ?? a;
25
29
  for (let t of _) {
26
30
  let n = i(c, t), a = e("line", {
27
31
  "aria-hidden": "true",
@@ -31,8 +35,8 @@ function s(s, c, l, u, d = "bottom") {
31
35
  y1: p ? 0 : n,
32
36
  y2: p ? 6 * h : n
33
37
  });
34
- s.appendChild(a);
35
- let o = r(v(t), {
38
+ o.appendChild(a);
39
+ let s = r(v(t), {
36
40
  "aria-hidden": "true",
37
41
  class: "prism-axis-label",
38
42
  "dominant-baseline": p ? m ? "auto" : "hanging" : "middle",
@@ -40,7 +44,7 @@ function s(s, c, l, u, d = "bottom") {
40
44
  x: p ? n : 6 * h * 1.5,
41
45
  y: p ? 6 * h * 1.5 : n
42
46
  });
43
- s.appendChild(o);
47
+ o.appendChild(s);
44
48
  }
45
49
  if (l.label) {
46
50
  let e = r(l.label, {
@@ -50,11 +54,11 @@ function s(s, c, l, u, d = "bottom") {
50
54
  });
51
55
  p ? n(e, {
52
56
  x: u / 2,
53
- y: 6 * h * 3.5
54
- }) : n(e, { transform: `translate(${6 * h * 4}, ${u / 2}) rotate(-90)` }), s.appendChild(e);
57
+ y: 6 * h * 6
58
+ }) : n(e, { transform: `translate(${6 * h * 7}, ${u / 2}) rotate(-90)` }), o.appendChild(e);
55
59
  }
56
60
  }
57
61
  //#endregion
58
- export { s as renderAxis, o as resolveTickCount };
62
+ export { o as positionAxis, c as renderAxis, s as resolveTickCount };
59
63
 
60
64
  //# 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 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 * 3.5 });\n } else {\n setAttributes(labelEl, {\n transform: `translate(${tickSize * tickDirection * 4}, ${length / 2}) rotate(-90)`,\n });\n }\n\n parent.appendChild(labelEl);\n }\n}\n"],"mappings":";;;;AAKA,IAAM,KAAqB,MACzB,aAAa,OAAO,EAAE,mBAAmB,KAAA,GAAW;CAAE,OAAO;CAAS,MAAM;AAAU,CAAC,IAAI,OAAO,CAAC;AAOrG,SAAgB,EAAi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AAkB,EAAO,OAAO;GAC9C,OAAO;GACP,qBAAqB;GACrB,eAAe;EACjB,CAAC;EAUD,AARI,IACF,EAAc,GAAS;GAAE,GAAG,IAAS;GAAG,GAAG,IAAW,IAAgB;EAAI,CAAC,IAE3E,EAAc,GAAS,EACrB,WAAW,aAAa,IAAW,IAAgB,EAAE,IAAI,IAAS,EAAE,eACtE,CAAC,GAGH,EAAO,YAAY,CAAO;CAC5B;AACF"}
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":";;;;AAKA,IAAM,KAAqB,MACzB,aAAa,OAAO,EAAE,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B,IAAM,IAAQ,EAAkB,EAAO,CAAI,GAAG;GAC5C,eAAe;GACf,OAAO;GACP,qBAAqB,IAAgB,IAAa,SAAS,YAAa;GACxE,eAAe,IAAe,WAAW,IAAa,QAAQ;GAC9D,GAAG,IAAe,IAAM,IAAW,IAAgB;GACnD,GAAG,IAAe,IAAW,IAAgB,MAAM;EACrD,CAAC;EAED,EAAO,YAAY,CAAK;CAC1B;CAEA,IAAI,EAAO,OAAO;EAChB,IAAM,IAAU,EAAkB,EAAO,OAAO;GAC9C,OAAO;GACP,qBAAqB;GACrB,eAAe;EACjB,CAAC;EAUD,AARI,IACF,EAAc,GAAS;GAAE,GAAG,IAAS;GAAG,GAAG,IAAW,IAAgB;EAAE,CAAC,IAEzE,EAAc,GAAS,EACrB,WAAW,aAAa,IAAW,IAAgB,EAAE,IAAI,IAAS,EAAE,eACtE,CAAC,GAGH,EAAO,YAAY,CAAO;CAC5B;AACF"}
@@ -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("../../core/cartesian-scales.cjs"),i=require("../../core/layout.cjs"),a=require("../../core/chart-scaffold.cjs"),o=require("../../core/resolve.cjs"),s=require("../../interaction/crosshair.cjs"),c=require("../../interaction/series-interaction.cjs"),l=require("../../theme/index.cjs"),u=require("./area-renderer.cjs");function d(d,f){let p=null,m=o.resolveMaybeSignal(f.series),h;try{return h=a.createChartScaffold(d,f,d=>{let{groups:h,legend:g,tooltip:_}=d,v=d.dimensions.value,y=i.chartArea(v.width,v.height,v.margin),b=m.value,x=b.map(e=>o.resolveMaybeSignal(e.data)).map(e=>e.value),S=x.flat().map(e=>e.key),C=x.flat().map(e=>e.value);if(S.length===0){a.clearCartesianDom(h,g,_,p);return}f.crosshair&&!p&&(p=s.createCrosshair(d.chartArea,f.crosshair));let w=r.buildXScale(S,y.width),T=r.buildYScale(C,y.height),E=T.map(0);for(f.yAxis?.grid&&n.renderGrid(h.grid,T,f.yAxis.grid,y.width,`horizontal`,t.resolveTickCount(f.yAxis,y.height,`left`)),f.xAxis?.grid&&n.renderGrid(h.grid,w,f.xAxis.grid,y.height,`vertical`,t.resolveTickCount(f.xAxis,y.width,`bottom`)),f.xAxis&&(h.xAxis.setAttribute(`transform`,`translate(0,${y.height})`),t.renderAxis(h.xAxis,w,f.xAxis,y.width,`bottom`)),f.yAxis&&t.renderAxis(h.yAxis,T,f.yAxis,y.height,`left`);h.series.children.length>b.length;)h.series.removeChild(h.series.lastChild);let D=[];for(let t=0;t<b.length;t++){let n=b[t],r=h.series.children[t];r||(r=e.createSvgElement(`g`,{class:`prism-area-series`}),h.series.appendChild(r));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,fillOpacity:n.fillOpacity??.3,showLine:n.showLine!==!1,transition:f.transition})}return g?.update(b.map((e,t)=>({color:l.seriesColor(t,e.color),name:e.name}))),_?.hide(),c.createSeriesInteraction({crosshair:p,dims:()=>d.dimensions.value,getData:()=>x,getPoints:()=>D,getSeriesList:()=>m.value,onClick:f.onClick,onHover:f.onHover,svg:d.svg,tooltip:_})}),h}catch(e){throw h?.dispose(),e}}exports.createAreaChart=d;
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 u(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=u;
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 { warn } from '../../_dev';\nimport { 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 { resolveMaybeSignal } from '../../core/resolve';\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, ChartHandle } from '../../types';\nimport { computeAreaPoints, renderArea } from './area-renderer';\n\nexport function createAreaChart(container: HTMLElement, config: AreaChartConfig): ChartHandle {\n let crosshair: ReturnType<typeof createCrosshair> | null = null;\n const seriesSignal = resolveMaybeSignal(config.series);\n\n let scaffold: ChartHandle | undefined;\n\n try {\n scaffold = createChartScaffold(container, config, (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions.value;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const seriesList = seriesSignal.value;\n const dataSignals = seriesList.map((s) => resolveMaybeSignal(s.data));\n const allData = dataSignals.map((signal) => signal.value);\n const allX = allData.flat().map((d) => d.key as Date | number);\n const allY = allData.flat().map((d) => d.value);\n\n if (allX.length === 0) {\n warn('createAreaChart: no data');\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 as (Date | number)[], 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 groups.xAxis.setAttribute('transform', `translate(0,${area.height})`);\n renderAxis(groups.xAxis, xScale, config.xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) renderAxis(groups.yAxis, yScale, config.yAxis, area.height, 'left');\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.value,\n getData: () => allData,\n getPoints: () => allPoints,\n getSeriesList: () => seriesSignal.value,\n onClick: config.onClick,\n onHover: config.onHover,\n svg: ctx.svg,\n tooltip,\n });\n });\n\n return scaffold;\n } catch (error) {\n scaffold?.dispose();\n throw error;\n }\n}\n"],"mappings":"2cAeA,SAAgB,EAAgB,EAAwB,EAAsC,CAC5F,IAAI,EAAuD,KACrD,EAAe,EAAA,mBAAmB,EAAO,MAAM,EAEjD,EAEJ,GAAI,CAoGF,MAnGA,GAAW,EAAA,oBAAoB,EAAW,EAAS,GAAQ,CACzD,GAAM,CAAE,SAAQ,SAAQ,WAAY,EAC9B,EAAO,EAAI,WAAW,MACtB,EAAO,EAAA,UAAU,EAAK,MAAO,EAAK,OAAQ,EAAK,MAAM,EACrD,EAAa,EAAa,MAE1B,EADc,EAAW,IAAK,GAAM,EAAA,mBAAmB,EAAE,IAAI,CACnD,CAAA,CAAY,IAAK,GAAW,EAAO,KAAK,EAClD,EAAO,EAAQ,KAAK,CAAC,CAAC,IAAK,GAAM,EAAE,GAAoB,EACvD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AK,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,WAAW,MAC3B,YAAe,EACf,cAAiB,EACjB,kBAAqB,EAAa,MAClC,QAAS,EAAO,QAChB,QAAS,EAAO,QAChB,IAAK,EAAI,IACT,SACF,CAAC,CACH,CAAC,EAEM,CACT,OAAS,EAAO,CAEd,MADA,GAAU,QAAQ,EACZ,CACR,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 { 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,EAAgB,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,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,EAEpD,MACF,CAEI,EAAO,WAAa,CAAC,IACvB,EAAY,EAAA,gBAAgB,EAAI,UAAW,EAAO,SAAS,GAG7D,IAAM,EAAS,EAAA,YAAY,EAAM,EAAK,KAAK,EACrC,EAAS,EAAA,YAAY,EAAM,EAAK,MAAM,EACtC,EAAY,EAAO,IAAI,CAAC,EAkC9B,IAhCI,EAAO,OAAO,MAChB,EAAA,WACE,EAAO,KACP,EACA,EAAO,MAAM,KACb,EAAK,MACL,aACA,EAAA,iBAAiB,EAAO,MAAO,EAAK,OAAQ,MAAM,CACpD,EAGE,EAAO,OAAO,MAChB,EAAA,WACE,EAAO,KACP,EACA,EAAO,MAAM,KACb,EAAK,OACL,WACA,EAAA,iBAAiB,EAAO,MAAO,EAAK,MAAO,QAAQ,CACrD,EAGE,EAAO,QACT,EAAA,aAAa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F,CACF"}
@@ -1,3 +1,3 @@
1
- import type { AreaChartConfig, ChartHandle } from '../../types';
2
- export declare function createAreaChart(container: HTMLElement, config: AreaChartConfig): ChartHandle;
1
+ import type { AreaChartConfig, AreaSeriesConfig, ChartHandle } from '../../types';
2
+ export declare function createAreaChart(container: HTMLElement, config: AreaChartConfig): ChartHandle<AreaSeriesConfig[]>;
3
3
  //# sourceMappingURL=area-chart.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"area-chart.d.ts","sourceRoot":"","sources":["../../../src/charts/area/area-chart.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAGhE,wBAAgB,eAAe,CAAC,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,eAAe,GAAG,WAAW,CA+G5F"}
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,60 +1,56 @@
1
- import "../../_dev.js";
2
1
  import { createSvgElement as e } from "../../svg/element.js";
3
- import { renderAxis as t, resolveTickCount as n } from "../../axes/axis.js";
4
- import { renderGrid as r } from "../../axes/grid.js";
5
- import { buildXScale as i, buildYScale as a } from "../../core/cartesian-scales.js";
6
- import { chartArea as o } from "../../core/layout.js";
7
- import { clearCartesianDom as s, createChartScaffold as c } from "../../core/chart-scaffold.js";
8
- import { resolveMaybeSignal as l } from "../../core/resolve.js";
2
+ import { positionAxis as t, renderAxis as n, resolveTickCount as r } from "../../axes/axis.js";
3
+ import { renderGrid as i } from "../../axes/grid.js";
4
+ import { buildXScale as a, buildYScale as o } from "../../core/cartesian-scales.js";
5
+ import { chartArea as s } from "../../core/layout.js";
6
+ import { clearCartesianDom as c, createChartScaffold as l } from "../../core/chart-scaffold.js";
9
7
  import { createCrosshair as u } from "../../interaction/crosshair.js";
10
8
  import { createSeriesInteraction as d } from "../../interaction/series-interaction.js";
11
9
  import { seriesColor as f } from "../../theme/index.js";
12
10
  import { computeAreaPoints as p, renderArea as m } from "./area-renderer.js";
13
11
  //#region src/charts/area/area-chart.ts
14
12
  function h(h, g) {
15
- let _ = null, v = l(g.series), y;
16
- try {
17
- return y = c(h, g, (c) => {
18
- let { groups: h, legend: y, tooltip: b } = c, x = c.dimensions.value, S = o(x.width, x.height, x.margin), C = v.value, w = C.map((e) => l(e.data)).map((e) => e.value), T = w.flat().map((e) => e.key), E = w.flat().map((e) => e.value);
19
- if (T.length === 0) {
20
- s(h, y, b, _);
21
- return;
22
- }
23
- g.crosshair && !_ && (_ = u(c.chartArea, g.crosshair));
24
- let D = i(T, S.width), O = a(E, S.height), k = O.map(0);
25
- for (g.yAxis?.grid && r(h.grid, O, g.yAxis.grid, S.width, "horizontal", n(g.yAxis, S.height, "left")), g.xAxis?.grid && r(h.grid, D, g.xAxis.grid, S.height, "vertical", n(g.xAxis, S.width, "bottom")), g.xAxis && (h.xAxis.setAttribute("transform", `translate(0,${S.height})`), t(h.xAxis, D, g.xAxis, S.width, "bottom")), g.yAxis && t(h.yAxis, O, g.yAxis, S.height, "left"); h.series.children.length > C.length;) h.series.removeChild(h.series.lastChild);
26
- let A = [];
27
- for (let t = 0; t < C.length; t++) {
28
- let n = C[t], r = h.series.children[t];
29
- r || (r = e("g", { class: "prism-area-series" }), h.series.appendChild(r));
30
- let i = p(w[t], D, O);
31
- A.push(i), m(r, i, k, {
32
- color: f(t, n.color),
33
- curve: n.curve ?? "linear",
34
- disposalSignal: c.disposalSignal,
35
- fillOpacity: n.fillOpacity ?? .3,
36
- showLine: n.showLine !== !1,
37
- transition: g.transition
38
- });
39
- }
40
- return y?.update(C.map((e, t) => ({
41
- color: f(t, e.color),
42
- name: e.name
43
- }))), b?.hide(), d({
44
- crosshair: _,
45
- dims: () => c.dimensions.value,
46
- getData: () => w,
47
- getPoints: () => A,
48
- getSeriesList: () => v.value,
49
- onClick: g.onClick,
50
- onHover: g.onHover,
51
- svg: c.svg,
52
- tooltip: b
13
+ let _ = null, v = g.series;
14
+ return l(h, g, (l) => {
15
+ 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);
16
+ if (w.length === 0) {
17
+ c(h, y, b, _);
18
+ return;
19
+ }
20
+ g.crosshair && !_ && (_ = u(l.chartArea, g.crosshair));
21
+ let E = a(w, S.width), D = o(T, S.height), O = D.map(0);
22
+ 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);
23
+ let k = [];
24
+ for (let t = 0; t < v.length; t++) {
25
+ let n = v[t], r = h.series.children[t];
26
+ r || (r = e("g", { class: "prism-area-series" }), h.series.appendChild(r));
27
+ let i = p(C[t], E, D);
28
+ k.push(i), m(r, i, O, {
29
+ color: f(t, n.color),
30
+ curve: n.curve ?? "linear",
31
+ disposalSignal: l.disposalSignal,
32
+ fillOpacity: n.fillOpacity ?? .3,
33
+ showLine: n.showLine !== !1,
34
+ transition: g.transition
53
35
  });
54
- }), y;
55
- } catch (e) {
56
- throw y?.dispose(), e;
57
- }
36
+ }
37
+ return y?.update(v.map((e, t) => ({
38
+ color: f(t, e.color),
39
+ name: e.name
40
+ }))), b?.hide(), d({
41
+ crosshair: _,
42
+ dims: () => l.dimensions,
43
+ getData: () => C,
44
+ getPoints: () => k,
45
+ getSeriesList: () => v,
46
+ onClick: g.onClick,
47
+ onHover: g.onHover,
48
+ svg: l.svg,
49
+ tooltip: b
50
+ });
51
+ }, (e) => {
52
+ v = e;
53
+ });
58
54
  }
59
55
  //#endregion
60
56
  export { h as createAreaChart };
@@ -1 +1 @@
1
- {"version":3,"file":"area-chart.js","names":[],"sources":["../../../src/charts/area/area-chart.ts"],"sourcesContent":["import { warn } from '../../_dev';\nimport { 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 { resolveMaybeSignal } from '../../core/resolve';\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, ChartHandle } from '../../types';\nimport { computeAreaPoints, renderArea } from './area-renderer';\n\nexport function createAreaChart(container: HTMLElement, config: AreaChartConfig): ChartHandle {\n let crosshair: ReturnType<typeof createCrosshair> | null = null;\n const seriesSignal = resolveMaybeSignal(config.series);\n\n let scaffold: ChartHandle | undefined;\n\n try {\n scaffold = createChartScaffold(container, config, (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions.value;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const seriesList = seriesSignal.value;\n const dataSignals = seriesList.map((s) => resolveMaybeSignal(s.data));\n const allData = dataSignals.map((signal) => signal.value);\n const allX = allData.flat().map((d) => d.key as Date | number);\n const allY = allData.flat().map((d) => d.value);\n\n if (allX.length === 0) {\n warn('createAreaChart: no data');\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 as (Date | number)[], 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 groups.xAxis.setAttribute('transform', `translate(0,${area.height})`);\n renderAxis(groups.xAxis, xScale, config.xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) renderAxis(groups.yAxis, yScale, config.yAxis, area.height, 'left');\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.value,\n getData: () => allData,\n getPoints: () => allPoints,\n getSeriesList: () => seriesSignal.value,\n onClick: config.onClick,\n onHover: config.onHover,\n svg: ctx.svg,\n tooltip,\n });\n });\n\n return scaffold;\n } catch (error) {\n scaffold?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,OAAO,GAAQ,EAAO,OAAO,EAAK,QAAQ,MAAM,GAE7E,EAAO,OAAO,SAAS,SAAS,EAAW,SAChD,EAAO,OAAO,YAAY,EAAO,OAAO,SAAU;GAGpD,IAAM,IAAuB,CAAC;GAE9B,KAAK,IAAI,IAAI,GAAG,IAAI,EAAW,QAAQ,KAAK;IAC1C,IAAM,IAAS,EAAW,IACtB,IAAQ,EAAO,OAAO,SAAS;IAEnC,AAAK,MACH,IAAQ,EAAiB,KAAK,EAAE,OAAO,oBAAoB,CAAC,GAC5D,EAAO,OAAO,YAAY,CAAK;IAGjC,IAAM,IAAS,EAAkB,EAAQ,IAAI,GAAQ,CAAM;IAI3D,AAFA,EAAU,KAAK,CAAM,GAErB,EAAW,GAAO,GAAQ,GAAW;KACnC,OAAO,EAAY,GAAG,EAAO,KAAK;KAClC,OAAO,EAAO,SAAS;KACvB,gBAAgB,EAAI;KACpB,aAAa,EAAO,eAAe;KACnC,UAAU,EAAO,aAAa;KAC9B,YAAY,EAAO;IACrB,CAAC;GACH;GAKA,OAHA,GAAQ,OAAO,EAAW,KAAK,GAAG,OAAO;IAAE,OAAO,EAAY,GAAG,EAAE,KAAK;IAAG,MAAM,EAAE;GAAK,EAAE,CAAC,GAC3F,GAAS,KAAK,GAEP,EAAwB;IAC7B;IACA,YAAY,EAAI,WAAW;IAC3B,eAAe;IACf,iBAAiB;IACjB,qBAAqB,EAAa;IAClC,SAAS,EAAO;IAChB,SAAS,EAAO;IAChB,KAAK,EAAI;IACT;GACF,CAAC;EACH,CAAC,GAEM;CACT,SAAS,GAAO;EAEd,MADA,GAAU,QAAQ,GACZ;CACR;AACF"}
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":";;;;;;;;;;;AAaA,SAAgB,EAAgB,GAAwB,GAA0D;CAChH,IAAI,IAAuD,MACvD,IAAa,EAAO;CAExB,OAAO,EACL,GACA,IACC,MAAQ;EACP,IAAM,EAAE,WAAQ,WAAQ,eAAY,GAC9B,IAAO,EAAI,YACX,IAAO,EAAU,EAAK,OAAO,EAAK,QAAQ,EAAK,MAAM,GACrD,IAAU,EAAW,KAAK,MAAW,EAAO,IAAI,GAChD,IAAO,EAAQ,KAAK,CAAC,CAAC,KAAK,MAAU,EAAM,GAAG,GAC9C,IAAO,EAAQ,KAAK,CAAC,CAAC,KAAK,MAAM,EAAE,KAAK;EAE9C,IAAI,EAAK,WAAW,GAAG;GACrB,EAAkB,GAAQ,GAAQ,GAAS,CAAS;GAEpD;EACF;EAEA,AAAI,EAAO,aAAa,CAAC,MACvB,IAAY,EAAgB,EAAI,WAAW,EAAO,SAAS;EAG7D,IAAM,IAAS,EAAY,GAA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A,GAAQ,OAAO,EAAW,KAAK,GAAG,OAAO;GAAE,OAAO,EAAY,GAAG,EAAE,KAAK;GAAG,MAAM,EAAE;EAAK,EAAE,CAAC,GAC3F,GAAS,KAAK,GAEP,EAAwB;GAC7B;GACA,YAAY,EAAI;GAChB,eAAe;GACf,iBAAiB;GACjB,qBAAqB;GACrB,SAAS,EAAO;GAChB,SAAS,EAAO;GAChB,KAAK,EAAI;GACT;EACF,CAAC;CACH,IACC,MAAS;EACR,IAAa;CACf,CACF;AACF"}
@@ -1,2 +1,2 @@
1
- const e=require("../../animation/easing.cjs"),t=require("../../animation/motion.cjs"),n=require("../../animation/tween.cjs");require("../../_dev.cjs");const r=require("../../svg/element.cjs"),i=require("../../svg/path.cjs");var a=new WeakMap,o=new WeakMap;function s(e,t){return t===`monotone`?i.monotonePath(e):t===`step`?i.stepPath(e):i.linePath(e)}function c(c,l,u,d){let f=t.resolveMotion(d.transition,0),p=f.duration,m=e.resolveEasing(f.easing),h=c.querySelector(`.prism-area-fill`);h||(h=r.createSvgElement(`path`,{class:`prism-area-fill`}),c.appendChild(h)),r.setAttributes(h,{fill:d.color,"fill-opacity":d.fillOpacity,stroke:`none`});let g=null;if(d.showLine?(g=c.querySelector(`.prism-area-line`),g||(g=r.createSvgElement(`path`,{class:`prism-area-line`,fill:`none`}),c.appendChild(g)),r.setAttributes(g,{stroke:d.color,"stroke-width":2})):c.querySelector(`.prism-area-line`)?.remove(),p===0){let e=l.map(e=>({x:e.x,y:u}));r.setAttributes(h,{d:i.areaPath(l,e,d.curve)}),g&&r.setAttributes(g,{d:s(l,d.curve)});return}if(a.get(c)?.(),!h.hasAttribute(`d`)){let e=l.map(e=>({x:e.x,y:u}));r.setAttributes(h,{d:i.areaPath(l,e,d.curve)}),g&&r.setAttributes(g,{d:s(l,d.curve)}),o.set(c,l);return}let _=o.get(c)??l,v=l.map((e,t)=>_[t]??_[_.length-1]??l[t]),y=null;function b(e){if(d.disposalSignal?.aborted){a.delete(c);return}y===null&&(y=e);let t=Math.min(1,(e-y)/p),f=m(t),_=l.map((e,t)=>({x:n.tweenNumber(v[t].x,e.x,f),y:n.tweenNumber(v[t].y,e.y,f)})),x=_.map(e=>({x:e.x,y:u}));if(r.setAttributes(h,{d:i.areaPath(_,x,d.curve)}),g&&r.setAttributes(g,{d:s(_,d.curve)}),t<1){let e=requestAnimationFrame(b);a.set(c,()=>cancelAnimationFrame(e))}else a.delete(c),o.set(c,l)}o.set(c,v);let x=requestAnimationFrame(b);a.set(c,()=>cancelAnimationFrame(x))}function l(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=l,exports.renderArea=c;
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 s(e,t){return t===`monotone`?i.monotonePath(e):t===`step`?i.stepPath(e):i.linePath(e)}function c(c,l,u,d){let f=n.resolveMotion(d.transition,0),p=f.duration,m=t.resolveEasing(f.easing),h=c.querySelector(`.prism-area-fill`);h||(h=e.createSvgElement(`path`,{class:`prism-area-fill`}),c.appendChild(h)),e.setAttributes(h,{fill:d.color,"fill-opacity":d.fillOpacity,stroke:`none`});let g=null;if(d.showLine?(g=c.querySelector(`.prism-area-line`),g||(g=e.createSvgElement(`path`,{class:`prism-area-line`,fill:`none`}),c.appendChild(g)),e.setAttributes(g,{stroke:d.color,"stroke-width":2})):c.querySelector(`.prism-area-line`)?.remove(),p===0){let t=l.map(e=>({x:e.x,y:u}));e.setAttributes(h,{d:i.areaPath(l,t,d.curve)}),g&&e.setAttributes(g,{d:s(l,d.curve)});return}if(a.get(c)?.(),!h.hasAttribute(`d`)){let t=l.map(e=>({x:e.x,y:u}));e.setAttributes(h,{d:i.areaPath(l,t,d.curve)}),g&&e.setAttributes(g,{d:s(l,d.curve)}),o.set(c,l);return}let _=o.get(c)??l,v=l.map((e,t)=>_[t]??_[_.length-1]??l[t]),y=null;function b(t){if(d.disposalSignal?.aborted){a.delete(c);return}y===null&&(y=t);let n=Math.min(1,(t-y)/p),f=m(n),_=l.map((e,t)=>({x:r.tweenNumber(v[t].x,e.x,f),y:r.tweenNumber(v[t].y,e.y,f)})),x=_.map(e=>({x:e.x,y:u}));if(e.setAttributes(h,{d:i.areaPath(_,x,d.curve)}),g&&e.setAttributes(g,{d:s(_,d.curve)}),n<1){let e=requestAnimationFrame(b);a.set(c,()=>cancelAnimationFrame(e))}else a.delete(c),o.set(c,l)}o.set(c,v);let x=requestAnimationFrame(b);a.set(c,()=>cancelAnimationFrame(x))}function l(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=l,exports.renderArea=c;
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 { Datum, 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(data: Datum[], xScale: Scale<Date | number>, yScale: Scale<number>): 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":"gOAmBA,IAAM,EAAuB,IAAI,QAC3B,EAAiB,IAAI,QAE3B,SAAS,EAAc,EAAc,EAA2C,CAC9E,OAAO,IAAU,WAAa,EAAA,aAAa,CAAG,EAAI,IAAU,OAAS,EAAA,SAAS,CAAG,EAAI,EAAA,SAAS,CAAG,CACnG,CAEA,SAAgB,EAAW,EAAqB,EAAiB,EAAmB,EAAkC,CACpH,IAAM,EAAS,EAAA,cAAc,EAAQ,WAAY,CAAC,EAC5C,EAAM,EAAO,SACb,EAAS,EAAA,cAAc,EAAO,MAAM,EAEtC,EAAO,EAAO,cAA8B,kBAAkB,EAE7D,IACH,EAAO,EAAA,iBAAiB,OAAQ,CAAE,MAAO,iBAAkB,CAAC,EAC5D,EAAO,YAAY,CAAI,GAGzB,EAAA,cAAc,EAAM,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AO,CAAM,EAElC,MACF,CAEI,IAAc,OAAM,EAAY,GAEpC,IAAM,EAAI,KAAK,IAAI,GAAI,EAAK,GAAa,CAAG,EACtC,EAAI,EAAO,CAAC,EACZ,EAAwB,EAAO,KAAK,EAAI,KAAO,CACnD,EAAG,EAAA,YAAY,EAAW,EAAE,CAAC,EAAG,EAAG,EAAG,CAAC,EACvC,EAAG,EAAA,YAAY,EAAW,EAAE,CAAC,EAAG,EAAG,EAAG,CAAC,CACzC,EAAE,EACI,EAAqB,EAAa,IAAK,IAAO,CAAE,EAAG,EAAE,EAAG,EAAG,CAAU,EAAE,EAM7E,GAJA,EAAA,cAAc,EAAO,CAAE,EAAG,EAAA,SAAS,EAAc,EAAoB,EAAQ,KAAK,CAAE,CAAC,EAEjF,GAAM,EAAA,cAAc,EAAM,CAAE,EAAG,EAAc,EAAc,EAAQ,KAAK,CAAE,CAAC,EAE3E,EAAI,EAAG,CACT,IAAM,EAAK,sBAAsB,CAAK,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,CAAK,EAEtC,EAAqB,IAAI,MAAc,qBAAqB,CAAE,CAAC,CACjE,CAEA,SAAgB,EAAkB,EAAe,EAA8B,EAAgC,CAS7G,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.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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Ae,IAAI,EAAQ,CAAU,EAErC,IAAM,EAAK,sBAAsB,CAAK,EAEtC,EAAqB,IAAI,MAAc,qBAAqB,CAAE,CAAC,CACjE,CAEA,SAAgB,EACd,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,5 +1,5 @@
1
1
  import type { Point } from '../../svg/path';
2
- import type { Datum, Scale, TransitionConfig } from '../../types';
2
+ import type { ContinuousDatum, Scale, TransitionConfig } from '../../types';
3
3
  export interface AreaRenderOptions {
4
4
  color: string;
5
5
  curve: 'linear' | 'monotone' | 'step';
@@ -10,5 +10,5 @@ export interface AreaRenderOptions {
10
10
  transition?: TransitionConfig;
11
11
  }
12
12
  export declare function renderArea(parent: SVGGElement, points: Point[], baselineY: number, options: AreaRenderOptions): void;
13
- export declare function computeAreaPoints(data: Datum[], xScale: Scale<Date | number>, yScale: Scale<number>): Point[];
13
+ export declare function computeAreaPoints(data: ContinuousDatum[], xScale: Scale<Date | number>, yScale: Scale<number>): Point[];
14
14
  //# sourceMappingURL=area-renderer.d.ts.map
@@ -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,KAAK,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAElE,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAC;IACtC,yHAAyH;IACzH,cAAc,CAAC,EAAE,WAAW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