@vielzeug/prism 2.0.0 → 2.1.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.
- package/README.md +3 -2
- package/dist/animation/motion.cjs +2 -0
- package/dist/animation/motion.cjs.map +1 -0
- package/dist/animation/motion.d.ts +3 -0
- package/dist/animation/motion.d.ts.map +1 -0
- package/dist/animation/motion.js +13 -0
- package/dist/animation/motion.js.map +1 -0
- package/dist/animation/transition.cjs +1 -1
- package/dist/animation/transition.cjs.map +1 -1
- package/dist/animation/transition.d.ts.map +1 -1
- package/dist/animation/transition.js +19 -18
- package/dist/animation/transition.js.map +1 -1
- package/dist/charts/area/area-renderer.cjs +1 -1
- package/dist/charts/area/area-renderer.cjs.map +1 -1
- package/dist/charts/area/area-renderer.d.ts.map +1 -1
- package/dist/charts/area/area-renderer.js +42 -41
- package/dist/charts/area/area-renderer.js.map +1 -1
- package/dist/charts/bar/bar-chart.cjs +1 -1
- package/dist/charts/bar/bar-chart.cjs.map +1 -1
- package/dist/charts/bar/bar-chart.d.ts.map +1 -1
- package/dist/charts/bar/bar-chart.js +104 -87
- package/dist/charts/bar/bar-chart.js.map +1 -1
- package/dist/charts/bar/bar-hit-test.cjs.map +1 -1
- package/dist/charts/bar/bar-hit-test.d.ts +1 -1
- package/dist/charts/bar/bar-hit-test.d.ts.map +1 -1
- package/dist/charts/bar/bar-hit-test.js.map +1 -1
- package/dist/charts/bar/bar-renderer.cjs +1 -1
- package/dist/charts/bar/bar-renderer.cjs.map +1 -1
- package/dist/charts/bar/bar-renderer.d.ts +1 -0
- package/dist/charts/bar/bar-renderer.d.ts.map +1 -1
- package/dist/charts/bar/bar-renderer.js +1 -1
- package/dist/charts/bar/bar-renderer.js.map +1 -1
- package/dist/charts/line/line-renderer.cjs +1 -1
- package/dist/charts/line/line-renderer.cjs.map +1 -1
- package/dist/charts/line/line-renderer.d.ts.map +1 -1
- package/dist/charts/line/line-renderer.js +58 -57
- package/dist/charts/line/line-renderer.js.map +1 -1
- package/dist/charts/pie/pie-chart.cjs +1 -1
- package/dist/charts/pie/pie-chart.cjs.map +1 -1
- package/dist/charts/pie/pie-chart.d.ts.map +1 -1
- package/dist/charts/pie/pie-chart.js +72 -70
- package/dist/charts/pie/pie-chart.js.map +1 -1
- package/dist/charts/sparkline/sparkline.cjs +1 -1
- package/dist/charts/sparkline/sparkline.cjs.map +1 -1
- package/dist/charts/sparkline/sparkline.d.ts.map +1 -1
- package/dist/charts/sparkline/sparkline.js +63 -62
- package/dist/charts/sparkline/sparkline.js.map +1 -1
- package/dist/core/cartesian-model.cjs +2 -0
- package/dist/core/cartesian-model.cjs.map +1 -0
- package/dist/core/cartesian-model.d.ts +14 -0
- package/dist/core/cartesian-model.d.ts.map +1 -0
- package/dist/core/cartesian-model.js +31 -0
- package/dist/core/cartesian-model.js.map +1 -0
- package/dist/core/chart-base.cjs +1 -1
- package/dist/core/chart-base.cjs.map +1 -1
- package/dist/core/chart-base.d.ts +2 -1
- package/dist/core/chart-base.d.ts.map +1 -1
- package/dist/core/chart-base.js +28 -25
- package/dist/core/chart-base.js.map +1 -1
- package/dist/core/chart-scaffold.cjs +1 -1
- package/dist/core/chart-scaffold.cjs.map +1 -1
- package/dist/core/chart-scaffold.d.ts +1 -0
- package/dist/core/chart-scaffold.d.ts.map +1 -1
- package/dist/core/chart-scaffold.js +2 -1
- package/dist/core/chart-scaffold.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/interaction/series-interaction.cjs +1 -1
- package/dist/interaction/series-interaction.cjs.map +1 -1
- package/dist/interaction/series-interaction.d.ts.map +1 -1
- package/dist/interaction/series-interaction.js +73 -34
- package/dist/interaction/series-interaction.js.map +1 -1
- package/dist/interaction/tooltip.cjs +1 -1
- package/dist/interaction/tooltip.cjs.map +1 -1
- package/dist/interaction/tooltip.d.ts.map +1 -1
- package/dist/interaction/tooltip.js +28 -15
- package/dist/interaction/tooltip.js.map +1 -1
- package/dist/prism.cjs +1 -1
- package/dist/prism.cjs.map +1 -1
- package/dist/prism.iife.js +1 -1
- package/dist/prism.iife.js.map +1 -1
- package/dist/prism.js +1 -1
- package/dist/prism.js.map +1 -1
- package/dist/theme/prism.css +1 -0
- package/dist/types.d.ts +13 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +10 -6
- package/dist/interaction/hit-test.cjs +0 -2
- package/dist/interaction/hit-test.cjs.map +0 -1
- package/dist/interaction/hit-test.js +0 -14
- package/dist/interaction/hit-test.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @vielzeug/prism
|
|
2
2
|
|
|
3
|
-
> Reactive SVG charting library — line, bar, area, pie, and sparkline charts
|
|
3
|
+
> Reactive SVG charting library — line, bar, area, pie, and sparkline charts with keyed data, accessible interactions, and signal-driven updates.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@vielzeug/prism) [](https://opensource.org/licenses/MIT)
|
|
6
6
|
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
</details>
|
|
19
19
|
|
|
20
|
-
`@vielzeug/prism` is part of Vielzeug. It depends on
|
|
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.
|
|
21
21
|
|
|
22
22
|
## Installation
|
|
23
23
|
|
|
@@ -56,6 +56,7 @@ const data = signal([
|
|
|
56
56
|
]);
|
|
57
57
|
|
|
58
58
|
const chart = createLineChart(document.getElementById('chart')!, {
|
|
59
|
+
a11y: { ariaLabel: 'Revenue by month' },
|
|
59
60
|
series: [{ name: 'Revenue', data, color: '#3b82f6' }],
|
|
60
61
|
xAxis: { position: 'bottom' },
|
|
61
62
|
yAxis: { position: 'left', grid: true },
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function e(e,t=300){let n=e?.preference??`system`,r=typeof matchMedia<`u`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches,i=n===`never`||n===`system`&&r?0:e?.duration??t;return{...e,duration:i,stagger:Math.max(0,e?.stagger??0)}}exports.resolveMotion=e;
|
|
2
|
+
//# sourceMappingURL=motion.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"motion.cjs","names":[],"sources":["../../src/animation/motion.ts"],"sourcesContent":["import type { TransitionConfig } from '../types';\n\nexport function resolveMotion(\n config?: TransitionConfig,\n defaultDuration = 300,\n): Required<Pick<TransitionConfig, 'duration' | 'stagger'>> & TransitionConfig {\n const preference = config?.preference ?? 'system';\n const reduced = typeof matchMedia !== 'undefined' && matchMedia('(prefers-reduced-motion: reduce)').matches;\n const duration =\n preference === 'never' || (preference === 'system' && reduced) ? 0 : (config?.duration ?? defaultDuration);\n\n return { ...config, duration, stagger: Math.max(0, config?.stagger ?? 0) };\n}\n"],"mappings":"AAEA,SAAgB,EACd,EACA,EAAkB,IAC2D,CAC7E,IAAM,EAAa,GAAQ,YAAc,SACnC,EAAU,OAAO,WAAe,KAAe,WAAW,kCAAkC,CAAC,CAAC,QAC9F,EACJ,IAAe,SAAY,IAAe,UAAY,EAAW,EAAK,GAAQ,UAAY,EAE5F,MAAO,CAAE,GAAG,EAAQ,WAAU,QAAS,KAAK,IAAI,EAAG,GAAQ,SAAW,CAAC,CAAE,CAC3E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"motion.d.ts","sourceRoot":"","sources":["../../src/animation/motion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD,wBAAgB,aAAa,CAC3B,MAAM,CAAC,EAAE,gBAAgB,EACzB,eAAe,SAAM,GACpB,QAAQ,CAAC,IAAI,CAAC,gBAAgB,EAAE,UAAU,GAAG,SAAS,CAAC,CAAC,GAAG,gBAAgB,CAO7E"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/animation/motion.ts
|
|
2
|
+
function e(e, t = 300) {
|
|
3
|
+
let n = e?.preference ?? "system", r = typeof matchMedia < "u" && matchMedia("(prefers-reduced-motion: reduce)").matches, i = n === "never" || n === "system" && r ? 0 : e?.duration ?? t;
|
|
4
|
+
return {
|
|
5
|
+
...e,
|
|
6
|
+
duration: i,
|
|
7
|
+
stagger: Math.max(0, e?.stagger ?? 0)
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { e as resolveMotion };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=motion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"motion.js","names":[],"sources":["../../src/animation/motion.ts"],"sourcesContent":["import type { TransitionConfig } from '../types';\n\nexport function resolveMotion(\n config?: TransitionConfig,\n defaultDuration = 300,\n): Required<Pick<TransitionConfig, 'duration' | 'stagger'>> & TransitionConfig {\n const preference = config?.preference ?? 'system';\n const reduced = typeof matchMedia !== 'undefined' && matchMedia('(prefers-reduced-motion: reduce)').matches;\n const duration =\n preference === 'never' || (preference === 'system' && reduced) ? 0 : (config?.duration ?? defaultDuration);\n\n return { ...config, duration, stagger: Math.max(0, config?.stagger ?? 0) };\n}\n"],"mappings":";AAEA,SAAgB,EACd,GACA,IAAkB,KAC2D;CAC7E,IAAM,IAAa,GAAQ,cAAc,UACnC,IAAU,OAAO,aAAe,OAAe,WAAW,kCAAkC,CAAC,CAAC,SAC9F,IACJ,MAAe,WAAY,MAAe,YAAY,IAAW,IAAK,GAAQ,YAAY;CAE5F,OAAO;EAAE,GAAG;EAAQ;EAAU,SAAS,KAAK,IAAI,GAAG,GAAQ,WAAW,CAAC;CAAE;AAC3E"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./easing.cjs"),t=require("./tween.cjs");function
|
|
1
|
+
const e=require("./easing.cjs"),t=require("./motion.cjs"),n=require("./tween.cjs");function r(r,i,a,o){let s=t.resolveMotion(i),c=s.duration,l=e.resolveEasing(s.easing),u=s.stagger;if(c===0||r.length===0){for(let e of r)for(let[t,{to:n}]of Object.entries(e.attrs))e.el.setAttribute(t,String(n));return a?.(),()=>{}}let d=null,f=!1,p=Math.max(c,c+u*(r.length-1));function m(e){if(f||o?.aborted)return;d===null&&(d=e);let t=e-d;for(let e=0;e<r.length;e++){let i=r[e],a=u*e,o=Math.max(0,t-a),s=Math.min(1,o/c),d=l(s);for(let[e,{from:t,to:r}]of Object.entries(i.attrs))i.el.setAttribute(e,String(n.tweenNumber(t,r,d)))}t<p?requestAnimationFrame(m):a?.()}return requestAnimationFrame(m),()=>{f=!0}}exports.animate=r;
|
|
2
2
|
//# sourceMappingURL=transition.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transition.cjs","names":[],"sources":["../../src/animation/transition.ts"],"sourcesContent":["import type { TransitionConfig } from '../types';\n\nimport { resolveEasing } from './easing';\nimport { tweenNumber } from './tween';\n\nexport interface AnimationTarget {\n attrs: Record<string, { from: number; to: number }>;\n el: SVGElement;\n}\n\n/**\n * Runs a batch of attribute tweens, sharing one `requestAnimationFrame` loop.\n * Returns a `cancel()` function the caller can invoke to stop the loop early\n * (e.g. a fresh render superseding this batch, or `signal` aborting).\n */\nexport function animate(\n targets: AnimationTarget[],\n config?: TransitionConfig,\n onComplete?: () => void,\n signal?: AbortSignal,\n): () => void {\n const
|
|
1
|
+
{"version":3,"file":"transition.cjs","names":[],"sources":["../../src/animation/transition.ts"],"sourcesContent":["import type { TransitionConfig } from '../types';\n\nimport { resolveEasing } from './easing';\nimport { resolveMotion } from './motion';\nimport { tweenNumber } from './tween';\n\nexport interface AnimationTarget {\n attrs: Record<string, { from: number; to: number }>;\n el: SVGElement;\n}\n\n/**\n * Runs a batch of attribute tweens, sharing one `requestAnimationFrame` loop.\n * Returns a `cancel()` function the caller can invoke to stop the loop early\n * (e.g. a fresh render superseding this batch, or `signal` aborting).\n */\nexport function animate(\n targets: AnimationTarget[],\n config?: TransitionConfig,\n onComplete?: () => void,\n signal?: AbortSignal,\n): () => void {\n const motion = resolveMotion(config);\n const duration = motion.duration;\n const easing = resolveEasing(motion.easing);\n const stagger = motion.stagger;\n\n if (duration === 0 || targets.length === 0) {\n for (const target of targets) {\n for (const [attr, { to }] of Object.entries(target.attrs)) {\n target.el.setAttribute(attr, String(to));\n }\n }\n\n onComplete?.();\n\n return () => {};\n }\n\n let startTime: number | null = null;\n let cancelled = false;\n const totalDuration = Math.max(duration, duration + stagger * (targets.length - 1));\n\n function frame(timestamp: number) {\n if (cancelled || signal?.aborted) return;\n\n if (startTime === null) startTime = timestamp;\n\n const elapsed = timestamp - startTime;\n\n for (let i = 0; i < targets.length; i++) {\n const target = targets[i];\n const delay = stagger * i;\n const localElapsed = Math.max(0, elapsed - delay);\n const t = Math.min(1, localElapsed / duration);\n const eased = easing(t);\n\n for (const [attr, { from, to }] of Object.entries(target.attrs)) {\n target.el.setAttribute(attr, String(tweenNumber(from, to, eased)));\n }\n }\n\n if (elapsed < totalDuration) {\n requestAnimationFrame(frame);\n } else {\n onComplete?.();\n }\n }\n\n requestAnimationFrame(frame);\n\n return () => {\n cancelled = true;\n };\n}\n"],"mappings":"mFAgBA,SAAgB,EACd,EACA,EACA,EACA,EACY,CACZ,IAAM,EAAS,EAAA,cAAc,CAAM,EAC7B,EAAW,EAAO,SAClB,EAAS,EAAA,cAAc,EAAO,MAAM,EACpC,EAAU,EAAO,QAEvB,GAAI,IAAa,GAAK,EAAQ,SAAW,EAAG,CAC1C,IAAK,IAAM,KAAU,EACnB,IAAK,GAAM,CAAC,EAAM,CAAE,SAAS,OAAO,QAAQ,EAAO,KAAK,EACtD,EAAO,GAAG,aAAa,EAAM,OAAO,CAAE,CAAC,EAM3C,OAFA,IAAa,MAEA,CAAC,CAChB,CAEA,IAAI,EAA2B,KAC3B,EAAY,GACV,EAAgB,KAAK,IAAI,EAAU,EAAW,GAAW,EAAQ,OAAS,EAAE,EAElF,SAAS,EAAM,EAAmB,CAChC,GAAI,GAAa,GAAQ,QAAS,OAE9B,IAAc,OAAM,EAAY,GAEpC,IAAM,EAAU,EAAY,EAE5B,IAAK,IAAI,EAAI,EAAG,EAAI,EAAQ,OAAQ,IAAK,CACvC,IAAM,EAAS,EAAQ,GACjB,EAAQ,EAAU,EAClB,EAAe,KAAK,IAAI,EAAG,EAAU,CAAK,EAC1C,EAAI,KAAK,IAAI,EAAG,EAAe,CAAQ,EACvC,EAAQ,EAAO,CAAC,EAEtB,IAAK,GAAM,CAAC,EAAM,CAAE,OAAM,SAAS,OAAO,QAAQ,EAAO,KAAK,EAC5D,EAAO,GAAG,aAAa,EAAM,OAAO,EAAA,YAAY,EAAM,EAAI,CAAK,CAAC,CAAC,CAErE,CAEI,EAAU,EACZ,sBAAsB,CAAK,EAE3B,IAAa,CAEjB,CAIA,OAFA,sBAAsB,CAAK,MAEd,CACX,EAAY,EACd,CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transition.d.ts","sourceRoot":"","sources":["../../src/animation/transition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"transition.d.ts","sourceRoot":"","sources":["../../src/animation/transition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAMjD,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACpD,EAAE,EAAE,UAAU,CAAC;CAChB;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CACrB,OAAO,EAAE,eAAe,EAAE,EAC1B,MAAM,CAAC,EAAE,gBAAgB,EACzB,UAAU,CAAC,EAAE,MAAM,IAAI,EACvB,MAAM,CAAC,EAAE,WAAW,GACnB,MAAM,IAAI,CAqDZ"}
|
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
import { resolveEasing as e } from "./easing.js";
|
|
2
|
-
import {
|
|
2
|
+
import { resolveMotion as t } from "./motion.js";
|
|
3
|
+
import { tweenNumber as n } from "./tween.js";
|
|
3
4
|
//#region src/animation/transition.ts
|
|
4
|
-
function
|
|
5
|
-
let
|
|
6
|
-
if (
|
|
7
|
-
for (let e of
|
|
8
|
-
return
|
|
5
|
+
function r(r, i, a, o) {
|
|
6
|
+
let s = t(i), c = s.duration, l = e(s.easing), u = s.stagger;
|
|
7
|
+
if (c === 0 || r.length === 0) {
|
|
8
|
+
for (let e of r) for (let [t, { to: n }] of Object.entries(e.attrs)) e.el.setAttribute(t, String(n));
|
|
9
|
+
return a?.(), () => {};
|
|
9
10
|
}
|
|
10
|
-
let
|
|
11
|
-
function
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
let
|
|
15
|
-
for (let e = 0; e <
|
|
16
|
-
let i =
|
|
17
|
-
for (let [e, { from:
|
|
11
|
+
let d = null, f = !1, p = Math.max(c, c + u * (r.length - 1));
|
|
12
|
+
function m(e) {
|
|
13
|
+
if (f || o?.aborted) return;
|
|
14
|
+
d === null && (d = e);
|
|
15
|
+
let t = e - d;
|
|
16
|
+
for (let e = 0; e < r.length; e++) {
|
|
17
|
+
let i = r[e], a = u * e, o = Math.max(0, t - a), s = Math.min(1, o / c), d = l(s);
|
|
18
|
+
for (let [e, { from: t, to: r }] of Object.entries(i.attrs)) i.el.setAttribute(e, String(n(t, r, d)));
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
+
t < p ? requestAnimationFrame(m) : a?.();
|
|
20
21
|
}
|
|
21
|
-
return requestAnimationFrame(
|
|
22
|
-
|
|
22
|
+
return requestAnimationFrame(m), () => {
|
|
23
|
+
f = !0;
|
|
23
24
|
};
|
|
24
25
|
}
|
|
25
26
|
//#endregion
|
|
26
|
-
export {
|
|
27
|
+
export { r as animate };
|
|
27
28
|
|
|
28
29
|
//# sourceMappingURL=transition.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transition.js","names":[],"sources":["../../src/animation/transition.ts"],"sourcesContent":["import type { TransitionConfig } from '../types';\n\nimport { resolveEasing } from './easing';\nimport { tweenNumber } from './tween';\n\nexport interface AnimationTarget {\n attrs: Record<string, { from: number; to: number }>;\n el: SVGElement;\n}\n\n/**\n * Runs a batch of attribute tweens, sharing one `requestAnimationFrame` loop.\n * Returns a `cancel()` function the caller can invoke to stop the loop early\n * (e.g. a fresh render superseding this batch, or `signal` aborting).\n */\nexport function animate(\n targets: AnimationTarget[],\n config?: TransitionConfig,\n onComplete?: () => void,\n signal?: AbortSignal,\n): () => void {\n const
|
|
1
|
+
{"version":3,"file":"transition.js","names":[],"sources":["../../src/animation/transition.ts"],"sourcesContent":["import type { TransitionConfig } from '../types';\n\nimport { resolveEasing } from './easing';\nimport { resolveMotion } from './motion';\nimport { tweenNumber } from './tween';\n\nexport interface AnimationTarget {\n attrs: Record<string, { from: number; to: number }>;\n el: SVGElement;\n}\n\n/**\n * Runs a batch of attribute tweens, sharing one `requestAnimationFrame` loop.\n * Returns a `cancel()` function the caller can invoke to stop the loop early\n * (e.g. a fresh render superseding this batch, or `signal` aborting).\n */\nexport function animate(\n targets: AnimationTarget[],\n config?: TransitionConfig,\n onComplete?: () => void,\n signal?: AbortSignal,\n): () => void {\n const motion = resolveMotion(config);\n const duration = motion.duration;\n const easing = resolveEasing(motion.easing);\n const stagger = motion.stagger;\n\n if (duration === 0 || targets.length === 0) {\n for (const target of targets) {\n for (const [attr, { to }] of Object.entries(target.attrs)) {\n target.el.setAttribute(attr, String(to));\n }\n }\n\n onComplete?.();\n\n return () => {};\n }\n\n let startTime: number | null = null;\n let cancelled = false;\n const totalDuration = Math.max(duration, duration + stagger * (targets.length - 1));\n\n function frame(timestamp: number) {\n if (cancelled || signal?.aborted) return;\n\n if (startTime === null) startTime = timestamp;\n\n const elapsed = timestamp - startTime;\n\n for (let i = 0; i < targets.length; i++) {\n const target = targets[i];\n const delay = stagger * i;\n const localElapsed = Math.max(0, elapsed - delay);\n const t = Math.min(1, localElapsed / duration);\n const eased = easing(t);\n\n for (const [attr, { from, to }] of Object.entries(target.attrs)) {\n target.el.setAttribute(attr, String(tweenNumber(from, to, eased)));\n }\n }\n\n if (elapsed < totalDuration) {\n requestAnimationFrame(frame);\n } else {\n onComplete?.();\n }\n }\n\n requestAnimationFrame(frame);\n\n return () => {\n cancelled = true;\n };\n}\n"],"mappings":";;;;AAgBA,SAAgB,EACd,GACA,GACA,GACA,GACY;CACZ,IAAM,IAAS,EAAc,CAAM,GAC7B,IAAW,EAAO,UAClB,IAAS,EAAc,EAAO,MAAM,GACpC,IAAU,EAAO;CAEvB,IAAI,MAAa,KAAK,EAAQ,WAAW,GAAG;EAC1C,KAAK,IAAM,KAAU,GACnB,KAAK,IAAM,CAAC,GAAM,EAAE,YAAS,OAAO,QAAQ,EAAO,KAAK,GACtD,EAAO,GAAG,aAAa,GAAM,OAAO,CAAE,CAAC;EAM3C,OAFA,IAAa,SAEA,CAAC;CAChB;CAEA,IAAI,IAA2B,MAC3B,IAAY,IACV,IAAgB,KAAK,IAAI,GAAU,IAAW,KAAW,EAAQ,SAAS,EAAE;CAElF,SAAS,EAAM,GAAmB;EAChC,IAAI,KAAa,GAAQ,SAAS;EAElC,AAAI,MAAc,SAAM,IAAY;EAEpC,IAAM,IAAU,IAAY;EAE5B,KAAK,IAAI,IAAI,GAAG,IAAI,EAAQ,QAAQ,KAAK;GACvC,IAAM,IAAS,EAAQ,IACjB,IAAQ,IAAU,GAClB,IAAe,KAAK,IAAI,GAAG,IAAU,CAAK,GAC1C,IAAI,KAAK,IAAI,GAAG,IAAe,CAAQ,GACvC,IAAQ,EAAO,CAAC;GAEtB,KAAK,IAAM,CAAC,GAAM,EAAE,SAAM,YAAS,OAAO,QAAQ,EAAO,KAAK,GAC5D,EAAO,GAAG,aAAa,GAAM,OAAO,EAAY,GAAM,GAAI,CAAK,CAAC,CAAC;EAErE;EAEA,AAAI,IAAU,IACZ,sBAAsB,CAAK,IAE3B,IAAa;CAEjB;CAIA,OAFA,sBAAsB,CAAK,SAEd;EACX,IAAY;CACd;AACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
require("../../_dev.cjs");const e=require("../../svg/element.cjs"),t=require("../../animation/easing.cjs"),n=require("../../animation/
|
|
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 type { Point } from '../../svg/path';\nimport type { Datum, Scale, TransitionConfig } from '../../types';\n\nimport { warn } from '../../_dev';\nimport { resolveEasing } from '../../animation/easing';\nimport { tweenNumber } from '../../animation/tween';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport { areaPath, linePath, monotonePath, stepPath } from '../../svg/path';\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
|
|
1
|
+
{"version":3,"file":"area-renderer.cjs","names":[],"sources":["../../../src/charts/area/area-renderer.ts"],"sourcesContent":["import type { Point } from '../../svg/path';\nimport type { Datum, Scale, TransitionConfig } from '../../types';\n\nimport { 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 { areaPath, linePath, monotonePath, stepPath } from '../../svg/path';\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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Ae,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"area-renderer.d.ts","sourceRoot":"","sources":["../../../src/charts/area/area-renderer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"area-renderer.d.ts","sourceRoot":"","sources":["../../../src/charts/area/area-renderer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AASlE,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAC;IACtC,yHAAyH;IACzH,cAAc,CAAC,EAAE,WAAW,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC/B;AASD,wBAAgB,UAAU,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAgGpH;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,IAAI,GAAG,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,EAAE,CAa7G"}
|
|
@@ -1,73 +1,74 @@
|
|
|
1
1
|
import "../../_dev.js";
|
|
2
2
|
import { createSvgElement as e, setAttributes as t } from "../../svg/element.js";
|
|
3
3
|
import { resolveEasing as n } from "../../animation/easing.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { resolveMotion as r } from "../../animation/motion.js";
|
|
5
|
+
import { tweenNumber as i } from "../../animation/tween.js";
|
|
6
|
+
import { areaPath as a, linePath as o, monotonePath as s, stepPath as c } from "../../svg/path.js";
|
|
6
7
|
//#region src/charts/area/area-renderer.ts
|
|
7
|
-
var
|
|
8
|
-
function
|
|
9
|
-
return t === "monotone" ?
|
|
8
|
+
var l = /* @__PURE__ */ new WeakMap(), u = /* @__PURE__ */ new WeakMap();
|
|
9
|
+
function d(e, t) {
|
|
10
|
+
return t === "monotone" ? s(e) : t === "step" ? c(e) : o(e);
|
|
10
11
|
}
|
|
11
|
-
function
|
|
12
|
-
let
|
|
13
|
-
|
|
14
|
-
fill:
|
|
15
|
-
"fill-opacity":
|
|
12
|
+
function f(o, s, c, f) {
|
|
13
|
+
let p = r(f.transition, 0), m = p.duration, h = n(p.easing), g = o.querySelector(".prism-area-fill");
|
|
14
|
+
g || (g = e("path", { class: "prism-area-fill" }), o.appendChild(g)), t(g, {
|
|
15
|
+
fill: f.color,
|
|
16
|
+
"fill-opacity": f.fillOpacity,
|
|
16
17
|
stroke: "none"
|
|
17
18
|
});
|
|
18
|
-
let
|
|
19
|
-
if (
|
|
19
|
+
let _ = null;
|
|
20
|
+
if (f.showLine ? (_ = o.querySelector(".prism-area-line"), _ || (_ = e("path", {
|
|
20
21
|
class: "prism-area-line",
|
|
21
22
|
fill: "none"
|
|
22
|
-
}),
|
|
23
|
-
stroke:
|
|
23
|
+
}), o.appendChild(_)), t(_, {
|
|
24
|
+
stroke: f.color,
|
|
24
25
|
"stroke-width": 2
|
|
25
|
-
})) :
|
|
26
|
-
let e =
|
|
26
|
+
})) : o.querySelector(".prism-area-line")?.remove(), m === 0) {
|
|
27
|
+
let e = s.map((e) => ({
|
|
27
28
|
x: e.x,
|
|
28
|
-
y:
|
|
29
|
+
y: c
|
|
29
30
|
}));
|
|
30
|
-
t(
|
|
31
|
+
t(g, { d: a(s, e, f.curve) }), _ && t(_, { d: d(s, f.curve) });
|
|
31
32
|
return;
|
|
32
33
|
}
|
|
33
|
-
if (
|
|
34
|
-
let e =
|
|
34
|
+
if (l.get(o)?.(), !g.hasAttribute("d")) {
|
|
35
|
+
let e = s.map((e) => ({
|
|
35
36
|
x: e.x,
|
|
36
|
-
y:
|
|
37
|
+
y: c
|
|
37
38
|
}));
|
|
38
|
-
t(
|
|
39
|
+
t(g, { d: a(s, e, f.curve) }), _ && t(_, { d: d(s, f.curve) }), u.set(o, s);
|
|
39
40
|
return;
|
|
40
41
|
}
|
|
41
|
-
let
|
|
42
|
-
function
|
|
43
|
-
if (
|
|
44
|
-
|
|
42
|
+
let v = u.get(o) ?? s, y = s.map((e, t) => v[t] ?? v[v.length - 1] ?? s[t]), b = null;
|
|
43
|
+
function x(e) {
|
|
44
|
+
if (f.disposalSignal?.aborted) {
|
|
45
|
+
l.delete(o);
|
|
45
46
|
return;
|
|
46
47
|
}
|
|
47
|
-
|
|
48
|
-
let n = Math.min(1, (e -
|
|
49
|
-
x:
|
|
50
|
-
y:
|
|
51
|
-
})),
|
|
48
|
+
b === null && (b = e);
|
|
49
|
+
let n = Math.min(1, (e - b) / m), r = h(n), p = s.map((e, t) => ({
|
|
50
|
+
x: i(y[t].x, e.x, r),
|
|
51
|
+
y: i(y[t].y, e.y, r)
|
|
52
|
+
})), v = p.map((e) => ({
|
|
52
53
|
x: e.x,
|
|
53
|
-
y:
|
|
54
|
+
y: c
|
|
54
55
|
}));
|
|
55
|
-
if (t(
|
|
56
|
-
let e = requestAnimationFrame(
|
|
57
|
-
|
|
58
|
-
} else
|
|
56
|
+
if (t(g, { d: a(p, v, f.curve) }), _ && t(_, { d: d(p, f.curve) }), n < 1) {
|
|
57
|
+
let e = requestAnimationFrame(x);
|
|
58
|
+
l.set(o, () => cancelAnimationFrame(e));
|
|
59
|
+
} else l.delete(o), u.set(o, s);
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
-
let
|
|
62
|
-
|
|
61
|
+
u.set(o, y);
|
|
62
|
+
let S = requestAnimationFrame(x);
|
|
63
|
+
l.set(o, () => cancelAnimationFrame(S));
|
|
63
64
|
}
|
|
64
|
-
function
|
|
65
|
+
function p(e, t, n) {
|
|
65
66
|
return e.some((e) => e.key == null) || e.some((e) => typeof e.key == "string"), e.map((e) => ({
|
|
66
67
|
x: t.map(e.key),
|
|
67
68
|
y: n.map(e.value)
|
|
68
69
|
}));
|
|
69
70
|
}
|
|
70
71
|
//#endregion
|
|
71
|
-
export {
|
|
72
|
+
export { p as computeAreaPoints, f as renderArea };
|
|
72
73
|
|
|
73
74
|
//# sourceMappingURL=area-renderer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"area-renderer.js","names":[],"sources":["../../../src/charts/area/area-renderer.ts"],"sourcesContent":["import type { Point } from '../../svg/path';\nimport type { Datum, Scale, TransitionConfig } from '../../types';\n\nimport { warn } from '../../_dev';\nimport { resolveEasing } from '../../animation/easing';\nimport { tweenNumber } from '../../animation/tween';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport { areaPath, linePath, monotonePath, stepPath } from '../../svg/path';\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
|
|
1
|
+
{"version":3,"file":"area-renderer.js","names":[],"sources":["../../../src/charts/area/area-renderer.ts"],"sourcesContent":["import type { Point } from '../../svg/path';\nimport type { Datum, Scale, TransitionConfig } from '../../types';\n\nimport { 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 { areaPath, linePath, monotonePath, stepPath } from '../../svg/path';\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":";;;;;;;AAoBA,IAAM,oBAAuB,IAAI,QAAiC,GAC5D,oBAAiB,IAAI,QAA8B;AAEzD,SAAS,EAAc,GAAc,GAA2C;CAC9E,OAAO,MAAU,aAAa,EAAa,CAAG,IAAI,MAAU,SAAS,EAAS,CAAG,IAAI,EAAS,CAAG;AACnG;AAEA,SAAgB,EAAW,GAAqB,GAAiB,GAAmB,GAAkC;CACpH,IAAM,IAAS,EAAc,EAAQ,YAAY,CAAC,GAC5C,IAAM,EAAO,UACb,IAAS,EAAc,EAAO,MAAM,GAEtC,IAAO,EAAO,cAA8B,kBAAkB;CAOlE,AALK,MACH,IAAO,EAAiB,QAAQ,EAAE,OAAO,kBAAkB,CAAC,GAC5D,EAAO,YAAY,CAAI,IAGzB,EAAc,GAAM;EAAE,MAAM,EAAQ;EAAO,gBAAgB,EAAQ;EAAa,QAAQ;CAAO,CAAC;CAEhG,IAAI,IAA8B;CAelC,IAbI,EAAQ,YACV,IAAO,EAAO,cAA8B,kBAAkB,GAEzD,MACH,IAAO,EAAiB,QAAQ;EAAE,OAAO;EAAmB,MAAM;CAAO,CAAC,GAC1E,EAAO,YAAY,CAAI,IAGzB,EAAc,GAAM;EAAE,QAAQ,EAAQ;EAAO,gBAAgB;CAAE,CAAC,KAEhE,EAAO,cAAc,kBAAkB,CAAC,EAAE,OAAO,GAG/C,M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,GAAO,EAAE,GAAG,EAAS,GAAc,GAAoB,EAAQ,KAAK,EAAE,CAAC,GAEjF,KAAM,EAAc,GAAM,EAAE,GAAG,EAAc,GAAc,EAAQ,KAAK,EAAE,CAAC,GAE3E,IAAI,GAAG;GACT,IAAM,IAAK,sBAAsB,CAAK;GAEtC,EAAqB,IAAI,SAAc,qBAAqB,CAAE,CAAC;EACjE,OAEE,AADA,EAAqB,OAAO,CAAM,GAClC,EAAe,IAAI,GAAQ,CAAM;CAErC;CAEA,EAAe,IAAI,GAAQ,CAAU;CAErC,IAAM,IAAK,sBAAsB,CAAK;CAEtC,EAAqB,IAAI,SAAc,qBAAqB,CAAE,CAAC;AACjE;AAEA,SAAgB,EAAkB,GAAe,GAA8B,GAAgC;CAS7G,OARI,EAAK,MAAM,MAAM,EAAE,OAAO,IAAI,KAIvB,EAAK,MAAM,MAAM,OAAO,EAAE,OAAQ,QAAQ,GAI9C,EAAK,KAAK,OAAO;EACtB,GAAG,EAAO,IAAI,EAAE,GAAoB;EACpC,GAAG,EAAO,IAAI,EAAE,KAAK;CACvB,EAAE;AACJ"}
|
|
@@ -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("../../interaction/events.cjs"),
|
|
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");let f=require("@vielzeug/ripple");function p(e){return{horizontal:e===`grouped-horizontal`||e===`stacked-horizontal`,stacked:e===`stacked`||e===`stacked-horizontal`}}function m(m,h){return a.createChartScaffold(m,h,m=>{let{groups:g,legend:_,tooltip:v}=m,y=m.dimensions.value,b=i.chartArea(y.width,y.height,y.margin),x=(0,f.isReactive)(h.series)?h.series.value:h.series,S=x.map(e=>(0,f.isReactive)(e.data)?e.data.value:e.data),C=o.normalizeCartesianSeries(x,S),w=C.domain,T=C.series.map(({byKey:e})=>w.map(t=>e.get(t))),E=e=>{if(e)return{...e,tickFormat:t=>{let n=String(t),r=C.labels.get(n)??t;return e.tickFormat?e.tickFormat(r):String(r)}}};if(w.length===0){a.clearCartesianDom(g,_,v);return}let{horizontal:D,stacked:O}=p(h.variant??`grouped`),k,A;if(O){T.some(e=>e.some(e=>(e?.value??0)<0));let e=w.map((e,t)=>T.reduce((e,n)=>e+Math.max(0,n[t]?.value??0),0));k=Math.max(...e),A=0}else{let e=T.flatMap(e=>e.flatMap(e=>e?[e.value]:[]));k=Math.max(...e),A=Math.min(0,...e)}let j=D?l.bandScale({domain:w,range:[0,b.height]}):l.bandScale({domain:w,range:[0,b.width]}),M=D?r.linearScale({domain:[A,k],range:[0,b.width]}):r.linearScale({domain:[A,k],range:[b.height,0]}),N=[],P=Object.create(null);for(let e of w)P[e]=0;let F={bandCenter:e=>j.map(e)+j.bandwidth()/2,bandwidth:j.bandwidth(),baselinePx:M.map(0),horizontal:D,stacked:O,stackedTops:N,valueScale:M};if(D){h.xAxis?.grid&&n.renderGrid(g.grid,M,h.xAxis.grid,b.height,`vertical`,t.resolveTickCount(h.xAxis,b.width,`bottom`));let e=E(h.yAxis);e&&t.renderAxis(g.yAxis,j,e,b.height,`left`),h.xAxis&&(g.xAxis.setAttribute(`transform`,`translate(0,${b.height})`),t.renderAxis(g.xAxis,M,h.xAxis,b.width,`bottom`))}else{h.yAxis?.grid&&n.renderGrid(g.grid,M,h.yAxis.grid,b.width,`horizontal`,t.resolveTickCount(h.yAxis,b.height,`left`));let e=E(h.xAxis);e&&(g.xAxis.setAttribute(`transform`,`translate(0,${b.height})`),t.renderAxis(g.xAxis,j,e,b.width,`bottom`)),h.yAxis&&t.renderAxis(g.yAxis,M,h.yAxis,b.height,`left`)}for(;g.series.children.length>x.length;){let e=g.series.lastElementChild;e&&g.series.removeChild(e)}for(let t=0;t<x.length;t++){let n=x[t],r=g.series.children[t];r||(r=e.createSvgElement(`g`,{class:`prism-bar-series`}),g.series.appendChild(r));let i=w.map((e,n)=>{let r=T[t]?.[n];if(O){let t=P[e]??0,n=t+Math.max(0,r?.value??0);return P[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}});N[t]=i.map(e=>e.y);let a=O?i.map(e=>M.map(e.base)):void 0;d.renderBars(r,i,j,M,F.baselinePx,{baselineYs:a,borderRadius:n.borderRadius??0,color:c.seriesColor(t,n.color),disposalSignal:m.disposalSignal,horizontal:D,seriesCount:x.length,seriesIndex:t,stacked:O,transition:h.transition})}return _?.update(x.map((e,t)=>({color:c.seriesColor(t,e.color),name:e.name}))),v?.hide(),{onClick:e=>{if(!h.onClick)return;let t=m.dimensions.value,n=s.getMousePosition(m.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=D?n.y:n.x,o=u.findCatIdx(a,w,F);if(o===-1)return;let c=u.findSeriesIdx(n,o,w,F,x.length),l=T[c]?.[o];l&&h.onClick({datum:l,originalEvent:e,series:x[c]})},onMouseLeave:()=>{v?.hide(),h.onHover?.(null)},onMouseMove:e=>{let t=m.dimensions.value,n=s.getMousePosition(m.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){v?.hide();return}let a=D?n.y:n.x,o=u.findCatIdx(a,w,F);if(o===-1){v?.hide();return}if(u.isOutsideBars(n,o,T,F,x.length)){v?.hide();return}let c=u.findSeriesIdx(n,o,w,F,x.length),l=T[c]?.[o];if(l){let n=F.bandCenter(w[o]),r=O?N[c]?.[o]??l.value:l.value,i=M.map(r),a=D?i+t.margin.left:n+t.margin.left,s=D?n+t.margin.top:i+t.margin.top;v?.show(a,s,l,x[c]),h.onHover?.({datum:l,originalEvent:e,series:x[c]})}}}})}exports.createBarChart=m;
|
|
2
2
|
//# sourceMappingURL=bar-chart.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bar-chart.cjs","names":[],"sources":["../../../src/charts/bar/bar-chart.ts"],"sourcesContent":["import { isReactive } from '@vielzeug/ripple';\n\nimport type { BarChartConfig, BarVariant, ChartHandle } from '../../types';\nimport type { BarScaleContext } from './bar-scale-context';\n\nimport { warn } from '../../_dev';\nimport { renderAxis, resolveTickCount } from '../../axes/axis';\nimport { renderGrid } from '../../axes/grid';\nimport { clearCartesianDom, createChartScaffold } from '../../core/chart-scaffold';\nimport { chartArea } from '../../core/layout';\nimport { getMousePosition } from '../../interaction/events';\nimport { bandScale } from '../../scales/band';\nimport { linearScale } from '../../scales/linear';\nimport { createSvgElement } from '../../svg/element';\nimport { seriesColor } from '../../theme';\nimport { findCatIdx, findSeriesIdx, isOutsideBars } from './bar-hit-test';\nimport { renderBars } from './bar-renderer';\n\nfunction variantFlags(variant: BarVariant): { horizontal: boolean; stacked: boolean } {\n return {\n horizontal: variant === 'grouped-horizontal' || variant === 'stacked-horizontal',\n stacked: variant === 'stacked' || variant === 'stacked-horizontal',\n };\n}\n\n// ─── Chart ────────────────────────────────────────────────────────────────────\n\nexport function createBarChart(container: HTMLElement, config: BarChartConfig): ChartHandle {\n return 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 = isReactive(config.series) ? config.series.value : config.series;\n const allData = seriesList.map((s) => (isReactive(s.data) ? s.data.value : s.data));\n const categories = [...new Set(allData.flat().map((d) => String(d.key)))];\n\n if (categories.length === 0) {\n warn('createBarChart: no data');\n clearCartesianDom(groups, legend, tooltip);\n\n return;\n }\n\n const { horizontal, stacked } = variantFlags(config.variant ?? 'grouped');\n\n // Value domain\n let vMax: number;\n let vMin: number;\n\n if (stacked) {\n if (allData.some((sd) => sd.some((d) => d.value < 0))) {\n warn(\n 'createBarChart: negative values in a stacked/stacked-horizontal series are clamped to 0 — stacking mixed-sign data is not supported.',\n );\n }\n\n const sums = categories.map((cat) =>\n allData.reduce((sum, sd) => {\n const pt = sd.find((d) => String(d.key) === cat);\n\n return sum + (pt ? Math.max(0, pt.value) : 0);\n }, 0),\n );\n\n vMax = Math.max(...sums);\n vMin = 0;\n } else {\n const allY = allData.flat().map((d) => d.value);\n\n vMax = Math.max(...allY);\n vMin = Math.min(0, ...allY);\n }\n\n // Build uniform scale context\n const catScale = horizontal\n ? bandScale({ domain: categories, range: [0, area.height] })\n : bandScale({ domain: categories, range: [0, area.width] });\n\n const valScale = horizontal\n ? linearScale({ domain: [vMin, vMax], range: [0, area.width] })\n : linearScale({ domain: [vMin, vMax], range: [area.height, 0] });\n\n const stackedTops: number[][] = [];\n const stackTops = Object.create(null) as Record<string, number>;\n\n for (const cat of categories) stackTops[cat] = 0;\n\n const sc: BarScaleContext = {\n bandCenter: (cat) => catScale.map(cat) + catScale.bandwidth() / 2,\n bandwidth: catScale.bandwidth(),\n baselinePx: valScale.map(0),\n horizontal,\n stacked,\n stackedTops,\n valueScale: valScale,\n };\n\n // Axes & grid\n if (horizontal) {\n if (config.xAxis?.grid) {\n renderGrid(\n groups.grid,\n valScale,\n config.xAxis.grid,\n area.height,\n 'vertical',\n resolveTickCount(config.xAxis, area.width, 'bottom'),\n );\n }\n\n if (config.yAxis) renderAxis(groups.yAxis, catScale, config.yAxis, area.height, 'left');\n\n if (config.xAxis) {\n groups.xAxis.setAttribute('transform', `translate(0,${area.height})`);\n renderAxis(groups.xAxis, valScale, config.xAxis, area.width, 'bottom');\n }\n } else {\n if (config.yAxis?.grid) {\n renderGrid(\n groups.grid,\n valScale,\n config.yAxis.grid,\n area.width,\n 'horizontal',\n resolveTickCount(config.yAxis, area.height, 'left'),\n );\n }\n\n if (config.xAxis) {\n groups.xAxis.setAttribute('transform', `translate(0,${area.height})`);\n renderAxis(groups.xAxis, catScale, config.xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) renderAxis(groups.yAxis, valScale, config.yAxis, area.height, 'left');\n }\n\n // Series groups\n while (groups.series.children.length > seriesList.length) {\n const last = groups.series.lastElementChild;\n\n if (last) groups.series.removeChild(last);\n }\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-bar-series' });\n groups.series.appendChild(group);\n }\n\n const barData = allData[i].map((d) => {\n const key = String(d.key);\n\n if (stacked) {\n const base = stackTops[key] ?? 0;\n const top = base + Math.max(0, d.value);\n\n stackTops[key] = top;\n\n return { base, key, y: top };\n }\n\n return { base: 0, key, y: d.value };\n });\n\n stackedTops[i] = barData.map((d) => d.y);\n\n const baselineYs = stacked ? barData.map((d) => valScale.map(d.base)) : undefined;\n\n renderBars(group, barData, catScale, valScale, sc.baselinePx, {\n baselineYs,\n borderRadius: series.borderRadius ?? 0,\n color: seriesColor(i, series.color),\n disposalSignal: ctx.disposalSignal,\n horizontal,\n seriesCount: seriesList.length,\n seriesIndex: i,\n stacked,\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 // ─── Event handlers (close over render-derived state) ─────────────────────\n\n const onMouseMove = (event: MouseEvent) => {\n const d = ctx.dimensions.value;\n const pos = getMousePosition(ctx.svg, event, d.margin.left, d.margin.top);\n const a = chartArea(d.width, d.height, d.margin);\n\n if (pos.x < 0 || pos.x > a.width || pos.y < 0 || pos.y > a.height) {\n tooltip?.hide();\n\n return;\n }\n\n const posBand = horizontal ? pos.y : pos.x;\n const catIdx = findCatIdx(posBand, categories, sc);\n\n if (catIdx === -1) {\n tooltip?.hide();\n\n return;\n }\n\n if (isOutsideBars(pos, catIdx, allData, sc, seriesList.length)) {\n tooltip?.hide();\n\n return;\n }\n\n const seriesIdx = findSeriesIdx(pos, catIdx, categories, sc, seriesList.length);\n const point = allData[seriesIdx]?.[catIdx];\n\n if (point) {\n const bandCenterPx = sc.bandCenter(categories[catIdx]);\n const stackedTop = stacked ? (stackedTops[seriesIdx]?.[catIdx] ?? point.value) : point.value;\n const valuePx = valScale.map(stackedTop);\n\n const tooltipX = horizontal ? valuePx + d.margin.left : bandCenterPx + d.margin.left;\n const tooltipY = horizontal ? bandCenterPx + d.margin.top : valuePx + d.margin.top;\n\n tooltip?.show(tooltipX, tooltipY, point, seriesList[seriesIdx]);\n config.onHover?.({ datum: point, originalEvent: event, series: seriesList[seriesIdx] });\n }\n };\n\n const onMouseLeave = () => {\n tooltip?.hide();\n config.onHover?.(null);\n };\n\n const onClick = (event: MouseEvent) => {\n if (!config.onClick) return;\n\n const d = ctx.dimensions.value;\n const pos = getMousePosition(ctx.svg, event, d.margin.left, d.margin.top);\n const a = chartArea(d.width, d.height, d.margin);\n\n if (pos.x < 0 || pos.x > a.width || pos.y < 0 || pos.y > a.height) return;\n\n const posBand = horizontal ? pos.y : pos.x;\n const catIdx = findCatIdx(posBand, categories, sc);\n\n if (catIdx === -1) return;\n\n const seriesIdx = findSeriesIdx(pos, catIdx, categories, sc, seriesList.length);\n const point = allData[seriesIdx]?.[catIdx];\n\n if (point) {\n config.onClick({ datum: point, originalEvent: event, series: seriesList[seriesIdx] });\n }\n };\n\n return { onClick, onMouseLeave, onMouseMove };\n });\n}\n"],"mappings":"0cAkBA,SAAS,EAAa,EAAgE,CACpF,MAAO,CACL,WAAY,IAAY,sBAAwB,IAAY,qBAC5D,QAAS,IAAY,WAAa,IAAY,oBAChD,CACF,CAIA,SAAgB,EAAe,EAAwB,EAAqC,CAC1F,OAAO,EAAA,oBAAoB,EAAW,EAAS,GAAQ,C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,EAAU,GAAG,GAEnC,GAAI,EAAO,CACT,IAAM,EAAe,EAAG,WAAW,EAAW,EAAO,EAC/C,EAAa,EAAW,EAAY,EAAU,GAAG,IAAW,EAAM,MAAS,EAAM,MACjF,EAAU,EAAS,IAAI,CAAU,EAEjC,EAAW,EAAa,EAAU,EAAE,OAAO,KAAO,EAAe,EAAE,OAAO,KAC1E,EAAW,EAAa,EAAe,EAAE,OAAO,IAAM,EAAU,EAAE,OAAO,IAE/E,GAAS,KAAK,EAAU,EAAU,EAAO,EAAW,EAAU,EAC9D,EAAO,UAAU,CAAE,MAAO,EAAO,cAAe,EAAO,OAAQ,EAAW,EAAW,CAAC,CACxF,CACF,CA6B4C,CAC9C,CAAC,CACH"}
|
|
1
|
+
{"version":3,"file":"bar-chart.cjs","names":[],"sources":["../../../src/charts/bar/bar-chart.ts"],"sourcesContent":["import { isReactive } from '@vielzeug/ripple';\n\nimport type { BarChartConfig, BarVariant, ChartHandle } from '../../types';\nimport type { BarScaleContext } from './bar-scale-context';\n\nimport { warn } from '../../_dev';\nimport { renderAxis, resolveTickCount } from '../../axes/axis';\nimport { renderGrid } from '../../axes/grid';\nimport { normalizeCartesianSeries } from '../../core/cartesian-model';\nimport { clearCartesianDom, createChartScaffold } from '../../core/chart-scaffold';\nimport { chartArea } from '../../core/layout';\nimport { getMousePosition } from '../../interaction/events';\nimport { bandScale } from '../../scales/band';\nimport { linearScale } from '../../scales/linear';\nimport { createSvgElement } from '../../svg/element';\nimport { seriesColor } from '../../theme';\nimport { findCatIdx, findSeriesIdx, isOutsideBars } from './bar-hit-test';\nimport { renderBars } from './bar-renderer';\n\nfunction variantFlags(variant: BarVariant): { horizontal: boolean; stacked: boolean } {\n return {\n horizontal: variant === 'grouped-horizontal' || variant === 'stacked-horizontal',\n stacked: variant === 'stacked' || variant === 'stacked-horizontal',\n };\n}\n\n// ─── Chart ────────────────────────────────────────────────────────────────────\n\nexport function createBarChart(container: HTMLElement, config: BarChartConfig): ChartHandle {\n return 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 = isReactive(config.series) ? config.series.value : config.series;\n const sourceData = seriesList.map((series) => (isReactive(series.data) ? series.data.value : series.data));\n const model = normalizeCartesianSeries(seriesList, sourceData);\n const categories = model.domain;\n const allData = model.series.map(({ byKey }) => categories.map((key) => byKey.get(key)));\n const categoryAxis = (axis: BarChartConfig['xAxis'] | BarChartConfig['yAxis']) => {\n if (!axis) return undefined;\n\n return {\n ...axis,\n tickFormat: (value: Date | number | string) => {\n const key = String(value);\n const label = model.labels.get(key) ?? value;\n\n return axis.tickFormat ? axis.tickFormat(label) : String(label);\n },\n };\n };\n\n if (categories.length === 0) {\n warn('createBarChart: no data');\n clearCartesianDom(groups, legend, tooltip);\n\n return;\n }\n\n const { horizontal, stacked } = variantFlags(config.variant ?? 'grouped');\n\n // Value domain\n let vMax: number;\n let vMin: number;\n\n if (stacked) {\n if (allData.some((seriesData) => seriesData.some((datum) => (datum?.value ?? 0) < 0))) {\n warn(\n 'createBarChart: negative values in a stacked/stacked-horizontal series are clamped to 0 — stacking mixed-sign data is not supported.',\n );\n }\n\n const sums = categories.map((_, categoryIndex) =>\n allData.reduce((sum, seriesData) => sum + Math.max(0, seriesData[categoryIndex]?.value ?? 0), 0),\n );\n\n vMax = Math.max(...sums);\n vMin = 0;\n } else {\n const allY = allData.flatMap((seriesData) => seriesData.flatMap((datum) => (datum ? [datum.value] : [])));\n\n vMax = Math.max(...allY);\n vMin = Math.min(0, ...allY);\n }\n\n // Build uniform scale context\n const catScale = horizontal\n ? bandScale({ domain: categories, range: [0, area.height] })\n : bandScale({ domain: categories, range: [0, area.width] });\n\n const valScale = horizontal\n ? linearScale({ domain: [vMin, vMax], range: [0, area.width] })\n : linearScale({ domain: [vMin, vMax], range: [area.height, 0] });\n\n const stackedTops: number[][] = [];\n const stackTops = Object.create(null) as Record<string, number>;\n\n for (const cat of categories) stackTops[cat] = 0;\n\n const sc: BarScaleContext = {\n bandCenter: (cat) => catScale.map(cat) + catScale.bandwidth() / 2,\n bandwidth: catScale.bandwidth(),\n baselinePx: valScale.map(0),\n horizontal,\n stacked,\n stackedTops,\n valueScale: valScale,\n };\n\n // Axes & grid\n if (horizontal) {\n if (config.xAxis?.grid) {\n renderGrid(\n groups.grid,\n valScale,\n config.xAxis.grid,\n area.height,\n 'vertical',\n resolveTickCount(config.xAxis, area.width, 'bottom'),\n );\n }\n\n const yAxis = categoryAxis(config.yAxis);\n\n if (yAxis) renderAxis(groups.yAxis, catScale, yAxis, area.height, 'left');\n\n if (config.xAxis) {\n groups.xAxis.setAttribute('transform', `translate(0,${area.height})`);\n renderAxis(groups.xAxis, valScale, config.xAxis, area.width, 'bottom');\n }\n } else {\n if (config.yAxis?.grid) {\n renderGrid(\n groups.grid,\n valScale,\n config.yAxis.grid,\n area.width,\n 'horizontal',\n resolveTickCount(config.yAxis, area.height, 'left'),\n );\n }\n\n const xAxis = categoryAxis(config.xAxis);\n\n if (xAxis) {\n groups.xAxis.setAttribute('transform', `translate(0,${area.height})`);\n renderAxis(groups.xAxis, catScale, xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) renderAxis(groups.yAxis, valScale, config.yAxis, area.height, 'left');\n }\n\n // Series groups\n while (groups.series.children.length > seriesList.length) {\n const last = groups.series.lastElementChild;\n\n if (last) groups.series.removeChild(last);\n }\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-bar-series' });\n groups.series.appendChild(group);\n }\n\n const barData = categories.map((key, categoryIndex) => {\n const datum = allData[i]?.[categoryIndex];\n\n if (stacked) {\n const base = stackTops[key] ?? 0;\n const top = base + Math.max(0, datum?.value ?? 0);\n\n stackTops[key] = top;\n\n return { base, key, present: datum !== undefined, y: top };\n }\n\n return { base: 0, key, present: datum !== undefined, y: datum?.value ?? 0 };\n });\n\n stackedTops[i] = barData.map((d) => d.y);\n\n const baselineYs = stacked ? barData.map((d) => valScale.map(d.base)) : undefined;\n\n renderBars(group, barData, catScale, valScale, sc.baselinePx, {\n baselineYs,\n borderRadius: series.borderRadius ?? 0,\n color: seriesColor(i, series.color),\n disposalSignal: ctx.disposalSignal,\n horizontal,\n seriesCount: seriesList.length,\n seriesIndex: i,\n stacked,\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 // ─── Event handlers (close over render-derived state) ─────────────────────\n\n const onMouseMove = (event: MouseEvent) => {\n const d = ctx.dimensions.value;\n const pos = getMousePosition(ctx.svg, event, d.margin.left, d.margin.top);\n const a = chartArea(d.width, d.height, d.margin);\n\n if (pos.x < 0 || pos.x > a.width || pos.y < 0 || pos.y > a.height) {\n tooltip?.hide();\n\n return;\n }\n\n const posBand = horizontal ? pos.y : pos.x;\n const catIdx = findCatIdx(posBand, categories, sc);\n\n if (catIdx === -1) {\n tooltip?.hide();\n\n return;\n }\n\n if (isOutsideBars(pos, catIdx, allData, sc, seriesList.length)) {\n tooltip?.hide();\n\n return;\n }\n\n const seriesIdx = findSeriesIdx(pos, catIdx, categories, sc, seriesList.length);\n const point = allData[seriesIdx]?.[catIdx];\n\n if (point) {\n const bandCenterPx = sc.bandCenter(categories[catIdx]);\n const stackedTop = stacked ? (stackedTops[seriesIdx]?.[catIdx] ?? point.value) : point.value;\n const valuePx = valScale.map(stackedTop);\n\n const tooltipX = horizontal ? valuePx + d.margin.left : bandCenterPx + d.margin.left;\n const tooltipY = horizontal ? bandCenterPx + d.margin.top : valuePx + d.margin.top;\n\n tooltip?.show(tooltipX, tooltipY, point, seriesList[seriesIdx]);\n config.onHover?.({ datum: point, originalEvent: event, series: seriesList[seriesIdx] });\n }\n };\n\n const onMouseLeave = () => {\n tooltip?.hide();\n config.onHover?.(null);\n };\n\n const onClick = (event: MouseEvent) => {\n if (!config.onClick) return;\n\n const d = ctx.dimensions.value;\n const pos = getMousePosition(ctx.svg, event, d.margin.left, d.margin.top);\n const a = chartArea(d.width, d.height, d.margin);\n\n if (pos.x < 0 || pos.x > a.width || pos.y < 0 || pos.y > a.height) return;\n\n const posBand = horizontal ? pos.y : pos.x;\n const catIdx = findCatIdx(posBand, categories, sc);\n\n if (catIdx === -1) return;\n\n const seriesIdx = findSeriesIdx(pos, catIdx, categories, sc, seriesList.length);\n const point = allData[seriesIdx]?.[catIdx];\n\n if (point) {\n config.onClick({ datum: point, originalEvent: event, series: seriesList[seriesIdx] });\n }\n };\n\n return { onClick, onMouseLeave, onMouseMove };\n });\n}\n"],"mappings":"sfAmBA,SAAS,EAAa,EAAgE,CACpF,MAAO,CACL,WAAY,IAAY,sBAAwB,IAAY,qBAC5D,QAAS,IAAY,WAAa,IAAY,oBAChD,CACF,CAIA,SAAgB,EAAe,EAAwB,EAAqC,CAC1F,OAAO,EAAA,oBAAoB,EAAW,EAAS,GAAQ,CACrD,GAAM,CAAE,SAAQ,SAAQ,WAAY,EAC9B,EAAO,EAAI,WAAW,MACtB,EAAO,EAAA,UAAU,EAAK,MAAO,EAAK,OAAQ,EAAK,MAAM,EACrD,GAAA,EAAa,EAAA,WAAA,CAAW,EAAO,MAAM,EAAI,EAAO,OAAO,MAAQ,EAAO,OACtE,EAAa,EAAW,IAAK,IAAA,EAAY,EAAA,WAAA,CAAW,EAAO,IAAI,EAAI,EAAO,KAAK,MAAQ,EAAO,IAAK,EACnG,EAAQ,EAAA,yBAAyB,EAAY,CAAU,EACvD,EAAa,EAAM,OACnB,EAAU,EAAM,OAAO,KAAK,CAAE,WAAY,EAAW,IAAK,GAAQ,EAAM,IAAI,CAAG,CAAC,CAAC,EACjF,EAAgB,GAA4D,CAC3E,KAEL,MAAO,CACL,GAAG,EACH,WAAa,GAAkC,CAC7C,IAAM,EAAM,OAAO,CAAK,EAClB,EAAQ,EAAM,OAAO,IAAI,CAAG,GAAK,EAEvC,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Aa,EAAe,EAAE,OAAO,IAAM,EAAU,EAAE,OAAO,IAE/E,GAAS,KAAK,EAAU,EAAU,EAAO,EAAW,EAAU,EAC9D,EAAO,UAAU,CAAE,MAAO,EAAO,cAAe,EAAO,OAAQ,EAAW,EAAW,CAAC,CACxF,CACF,CA6B4C,CAC9C,CAAC,CACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bar-chart.d.ts","sourceRoot":"","sources":["../../../src/charts/bar/bar-chart.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAc,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"bar-chart.d.ts","sourceRoot":"","sources":["../../../src/charts/bar/bar-chart.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAc,WAAW,EAAE,MAAM,aAAa,CAAC;AA0B3E,wBAAgB,cAAc,CAAC,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,GAAG,WAAW,CAwP1F"}
|