@vielzeug/prism 26.10.3 → 26.10.4

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 (95) hide show
  1. package/README.md +1 -1
  2. package/dist/animation/easing.cjs +1 -1
  3. package/dist/animation/easing.cjs.map +1 -1
  4. package/dist/animation/easing.d.ts +15 -1
  5. package/dist/animation/easing.d.ts.map +1 -1
  6. package/dist/animation/easing.js +1 -1
  7. package/dist/animation/easing.js.map +1 -1
  8. package/dist/animation/motion.cjs +1 -1
  9. package/dist/animation/motion.cjs.map +1 -1
  10. package/dist/animation/motion.d.ts +17 -2
  11. package/dist/animation/motion.d.ts.map +1 -1
  12. package/dist/animation/motion.js +1 -1
  13. package/dist/animation/motion.js.map +1 -1
  14. package/dist/charts/area/area-chart.cjs +1 -1
  15. package/dist/charts/area/area-chart.cjs.map +1 -1
  16. package/dist/charts/area/area-chart.d.ts.map +1 -1
  17. package/dist/charts/area/area-chart.js +1 -1
  18. package/dist/charts/area/area-chart.js.map +1 -1
  19. package/dist/charts/area/area-renderer.cjs +1 -1
  20. package/dist/charts/area/area-renderer.cjs.map +1 -1
  21. package/dist/charts/area/area-renderer.d.ts +2 -2
  22. package/dist/charts/area/area-renderer.d.ts.map +1 -1
  23. package/dist/charts/area/area-renderer.js +1 -1
  24. package/dist/charts/area/area-renderer.js.map +1 -1
  25. package/dist/charts/bar/bar-chart.cjs +1 -1
  26. package/dist/charts/bar/bar-chart.cjs.map +1 -1
  27. package/dist/charts/bar/bar-chart.d.ts.map +1 -1
  28. package/dist/charts/bar/bar-chart.js +1 -1
  29. package/dist/charts/bar/bar-chart.js.map +1 -1
  30. package/dist/charts/bar/bar-renderer.cjs +1 -1
  31. package/dist/charts/bar/bar-renderer.cjs.map +1 -1
  32. package/dist/charts/bar/bar-renderer.d.ts +2 -2
  33. package/dist/charts/bar/bar-renderer.d.ts.map +1 -1
  34. package/dist/charts/bar/bar-renderer.js +1 -1
  35. package/dist/charts/bar/bar-renderer.js.map +1 -1
  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.map +1 -1
  39. package/dist/charts/line/line-chart.js +1 -1
  40. package/dist/charts/line/line-chart.js.map +1 -1
  41. package/dist/charts/line/line-renderer.cjs +1 -1
  42. package/dist/charts/line/line-renderer.cjs.map +1 -1
  43. package/dist/charts/line/line-renderer.d.ts +4 -2
  44. package/dist/charts/line/line-renderer.d.ts.map +1 -1
  45. package/dist/charts/line/line-renderer.js +1 -1
  46. package/dist/charts/line/line-renderer.js.map +1 -1
  47. package/dist/charts/pie/pie-chart.cjs +1 -1
  48. package/dist/charts/pie/pie-chart.cjs.map +1 -1
  49. package/dist/charts/pie/pie-chart.d.ts.map +1 -1
  50. package/dist/charts/pie/pie-chart.js +1 -1
  51. package/dist/charts/pie/pie-chart.js.map +1 -1
  52. package/dist/charts/radar/radar-chart.cjs +1 -1
  53. package/dist/charts/radar/radar-chart.cjs.map +1 -1
  54. package/dist/charts/radar/radar-chart.d.ts.map +1 -1
  55. package/dist/charts/radar/radar-chart.js +1 -1
  56. package/dist/charts/radar/radar-chart.js.map +1 -1
  57. package/dist/charts/sparkline/sparkline.cjs +1 -1
  58. package/dist/charts/sparkline/sparkline.cjs.map +1 -1
  59. package/dist/charts/sparkline/sparkline.d.ts.map +1 -1
  60. package/dist/charts/sparkline/sparkline.js +1 -1
  61. package/dist/charts/sparkline/sparkline.js.map +1 -1
  62. package/dist/core/responsive.cjs +1 -1
  63. package/dist/core/responsive.cjs.map +1 -1
  64. package/dist/core/responsive.d.ts.map +1 -1
  65. package/dist/core/responsive.js +1 -1
  66. package/dist/core/responsive.js.map +1 -1
  67. package/dist/index.d.ts +2 -2
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/interaction/crosshair.cjs +1 -1
  70. package/dist/interaction/crosshair.cjs.map +1 -1
  71. package/dist/interaction/crosshair.d.ts +7 -0
  72. package/dist/interaction/crosshair.d.ts.map +1 -1
  73. package/dist/interaction/crosshair.js +1 -1
  74. package/dist/interaction/crosshair.js.map +1 -1
  75. package/dist/interaction/tooltip.cjs +1 -1
  76. package/dist/interaction/tooltip.cjs.map +1 -1
  77. package/dist/interaction/tooltip.d.ts.map +1 -1
  78. package/dist/interaction/tooltip.js +1 -1
  79. package/dist/interaction/tooltip.js.map +1 -1
  80. package/dist/prism.cjs +1 -1
  81. package/dist/prism.cjs.map +1 -1
  82. package/dist/prism.iife.js +1 -1
  83. package/dist/prism.iife.js.map +1 -1
  84. package/dist/prism.js +1 -1
  85. package/dist/prism.js.map +1 -1
  86. package/dist/theme/index.cjs +1 -1
  87. package/dist/theme/index.cjs.map +1 -1
  88. package/dist/theme/index.d.ts +9 -4
  89. package/dist/theme/index.d.ts.map +1 -1
  90. package/dist/theme/index.js +1 -1
  91. package/dist/theme/index.js.map +1 -1
  92. package/dist/theme/prism.css +18 -4
  93. package/dist/types.d.ts +39 -5
  94. package/dist/types.d.ts.map +1 -1
  95. package/package.json +3 -6
@@ -1,2 +1,2 @@
1
- require("../../_dev.cjs");const e=require("../../svg/element.cjs"),t=require("../../animation/easing.cjs"),n=require("../../animation/motion.cjs"),r=require("../../animation/tween.cjs"),i=require("../../animation/transition.cjs"),a=require("../../core/datum-style.cjs"),o=require("../../svg/path.cjs");var s=new WeakMap;function buildPath(e,t){return t===`monotone`?o.monotonePath(e):t===`step`?o.stepPath(e):o.linePath(e)}function renderLine(o,c,l){let u=a.hasStyledRuns(l.marks),d=l.marks??[],f=n.resolveMotion(l.transition,0),p=f.duration,m=t.resolveEasing(f.easing),h=null,g=[],_=[];if(u){g=a.computeStyleRuns(d,c.length);let t=[...o.querySelectorAll(`.prism-line-path`)];for(let e of t.slice(g.length))e.remove();_=g.map((n,r)=>{let i=t[r];if(i)return i;let a=e.createSvgElement(`path`,{class:`prism-line-path`,fill:`none`});return o.appendChild(a),a});for(let[t,n]of g.entries())e.setAttributes(_[t],{opacity:n.opacity,stroke:l.color,"stroke-dasharray":n.dash,"stroke-width":l.strokeWidth??2}),_[t].style.strokeWidth=l.strokeWidth===void 0?``:String(l.strokeWidth)}else{let t=[...o.querySelectorAll(`.prism-line-path`)];h=t[0]??null;for(let e of t.slice(1))e.remove();h||(h=e.createSvgElement(`path`,{class:`prism-line-path`,fill:`none`}),o.appendChild(h)),e.setAttributes(h,{opacity:void 0,stroke:l.color,"stroke-dasharray":void 0,"stroke-width":l.strokeWidth??2}),h.style.strokeWidth=l.strokeWidth===void 0?``:String(l.strokeWidth)}let draw=t=>{if(u)for(let[n,r]of g.entries())e.setAttributes(_[n],{d:buildPath(t.slice(r.start,r.end+1),l.curve)});else e.setAttributes(h,{d:buildPath(t,l.curve)})},v=o.querySelector(`.prism-line-dots`);if(l.showPoints?v||(v=e.createSvgElement(`g`,{class:`prism-line-dots`}),o.appendChild(v)):v&&=(v.remove(),null),p===0){if(draw(c),v){for(;v.children.length>c.length;)v.removeChild(v.lastChild);for(let t=0;t<c.length;t++){let n=v.children[t];n||(n=e.createSvgElement(`circle`,{class:`prism-line-dot`}),v.appendChild(n)),e.setAttributes(n,{cx:c[t].x,cy:c[t].y,fill:l.color,opacity:d[t]?.opacity,r:l.pointRadius})}}return}s.get(o)?.();let y=u?_.some(e=>e.hasAttribute(`d`)):!!h?.getAttribute(`d`),b=[],x=null;if(v){let t=v.children.length;for(let e=0;e<t;e++){let t=v.children[e],n={x:Number(t.getAttribute(`cx`)),y:Number(t.getAttribute(`cy`))};b.push(n),x=n}for(;v.children.length>c.length;)v.removeChild(v.lastChild);for(let t=v.children.length;t<c.length;t++){let n=e.createSvgElement(`circle`,{class:`prism-line-dot`});e.setAttributes(n,{cx:c[t].x,cy:c[t].y,fill:l.color,opacity:d[t]?.opacity,r:l.pointRadius}),v.appendChild(n)}for(let t=0;t<v.children.length;t++)e.setAttributes(v.children[t],{opacity:d[t]?.opacity})}for(let e=b.length;e<c.length;e++)b.push(x??c[e]);if(!y){draw(c);return}s.set(o,i.startTween({count:1,duration:p,easing:m,onComplete:()=>s.delete(o),onFrame:t=>{let n=t(0),i=c.map((e,t)=>{let i=b[t]??e;return{x:r.tweenNumber(i.x,e.x,n),y:r.tweenNumber(i.y,e.y,n)}});if(draw(i),v)for(let t=0;t<c.length;t++){let n=v.children[t];n&&e.setAttributes(n,{cx:i[t].x,cy:i[t].y})}},signal:l.disposalSignal}))}function computePoints(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.computePoints=computePoints,exports.renderLine=renderLine;
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("../../animation/transition.cjs"),a=require("../../core/datum-style.cjs"),o=require("../../svg/path.cjs");var s=new WeakMap,c=new WeakMap;function buildPath(e,t){return t===`monotone`?o.monotonePath(e):t===`step`?o.stepPath(e):o.linePath(e)}function renderLine(o,l,u){let d=a.hasStyledRuns(u.marks),f=u.marks??[],p=n.resolveMotion(u.transition),m=p.duration,h=t.resolveEasing(p.easing),g=null,_=[],v=[];if(d){_=a.computeStyleRuns(f,l.length);let t=[...o.querySelectorAll(`.prism-line-path`)];for(let e of t.slice(_.length))e.remove();v=_.map((n,r)=>{let i=t[r];if(i)return i;let a=e.createSvgElement(`path`,{class:`prism-line-path`,fill:`none`});return o.appendChild(a),a});for(let[t,n]of _.entries())e.setAttributes(v[t],{opacity:n.opacity,stroke:u.color,"stroke-dasharray":n.dash,"stroke-width":u.strokeWidth??2}),v[t].style.strokeWidth=u.strokeWidth===void 0?``:String(u.strokeWidth)}else{let t=[...o.querySelectorAll(`.prism-line-path`)];g=t[0]??null;for(let e of t.slice(1))e.remove();g||(g=e.createSvgElement(`path`,{class:`prism-line-path`,fill:`none`}),o.appendChild(g)),e.setAttributes(g,{opacity:void 0,stroke:u.color,"stroke-dasharray":void 0,"stroke-width":u.strokeWidth??2}),g.style.strokeWidth=u.strokeWidth===void 0?``:String(u.strokeWidth)}let draw=t=>{if(d)for(let[n,r]of _.entries())e.setAttributes(v[n],{d:buildPath(t.slice(r.start,r.end+1),u.curve)});else e.setAttributes(g,{d:buildPath(t,u.curve)})},y=o.querySelector(`.prism-line-dots`);if(u.showPoints?y||(y=e.createSvgElement(`g`,{class:`prism-line-dots`}),o.appendChild(y)):y&&=(y.remove(),null),m===0){if(draw(l),c.set(o,l),y){for(;y.children.length>l.length;)y.removeChild(y.lastChild);for(let t=0;t<l.length;t++){let n=y.children[t];n||(n=e.createSvgElement(`circle`,{class:`prism-line-dot`}),y.appendChild(n)),e.setAttributes(n,{cx:l[t].x,cy:l[t].y,fill:u.color,opacity:f[t]?.opacity,r:u.pointRadius})}}return}s.get(o)?.();let b=!c.has(o),x=b?l.map(e=>({x:e.x,y:u.baselineY})):[];if(y){for(;y.children.length>l.length;)y.removeChild(y.lastChild);for(let t=y.children.length;t<l.length;t++){let n=e.createSvgElement(`circle`,{class:`prism-line-dot`});e.setAttributes(n,{fill:u.color,opacity:f[t]?.opacity,r:u.pointRadius}),y.appendChild(n)}for(let t=0;t<y.children.length;t++)e.setAttributes(y.children[t],{opacity:f[t]?.opacity})}if(!b){let e=c.get(o)??l;for(let[t,n]of l.entries())x.push(e[t]??e.at(-1)??n)}let paintFrame=t=>{let n=l.map((e,n)=>{let i=x[n]??e;return{x:r.tweenNumber(i.x,e.x,t),y:r.tweenNumber(i.y,e.y,t)}});if(c.set(o,n),draw(n),y)for(let t=0;t<l.length;t++){let r=y.children[t];r&&e.setAttributes(r,{cx:n[t].x,cy:n[t].y})}};paintFrame(0),s.set(o,i.startTween({count:1,duration:m,easing:h,onComplete:()=>{s.delete(o),c.set(o,l)},onFrame:e=>paintFrame(e(0)),signal:u.disposalSignal}))}function computePoints(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.computePoints=computePoints,exports.renderLine=renderLine;
2
2
  //# sourceMappingURL=line-renderer.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"line-renderer.cjs","names":[],"sources":["../../../src/charts/line/line-renderer.ts"],"sourcesContent":["import { warn } from '../../_dev';\nimport { resolveEasing } from '../../animation/easing';\nimport { resolveMotion } from '../../animation/motion';\nimport { startTween } from '../../animation/transition';\nimport { tweenNumber } from '../../animation/tween';\nimport { computeStyleRuns, type DatumMark, hasStyledRuns, type StyleRun } from '../../core/datum-style';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport type { Point } from '../../svg/path';\nimport { linePath, monotonePath, stepPath } from '../../svg/path';\nimport type { ContinuousDatum, Scale, TransitionConfig } from '../../types';\n\nexport interface LineRenderOptions {\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 /** Per-datum presentation parallel to `points`; styled runs split the line into subpaths. */\n marks?: readonly DatumMark[];\n pointRadius: number;\n showPoints: boolean;\n /** Explicit width beats the `--prism-line-width` theme token. */\n strokeWidth?: number;\n transition?: TransitionConfig;\n}\n\nconst activeAnimations = new WeakMap<SVGGElement, () => void>();\n\nfunction buildPath(pts: Point[], curve: LineRenderOptions['curve']): string {\n return curve === 'monotone' ? monotonePath(pts) : curve === 'step' ? stepPath(pts) : linePath(pts);\n}\n\nexport function renderLine(parent: SVGGElement, points: Point[], options: LineRenderOptions): void {\n const styled = hasStyledRuns(options.marks);\n const marks = options.marks ?? [];\n const motion = resolveMotion(options.transition, 0);\n const dur = motion.duration;\n const easing = resolveEasing(motion.easing);\n\n let path: SVGPathElement | null = null;\n let runs: readonly StyleRun[] = [];\n let runPaths: SVGPathElement[] = [];\n\n if (styled) {\n runs = computeStyleRuns(marks, points.length);\n\n const existing = [...parent.querySelectorAll<SVGPathElement>('.prism-line-path')];\n\n for (const extra of existing.slice(runs.length)) extra.remove();\n\n runPaths = runs.map((_, r) => {\n const reuse = existing[r];\n\n if (reuse) return reuse;\n\n const created = createSvgElement('path', { class: 'prism-line-path', fill: 'none' });\n\n parent.appendChild(created);\n\n return created;\n });\n\n for (const [r, run] of runs.entries()) {\n setAttributes(runPaths[r], {\n opacity: run.opacity,\n stroke: options.color,\n 'stroke-dasharray': run.dash,\n 'stroke-width': options.strokeWidth ?? 2,\n });\n runPaths[r].style.strokeWidth = options.strokeWidth === undefined ? '' : String(options.strokeWidth);\n }\n } else {\n const existing = [...parent.querySelectorAll<SVGPathElement>('.prism-line-path')];\n\n path = existing[0] ?? null;\n\n for (const stale of existing.slice(1)) stale.remove();\n\n if (!path) {\n path = createSvgElement('path', { class: 'prism-line-path', fill: 'none' });\n parent.appendChild(path);\n }\n\n setAttributes(path, {\n opacity: undefined,\n stroke: options.color,\n 'stroke-dasharray': undefined,\n 'stroke-width': options.strokeWidth ?? 2,\n });\n path.style.strokeWidth = options.strokeWidth === undefined ? '' : String(options.strokeWidth);\n }\n\n const draw = (pts: Point[]): void => {\n if (styled) {\n for (const [r, run] of runs.entries()) {\n setAttributes(runPaths[r], { d: buildPath(pts.slice(run.start, run.end + 1), options.curve) });\n }\n } else {\n setAttributes(path!, { d: buildPath(pts, options.curve) });\n }\n };\n\n let dotsGroup = parent.querySelector<SVGGElement>('.prism-line-dots');\n\n if (options.showPoints) {\n if (!dotsGroup) {\n dotsGroup = createSvgElement('g', { class: 'prism-line-dots' });\n parent.appendChild(dotsGroup);\n }\n } else if (dotsGroup) {\n dotsGroup.remove();\n dotsGroup = null;\n }\n\n if (dur === 0) {\n draw(points);\n\n if (dotsGroup) {\n while (dotsGroup.children.length > points.length) dotsGroup.removeChild(dotsGroup.lastChild!);\n\n for (let i = 0; i < points.length; i++) {\n let c = dotsGroup.children[i] as SVGCircleElement | undefined;\n\n if (!c) {\n c = createSvgElement('circle', { class: 'prism-line-dot' });\n dotsGroup.appendChild(c);\n }\n\n setAttributes(c, {\n cx: points[i].x,\n cy: points[i].y,\n fill: options.color,\n opacity: marks[i]?.opacity,\n r: options.pointRadius,\n });\n }\n }\n\n return;\n }\n\n activeAnimations.get(parent)?.();\n\n const hasExisting = styled ? runPaths.some((p) => p.hasAttribute('d')) : !!path?.getAttribute('d');\n\n const fromPts: Point[] = [];\n let lastKnown: Point | null = null;\n\n if (dotsGroup) {\n const existingCount = dotsGroup.children.length;\n\n for (let i = 0; i < existingCount; i++) {\n const c = dotsGroup.children[i] as SVGCircleElement;\n const pt = { x: Number(c.getAttribute('cx')), y: Number(c.getAttribute('cy')) };\n\n fromPts.push(pt);\n lastKnown = pt;\n }\n\n while (dotsGroup.children.length > points.length) dotsGroup.removeChild(dotsGroup.lastChild!);\n\n for (let i = dotsGroup.children.length; i < points.length; i++) {\n const c = createSvgElement('circle', { class: 'prism-line-dot' });\n\n setAttributes(c, {\n cx: points[i].x,\n cy: points[i].y,\n fill: options.color,\n opacity: marks[i]?.opacity,\n r: options.pointRadius,\n });\n dotsGroup.appendChild(c);\n }\n\n for (let i = 0; i < dotsGroup.children.length; i++) {\n setAttributes(dotsGroup.children[i] as SVGCircleElement, { opacity: marks[i]?.opacity });\n }\n }\n\n for (let i = fromPts.length; i < points.length; i++) {\n fromPts.push(lastKnown ?? points[i]);\n }\n\n if (!hasExisting) {\n draw(points);\n\n return;\n }\n\n activeAnimations.set(\n parent,\n startTween({\n count: 1,\n duration: dur,\n easing,\n onComplete: () => activeAnimations.delete(parent),\n onFrame: (progress) => {\n const e = progress(0);\n const interpolated: Point[] = points.map((to, i) => {\n const from = fromPts[i] ?? to;\n\n return { x: tweenNumber(from.x, to.x, e), y: tweenNumber(from.y, to.y, e) };\n });\n\n draw(interpolated);\n\n if (dotsGroup) {\n for (let i = 0; i < points.length; i++) {\n const c = dotsGroup.children[i] as SVGCircleElement | undefined;\n\n if (c) setAttributes(c, { cx: interpolated[i].x, cy: interpolated[i].y });\n }\n }\n },\n signal: options.disposalSignal,\n }),\n );\n}\n\nexport function computePoints(data: ContinuousDatum[], xScale: Scale<Date | number>, yScale: Scale<number>): Point[] {\n if (data.some((d) => d.key == null)) {\n warn(\n 'computePoints: 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('computePoints: 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":"8SAyBA,IAAM,EAAmB,IAAI,QAE7B,SAAS,UAAU,EAAc,EAA2C,CAC1E,OAAO,IAAU,WAAa,EAAA,aAAa,CAAG,EAAI,IAAU,OAAS,EAAA,SAAS,CAAG,EAAI,EAAA,SAAS,CAAG,CACnG,CAEA,SAAgB,WAAW,EAAqB,EAAiB,EAAkC,CACjG,IAAM,EAAS,EAAA,cAAc,EAAQ,KAAK,EACpC,EAAQ,EAAQ,OAAS,CAAC,EAC1B,EAAS,EAAA,cAAc,EAAQ,WAAY,CAAC,EAC5C,EAAM,EAAO,SACb,EAAS,EAAA,cAAc,EAAO,MAAM,EAEtC,EAA8B,KAC9B,EAA4B,CAAC,EAC7B,EAA6B,CAAC,EAElC,GAAI,EAAQ,CACV,EAAO,EAAA,iBAAiB,EAAO,EAAO,MAAM,EAE5C,IAAM,EAAW,CAAC,GAAG,EAAO,iBAAiC,kBAAkB,CAAC,EAEhF,IAAK,IAAM,KAAS,EAAS,MAAM,EAAK,MAAM,EAAG,EAAM,OAAO,EAE9D,EAAW,EAAK,KAAK,EAAG,IAAM,CAC5B,IAAM,EAAQ,EAAS,GAEvB,GAAI,EAAO,OAAO,EAElB,IAAM,EAAU,EAAA,iBAAiB,OAAQ,CAAE,MAAO,kBAAmB,KAAM,MAAO,CAAC,EAInF,OAFA,EAAO,YAAY,CAAO,EAEnB,CACT,CAAC,EAED,IAAK,GAAM,CAAC,EAAG,KAAQ,EAAK,QAAQ,EAClC,EAAA,cAAc,EAAS,GAAI,CACzB,QAAS,EAAI,QACb,OAAQ,EAAQ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AA,cAAc,EAAU,SAAS,GAAwB,CAAE,QAAS,EAAM,EAAE,EAAE,OAAQ,CAAC,CAE3F,CAEA,IAAK,IAAI,EAAI,EAAQ,OAAQ,EAAI,EAAO,OAAQ,IAC9C,EAAQ,KAAK,GAAa,EAAO,EAAE,EAGrC,GAAI,CAAC,EAAa,CAChB,KAAK,CAAM,EAEX,MACF,CAEA,EAAiB,IACf,EACA,EAAA,WAAW,CACT,MAAO,EACP,SAAU,EACV,SACA,eAAkB,EAAiB,OAAO,CAAM,EAChD,QAAU,GAAa,CACrB,IAAM,EAAI,EAAS,CAAC,EACd,EAAwB,EAAO,KAAK,EAAI,IAAM,CAClD,IAAM,EAAO,EAAQ,IAAM,EAE3B,MAAO,CAAE,EAAG,EAAA,YAAY,EAAK,EAAG,EAAG,EAAG,CAAC,EAAG,EAAG,EAAA,YAAY,EAAK,EAAG,EAAG,EAAG,CAAC,CAAE,CAC5E,CAAC,EAID,GAFA,KAAK,CAAY,EAEb,EACF,IAAK,IAAI,EAAI,EAAG,EAAI,EAAO,OAAQ,IAAK,CACtC,IAAM,EAAI,EAAU,SAAS,GAEzB,GAAG,EAAA,cAAc,EAAG,CAAE,GAAI,EAAa,EAAE,CAAC,EAAG,GAAI,EAAa,EAAE,CAAC,CAAE,CAAC,CAC1E,CAEJ,EACA,OAAQ,EAAQ,cAClB,CAAC,CACH,CACF,CAEA,SAAgB,cAAc,EAAyB,EAA8B,EAAgC,CASnH,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":"line-renderer.cjs","names":[],"sources":["../../../src/charts/line/line-renderer.ts"],"sourcesContent":["import { warn } from '../../_dev';\nimport { resolveEasing } from '../../animation/easing';\nimport { resolveMotion } from '../../animation/motion';\nimport { startTween } from '../../animation/transition';\nimport { tweenNumber } from '../../animation/tween';\nimport { computeStyleRuns, type DatumMark, hasStyledRuns, type StyleRun } from '../../core/datum-style';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport type { Point } from '../../svg/path';\nimport { linePath, monotonePath, stepPath } from '../../svg/path';\nimport type { ContinuousDatum, Scale, TransitionOption } from '../../types';\n\nexport interface LineRenderOptions {\n /** Plot-area bottom in area-local coordinates: the mount animation raises the line from here. */\n baselineY: number;\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 /** Per-datum presentation parallel to `points`; styled runs split the line into subpaths. */\n marks?: readonly DatumMark[];\n pointRadius: number;\n showPoints: boolean;\n /** Explicit width beats the `--prism-line-width` theme token. */\n strokeWidth?: number;\n transition?: TransitionOption;\n}\n\nconst activeAnimations = new WeakMap<SVGGElement, () => void>();\n// Geometry currently on screen, so an update interpolates from it even when the\n// series hides its point markers (the dots would otherwise be the only record).\nconst drawnPoints = new WeakMap<SVGGElement, Point[]>();\n\nfunction buildPath(pts: Point[], curve: LineRenderOptions['curve']): string {\n return curve === 'monotone' ? monotonePath(pts) : curve === 'step' ? stepPath(pts) : linePath(pts);\n}\n\nexport function renderLine(parent: SVGGElement, points: Point[], options: LineRenderOptions): void {\n const styled = hasStyledRuns(options.marks);\n const marks = options.marks ?? [];\n const motion = resolveMotion(options.transition);\n const dur = motion.duration;\n const easing = resolveEasing(motion.easing);\n\n let path: SVGPathElement | null = null;\n let runs: readonly StyleRun[] = [];\n let runPaths: SVGPathElement[] = [];\n\n if (styled) {\n runs = computeStyleRuns(marks, points.length);\n\n const existing = [...parent.querySelectorAll<SVGPathElement>('.prism-line-path')];\n\n for (const extra of existing.slice(runs.length)) extra.remove();\n\n runPaths = runs.map((_, r) => {\n const reuse = existing[r];\n\n if (reuse) return reuse;\n\n const created = createSvgElement('path', { class: 'prism-line-path', fill: 'none' });\n\n parent.appendChild(created);\n\n return created;\n });\n\n for (const [r, run] of runs.entries()) {\n setAttributes(runPaths[r], {\n opacity: run.opacity,\n stroke: options.color,\n 'stroke-dasharray': run.dash,\n 'stroke-width': options.strokeWidth ?? 2,\n });\n runPaths[r].style.strokeWidth = options.strokeWidth === undefined ? '' : String(options.strokeWidth);\n }\n } else {\n const existing = [...parent.querySelectorAll<SVGPathElement>('.prism-line-path')];\n\n path = existing[0] ?? null;\n\n for (const stale of existing.slice(1)) stale.remove();\n\n if (!path) {\n path = createSvgElement('path', { class: 'prism-line-path', fill: 'none' });\n parent.appendChild(path);\n }\n\n setAttributes(path, {\n opacity: undefined,\n stroke: options.color,\n 'stroke-dasharray': undefined,\n 'stroke-width': options.strokeWidth ?? 2,\n });\n path.style.strokeWidth = options.strokeWidth === undefined ? '' : String(options.strokeWidth);\n }\n\n const draw = (pts: Point[]): void => {\n if (styled) {\n for (const [r, run] of runs.entries()) {\n setAttributes(runPaths[r], { d: buildPath(pts.slice(run.start, run.end + 1), options.curve) });\n }\n } else {\n setAttributes(path!, { d: buildPath(pts, options.curve) });\n }\n };\n\n let dotsGroup = parent.querySelector<SVGGElement>('.prism-line-dots');\n\n if (options.showPoints) {\n if (!dotsGroup) {\n dotsGroup = createSvgElement('g', { class: 'prism-line-dots' });\n parent.appendChild(dotsGroup);\n }\n } else if (dotsGroup) {\n dotsGroup.remove();\n dotsGroup = null;\n }\n\n if (dur === 0) {\n draw(points);\n drawnPoints.set(parent, points);\n\n if (dotsGroup) {\n while (dotsGroup.children.length > points.length) dotsGroup.removeChild(dotsGroup.lastChild!);\n\n for (let i = 0; i < points.length; i++) {\n let c = dotsGroup.children[i] as SVGCircleElement | undefined;\n\n if (!c) {\n c = createSvgElement('circle', { class: 'prism-line-dot' });\n dotsGroup.appendChild(c);\n }\n\n setAttributes(c, {\n cx: points[i].x,\n cy: points[i].y,\n fill: options.color,\n opacity: marks[i]?.opacity,\n r: options.pointRadius,\n });\n }\n }\n\n return;\n }\n\n activeAnimations.get(parent)?.();\n\n const hasExisting = drawnPoints.has(parent);\n // A first render has no drawn shape to interpolate between: the mount animation\n // raises the whole line from the plot baseline instead.\n const isMount = !hasExisting;\n\n const fromPts: Point[] = isMount ? points.map((p) => ({ x: p.x, y: options.baselineY })) : [];\n\n if (dotsGroup) {\n while (dotsGroup.children.length > points.length) dotsGroup.removeChild(dotsGroup.lastChild!);\n\n for (let i = dotsGroup.children.length; i < points.length; i++) {\n const c = createSvgElement('circle', { class: 'prism-line-dot' });\n\n setAttributes(c, {\n fill: options.color,\n opacity: marks[i]?.opacity,\n r: options.pointRadius,\n });\n dotsGroup.appendChild(c);\n }\n\n for (let i = 0; i < dotsGroup.children.length; i++) {\n setAttributes(dotsGroup.children[i] as SVGCircleElement, { opacity: marks[i]?.opacity });\n }\n }\n\n if (!isMount) {\n const drawn = drawnPoints.get(parent) ?? points;\n\n for (const [i, to] of points.entries()) {\n fromPts.push(drawn[i] ?? drawn.at(-1) ?? to);\n }\n }\n\n const paintFrame = (e: number): void => {\n const interpolated: Point[] = points.map((to, i) => {\n const from = fromPts[i] ?? to;\n\n return { x: tweenNumber(from.x, to.x, e), y: tweenNumber(from.y, to.y, e) };\n });\n\n drawnPoints.set(parent, interpolated);\n draw(interpolated);\n\n if (dotsGroup) {\n for (let i = 0; i < points.length; i++) {\n const c = dotsGroup.children[i] as SVGCircleElement | undefined;\n\n if (c) setAttributes(c, { cx: interpolated[i].x, cy: interpolated[i].y });\n }\n }\n };\n\n // The starting geometry goes on screen immediately: `startTween` only paints on\n // the first frame callback, which would otherwise leave one blank frame.\n paintFrame(0);\n\n activeAnimations.set(\n parent,\n startTween({\n count: 1,\n duration: dur,\n easing,\n onComplete: () => {\n activeAnimations.delete(parent);\n drawnPoints.set(parent, points);\n },\n onFrame: (progress) => paintFrame(progress(0)),\n signal: options.disposalSignal,\n }),\n );\n}\n\nexport function computePoints(data: ContinuousDatum[], xScale: Scale<Date | number>, yScale: Scale<number>): Point[] {\n if (data.some((d) => d.key == null)) {\n warn(\n 'computePoints: 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('computePoints: 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":"8SA2BA,IAAM,EAAmB,IAAI,QAGvB,EAAc,IAAI,QAExB,SAAS,UAAU,EAAc,EAA2C,CAC1E,OAAO,IAAU,WAAa,EAAA,aAAa,CAAG,EAAI,IAAU,OAAS,EAAA,SAAS,CAAG,EAAI,EAAA,SAAS,CAAG,CACnG,CAEA,SAAgB,WAAW,EAAqB,EAAiB,EAAkC,CACjG,IAAM,EAAS,EAAA,cAAc,EAAQ,KAAK,EACpC,EAAQ,EAAQ,OAAS,CAAC,EAC1B,EAAS,EAAA,cAAc,EAAQ,UAAU,EACzC,EAAM,EAAO,SACb,EAAS,EAAA,cAAc,EAAO,MAAM,EAEtC,EAA8B,KAC9B,EAA4B,CAAC,EAC7B,EAA6B,CAAC,EAElC,GAAI,EAAQ,CACV,EAAO,EAAA,iBAAiB,EAAO,EAAO,MAAM,EAE5C,IAAM,EAAW,CAAC,GAAG,EAAO,iBAAiC,kBAAkB,CAAC,EAEhF,IAAK,IAAM,KAAS,EAAS,MAAM,EAAK,MAAM,EAAG,EAAM,OAAO,EAE9D,EAAW,EAAK,KAAK,EAAG,IAAM,CAC5B,IAAM,EAAQ,EAAS,GAEvB,GAAI,EAAO,OAAO,EAElB,IAAM,EAAU,EAAA,iBAAiB,OAAQ,CAAE,MAAO,kBAAmB,KAAM,MAAO,CAAC,EAInF,OAFA,EAAO,YAAY,CAAO,EAEnB,CACT,CAAC,EAED,IAAK,GAAM,CAAC,EAAG,KAAQ,EAAK,QAAQ,EAClC,EAAA,cAAc,EAAS,GAAI,CACzB,QAAS,EAAI,QACb,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C,CAEA,IAAM,WAAc,GAAoB,CACtC,IAAM,EAAwB,EAAO,KAAK,EAAI,IAAM,CAClD,IAAM,EAAO,EAAQ,IAAM,EAE3B,MAAO,CAAE,EAAG,EAAA,YAAY,EAAK,EAAG,EAAG,EAAG,CAAC,EAAG,EAAG,EAAA,YAAY,EAAK,EAAG,EAAG,EAAG,CAAC,CAAE,CAC5E,CAAC,EAKD,GAHA,EAAY,IAAI,EAAQ,CAAY,EACpC,KAAK,CAAY,EAEb,EACF,IAAK,IAAI,EAAI,EAAG,EAAI,EAAO,OAAQ,IAAK,CACtC,IAAM,EAAI,EAAU,SAAS,GAEzB,GAAG,EAAA,cAAc,EAAG,CAAE,GAAI,EAAa,EAAE,CAAC,EAAG,GAAI,EAAa,EAAE,CAAC,CAAE,CAAC,CAC1E,CAEJ,EAIA,WAAW,CAAC,EAEZ,EAAiB,IACf,EACA,EAAA,WAAW,CACT,MAAO,EACP,SAAU,EACV,SACA,eAAkB,CAChB,EAAiB,OAAO,CAAM,EAC9B,EAAY,IAAI,EAAQ,CAAM,CAChC,EACA,QAAU,GAAa,WAAW,EAAS,CAAC,CAAC,EAC7C,OAAQ,EAAQ,cAClB,CAAC,CACH,CACF,CAEA,SAAgB,cAAc,EAAyB,EAA8B,EAAgC,CASnH,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,7 +1,9 @@
1
1
  import { type DatumMark } from '../../core/datum-style';
2
2
  import type { Point } from '../../svg/path';
3
- import type { ContinuousDatum, Scale, TransitionConfig } from '../../types';
3
+ import type { ContinuousDatum, Scale, TransitionOption } from '../../types';
4
4
  export interface LineRenderOptions {
5
+ /** Plot-area bottom in area-local coordinates: the mount animation raises the line from here. */
6
+ baselineY: number;
5
7
  color: string;
6
8
  curve: 'linear' | 'monotone' | 'step';
7
9
  /** Aborted when the owning chart is disposed: stops the transition's `requestAnimationFrame` loop from rescheduling. */
@@ -12,7 +14,7 @@ export interface LineRenderOptions {
12
14
  showPoints: boolean;
13
15
  /** Explicit width beats the `--prism-line-width` theme token. */
14
16
  strokeWidth?: number;
15
- transition?: TransitionConfig;
17
+ transition?: TransitionOption;
16
18
  }
17
19
  export declare function renderLine(parent: SVGGElement, points: Point[], options: LineRenderOptions): void;
18
20
  export declare function computePoints(data: ContinuousDatum[], xScale: Scale<Date | number>, yScale: Scale<number>): Point[];
@@ -1 +1 @@
1
- {"version":3,"file":"line-renderer.d.ts","sourceRoot":"","sources":["../../../src/charts/line/line-renderer.ts"],"names":[],"mappings":"AAKA,OAAO,EAAoB,KAAK,SAAS,EAAgC,MAAM,wBAAwB,CAAC;AAExG,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE5E,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAC;IACtC,wHAAwH;IACxH,cAAc,CAAC,EAAE,WAAW,CAAC;IAC7B,6FAA6F;IAC7F,KAAK,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,iEAAiE;IACjE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC/B;AAQD,wBAAgB,UAAU,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAyLjG;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,eAAe,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,IAAI,GAAG,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,EAAE,CAanH"}
1
+ {"version":3,"file":"line-renderer.d.ts","sourceRoot":"","sources":["../../../src/charts/line/line-renderer.ts"],"names":[],"mappings":"AAKA,OAAO,EAAoB,KAAK,SAAS,EAAgC,MAAM,wBAAwB,CAAC;AAExG,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE5E,MAAM,WAAW,iBAAiB;IAChC,iGAAiG;IACjG,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAC;IACtC,wHAAwH;IACxH,cAAc,CAAC,EAAE,WAAW,CAAC;IAC7B,6FAA6F;IAC7F,KAAK,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,iEAAiE;IACjE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC/B;AAWD,wBAAgB,UAAU,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAuLjG;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,eAAe,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,IAAI,GAAG,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,EAAE,CAanH"}
@@ -1,2 +1,2 @@
1
- import"../../_dev.js";import{createSvgElement as e,setAttributes as t}from"../../svg/element.js";import{resolveEasing as n}from"../../animation/easing.js";import{resolveMotion as r}from"../../animation/motion.js";import{tweenNumber as i}from"../../animation/tween.js";import{startTween as a}from"../../animation/transition.js";import{computeStyleRuns as o,hasStyledRuns as s}from"../../core/datum-style.js";import{linePath as c,monotonePath as l,stepPath as u}from"../../svg/path.js";var d=new WeakMap;function buildPath(e,t){return t===`monotone`?l(e):t===`step`?u(e):c(e)}function renderLine(c,l,u){let f=s(u.marks),p=u.marks??[],m=r(u.transition,0),h=m.duration,g=n(m.easing),_=null,v=[],y=[];if(f){v=o(p,l.length);let n=[...c.querySelectorAll(`.prism-line-path`)];for(let e of n.slice(v.length))e.remove();y=v.map((t,r)=>{let i=n[r];if(i)return i;let a=e(`path`,{class:`prism-line-path`,fill:`none`});return c.appendChild(a),a});for(let[e,n]of v.entries())t(y[e],{opacity:n.opacity,stroke:u.color,"stroke-dasharray":n.dash,"stroke-width":u.strokeWidth??2}),y[e].style.strokeWidth=u.strokeWidth===void 0?``:String(u.strokeWidth)}else{let n=[...c.querySelectorAll(`.prism-line-path`)];_=n[0]??null;for(let e of n.slice(1))e.remove();_||(_=e(`path`,{class:`prism-line-path`,fill:`none`}),c.appendChild(_)),t(_,{opacity:void 0,stroke:u.color,"stroke-dasharray":void 0,"stroke-width":u.strokeWidth??2}),_.style.strokeWidth=u.strokeWidth===void 0?``:String(u.strokeWidth)}let draw=e=>{if(f)for(let[n,r]of v.entries())t(y[n],{d:buildPath(e.slice(r.start,r.end+1),u.curve)});else t(_,{d:buildPath(e,u.curve)})},b=c.querySelector(`.prism-line-dots`);if(u.showPoints?b||(b=e(`g`,{class:`prism-line-dots`}),c.appendChild(b)):b&&=(b.remove(),null),h===0){if(draw(l),b){for(;b.children.length>l.length;)b.removeChild(b.lastChild);for(let n=0;n<l.length;n++){let r=b.children[n];r||(r=e(`circle`,{class:`prism-line-dot`}),b.appendChild(r)),t(r,{cx:l[n].x,cy:l[n].y,fill:u.color,opacity:p[n]?.opacity,r:u.pointRadius})}}return}d.get(c)?.();let x=f?y.some(e=>e.hasAttribute(`d`)):!!_?.getAttribute(`d`),S=[],C=null;if(b){let n=b.children.length;for(let e=0;e<n;e++){let t=b.children[e],n={x:Number(t.getAttribute(`cx`)),y:Number(t.getAttribute(`cy`))};S.push(n),C=n}for(;b.children.length>l.length;)b.removeChild(b.lastChild);for(let n=b.children.length;n<l.length;n++){let r=e(`circle`,{class:`prism-line-dot`});t(r,{cx:l[n].x,cy:l[n].y,fill:u.color,opacity:p[n]?.opacity,r:u.pointRadius}),b.appendChild(r)}for(let e=0;e<b.children.length;e++)t(b.children[e],{opacity:p[e]?.opacity})}for(let e=S.length;e<l.length;e++)S.push(C??l[e]);if(!x){draw(l);return}d.set(c,a({count:1,duration:h,easing:g,onComplete:()=>d.delete(c),onFrame:e=>{let n=e(0),r=l.map((e,t)=>{let r=S[t]??e;return{x:i(r.x,e.x,n),y:i(r.y,e.y,n)}});if(draw(r),b)for(let e=0;e<l.length;e++){let n=b.children[e];n&&t(n,{cx:r[e].x,cy:r[e].y})}},signal:u.disposalSignal}))}function computePoints(e,t,n){return e.some(e=>e.key==null)||e.some(e=>typeof e.key==`string`),e.map(e=>({x:t.map(e.key),y:n.map(e.value)}))}export{computePoints,renderLine};
1
+ import"../../_dev.js";import{createSvgElement as e,setAttributes as t}from"../../svg/element.js";import{resolveEasing as n}from"../../animation/easing.js";import{resolveMotion as r}from"../../animation/motion.js";import{tweenNumber as i}from"../../animation/tween.js";import{startTween as a}from"../../animation/transition.js";import{computeStyleRuns as o,hasStyledRuns as s}from"../../core/datum-style.js";import{linePath as c,monotonePath as l,stepPath as u}from"../../svg/path.js";var d=new WeakMap,f=new WeakMap;function buildPath(e,t){return t===`monotone`?l(e):t===`step`?u(e):c(e)}function renderLine(c,l,u){let p=s(u.marks),m=u.marks??[],h=r(u.transition),g=h.duration,_=n(h.easing),v=null,y=[],b=[];if(p){y=o(m,l.length);let n=[...c.querySelectorAll(`.prism-line-path`)];for(let e of n.slice(y.length))e.remove();b=y.map((t,r)=>{let i=n[r];if(i)return i;let a=e(`path`,{class:`prism-line-path`,fill:`none`});return c.appendChild(a),a});for(let[e,n]of y.entries())t(b[e],{opacity:n.opacity,stroke:u.color,"stroke-dasharray":n.dash,"stroke-width":u.strokeWidth??2}),b[e].style.strokeWidth=u.strokeWidth===void 0?``:String(u.strokeWidth)}else{let n=[...c.querySelectorAll(`.prism-line-path`)];v=n[0]??null;for(let e of n.slice(1))e.remove();v||(v=e(`path`,{class:`prism-line-path`,fill:`none`}),c.appendChild(v)),t(v,{opacity:void 0,stroke:u.color,"stroke-dasharray":void 0,"stroke-width":u.strokeWidth??2}),v.style.strokeWidth=u.strokeWidth===void 0?``:String(u.strokeWidth)}let draw=e=>{if(p)for(let[n,r]of y.entries())t(b[n],{d:buildPath(e.slice(r.start,r.end+1),u.curve)});else t(v,{d:buildPath(e,u.curve)})},x=c.querySelector(`.prism-line-dots`);if(u.showPoints?x||(x=e(`g`,{class:`prism-line-dots`}),c.appendChild(x)):x&&=(x.remove(),null),g===0){if(draw(l),f.set(c,l),x){for(;x.children.length>l.length;)x.removeChild(x.lastChild);for(let n=0;n<l.length;n++){let r=x.children[n];r||(r=e(`circle`,{class:`prism-line-dot`}),x.appendChild(r)),t(r,{cx:l[n].x,cy:l[n].y,fill:u.color,opacity:m[n]?.opacity,r:u.pointRadius})}}return}d.get(c)?.();let S=!f.has(c),C=S?l.map(e=>({x:e.x,y:u.baselineY})):[];if(x){for(;x.children.length>l.length;)x.removeChild(x.lastChild);for(let n=x.children.length;n<l.length;n++){let r=e(`circle`,{class:`prism-line-dot`});t(r,{fill:u.color,opacity:m[n]?.opacity,r:u.pointRadius}),x.appendChild(r)}for(let e=0;e<x.children.length;e++)t(x.children[e],{opacity:m[e]?.opacity})}if(!S){let e=f.get(c)??l;for(let[t,n]of l.entries())C.push(e[t]??e.at(-1)??n)}let paintFrame=e=>{let n=l.map((t,n)=>{let r=C[n]??t;return{x:i(r.x,t.x,e),y:i(r.y,t.y,e)}});if(f.set(c,n),draw(n),x)for(let e=0;e<l.length;e++){let r=x.children[e];r&&t(r,{cx:n[e].x,cy:n[e].y})}};paintFrame(0),d.set(c,a({count:1,duration:g,easing:_,onComplete:()=>{d.delete(c),f.set(c,l)},onFrame:e=>paintFrame(e(0)),signal:u.disposalSignal}))}function computePoints(e,t,n){return e.some(e=>e.key==null)||e.some(e=>typeof e.key==`string`),e.map(e=>({x:t.map(e.key),y:n.map(e.value)}))}export{computePoints,renderLine};
2
2
  //# sourceMappingURL=line-renderer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"line-renderer.js","names":[],"sources":["../../../src/charts/line/line-renderer.ts"],"sourcesContent":["import { warn } from '../../_dev';\nimport { resolveEasing } from '../../animation/easing';\nimport { resolveMotion } from '../../animation/motion';\nimport { startTween } from '../../animation/transition';\nimport { tweenNumber } from '../../animation/tween';\nimport { computeStyleRuns, type DatumMark, hasStyledRuns, type StyleRun } from '../../core/datum-style';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport type { Point } from '../../svg/path';\nimport { linePath, monotonePath, stepPath } from '../../svg/path';\nimport type { ContinuousDatum, Scale, TransitionConfig } from '../../types';\n\nexport interface LineRenderOptions {\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 /** Per-datum presentation parallel to `points`; styled runs split the line into subpaths. */\n marks?: readonly DatumMark[];\n pointRadius: number;\n showPoints: boolean;\n /** Explicit width beats the `--prism-line-width` theme token. */\n strokeWidth?: number;\n transition?: TransitionConfig;\n}\n\nconst activeAnimations = new WeakMap<SVGGElement, () => void>();\n\nfunction buildPath(pts: Point[], curve: LineRenderOptions['curve']): string {\n return curve === 'monotone' ? monotonePath(pts) : curve === 'step' ? stepPath(pts) : linePath(pts);\n}\n\nexport function renderLine(parent: SVGGElement, points: Point[], options: LineRenderOptions): void {\n const styled = hasStyledRuns(options.marks);\n const marks = options.marks ?? [];\n const motion = resolveMotion(options.transition, 0);\n const dur = motion.duration;\n const easing = resolveEasing(motion.easing);\n\n let path: SVGPathElement | null = null;\n let runs: readonly StyleRun[] = [];\n let runPaths: SVGPathElement[] = [];\n\n if (styled) {\n runs = computeStyleRuns(marks, points.length);\n\n const existing = [...parent.querySelectorAll<SVGPathElement>('.prism-line-path')];\n\n for (const extra of existing.slice(runs.length)) extra.remove();\n\n runPaths = runs.map((_, r) => {\n const reuse = existing[r];\n\n if (reuse) return reuse;\n\n const created = createSvgElement('path', { class: 'prism-line-path', fill: 'none' });\n\n parent.appendChild(created);\n\n return created;\n });\n\n for (const [r, run] of runs.entries()) {\n setAttributes(runPaths[r], {\n opacity: run.opacity,\n stroke: options.color,\n 'stroke-dasharray': run.dash,\n 'stroke-width': options.strokeWidth ?? 2,\n });\n runPaths[r].style.strokeWidth = options.strokeWidth === undefined ? '' : String(options.strokeWidth);\n }\n } else {\n const existing = [...parent.querySelectorAll<SVGPathElement>('.prism-line-path')];\n\n path = existing[0] ?? null;\n\n for (const stale of existing.slice(1)) stale.remove();\n\n if (!path) {\n path = createSvgElement('path', { class: 'prism-line-path', fill: 'none' });\n parent.appendChild(path);\n }\n\n setAttributes(path, {\n opacity: undefined,\n stroke: options.color,\n 'stroke-dasharray': undefined,\n 'stroke-width': options.strokeWidth ?? 2,\n });\n path.style.strokeWidth = options.strokeWidth === undefined ? '' : String(options.strokeWidth);\n }\n\n const draw = (pts: Point[]): void => {\n if (styled) {\n for (const [r, run] of runs.entries()) {\n setAttributes(runPaths[r], { d: buildPath(pts.slice(run.start, run.end + 1), options.curve) });\n }\n } else {\n setAttributes(path!, { d: buildPath(pts, options.curve) });\n }\n };\n\n let dotsGroup = parent.querySelector<SVGGElement>('.prism-line-dots');\n\n if (options.showPoints) {\n if (!dotsGroup) {\n dotsGroup = createSvgElement('g', { class: 'prism-line-dots' });\n parent.appendChild(dotsGroup);\n }\n } else if (dotsGroup) {\n dotsGroup.remove();\n dotsGroup = null;\n }\n\n if (dur === 0) {\n draw(points);\n\n if (dotsGroup) {\n while (dotsGroup.children.length > points.length) dotsGroup.removeChild(dotsGroup.lastChild!);\n\n for (let i = 0; i < points.length; i++) {\n let c = dotsGroup.children[i] as SVGCircleElement | undefined;\n\n if (!c) {\n c = createSvgElement('circle', { class: 'prism-line-dot' });\n dotsGroup.appendChild(c);\n }\n\n setAttributes(c, {\n cx: points[i].x,\n cy: points[i].y,\n fill: options.color,\n opacity: marks[i]?.opacity,\n r: options.pointRadius,\n });\n }\n }\n\n return;\n }\n\n activeAnimations.get(parent)?.();\n\n const hasExisting = styled ? runPaths.some((p) => p.hasAttribute('d')) : !!path?.getAttribute('d');\n\n const fromPts: Point[] = [];\n let lastKnown: Point | null = null;\n\n if (dotsGroup) {\n const existingCount = dotsGroup.children.length;\n\n for (let i = 0; i < existingCount; i++) {\n const c = dotsGroup.children[i] as SVGCircleElement;\n const pt = { x: Number(c.getAttribute('cx')), y: Number(c.getAttribute('cy')) };\n\n fromPts.push(pt);\n lastKnown = pt;\n }\n\n while (dotsGroup.children.length > points.length) dotsGroup.removeChild(dotsGroup.lastChild!);\n\n for (let i = dotsGroup.children.length; i < points.length; i++) {\n const c = createSvgElement('circle', { class: 'prism-line-dot' });\n\n setAttributes(c, {\n cx: points[i].x,\n cy: points[i].y,\n fill: options.color,\n opacity: marks[i]?.opacity,\n r: options.pointRadius,\n });\n dotsGroup.appendChild(c);\n }\n\n for (let i = 0; i < dotsGroup.children.length; i++) {\n setAttributes(dotsGroup.children[i] as SVGCircleElement, { opacity: marks[i]?.opacity });\n }\n }\n\n for (let i = fromPts.length; i < points.length; i++) {\n fromPts.push(lastKnown ?? points[i]);\n }\n\n if (!hasExisting) {\n draw(points);\n\n return;\n }\n\n activeAnimations.set(\n parent,\n startTween({\n count: 1,\n duration: dur,\n easing,\n onComplete: () => activeAnimations.delete(parent),\n onFrame: (progress) => {\n const e = progress(0);\n const interpolated: Point[] = points.map((to, i) => {\n const from = fromPts[i] ?? to;\n\n return { x: tweenNumber(from.x, to.x, e), y: tweenNumber(from.y, to.y, e) };\n });\n\n draw(interpolated);\n\n if (dotsGroup) {\n for (let i = 0; i < points.length; i++) {\n const c = dotsGroup.children[i] as SVGCircleElement | undefined;\n\n if (c) setAttributes(c, { cx: interpolated[i].x, cy: interpolated[i].y });\n }\n }\n },\n signal: options.disposalSignal,\n }),\n );\n}\n\nexport function computePoints(data: ContinuousDatum[], xScale: Scale<Date | number>, yScale: Scale<number>): Point[] {\n if (data.some((d) => d.key == null)) {\n warn(\n 'computePoints: 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('computePoints: string keys are not supported for line/area charts: use numeric or Date keys.');\n }\n\n return data.map((d) => ({\n x: xScale.map(d.key as Date | number),\n y: yScale.map(d.value),\n }));\n}\n"],"mappings":"oeAyBA,IAAM,EAAmB,IAAI,QAE7B,SAAS,UAAU,EAAc,EAA2C,CAC1E,OAAO,IAAU,WAAa,EAAa,CAAG,EAAI,IAAU,OAAS,EAAS,CAAG,EAAI,EAAS,CAAG,CACnG,CAEA,SAAgB,WAAW,EAAqB,EAAiB,EAAkC,CACjG,IAAM,EAAS,EAAc,EAAQ,KAAK,EACpC,EAAQ,EAAQ,OAAS,CAAC,EAC1B,EAAS,EAAc,EAAQ,WAAY,CAAC,EAC5C,EAAM,EAAO,SACb,EAAS,EAAc,EAAO,MAAM,EAEtC,EAA8B,KAC9B,EAA4B,CAAC,EAC7B,EAA6B,CAAC,EAElC,GAAI,EAAQ,CACV,EAAO,EAAiB,EAAO,EAAO,MAAM,EAE5C,IAAM,EAAW,CAAC,GAAG,EAAO,iBAAiC,kBAAkB,CAAC,EAEhF,IAAK,IAAM,KAAS,EAAS,MAAM,EAAK,MAAM,EAAG,EAAM,OAAO,EAE9D,EAAW,EAAK,KAAK,EAAG,IAAM,CAC5B,IAAM,EAAQ,EAAS,GAEvB,GAAI,EAAO,OAAO,EAElB,IAAM,EAAU,EAAiB,OAAQ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"line-renderer.js","names":[],"sources":["../../../src/charts/line/line-renderer.ts"],"sourcesContent":["import { warn } from '../../_dev';\nimport { resolveEasing } from '../../animation/easing';\nimport { resolveMotion } from '../../animation/motion';\nimport { startTween } from '../../animation/transition';\nimport { tweenNumber } from '../../animation/tween';\nimport { computeStyleRuns, type DatumMark, hasStyledRuns, type StyleRun } from '../../core/datum-style';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport type { Point } from '../../svg/path';\nimport { linePath, monotonePath, stepPath } from '../../svg/path';\nimport type { ContinuousDatum, Scale, TransitionOption } from '../../types';\n\nexport interface LineRenderOptions {\n /** Plot-area bottom in area-local coordinates: the mount animation raises the line from here. */\n baselineY: number;\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 /** Per-datum presentation parallel to `points`; styled runs split the line into subpaths. */\n marks?: readonly DatumMark[];\n pointRadius: number;\n showPoints: boolean;\n /** Explicit width beats the `--prism-line-width` theme token. */\n strokeWidth?: number;\n transition?: TransitionOption;\n}\n\nconst activeAnimations = new WeakMap<SVGGElement, () => void>();\n// Geometry currently on screen, so an update interpolates from it even when the\n// series hides its point markers (the dots would otherwise be the only record).\nconst drawnPoints = new WeakMap<SVGGElement, Point[]>();\n\nfunction buildPath(pts: Point[], curve: LineRenderOptions['curve']): string {\n return curve === 'monotone' ? monotonePath(pts) : curve === 'step' ? stepPath(pts) : linePath(pts);\n}\n\nexport function renderLine(parent: SVGGElement, points: Point[], options: LineRenderOptions): void {\n const styled = hasStyledRuns(options.marks);\n const marks = options.marks ?? [];\n const motion = resolveMotion(options.transition);\n const dur = motion.duration;\n const easing = resolveEasing(motion.easing);\n\n let path: SVGPathElement | null = null;\n let runs: readonly StyleRun[] = [];\n let runPaths: SVGPathElement[] = [];\n\n if (styled) {\n runs = computeStyleRuns(marks, points.length);\n\n const existing = [...parent.querySelectorAll<SVGPathElement>('.prism-line-path')];\n\n for (const extra of existing.slice(runs.length)) extra.remove();\n\n runPaths = runs.map((_, r) => {\n const reuse = existing[r];\n\n if (reuse) return reuse;\n\n const created = createSvgElement('path', { class: 'prism-line-path', fill: 'none' });\n\n parent.appendChild(created);\n\n return created;\n });\n\n for (const [r, run] of runs.entries()) {\n setAttributes(runPaths[r], {\n opacity: run.opacity,\n stroke: options.color,\n 'stroke-dasharray': run.dash,\n 'stroke-width': options.strokeWidth ?? 2,\n });\n runPaths[r].style.strokeWidth = options.strokeWidth === undefined ? '' : String(options.strokeWidth);\n }\n } else {\n const existing = [...parent.querySelectorAll<SVGPathElement>('.prism-line-path')];\n\n path = existing[0] ?? null;\n\n for (const stale of existing.slice(1)) stale.remove();\n\n if (!path) {\n path = createSvgElement('path', { class: 'prism-line-path', fill: 'none' });\n parent.appendChild(path);\n }\n\n setAttributes(path, {\n opacity: undefined,\n stroke: options.color,\n 'stroke-dasharray': undefined,\n 'stroke-width': options.strokeWidth ?? 2,\n });\n path.style.strokeWidth = options.strokeWidth === undefined ? '' : String(options.strokeWidth);\n }\n\n const draw = (pts: Point[]): void => {\n if (styled) {\n for (const [r, run] of runs.entries()) {\n setAttributes(runPaths[r], { d: buildPath(pts.slice(run.start, run.end + 1), options.curve) });\n }\n } else {\n setAttributes(path!, { d: buildPath(pts, options.curve) });\n }\n };\n\n let dotsGroup = parent.querySelector<SVGGElement>('.prism-line-dots');\n\n if (options.showPoints) {\n if (!dotsGroup) {\n dotsGroup = createSvgElement('g', { class: 'prism-line-dots' });\n parent.appendChild(dotsGroup);\n }\n } else if (dotsGroup) {\n dotsGroup.remove();\n dotsGroup = null;\n }\n\n if (dur === 0) {\n draw(points);\n drawnPoints.set(parent, points);\n\n if (dotsGroup) {\n while (dotsGroup.children.length > points.length) dotsGroup.removeChild(dotsGroup.lastChild!);\n\n for (let i = 0; i < points.length; i++) {\n let c = dotsGroup.children[i] as SVGCircleElement | undefined;\n\n if (!c) {\n c = createSvgElement('circle', { class: 'prism-line-dot' });\n dotsGroup.appendChild(c);\n }\n\n setAttributes(c, {\n cx: points[i].x,\n cy: points[i].y,\n fill: options.color,\n opacity: marks[i]?.opacity,\n r: options.pointRadius,\n });\n }\n }\n\n return;\n }\n\n activeAnimations.get(parent)?.();\n\n const hasExisting = drawnPoints.has(parent);\n // A first render has no drawn shape to interpolate between: the mount animation\n // raises the whole line from the plot baseline instead.\n const isMount = !hasExisting;\n\n const fromPts: Point[] = isMount ? points.map((p) => ({ x: p.x, y: options.baselineY })) : [];\n\n if (dotsGroup) {\n while (dotsGroup.children.length > points.length) dotsGroup.removeChild(dotsGroup.lastChild!);\n\n for (let i = dotsGroup.children.length; i < points.length; i++) {\n const c = createSvgElement('circle', { class: 'prism-line-dot' });\n\n setAttributes(c, {\n fill: options.color,\n opacity: marks[i]?.opacity,\n r: options.pointRadius,\n });\n dotsGroup.appendChild(c);\n }\n\n for (let i = 0; i < dotsGroup.children.length; i++) {\n setAttributes(dotsGroup.children[i] as SVGCircleElement, { opacity: marks[i]?.opacity });\n }\n }\n\n if (!isMount) {\n const drawn = drawnPoints.get(parent) ?? points;\n\n for (const [i, to] of points.entries()) {\n fromPts.push(drawn[i] ?? drawn.at(-1) ?? to);\n }\n }\n\n const paintFrame = (e: number): void => {\n const interpolated: Point[] = points.map((to, i) => {\n const from = fromPts[i] ?? to;\n\n return { x: tweenNumber(from.x, to.x, e), y: tweenNumber(from.y, to.y, e) };\n });\n\n drawnPoints.set(parent, interpolated);\n draw(interpolated);\n\n if (dotsGroup) {\n for (let i = 0; i < points.length; i++) {\n const c = dotsGroup.children[i] as SVGCircleElement | undefined;\n\n if (c) setAttributes(c, { cx: interpolated[i].x, cy: interpolated[i].y });\n }\n }\n };\n\n // The starting geometry goes on screen immediately: `startTween` only paints on\n // the first frame callback, which would otherwise leave one blank frame.\n paintFrame(0);\n\n activeAnimations.set(\n parent,\n startTween({\n count: 1,\n duration: dur,\n easing,\n onComplete: () => {\n activeAnimations.delete(parent);\n drawnPoints.set(parent, points);\n },\n onFrame: (progress) => paintFrame(progress(0)),\n signal: options.disposalSignal,\n }),\n );\n}\n\nexport function computePoints(data: ContinuousDatum[], xScale: Scale<Date | number>, yScale: Scale<number>): Point[] {\n if (data.some((d) => d.key == null)) {\n warn(\n 'computePoints: 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('computePoints: 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":"oeA2BA,IAAM,EAAmB,IAAI,QAGvB,EAAc,IAAI,QAExB,SAAS,UAAU,EAAc,EAA2C,CAC1E,OAAO,IAAU,WAAa,EAAa,CAAG,EAAI,IAAU,OAAS,EAAS,CAAG,EAAI,EAAS,CAAG,CACnG,CAEA,SAAgB,WAAW,EAAqB,EAAiB,EAAkC,CACjG,IAAM,EAAS,EAAc,EAAQ,KAAK,EACpC,EAAQ,EAAQ,OAAS,CAAC,EAC1B,EAAS,EAAc,EAAQ,UAAU,EACzC,EAAM,EAAO,SACb,EAAS,EAAc,EAAO,MAAM,EAEtC,EAA8B,KAC9B,EAA4B,CAAC,EAC7B,EAA6B,CAAC,EAElC,GAAI,EAAQ,CACV,EAAO,EAAiB,EAAO,EAAO,MAAM,EAE5C,IAAM,EAAW,CAAC,GAAG,EAAO,iBAAiC,kBAAkB,CAAC,EAEhF,IAAK,IAAM,KAAS,EAAS,MAAM,EAAK,MAAM,EAAG,EAAM,OAAO,EAE9D,EAAW,EAAK,KAAK,EAAG,IAAM,CAC5B,IAAM,EAAQ,EAAS,GAEvB,GAAI,EAAO,OAAO,EAElB,IAAM,EAAU,EAAiB,OAAQ,CAAE,MAAO,kBAAmB,KAAM,MAAO,CAAC,EAInF,OAFA,EAAO,YAAY,CAAO,EAEnB,CACT,CAAC,EAED,IAAK,GAAM,CAAC,EAAG,KAAQ,EAAK,QAAQ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Ac,GAAoB,CACtC,IAAM,EAAwB,EAAO,KAAK,EAAI,IAAM,CAClD,IAAM,EAAO,EAAQ,IAAM,EAE3B,MAAO,CAAE,EAAG,EAAY,EAAK,EAAG,EAAG,EAAG,CAAC,EAAG,EAAG,EAAY,EAAK,EAAG,EAAG,EAAG,CAAC,CAAE,CAC5E,CAAC,EAKD,GAHA,EAAY,IAAI,EAAQ,CAAY,EACpC,KAAK,CAAY,EAEb,EACF,IAAK,IAAI,EAAI,EAAG,EAAI,EAAO,OAAQ,IAAK,CACtC,IAAM,EAAI,EAAU,SAAS,GAEzB,GAAG,EAAc,EAAG,CAAE,GAAI,EAAa,EAAE,CAAC,EAAG,GAAI,EAAa,EAAE,CAAC,CAAE,CAAC,CAC1E,CAEJ,EAIA,WAAW,CAAC,EAEZ,EAAiB,IACf,EACA,EAAW,CACT,MAAO,EACP,SAAU,EACV,SACA,eAAkB,CAChB,EAAiB,OAAO,CAAM,EAC9B,EAAY,IAAI,EAAQ,CAAM,CAChC,EACA,QAAU,GAAa,WAAW,EAAS,CAAC,CAAC,EAC7C,OAAQ,EAAQ,cAClB,CAAC,CACH,CACF,CAEA,SAAgB,cAAc,EAAyB,EAA8B,EAAgC,CASnH,OARI,EAAK,KAAM,GAAM,EAAE,KAAO,IAAI,GAIvB,EAAK,KAAM,GAAM,OAAO,EAAE,KAAQ,QAAQ,EAI9C,EAAK,IAAK,IAAO,CACtB,EAAG,EAAO,IAAI,EAAE,GAAoB,EACpC,EAAG,EAAO,IAAI,EAAE,KAAK,CACvB,EAAE,CACJ"}
@@ -1,2 +1,2 @@
1
- const e=require("../../svg/element.cjs"),t=require("../../svg/text.cjs"),n=require("../../core/chart-scaffold.cjs"),r=require("../../theme/index.cjs"),i=require("../../animation/easing.cjs"),a=require("../../animation/motion.cjs"),o=require("../../animation/tween.cjs"),s=require("../../animation/transition.cjs"),c=require("./pie-renderer.cjs");var l=2*Math.PI,u=12;function labelFits(e,n){let r=e.outerRadius-e.innerRadius,i=(e.outerRadius+e.innerRadius)/2,a=(e.endAngle-e.startAngle-2*e.padAngle)*i;return r>=u*1.4&&a>=t.estimateTextWidth(n,u)+8}var d=-Math.PI/2,f=Math.PI/2;function semiAngles(e){return e===`semi`?{end:f,start:d}:{end:l,start:0}}function createPieChart(t,l){let u=l.variant??`pie`,d=l.padPixels??(u===`pie`?0:8),f=l.cornerRadius??(u===`pie`?0:8),p=l.data,m=e.createSvgElement(`circle`,{class:`prism-pie-bg`,"pointer-events":`none`}),h=e.createSvgElement(`g`,{class:`prism-pie-slices`,"shape-rendering":`geometricPrecision`}),g=e.createSvgElement(`g`,{class:`prism-pie-labels`,"pointer-events":`none`}),_=[],v=null;function renderLabels(t){g.replaceChildren();for(let n=0;n<_.length;n++){let r=_[n],i=t[n];if(!i?.label||!labelFits(r,i.label))continue;let{x:a,y:o}=c.arcCentroid(r),s=e.createSvgElement(`text`,{class:`prism-pie-label`});e.setAttributes(s,{"dominant-baseline":`middle`,fill:`var(--prism-pie-label-color, #fff)`,"font-family":`var(--prism-font-family, system-ui)`,"font-size":`var(--prism-pie-label-size, 12px)`,"text-anchor":`middle`,x:a,y:o}),s.textContent=i.label,g.appendChild(s)}}return n.createRadialScaffold(t,{a11y:l.a11y,legend:l.legend,tooltip:l.tooltip},n=>{let{legend:y,svg:b,tooltip:x}=n;b.contains(m)||(b.appendChild(m),b.appendChild(h),b.appendChild(g));let{height:S,width:C}=n.dimensions,w=u===`semi`,T=C/2,E=w?S*.85:S/2,D=w?Math.min(T,E)-8:Math.min(C,S)/2-8,O=u===`pie`?0:Math.round(D*.55),k=l.innerRadius===void 0?O:l.innerRadius,A=Math.max(k+1,D),j=p,{end:M,start:N}=semiAngles(u);for(_=c.computeArcs(j,T,E,A,k,N,M,d,f,e=>r.seriesColor(e),!1),e.setAttributes(m,{cx:T,cy:E,r:k>0?k:0}),m.setAttribute(`style`,`fill:var(--prism-bg,#fff)`);h.children.length>_.length;)h.removeChild(h.lastChild);g.replaceChildren();let P=a.resolveMotion(l.transition,0),F=P.duration,I=i.resolveEasing(P.easing);for(let t=0;t<_.length;t++){let n=_[t],r=h.children[t];r||(r=e.createSvgElement(`path`,{class:`prism-pie-slice`}),h.appendChild(r)),r.setAttribute(`fill`,n.color),r.setAttribute(`stroke`,`none`),r.style.cursor=l.onClick||l.onHover?`pointer`:``}v?.(),v=s.startTween({count:1,duration:F,easing:I,onComplete:()=>renderLabels(j),onFrame:t=>{let n=o.tweenNumber(N,M,t(0));for(let t=0;t<_.length;t++){let r=_[t],i=h.children[t];if(i){if(n<=r.startAngle)e.setAttributes(i,{d:``});else{let t=Math.min(r.endAngle,n);e.setAttributes(i,{d:c.arcPath({...r,endAngle:t})})}}}},signal:n.disposalSignal}),y?.update(_.map(e=>({color:e.color,name:e.slice.label??``}))),x?.hide();let L=_.reduce((e,t)=>e+Math.max(0,t.slice.value),0),R=-1,describe=e=>{let t=L>0?Math.round(Math.max(0,e.slice.value)/L*1e3)/10:0;return`${e.slice.label??`Slice ${e.index+1}`}: ${e.slice.value} (${t}%)`},setActive=e=>{R=e,h.classList.toggle(`prism-pie-focused`,e>=0);for(let[t,n]of[...h.children].entries())n.classList.toggle(`prism-pie-slice--active`,t===e)},activate=(e,r)=>{let i=_[e];if(!i)return;setActive(e),l.onHover?.({index:e,originalEvent:r,slice:i.slice});let a=describe(i);if(!x){n.announcer.announce(a);return}let{x:o,y:s}=c.arcCentroid(i),u=b.getBoundingClientRect(),d=t.getBoundingClientRect();x.show(o+(u.left-d.left),s+(u.top-d.top),{key:e,value:i.slice.value},{color:i.color,data:[],name:i.slice.label??``},a)},deactivate=()=>{setActive(-1),x?.hide(),n.announcer.clear(),l.onHover?.(null)},hitAt=e=>{let t=b.getBoundingClientRect();return hitTestArc(_,e.clientX-t.left,e.clientY-t.top,u)},onMouseMove=e=>{let t=hitAt(e);t>=0?t!==R&&activate(t,e):R>=0&&deactivate()},onClick=e=>{if(!l.onClick)return;let t=hitAt(e);t>=0&&l.onClick({index:t,originalEvent:e,slice:_[t].slice})},onKeyDown=e=>{let t=_.length;if(t===0)return;let n={ArrowDown:1,ArrowLeft:-1,ArrowRight:1,ArrowUp:-1};e.key in n?(e.preventDefault(),activate(R<0?n[e.key]>0?0:t-1:(R+n[e.key]+t)%t,e)):e.key===`Home`||e.key===`End`?(e.preventDefault(),activate(e.key===`Home`?0:t-1,e)):(e.key===`Enter`||e.key===` `)&&R>=0&&l.onClick?(e.preventDefault(),l.onClick({index:R,originalEvent:e,slice:_[R].slice})):e.key===`Escape`&&deactivate()};return{onClick,onKeyDown,onMouseLeave:deactivate,onMouseMove}},e=>{p=e})}function hitTestArc(e,t,n,r){for(let i=0;i<e.length;i++){let a=e[i],o=t-a.centerX,s=n-a.centerY,c=Math.sqrt(o*o+s*s);if(c<a.outerRadius&&c>=a.innerRadius){let e=Math.atan2(o,-s);if(r===`semi`){if(e>=a.startAngle-1e-9&&e<=a.endAngle+1e-9)return i}else{let t=e<0?e+l:e;if(t>=a.startAngle-1e-9&&t<=a.endAngle+1e-9)return i}}}return-1}exports.createPieChart=createPieChart;
1
+ const e=require("../../svg/element.cjs"),t=require("../../svg/text.cjs"),n=require("../../core/chart-scaffold.cjs"),r=require("../../theme/index.cjs"),i=require("../../animation/easing.cjs"),a=require("../../animation/motion.cjs"),o=require("../../animation/tween.cjs"),s=require("../../animation/transition.cjs"),c=require("./pie-renderer.cjs");var l=2*Math.PI,u=12;function labelFits(e,n){let r=e.outerRadius-e.innerRadius,i=(e.outerRadius+e.innerRadius)/2,a=(e.endAngle-e.startAngle-2*e.padAngle)*i;return r>=u*1.4&&a>=t.estimateTextWidth(n,u)+8}var d=-Math.PI/2,f=Math.PI/2;function semiAngles(e){return e===`semi`?{end:f,start:d}:{end:l,start:0}}function createPieChart(t,l){let u=l.variant??`pie`,d=l.padPixels??(u===`pie`?0:8),f=l.cornerRadius??(u===`pie`?0:8),p=l.data,m=e.createSvgElement(`circle`,{class:`prism-pie-bg`,"pointer-events":`none`}),h=e.createSvgElement(`g`,{class:`prism-pie-slices`,"shape-rendering":`geometricPrecision`}),g=e.createSvgElement(`g`,{class:`prism-pie-labels`,"pointer-events":`none`}),_=[],v=[],y=null;function renderLabels(t){g.replaceChildren();for(let n=0;n<_.length;n++){let r=_[n],i=t[n];if(!i?.label||!labelFits(r,i.label))continue;let{x:a,y:o}=c.arcCentroid(r),s=e.createSvgElement(`text`,{class:`prism-pie-label`});e.setAttributes(s,{"dominant-baseline":`middle`,fill:`var(--prism-pie-label-color, #fff)`,"font-family":`var(--prism-font-family, system-ui)`,"font-size":`var(--prism-pie-label-size, 12px)`,"text-anchor":`middle`,x:a,y:o}),s.textContent=i.label,g.appendChild(s)}}return n.createRadialScaffold(t,{a11y:l.a11y,legend:l.legend,tooltip:l.tooltip},n=>{let{legend:b,svg:x,tooltip:S}=n;x.contains(m)||(x.appendChild(m),x.appendChild(h),x.appendChild(g));let{height:C,width:w}=n.dimensions,T=u===`semi`,E=w/2,D=T?C*.85:C/2,O=T?Math.min(E,D)-8:Math.min(w,C)/2-8,k=u===`pie`?0:Math.round(O*.55),A=l.innerRadius===void 0?k:l.innerRadius,j=Math.max(A+1,O),M=p,{end:N,start:P}=semiAngles(u);for(_=c.computeArcs(M,E,D,j,A,P,N,d,f,e=>r.seriesColor(e),!1),e.setAttributes(m,{cx:E,cy:D,r:A>0?A:0}),m.setAttribute(`style`,`fill:var(--prism-bg,#fff)`);h.children.length>_.length;)h.removeChild(h.lastChild);g.replaceChildren();let F=a.resolveMotion(l.transition),I=F.duration,L=i.resolveEasing(F.easing);for(let t=0;t<_.length;t++){let n=_[t],r=h.children[t];r||(r=e.createSvgElement(`path`,{class:`prism-pie-slice`}),h.appendChild(r)),r.setAttribute(`fill`,n.color),r.setAttribute(`stroke`,`none`),r.style.cursor=l.onClick||l.onHover?`pointer`:``}y?.();let R=v.length===0,z=v;y=s.startTween({count:1,duration:I,easing:L,onComplete:()=>renderLabels(M),onFrame:t=>{let n=t(0);if(R){let t=o.tweenNumber(P,N,n);v=_.map((n,r)=>{let i=h.children[r];if(!i)return n;if(t<=n.startAngle)return e.setAttributes(i,{d:``}),{...n,endAngle:n.startAngle};let a=Math.min(n.endAngle,t);return e.setAttributes(i,{d:c.arcPath({...n,endAngle:a})}),{...n,endAngle:a}});return}v=_.map((t,r)=>{let i=h.children[r],a=z.at(-1),s=z[r]??{...t,endAngle:a?.endAngle??P,startAngle:a?.endAngle??P},l={...t,endAngle:o.tweenNumber(s.endAngle,t.endAngle,n),innerRadius:o.tweenNumber(s.innerRadius,t.innerRadius,n),outerRadius:o.tweenNumber(s.outerRadius,t.outerRadius,n),padAngle:o.tweenNumber(s.padAngle,t.padAngle,n),startAngle:o.tweenNumber(s.startAngle,t.startAngle,n)};return i&&e.setAttributes(i,{d:l.endAngle-l.startAngle<=1e-6?``:c.arcPath(l)}),l})},signal:n.disposalSignal}),b?.update(_.map(e=>({color:e.color,name:e.slice.label??``}))),S?.hide();let B=_.reduce((e,t)=>e+Math.max(0,t.slice.value),0),V=-1,describe=e=>{let t=B>0?Math.round(Math.max(0,e.slice.value)/B*1e3)/10:0;return`${e.slice.label??`Slice ${e.index+1}`}: ${e.slice.value} (${t}%)`},setActive=e=>{V=e,h.classList.toggle(`prism-pie-focused`,e>=0);for(let[t,n]of[...h.children].entries())n.classList.toggle(`prism-pie-slice--active`,t===e)},activate=(e,r)=>{let i=_[e];if(!i)return;setActive(e),l.onHover?.({index:e,originalEvent:r,slice:i.slice});let a=describe(i);if(!S){n.announcer.announce(a);return}let{x:o,y:s}=c.arcCentroid(i),u=x.getBoundingClientRect(),d=t.getBoundingClientRect();S.show(o+(u.left-d.left),s+(u.top-d.top),{key:e,value:i.slice.value},{color:i.color,data:[],name:i.slice.label??``},a)},deactivate=()=>{setActive(-1),S?.hide(),n.announcer.clear(),l.onHover?.(null)},hitAt=e=>{let t=x.getBoundingClientRect();return hitTestArc(_,e.clientX-t.left,e.clientY-t.top,u)},onMouseMove=e=>{let t=hitAt(e);t>=0?t!==V&&activate(t,e):V>=0&&deactivate()},onClick=e=>{if(!l.onClick)return;let t=hitAt(e);t>=0&&l.onClick({index:t,originalEvent:e,slice:_[t].slice})},onKeyDown=e=>{let t=_.length;if(t===0)return;let n={ArrowDown:1,ArrowLeft:-1,ArrowRight:1,ArrowUp:-1};e.key in n?(e.preventDefault(),activate(V<0?n[e.key]>0?0:t-1:(V+n[e.key]+t)%t,e)):e.key===`Home`||e.key===`End`?(e.preventDefault(),activate(e.key===`Home`?0:t-1,e)):(e.key===`Enter`||e.key===` `)&&V>=0&&l.onClick?(e.preventDefault(),l.onClick({index:V,originalEvent:e,slice:_[V].slice})):e.key===`Escape`&&deactivate()};return{onClick,onKeyDown,onMouseLeave:deactivate,onMouseMove}},e=>{p=e})}function hitTestArc(e,t,n,r){for(let i=0;i<e.length;i++){let a=e[i],o=t-a.centerX,s=n-a.centerY,c=Math.sqrt(o*o+s*s);if(c<a.outerRadius&&c>=a.innerRadius){let e=Math.atan2(o,-s);if(r===`semi`){if(e>=a.startAngle-1e-9&&e<=a.endAngle+1e-9)return i}else{let t=e<0?e+l:e;if(t>=a.startAngle-1e-9&&t<=a.endAngle+1e-9)return i}}}return-1}exports.createPieChart=createPieChart;
2
2
  //# sourceMappingURL=pie-chart.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"pie-chart.cjs","names":[],"sources":["../../../src/charts/pie/pie-chart.ts"],"sourcesContent":["import { resolveEasing } from '../../animation/easing';\nimport { resolveMotion } from '../../animation/motion';\nimport { startTween } from '../../animation/transition';\nimport { tweenNumber } from '../../animation/tween';\nimport type { ChartEventHandlers } from '../../core/chart-scaffold';\nimport { createRadialScaffold } from '../../core/chart-scaffold';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport { estimateTextWidth } from '../../svg/text';\nimport { seriesColor } from '../../theme';\nimport type { ChartHandle, PieChartConfig, PieSliceConfig } from '../../types';\nimport { type Arc, arcCentroid, arcPath, computeArcs } from './pie-renderer';\n\nconst TWO_PI = 2 * Math.PI;\n/** Default `--prism-pie-label-size` in px, used to decide whether a label fits its slice. */\nconst LABEL_FONT_SIZE = 12;\n\n/** A label fits when its slice is wide enough along the centroid arc and thick enough radially. */\nfunction labelFits(arc: Arc, label: string): boolean {\n const thickness = arc.outerRadius - arc.innerRadius;\n const midRadius = (arc.outerRadius + arc.innerRadius) / 2;\n const arcLength = (arc.endAngle - arc.startAngle - 2 * arc.padAngle) * midRadius;\n\n return thickness >= LABEL_FONT_SIZE * 1.4 && arcLength >= estimateTextWidth(label, LABEL_FONT_SIZE) + 8;\n}\n\nconst SEMI_START = -Math.PI / 2; // -90° = 9-o'clock (left)\nconst SEMI_END = Math.PI / 2; // +90° = 3-o'clock (right) → true 180° half-circle\n\nfunction semiAngles(variant: PieChartConfig['variant']): { end: number; start: number } {\n return variant === 'semi' ? { end: SEMI_END, start: SEMI_START } : { end: TWO_PI, start: 0 };\n}\n\nexport function createPieChart(container: HTMLElement, config: PieChartConfig): ChartHandle<PieSliceConfig[]> {\n const variant = config.variant ?? 'pie';\n const padPixels = config.padPixels ?? (variant === 'pie' ? 0 : 8);\n const cornerRadius = config.cornerRadius ?? (variant === 'pie' ? 0 : 8);\n let data = config.data;\n\n // Pie SVG elements live directly on the SVG (not inside chartArea groups).\n // We create them once and reuse across renders.\n const bgCircle = createSvgElement('circle', { class: 'prism-pie-bg', 'pointer-events': 'none' });\n const pieGroup = createSvgElement('g', {\n class: 'prism-pie-slices',\n 'shape-rendering': 'geometricPrecision',\n });\n const labelGroup = createSvgElement('g', { class: 'prism-pie-labels', 'pointer-events': 'none' });\n\n // Current arcs shared between renderFn and event handlers via closure.\n let currentArcs: Arc[] = [];\n let activeTween: (() => void) | null = null;\n\n function renderLabels(slices: PieSliceConfig[]): void {\n labelGroup.replaceChildren();\n\n for (let i = 0; i < currentArcs.length; i++) {\n const arc = currentArcs[i];\n const slice = slices[i];\n\n if (!slice?.label || !labelFits(arc, slice.label)) continue;\n\n const { x, y } = arcCentroid(arc);\n const text = createSvgElement('text', { class: 'prism-pie-label' });\n\n setAttributes(text, {\n 'dominant-baseline': 'middle',\n fill: 'var(--prism-pie-label-color, #fff)',\n 'font-family': 'var(--prism-font-family, system-ui)',\n 'font-size': 'var(--prism-pie-label-size, 12px)',\n 'text-anchor': 'middle',\n x,\n y,\n });\n\n text.textContent = slice.label;\n labelGroup.appendChild(text);\n }\n }\n\n return createRadialScaffold(\n container,\n {\n a11y: config.a11y,\n legend: config.legend,\n tooltip: config.tooltip,\n },\n (ctx): ChartEventHandlers => {\n const { legend, svg, tooltip } = ctx;\n\n // Append pie groups to SVG on first render (idempotent).\n if (!svg.contains(bgCircle)) {\n svg.appendChild(bgCircle);\n svg.appendChild(pieGroup);\n svg.appendChild(labelGroup);\n }\n\n const { height: h, width: w } = ctx.dimensions;\n const isSemi = variant === 'semi';\n const cx = w / 2;\n const cy = isSemi ? h * 0.85 : h / 2;\n const padding = 8;\n const outer = isSemi ? Math.min(cx, cy) - padding : Math.min(w, h) / 2 - padding;\n const defaultInner = variant === 'pie' ? 0 : Math.round(outer * 0.55);\n const inner = config.innerRadius !== undefined ? config.innerRadius : defaultInner;\n const outerR = Math.max(inner + 1, outer);\n\n const slices = data;\n const { end, start } = semiAngles(variant);\n\n currentArcs = computeArcs(\n slices,\n cx,\n cy,\n outerR,\n inner,\n start,\n end,\n padPixels,\n cornerRadius,\n (i) => seriesColor(i),\n false,\n );\n\n setAttributes(bgCircle, { cx, cy, r: inner > 0 ? inner : 0 });\n bgCircle.setAttribute('style', 'fill:var(--prism-bg,#fff)');\n\n while (pieGroup.children.length > currentArcs.length) pieGroup.removeChild(pieGroup.lastChild!);\n\n labelGroup.replaceChildren();\n\n const motion = resolveMotion(config.transition, 0);\n const dur = motion.duration;\n const easing = resolveEasing(motion.easing);\n\n for (let i = 0; i < currentArcs.length; i++) {\n const arc = currentArcs[i];\n let path = pieGroup.children[i] as SVGPathElement | undefined;\n\n if (!path) {\n path = createSvgElement('path', { class: 'prism-pie-slice' });\n pieGroup.appendChild(path);\n }\n\n path.setAttribute('fill', arc.color);\n path.setAttribute('stroke', 'none');\n path.style.cursor = config.onClick || config.onHover ? 'pointer' : '';\n }\n\n activeTween?.();\n\n activeTween = startTween({\n count: 1,\n duration: dur,\n easing,\n onComplete: () => renderLabels(slices),\n onFrame: (progress) => {\n const revealAngle = tweenNumber(start, end, progress(0));\n\n for (let j = 0; j < currentArcs.length; j++) {\n const a = currentArcs[j];\n const el = pieGroup.children[j] as SVGPathElement | undefined;\n\n if (!el) continue;\n\n if (revealAngle <= a.startAngle) {\n setAttributes(el, { d: '' });\n } else {\n const visibleEnd = Math.min(a.endAngle, revealAngle);\n\n setAttributes(el, { d: arcPath({ ...a, endAngle: visibleEnd }) });\n }\n }\n },\n signal: ctx.disposalSignal,\n });\n\n legend?.update(currentArcs.map((arc) => ({ color: arc.color, name: arc.slice.label ?? '' })));\n tooltip?.hide();\n\n const total = currentArcs.reduce((sum, arc) => sum + Math.max(0, arc.slice.value), 0);\n let activeIndex = -1;\n\n const describe = (arc: Arc): string => {\n const percent = total > 0 ? Math.round((Math.max(0, arc.slice.value) / total) * 1000) / 10 : 0;\n\n return `${arc.slice.label ?? `Slice ${arc.index + 1}`}: ${arc.slice.value} (${percent}%)`;\n };\n\n const setActive = (index: number): void => {\n activeIndex = index;\n pieGroup.classList.toggle('prism-pie-focused', index >= 0);\n for (const [i, el] of [...pieGroup.children].entries())\n el.classList.toggle('prism-pie-slice--active', i === index);\n };\n\n const activate = (index: number, originalEvent: Event): void => {\n const arc = currentArcs[index];\n\n if (!arc) return;\n\n setActive(index);\n config.onHover?.({ index, originalEvent, slice: arc.slice });\n\n const text = describe(arc);\n\n if (!tooltip) {\n ctx.announcer.announce(text);\n\n return;\n }\n\n const { x, y } = arcCentroid(arc);\n const svgRect = svg.getBoundingClientRect();\n const contR = container.getBoundingClientRect();\n\n tooltip.show(\n x + (svgRect.left - contR.left),\n y + (svgRect.top - contR.top),\n { key: index, value: arc.slice.value },\n { color: arc.color, data: [], name: arc.slice.label ?? '' },\n text,\n );\n };\n\n const deactivate = (): void => {\n setActive(-1);\n tooltip?.hide();\n ctx.announcer.clear();\n config.onHover?.(null);\n };\n\n const hitAt = (e: MouseEvent): number => {\n const svgRect = svg.getBoundingClientRect();\n\n return hitTestArc(currentArcs, e.clientX - svgRect.left, e.clientY - svgRect.top, variant);\n };\n\n const onMouseMove = (e: MouseEvent): void => {\n const hit = hitAt(e);\n\n if (hit >= 0) {\n if (hit !== activeIndex) activate(hit, e);\n } else if (activeIndex >= 0) {\n deactivate();\n }\n };\n\n const onClick = (e: MouseEvent): void => {\n if (!config.onClick) return;\n\n const hit = hitAt(e);\n\n if (hit >= 0) config.onClick({ index: hit, originalEvent: e, slice: currentArcs[hit].slice });\n };\n\n const onKeyDown = (e: KeyboardEvent): void => {\n const count = currentArcs.length;\n\n if (count === 0) return;\n\n const step: Record<string, number> = { ArrowDown: 1, ArrowLeft: -1, ArrowRight: 1, ArrowUp: -1 };\n\n if (e.key in step) {\n e.preventDefault();\n activate(\n activeIndex < 0 ? (step[e.key] > 0 ? 0 : count - 1) : (activeIndex + step[e.key] + count) % count,\n e,\n );\n } else if (e.key === 'Home' || e.key === 'End') {\n e.preventDefault();\n activate(e.key === 'Home' ? 0 : count - 1, e);\n } else if ((e.key === 'Enter' || e.key === ' ') && activeIndex >= 0 && config.onClick) {\n e.preventDefault();\n config.onClick({ index: activeIndex, originalEvent: e, slice: currentArcs[activeIndex].slice });\n } else if (e.key === 'Escape') {\n deactivate();\n }\n };\n\n return { onClick, onKeyDown, onMouseLeave: deactivate, onMouseMove };\n },\n (next) => {\n data = next;\n },\n );\n}\n\nfunction hitTestArc(arcs: Arc[], mx: number, my: number, variant: PieChartConfig['variant']): number {\n for (let i = 0; i < arcs.length; i++) {\n const arc = arcs[i];\n const dx = mx - arc.centerX;\n const dy = my - arc.centerY;\n const dist = Math.sqrt(dx * dx + dy * dy);\n\n if (dist < arc.outerRadius && dist >= arc.innerRadius) {\n const rawAngle = Math.atan2(dx, -dy);\n\n if (variant === 'semi') {\n if (rawAngle >= arc.startAngle - 1e-9 && rawAngle <= arc.endAngle + 1e-9) return i;\n } else {\n const angle = rawAngle < 0 ? rawAngle + TWO_PI : rawAngle;\n\n if (angle >= arc.startAngle - 1e-9 && angle <= arc.endAngle + 1e-9) return i;\n }\n }\n }\n\n return -1;\n}\n"],"mappings":"0VAYA,IAAM,EAAS,EAAI,KAAK,GAElB,EAAkB,GAGxB,SAAS,UAAU,EAAU,EAAwB,CACnD,IAAM,EAAY,EAAI,YAAc,EAAI,YAClC,GAAa,EAAI,YAAc,EAAI,aAAe,EAClD,GAAa,EAAI,SAAW,EAAI,WAAa,EAAI,EAAI,UAAY,EAEvE,OAAO,GAAa,EAAkB,KAAO,GAAa,EAAA,kBAAkB,EAAO,CAAe,EAAI,CACxG,CAEA,IAAM,EAAa,CAAC,KAAK,GAAK,EACxB,EAAW,KAAK,GAAK,EAE3B,SAAS,WAAW,EAAoE,CACtF,OAAO,IAAY,OAAS,CAAE,IAAK,EAAU,MAAO,CAAW,EAAI,CAAE,IAAK,EAAQ,MAAO,CAAE,CAC7F,CAEA,SAAgB,eAAe,EAAwB,EAAuD,CAC5G,IAAM,EAAU,EAAO,SAAW,MAC5B,EAAY,EAAO,YAAc,IAAY,MAAQ,EAAI,GACzD,EAAe,EAAO,eAAiB,IAAY,MAAQ,EAAI,GACjE,EAAO,EAAO,KAIZ,EAAW,EAAA,iBAAiB,SAAU,CAAE,MAAO,eAAgB,iBAAkB,MAAO,CAAC,EACzF,EAAW,EAAA,iBAAiB,IAAK,CACrC,MAAO,mBACP,kBAAmB,oBACrB,CAAC,EACK,EAAa,EAAA,iBAAiB,IAAK,CAAE,MAAO,mBAAoB,iBAAkB,MAAO,CAAC,EAG5F,EAAqB,CAAC,EACtB,EAAmC,KAEvC,SAAS,aAAa,EAAgC,CACpD,EAAW,gBAAgB,EAE3B,IAAK,IAAI,EAAI,EAAG,EAAI,EAAY,OAAQ,IAAK,CAC3C,IAAM,EAAM,EAAY,GA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GACX,EAAK,EAAK,EAAI,QACd,EAAK,EAAK,EAAI,QACd,EAAO,KAAK,KAAK,EAAK,EAAK,EAAK,CAAE,EAExC,GAAI,EAAO,EAAI,aAAe,GAAQ,EAAI,YAAa,CACrD,IAAM,EAAW,KAAK,MAAM,EAAI,CAAC,CAAE,EAEnC,GAAI,IAAY,OACV,IAAA,GAAY,EAAI,WAAa,MAAQ,GAAY,EAAI,SAAW,KAAM,OAAO,CAAA,KAC5E,CACL,IAAM,EAAQ,EAAW,EAAI,EAAW,EAAS,EAEjD,GAAI,GAAS,EAAI,WAAa,MAAQ,GAAS,EAAI,SAAW,KAAM,OAAO,CAC7E,CACF,CACF,CAEA,MAAO,EACT"}
1
+ {"version":3,"file":"pie-chart.cjs","names":[],"sources":["../../../src/charts/pie/pie-chart.ts"],"sourcesContent":["import { resolveEasing } from '../../animation/easing';\nimport { resolveMotion } from '../../animation/motion';\nimport { startTween } from '../../animation/transition';\nimport { tweenNumber } from '../../animation/tween';\nimport type { ChartEventHandlers } from '../../core/chart-scaffold';\nimport { createRadialScaffold } from '../../core/chart-scaffold';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport { estimateTextWidth } from '../../svg/text';\nimport { seriesColor } from '../../theme';\nimport type { ChartHandle, PieChartConfig, PieSliceConfig } from '../../types';\nimport { type Arc, arcCentroid, arcPath, computeArcs } from './pie-renderer';\n\nconst TWO_PI = 2 * Math.PI;\n/** Default `--prism-pie-label-size` in px, used to decide whether a label fits its slice. */\nconst LABEL_FONT_SIZE = 12;\n\n/** A label fits when its slice is wide enough along the centroid arc and thick enough radially. */\nfunction labelFits(arc: Arc, label: string): boolean {\n const thickness = arc.outerRadius - arc.innerRadius;\n const midRadius = (arc.outerRadius + arc.innerRadius) / 2;\n const arcLength = (arc.endAngle - arc.startAngle - 2 * arc.padAngle) * midRadius;\n\n return thickness >= LABEL_FONT_SIZE * 1.4 && arcLength >= estimateTextWidth(label, LABEL_FONT_SIZE) + 8;\n}\n\nconst SEMI_START = -Math.PI / 2; // -90° = 9-o'clock (left)\nconst SEMI_END = Math.PI / 2; // +90° = 3-o'clock (right) → true 180° half-circle\n\nfunction semiAngles(variant: PieChartConfig['variant']): { end: number; start: number } {\n return variant === 'semi' ? { end: SEMI_END, start: SEMI_START } : { end: TWO_PI, start: 0 };\n}\n\nexport function createPieChart(container: HTMLElement, config: PieChartConfig): ChartHandle<PieSliceConfig[]> {\n const variant = config.variant ?? 'pie';\n const padPixels = config.padPixels ?? (variant === 'pie' ? 0 : 8);\n const cornerRadius = config.cornerRadius ?? (variant === 'pie' ? 0 : 8);\n let data = config.data;\n\n // Pie SVG elements live directly on the SVG (not inside chartArea groups).\n // We create them once and reuse across renders.\n const bgCircle = createSvgElement('circle', { class: 'prism-pie-bg', 'pointer-events': 'none' });\n const pieGroup = createSvgElement('g', {\n class: 'prism-pie-slices',\n 'shape-rendering': 'geometricPrecision',\n });\n const labelGroup = createSvgElement('g', { class: 'prism-pie-labels', 'pointer-events': 'none' });\n\n // Current arcs shared between renderFn and event handlers via closure.\n let currentArcs: Arc[] = [];\n // The geometry actually on screen right now (mid-tween included): the update\n // morph interpolates from this, so interrupting a tween never jumps.\n let drawnArcs: Arc[] = [];\n let activeTween: (() => void) | null = null;\n\n function renderLabels(slices: PieSliceConfig[]): void {\n labelGroup.replaceChildren();\n\n for (let i = 0; i < currentArcs.length; i++) {\n const arc = currentArcs[i];\n const slice = slices[i];\n\n if (!slice?.label || !labelFits(arc, slice.label)) continue;\n\n const { x, y } = arcCentroid(arc);\n const text = createSvgElement('text', { class: 'prism-pie-label' });\n\n setAttributes(text, {\n 'dominant-baseline': 'middle',\n fill: 'var(--prism-pie-label-color, #fff)',\n 'font-family': 'var(--prism-font-family, system-ui)',\n 'font-size': 'var(--prism-pie-label-size, 12px)',\n 'text-anchor': 'middle',\n x,\n y,\n });\n\n text.textContent = slice.label;\n labelGroup.appendChild(text);\n }\n }\n\n return createRadialScaffold(\n container,\n {\n a11y: config.a11y,\n legend: config.legend,\n tooltip: config.tooltip,\n },\n (ctx): ChartEventHandlers => {\n const { legend, svg, tooltip } = ctx;\n\n // Append pie groups to SVG on first render (idempotent).\n if (!svg.contains(bgCircle)) {\n svg.appendChild(bgCircle);\n svg.appendChild(pieGroup);\n svg.appendChild(labelGroup);\n }\n\n const { height: h, width: w } = ctx.dimensions;\n const isSemi = variant === 'semi';\n const cx = w / 2;\n const cy = isSemi ? h * 0.85 : h / 2;\n const padding = 8;\n const outer = isSemi ? Math.min(cx, cy) - padding : Math.min(w, h) / 2 - padding;\n const defaultInner = variant === 'pie' ? 0 : Math.round(outer * 0.55);\n const inner = config.innerRadius !== undefined ? config.innerRadius : defaultInner;\n const outerR = Math.max(inner + 1, outer);\n\n const slices = data;\n const { end, start } = semiAngles(variant);\n\n currentArcs = computeArcs(\n slices,\n cx,\n cy,\n outerR,\n inner,\n start,\n end,\n padPixels,\n cornerRadius,\n (i) => seriesColor(i),\n false,\n );\n\n setAttributes(bgCircle, { cx, cy, r: inner > 0 ? inner : 0 });\n bgCircle.setAttribute('style', 'fill:var(--prism-bg,#fff)');\n\n while (pieGroup.children.length > currentArcs.length) pieGroup.removeChild(pieGroup.lastChild!);\n\n labelGroup.replaceChildren();\n\n const motion = resolveMotion(config.transition);\n const dur = motion.duration;\n const easing = resolveEasing(motion.easing);\n\n for (let i = 0; i < currentArcs.length; i++) {\n const arc = currentArcs[i];\n let path = pieGroup.children[i] as SVGPathElement | undefined;\n\n if (!path) {\n path = createSvgElement('path', { class: 'prism-pie-slice' });\n pieGroup.appendChild(path);\n }\n\n path.setAttribute('fill', arc.color);\n path.setAttribute('stroke', 'none');\n path.style.cursor = config.onClick || config.onHover ? 'pointer' : '';\n }\n\n activeTween?.();\n\n // Mount sweeps the ring in once; an update morphs every slice from its\n // drawn angles to the new ones, which reads as the data changing rather\n // than the chart redrawing.\n const isMount = drawnArcs.length === 0;\n const fromArcs = drawnArcs;\n\n activeTween = startTween({\n count: 1,\n duration: dur,\n easing,\n onComplete: () => renderLabels(slices),\n onFrame: (progress) => {\n const e = progress(0);\n\n if (isMount) {\n const revealAngle = tweenNumber(start, end, e);\n\n drawnArcs = currentArcs.map((a, j) => {\n const el = pieGroup.children[j] as SVGPathElement | undefined;\n\n if (!el) return a;\n\n if (revealAngle <= a.startAngle) {\n setAttributes(el, { d: '' });\n\n return { ...a, endAngle: a.startAngle };\n }\n\n const visibleEnd = Math.min(a.endAngle, revealAngle);\n\n setAttributes(el, { d: arcPath({ ...a, endAngle: visibleEnd }) });\n\n return { ...a, endAngle: visibleEnd };\n });\n\n return;\n }\n\n drawnArcs = currentArcs.map((to, j) => {\n const el = pieGroup.children[j] as SVGPathElement | undefined;\n const lastDrawn = fromArcs.at(-1);\n // A slice that was not drawn before grows out of the end of the last drawn one.\n const from: Arc = fromArcs[j] ?? {\n ...to,\n endAngle: lastDrawn?.endAngle ?? start,\n startAngle: lastDrawn?.endAngle ?? start,\n };\n const morphed: Arc = {\n ...to,\n endAngle: tweenNumber(from.endAngle, to.endAngle, e),\n innerRadius: tweenNumber(from.innerRadius, to.innerRadius, e),\n outerRadius: tweenNumber(from.outerRadius, to.outerRadius, e),\n padAngle: tweenNumber(from.padAngle, to.padAngle, e),\n startAngle: tweenNumber(from.startAngle, to.startAngle, e),\n };\n\n if (!el) return morphed;\n\n setAttributes(el, {\n d: morphed.endAngle - morphed.startAngle <= 1e-6 ? '' : arcPath(morphed),\n });\n\n return morphed;\n });\n },\n signal: ctx.disposalSignal,\n });\n\n legend?.update(currentArcs.map((arc) => ({ color: arc.color, name: arc.slice.label ?? '' })));\n tooltip?.hide();\n\n const total = currentArcs.reduce((sum, arc) => sum + Math.max(0, arc.slice.value), 0);\n let activeIndex = -1;\n\n const describe = (arc: Arc): string => {\n const percent = total > 0 ? Math.round((Math.max(0, arc.slice.value) / total) * 1000) / 10 : 0;\n\n return `${arc.slice.label ?? `Slice ${arc.index + 1}`}: ${arc.slice.value} (${percent}%)`;\n };\n\n const setActive = (index: number): void => {\n activeIndex = index;\n pieGroup.classList.toggle('prism-pie-focused', index >= 0);\n for (const [i, el] of [...pieGroup.children].entries())\n el.classList.toggle('prism-pie-slice--active', i === index);\n };\n\n const activate = (index: number, originalEvent: Event): void => {\n const arc = currentArcs[index];\n\n if (!arc) return;\n\n setActive(index);\n config.onHover?.({ index, originalEvent, slice: arc.slice });\n\n const text = describe(arc);\n\n if (!tooltip) {\n ctx.announcer.announce(text);\n\n return;\n }\n\n const { x, y } = arcCentroid(arc);\n const svgRect = svg.getBoundingClientRect();\n const contR = container.getBoundingClientRect();\n\n tooltip.show(\n x + (svgRect.left - contR.left),\n y + (svgRect.top - contR.top),\n { key: index, value: arc.slice.value },\n { color: arc.color, data: [], name: arc.slice.label ?? '' },\n text,\n );\n };\n\n const deactivate = (): void => {\n setActive(-1);\n tooltip?.hide();\n ctx.announcer.clear();\n config.onHover?.(null);\n };\n\n const hitAt = (e: MouseEvent): number => {\n const svgRect = svg.getBoundingClientRect();\n\n return hitTestArc(currentArcs, e.clientX - svgRect.left, e.clientY - svgRect.top, variant);\n };\n\n const onMouseMove = (e: MouseEvent): void => {\n const hit = hitAt(e);\n\n if (hit >= 0) {\n if (hit !== activeIndex) activate(hit, e);\n } else if (activeIndex >= 0) {\n deactivate();\n }\n };\n\n const onClick = (e: MouseEvent): void => {\n if (!config.onClick) return;\n\n const hit = hitAt(e);\n\n if (hit >= 0) config.onClick({ index: hit, originalEvent: e, slice: currentArcs[hit].slice });\n };\n\n const onKeyDown = (e: KeyboardEvent): void => {\n const count = currentArcs.length;\n\n if (count === 0) return;\n\n const step: Record<string, number> = { ArrowDown: 1, ArrowLeft: -1, ArrowRight: 1, ArrowUp: -1 };\n\n if (e.key in step) {\n e.preventDefault();\n activate(\n activeIndex < 0 ? (step[e.key] > 0 ? 0 : count - 1) : (activeIndex + step[e.key] + count) % count,\n e,\n );\n } else if (e.key === 'Home' || e.key === 'End') {\n e.preventDefault();\n activate(e.key === 'Home' ? 0 : count - 1, e);\n } else if ((e.key === 'Enter' || e.key === ' ') && activeIndex >= 0 && config.onClick) {\n e.preventDefault();\n config.onClick({ index: activeIndex, originalEvent: e, slice: currentArcs[activeIndex].slice });\n } else if (e.key === 'Escape') {\n deactivate();\n }\n };\n\n return { onClick, onKeyDown, onMouseLeave: deactivate, onMouseMove };\n },\n (next) => {\n data = next;\n },\n );\n}\n\nfunction hitTestArc(arcs: Arc[], mx: number, my: number, variant: PieChartConfig['variant']): number {\n for (let i = 0; i < arcs.length; i++) {\n const arc = arcs[i];\n const dx = mx - arc.centerX;\n const dy = my - arc.centerY;\n const dist = Math.sqrt(dx * dx + dy * dy);\n\n if (dist < arc.outerRadius && dist >= arc.innerRadius) {\n const rawAngle = Math.atan2(dx, -dy);\n\n if (variant === 'semi') {\n if (rawAngle >= arc.startAngle - 1e-9 && rawAngle <= arc.endAngle + 1e-9) return i;\n } else {\n const angle = rawAngle < 0 ? rawAngle + TWO_PI : rawAngle;\n\n if (angle >= arc.startAngle - 1e-9 && angle <= arc.endAngle + 1e-9) return i;\n }\n }\n }\n\n return -1;\n}\n"],"mappings":"0VAYA,IAAM,EAAS,EAAI,KAAK,GAElB,EAAkB,GAGxB,SAAS,UAAU,EAAU,EAAwB,CACnD,IAAM,EAAY,EAAI,YAAc,EAAI,YAClC,GAAa,EAAI,YAAc,EAAI,aAAe,EAClD,GAAa,EAAI,SAAW,EAAI,WAAa,EAAI,EAAI,UAAY,EAEvE,OAAO,GAAa,EAAkB,KAAO,GAAa,EAAA,kBAAkB,EAAO,CAAe,EAAI,CACxG,CAEA,IAAM,EAAa,CAAC,KAAK,GAAK,EACxB,EAAW,KAAK,GAAK,EAE3B,SAAS,WAAW,EAAoE,CACtF,OAAO,IAAY,OAAS,CAAE,IAAK,EAAU,MAAO,CAAW,EAAI,CAAE,IAAK,EAAQ,MAAO,CAAE,CAC7F,CAEA,SAAgB,eAAe,EAAwB,EAAuD,CAC5G,IAAM,EAAU,EAAO,SAAW,MAC5B,EAAY,EAAO,YAAc,IAAY,MAAQ,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K,CACpC,IAAM,EAAM,EAAK,GACX,EAAK,EAAK,EAAI,QACd,EAAK,EAAK,EAAI,QACd,EAAO,KAAK,KAAK,EAAK,EAAK,EAAK,CAAE,EAExC,GAAI,EAAO,EAAI,aAAe,GAAQ,EAAI,YAAa,CACrD,IAAM,EAAW,KAAK,MAAM,EAAI,CAAC,CAAE,EAEnC,GAAI,IAAY,OACV,IAAA,GAAY,EAAI,WAAa,MAAQ,GAAY,EAAI,SAAW,KAAM,OAAO,CAAA,KAC5E,CACL,IAAM,EAAQ,EAAW,EAAI,EAAW,EAAS,EAEjD,GAAI,GAAS,EAAI,WAAa,MAAQ,GAAS,EAAI,SAAW,KAAM,OAAO,CAC7E,CACF,CACF,CAEA,MAAO,EACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"pie-chart.d.ts","sourceRoot":"","sources":["../../../src/charts/pie/pie-chart.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAuB/E,wBAAgB,cAAc,CAAC,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,GAAG,WAAW,CAAC,cAAc,EAAE,CAAC,CA4P5G"}
1
+ {"version":3,"file":"pie-chart.d.ts","sourceRoot":"","sources":["../../../src/charts/pie/pie-chart.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAuB/E,wBAAgB,cAAc,CAAC,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,GAAG,WAAW,CAAC,cAAc,EAAE,CAAC,CAyS5G"}
@@ -1,2 +1,2 @@
1
- import{createSvgElement as e,setAttributes as t}from"../../svg/element.js";import{estimateTextWidth as n}from"../../svg/text.js";import{createRadialScaffold as r}from"../../core/chart-scaffold.js";import{seriesColor as i}from"../../theme/index.js";import{resolveEasing as a}from"../../animation/easing.js";import{resolveMotion as o}from"../../animation/motion.js";import{tweenNumber as s}from"../../animation/tween.js";import{startTween as c}from"../../animation/transition.js";import{arcCentroid as l,arcPath as u,computeArcs as d}from"./pie-renderer.js";var f=2*Math.PI,p=12;function labelFits(e,t){let r=e.outerRadius-e.innerRadius,i=(e.outerRadius+e.innerRadius)/2,a=(e.endAngle-e.startAngle-2*e.padAngle)*i;return r>=p*1.4&&a>=n(t,p)+8}var m=-Math.PI/2,h=Math.PI/2;function semiAngles(e){return e===`semi`?{end:h,start:m}:{end:f,start:0}}function createPieChart(n,f){let p=f.variant??`pie`,m=f.padPixels??(p===`pie`?0:8),h=f.cornerRadius??(p===`pie`?0:8),g=f.data,_=e(`circle`,{class:`prism-pie-bg`,"pointer-events":`none`}),v=e(`g`,{class:`prism-pie-slices`,"shape-rendering":`geometricPrecision`}),y=e(`g`,{class:`prism-pie-labels`,"pointer-events":`none`}),b=[],x=null;function renderLabels(n){y.replaceChildren();for(let r=0;r<b.length;r++){let i=b[r],a=n[r];if(!a?.label||!labelFits(i,a.label))continue;let{x:o,y:s}=l(i),c=e(`text`,{class:`prism-pie-label`});t(c,{"dominant-baseline":`middle`,fill:`var(--prism-pie-label-color, #fff)`,"font-family":`var(--prism-font-family, system-ui)`,"font-size":`var(--prism-pie-label-size, 12px)`,"text-anchor":`middle`,x:o,y:s}),c.textContent=a.label,y.appendChild(c)}}return r(n,{a11y:f.a11y,legend:f.legend,tooltip:f.tooltip},r=>{let{legend:S,svg:C,tooltip:w}=r;C.contains(_)||(C.appendChild(_),C.appendChild(v),C.appendChild(y));let{height:T,width:E}=r.dimensions,D=p===`semi`,O=E/2,k=D?T*.85:T/2,A=D?Math.min(O,k)-8:Math.min(E,T)/2-8,j=p===`pie`?0:Math.round(A*.55),M=f.innerRadius===void 0?j:f.innerRadius,N=Math.max(M+1,A),P=g,{end:F,start:I}=semiAngles(p);for(b=d(P,O,k,N,M,I,F,m,h,e=>i(e),!1),t(_,{cx:O,cy:k,r:M>0?M:0}),_.setAttribute(`style`,`fill:var(--prism-bg,#fff)`);v.children.length>b.length;)v.removeChild(v.lastChild);y.replaceChildren();let L=o(f.transition,0),R=L.duration,z=a(L.easing);for(let t=0;t<b.length;t++){let n=b[t],r=v.children[t];r||(r=e(`path`,{class:`prism-pie-slice`}),v.appendChild(r)),r.setAttribute(`fill`,n.color),r.setAttribute(`stroke`,`none`),r.style.cursor=f.onClick||f.onHover?`pointer`:``}x?.(),x=c({count:1,duration:R,easing:z,onComplete:()=>renderLabels(P),onFrame:e=>{let n=s(I,F,e(0));for(let e=0;e<b.length;e++){let r=b[e],i=v.children[e];if(i){if(n<=r.startAngle)t(i,{d:``});else{let e=Math.min(r.endAngle,n);t(i,{d:u({...r,endAngle:e})})}}}},signal:r.disposalSignal}),S?.update(b.map(e=>({color:e.color,name:e.slice.label??``}))),w?.hide();let B=b.reduce((e,t)=>e+Math.max(0,t.slice.value),0),V=-1,describe=e=>{let t=B>0?Math.round(Math.max(0,e.slice.value)/B*1e3)/10:0;return`${e.slice.label??`Slice ${e.index+1}`}: ${e.slice.value} (${t}%)`},setActive=e=>{V=e,v.classList.toggle(`prism-pie-focused`,e>=0);for(let[t,n]of[...v.children].entries())n.classList.toggle(`prism-pie-slice--active`,t===e)},activate=(e,t)=>{let i=b[e];if(!i)return;setActive(e),f.onHover?.({index:e,originalEvent:t,slice:i.slice});let a=describe(i);if(!w){r.announcer.announce(a);return}let{x:o,y:s}=l(i),c=C.getBoundingClientRect(),u=n.getBoundingClientRect();w.show(o+(c.left-u.left),s+(c.top-u.top),{key:e,value:i.slice.value},{color:i.color,data:[],name:i.slice.label??``},a)},deactivate=()=>{setActive(-1),w?.hide(),r.announcer.clear(),f.onHover?.(null)},hitAt=e=>{let t=C.getBoundingClientRect();return hitTestArc(b,e.clientX-t.left,e.clientY-t.top,p)},onMouseMove=e=>{let t=hitAt(e);t>=0?t!==V&&activate(t,e):V>=0&&deactivate()},onClick=e=>{if(!f.onClick)return;let t=hitAt(e);t>=0&&f.onClick({index:t,originalEvent:e,slice:b[t].slice})},onKeyDown=e=>{let t=b.length;if(t===0)return;let n={ArrowDown:1,ArrowLeft:-1,ArrowRight:1,ArrowUp:-1};e.key in n?(e.preventDefault(),activate(V<0?n[e.key]>0?0:t-1:(V+n[e.key]+t)%t,e)):e.key===`Home`||e.key===`End`?(e.preventDefault(),activate(e.key===`Home`?0:t-1,e)):(e.key===`Enter`||e.key===` `)&&V>=0&&f.onClick?(e.preventDefault(),f.onClick({index:V,originalEvent:e,slice:b[V].slice})):e.key===`Escape`&&deactivate()};return{onClick,onKeyDown,onMouseLeave:deactivate,onMouseMove}},e=>{g=e})}function hitTestArc(e,t,n,r){for(let i=0;i<e.length;i++){let a=e[i],o=t-a.centerX,s=n-a.centerY,c=Math.sqrt(o*o+s*s);if(c<a.outerRadius&&c>=a.innerRadius){let e=Math.atan2(o,-s);if(r===`semi`){if(e>=a.startAngle-1e-9&&e<=a.endAngle+1e-9)return i}else{let t=e<0?e+f:e;if(t>=a.startAngle-1e-9&&t<=a.endAngle+1e-9)return i}}}return-1}export{createPieChart};
1
+ import{createSvgElement as e,setAttributes as t}from"../../svg/element.js";import{estimateTextWidth as n}from"../../svg/text.js";import{createRadialScaffold as r}from"../../core/chart-scaffold.js";import{seriesColor as i}from"../../theme/index.js";import{resolveEasing as a}from"../../animation/easing.js";import{resolveMotion as o}from"../../animation/motion.js";import{tweenNumber as s}from"../../animation/tween.js";import{startTween as c}from"../../animation/transition.js";import{arcCentroid as l,arcPath as u,computeArcs as d}from"./pie-renderer.js";var f=2*Math.PI,p=12;function labelFits(e,t){let r=e.outerRadius-e.innerRadius,i=(e.outerRadius+e.innerRadius)/2,a=(e.endAngle-e.startAngle-2*e.padAngle)*i;return r>=p*1.4&&a>=n(t,p)+8}var m=-Math.PI/2,h=Math.PI/2;function semiAngles(e){return e===`semi`?{end:h,start:m}:{end:f,start:0}}function createPieChart(n,f){let p=f.variant??`pie`,m=f.padPixels??(p===`pie`?0:8),h=f.cornerRadius??(p===`pie`?0:8),g=f.data,_=e(`circle`,{class:`prism-pie-bg`,"pointer-events":`none`}),v=e(`g`,{class:`prism-pie-slices`,"shape-rendering":`geometricPrecision`}),y=e(`g`,{class:`prism-pie-labels`,"pointer-events":`none`}),b=[],x=[],S=null;function renderLabels(n){y.replaceChildren();for(let r=0;r<b.length;r++){let i=b[r],a=n[r];if(!a?.label||!labelFits(i,a.label))continue;let{x:o,y:s}=l(i),c=e(`text`,{class:`prism-pie-label`});t(c,{"dominant-baseline":`middle`,fill:`var(--prism-pie-label-color, #fff)`,"font-family":`var(--prism-font-family, system-ui)`,"font-size":`var(--prism-pie-label-size, 12px)`,"text-anchor":`middle`,x:o,y:s}),c.textContent=a.label,y.appendChild(c)}}return r(n,{a11y:f.a11y,legend:f.legend,tooltip:f.tooltip},r=>{let{legend:C,svg:w,tooltip:T}=r;w.contains(_)||(w.appendChild(_),w.appendChild(v),w.appendChild(y));let{height:E,width:D}=r.dimensions,O=p===`semi`,k=D/2,A=O?E*.85:E/2,j=O?Math.min(k,A)-8:Math.min(D,E)/2-8,M=p===`pie`?0:Math.round(j*.55),N=f.innerRadius===void 0?M:f.innerRadius,P=Math.max(N+1,j),F=g,{end:I,start:L}=semiAngles(p);for(b=d(F,k,A,P,N,L,I,m,h,e=>i(e),!1),t(_,{cx:k,cy:A,r:N>0?N:0}),_.setAttribute(`style`,`fill:var(--prism-bg,#fff)`);v.children.length>b.length;)v.removeChild(v.lastChild);y.replaceChildren();let R=o(f.transition),z=R.duration,B=a(R.easing);for(let t=0;t<b.length;t++){let n=b[t],r=v.children[t];r||(r=e(`path`,{class:`prism-pie-slice`}),v.appendChild(r)),r.setAttribute(`fill`,n.color),r.setAttribute(`stroke`,`none`),r.style.cursor=f.onClick||f.onHover?`pointer`:``}S?.();let V=x.length===0,H=x;S=c({count:1,duration:z,easing:B,onComplete:()=>renderLabels(F),onFrame:e=>{let n=e(0);if(V){let e=s(L,I,n);x=b.map((n,r)=>{let i=v.children[r];if(!i)return n;if(e<=n.startAngle)return t(i,{d:``}),{...n,endAngle:n.startAngle};let a=Math.min(n.endAngle,e);return t(i,{d:u({...n,endAngle:a})}),{...n,endAngle:a}});return}x=b.map((e,r)=>{let i=v.children[r],a=H.at(-1),o=H[r]??{...e,endAngle:a?.endAngle??L,startAngle:a?.endAngle??L},c={...e,endAngle:s(o.endAngle,e.endAngle,n),innerRadius:s(o.innerRadius,e.innerRadius,n),outerRadius:s(o.outerRadius,e.outerRadius,n),padAngle:s(o.padAngle,e.padAngle,n),startAngle:s(o.startAngle,e.startAngle,n)};return i&&t(i,{d:c.endAngle-c.startAngle<=1e-6?``:u(c)}),c})},signal:r.disposalSignal}),C?.update(b.map(e=>({color:e.color,name:e.slice.label??``}))),T?.hide();let U=b.reduce((e,t)=>e+Math.max(0,t.slice.value),0),W=-1,describe=e=>{let t=U>0?Math.round(Math.max(0,e.slice.value)/U*1e3)/10:0;return`${e.slice.label??`Slice ${e.index+1}`}: ${e.slice.value} (${t}%)`},setActive=e=>{W=e,v.classList.toggle(`prism-pie-focused`,e>=0);for(let[t,n]of[...v.children].entries())n.classList.toggle(`prism-pie-slice--active`,t===e)},activate=(e,t)=>{let i=b[e];if(!i)return;setActive(e),f.onHover?.({index:e,originalEvent:t,slice:i.slice});let a=describe(i);if(!T){r.announcer.announce(a);return}let{x:o,y:s}=l(i),c=w.getBoundingClientRect(),u=n.getBoundingClientRect();T.show(o+(c.left-u.left),s+(c.top-u.top),{key:e,value:i.slice.value},{color:i.color,data:[],name:i.slice.label??``},a)},deactivate=()=>{setActive(-1),T?.hide(),r.announcer.clear(),f.onHover?.(null)},hitAt=e=>{let t=w.getBoundingClientRect();return hitTestArc(b,e.clientX-t.left,e.clientY-t.top,p)},onMouseMove=e=>{let t=hitAt(e);t>=0?t!==W&&activate(t,e):W>=0&&deactivate()},onClick=e=>{if(!f.onClick)return;let t=hitAt(e);t>=0&&f.onClick({index:t,originalEvent:e,slice:b[t].slice})},onKeyDown=e=>{let t=b.length;if(t===0)return;let n={ArrowDown:1,ArrowLeft:-1,ArrowRight:1,ArrowUp:-1};e.key in n?(e.preventDefault(),activate(W<0?n[e.key]>0?0:t-1:(W+n[e.key]+t)%t,e)):e.key===`Home`||e.key===`End`?(e.preventDefault(),activate(e.key===`Home`?0:t-1,e)):(e.key===`Enter`||e.key===` `)&&W>=0&&f.onClick?(e.preventDefault(),f.onClick({index:W,originalEvent:e,slice:b[W].slice})):e.key===`Escape`&&deactivate()};return{onClick,onKeyDown,onMouseLeave:deactivate,onMouseMove}},e=>{g=e})}function hitTestArc(e,t,n,r){for(let i=0;i<e.length;i++){let a=e[i],o=t-a.centerX,s=n-a.centerY,c=Math.sqrt(o*o+s*s);if(c<a.outerRadius&&c>=a.innerRadius){let e=Math.atan2(o,-s);if(r===`semi`){if(e>=a.startAngle-1e-9&&e<=a.endAngle+1e-9)return i}else{let t=e<0?e+f:e;if(t>=a.startAngle-1e-9&&t<=a.endAngle+1e-9)return i}}}return-1}export{createPieChart};
2
2
  //# sourceMappingURL=pie-chart.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pie-chart.js","names":[],"sources":["../../../src/charts/pie/pie-chart.ts"],"sourcesContent":["import { resolveEasing } from '../../animation/easing';\nimport { resolveMotion } from '../../animation/motion';\nimport { startTween } from '../../animation/transition';\nimport { tweenNumber } from '../../animation/tween';\nimport type { ChartEventHandlers } from '../../core/chart-scaffold';\nimport { createRadialScaffold } from '../../core/chart-scaffold';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport { estimateTextWidth } from '../../svg/text';\nimport { seriesColor } from '../../theme';\nimport type { ChartHandle, PieChartConfig, PieSliceConfig } from '../../types';\nimport { type Arc, arcCentroid, arcPath, computeArcs } from './pie-renderer';\n\nconst TWO_PI = 2 * Math.PI;\n/** Default `--prism-pie-label-size` in px, used to decide whether a label fits its slice. */\nconst LABEL_FONT_SIZE = 12;\n\n/** A label fits when its slice is wide enough along the centroid arc and thick enough radially. */\nfunction labelFits(arc: Arc, label: string): boolean {\n const thickness = arc.outerRadius - arc.innerRadius;\n const midRadius = (arc.outerRadius + arc.innerRadius) / 2;\n const arcLength = (arc.endAngle - arc.startAngle - 2 * arc.padAngle) * midRadius;\n\n return thickness >= LABEL_FONT_SIZE * 1.4 && arcLength >= estimateTextWidth(label, LABEL_FONT_SIZE) + 8;\n}\n\nconst SEMI_START = -Math.PI / 2; // -90° = 9-o'clock (left)\nconst SEMI_END = Math.PI / 2; // +90° = 3-o'clock (right) → true 180° half-circle\n\nfunction semiAngles(variant: PieChartConfig['variant']): { end: number; start: number } {\n return variant === 'semi' ? { end: SEMI_END, start: SEMI_START } : { end: TWO_PI, start: 0 };\n}\n\nexport function createPieChart(container: HTMLElement, config: PieChartConfig): ChartHandle<PieSliceConfig[]> {\n const variant = config.variant ?? 'pie';\n const padPixels = config.padPixels ?? (variant === 'pie' ? 0 : 8);\n const cornerRadius = config.cornerRadius ?? (variant === 'pie' ? 0 : 8);\n let data = config.data;\n\n // Pie SVG elements live directly on the SVG (not inside chartArea groups).\n // We create them once and reuse across renders.\n const bgCircle = createSvgElement('circle', { class: 'prism-pie-bg', 'pointer-events': 'none' });\n const pieGroup = createSvgElement('g', {\n class: 'prism-pie-slices',\n 'shape-rendering': 'geometricPrecision',\n });\n const labelGroup = createSvgElement('g', { class: 'prism-pie-labels', 'pointer-events': 'none' });\n\n // Current arcs shared between renderFn and event handlers via closure.\n let currentArcs: Arc[] = [];\n let activeTween: (() => void) | null = null;\n\n function renderLabels(slices: PieSliceConfig[]): void {\n labelGroup.replaceChildren();\n\n for (let i = 0; i < currentArcs.length; i++) {\n const arc = currentArcs[i];\n const slice = slices[i];\n\n if (!slice?.label || !labelFits(arc, slice.label)) continue;\n\n const { x, y } = arcCentroid(arc);\n const text = createSvgElement('text', { class: 'prism-pie-label' });\n\n setAttributes(text, {\n 'dominant-baseline': 'middle',\n fill: 'var(--prism-pie-label-color, #fff)',\n 'font-family': 'var(--prism-font-family, system-ui)',\n 'font-size': 'var(--prism-pie-label-size, 12px)',\n 'text-anchor': 'middle',\n x,\n y,\n });\n\n text.textContent = slice.label;\n labelGroup.appendChild(text);\n }\n }\n\n return createRadialScaffold(\n container,\n {\n a11y: config.a11y,\n legend: config.legend,\n tooltip: config.tooltip,\n },\n (ctx): ChartEventHandlers => {\n const { legend, svg, tooltip } = ctx;\n\n // Append pie groups to SVG on first render (idempotent).\n if (!svg.contains(bgCircle)) {\n svg.appendChild(bgCircle);\n svg.appendChild(pieGroup);\n svg.appendChild(labelGroup);\n }\n\n const { height: h, width: w } = ctx.dimensions;\n const isSemi = variant === 'semi';\n const cx = w / 2;\n const cy = isSemi ? h * 0.85 : h / 2;\n const padding = 8;\n const outer = isSemi ? Math.min(cx, cy) - padding : Math.min(w, h) / 2 - padding;\n const defaultInner = variant === 'pie' ? 0 : Math.round(outer * 0.55);\n const inner = config.innerRadius !== undefined ? config.innerRadius : defaultInner;\n const outerR = Math.max(inner + 1, outer);\n\n const slices = data;\n const { end, start } = semiAngles(variant);\n\n currentArcs = computeArcs(\n slices,\n cx,\n cy,\n outerR,\n inner,\n start,\n end,\n padPixels,\n cornerRadius,\n (i) => seriesColor(i),\n false,\n );\n\n setAttributes(bgCircle, { cx, cy, r: inner > 0 ? inner : 0 });\n bgCircle.setAttribute('style', 'fill:var(--prism-bg,#fff)');\n\n while (pieGroup.children.length > currentArcs.length) pieGroup.removeChild(pieGroup.lastChild!);\n\n labelGroup.replaceChildren();\n\n const motion = resolveMotion(config.transition, 0);\n const dur = motion.duration;\n const easing = resolveEasing(motion.easing);\n\n for (let i = 0; i < currentArcs.length; i++) {\n const arc = currentArcs[i];\n let path = pieGroup.children[i] as SVGPathElement | undefined;\n\n if (!path) {\n path = createSvgElement('path', { class: 'prism-pie-slice' });\n pieGroup.appendChild(path);\n }\n\n path.setAttribute('fill', arc.color);\n path.setAttribute('stroke', 'none');\n path.style.cursor = config.onClick || config.onHover ? 'pointer' : '';\n }\n\n activeTween?.();\n\n activeTween = startTween({\n count: 1,\n duration: dur,\n easing,\n onComplete: () => renderLabels(slices),\n onFrame: (progress) => {\n const revealAngle = tweenNumber(start, end, progress(0));\n\n for (let j = 0; j < currentArcs.length; j++) {\n const a = currentArcs[j];\n const el = pieGroup.children[j] as SVGPathElement | undefined;\n\n if (!el) continue;\n\n if (revealAngle <= a.startAngle) {\n setAttributes(el, { d: '' });\n } else {\n const visibleEnd = Math.min(a.endAngle, revealAngle);\n\n setAttributes(el, { d: arcPath({ ...a, endAngle: visibleEnd }) });\n }\n }\n },\n signal: ctx.disposalSignal,\n });\n\n legend?.update(currentArcs.map((arc) => ({ color: arc.color, name: arc.slice.label ?? '' })));\n tooltip?.hide();\n\n const total = currentArcs.reduce((sum, arc) => sum + Math.max(0, arc.slice.value), 0);\n let activeIndex = -1;\n\n const describe = (arc: Arc): string => {\n const percent = total > 0 ? Math.round((Math.max(0, arc.slice.value) / total) * 1000) / 10 : 0;\n\n return `${arc.slice.label ?? `Slice ${arc.index + 1}`}: ${arc.slice.value} (${percent}%)`;\n };\n\n const setActive = (index: number): void => {\n activeIndex = index;\n pieGroup.classList.toggle('prism-pie-focused', index >= 0);\n for (const [i, el] of [...pieGroup.children].entries())\n el.classList.toggle('prism-pie-slice--active', i === index);\n };\n\n const activate = (index: number, originalEvent: Event): void => {\n const arc = currentArcs[index];\n\n if (!arc) return;\n\n setActive(index);\n config.onHover?.({ index, originalEvent, slice: arc.slice });\n\n const text = describe(arc);\n\n if (!tooltip) {\n ctx.announcer.announce(text);\n\n return;\n }\n\n const { x, y } = arcCentroid(arc);\n const svgRect = svg.getBoundingClientRect();\n const contR = container.getBoundingClientRect();\n\n tooltip.show(\n x + (svgRect.left - contR.left),\n y + (svgRect.top - contR.top),\n { key: index, value: arc.slice.value },\n { color: arc.color, data: [], name: arc.slice.label ?? '' },\n text,\n );\n };\n\n const deactivate = (): void => {\n setActive(-1);\n tooltip?.hide();\n ctx.announcer.clear();\n config.onHover?.(null);\n };\n\n const hitAt = (e: MouseEvent): number => {\n const svgRect = svg.getBoundingClientRect();\n\n return hitTestArc(currentArcs, e.clientX - svgRect.left, e.clientY - svgRect.top, variant);\n };\n\n const onMouseMove = (e: MouseEvent): void => {\n const hit = hitAt(e);\n\n if (hit >= 0) {\n if (hit !== activeIndex) activate(hit, e);\n } else if (activeIndex >= 0) {\n deactivate();\n }\n };\n\n const onClick = (e: MouseEvent): void => {\n if (!config.onClick) return;\n\n const hit = hitAt(e);\n\n if (hit >= 0) config.onClick({ index: hit, originalEvent: e, slice: currentArcs[hit].slice });\n };\n\n const onKeyDown = (e: KeyboardEvent): void => {\n const count = currentArcs.length;\n\n if (count === 0) return;\n\n const step: Record<string, number> = { ArrowDown: 1, ArrowLeft: -1, ArrowRight: 1, ArrowUp: -1 };\n\n if (e.key in step) {\n e.preventDefault();\n activate(\n activeIndex < 0 ? (step[e.key] > 0 ? 0 : count - 1) : (activeIndex + step[e.key] + count) % count,\n e,\n );\n } else if (e.key === 'Home' || e.key === 'End') {\n e.preventDefault();\n activate(e.key === 'Home' ? 0 : count - 1, e);\n } else if ((e.key === 'Enter' || e.key === ' ') && activeIndex >= 0 && config.onClick) {\n e.preventDefault();\n config.onClick({ index: activeIndex, originalEvent: e, slice: currentArcs[activeIndex].slice });\n } else if (e.key === 'Escape') {\n deactivate();\n }\n };\n\n return { onClick, onKeyDown, onMouseLeave: deactivate, onMouseMove };\n },\n (next) => {\n data = next;\n },\n );\n}\n\nfunction hitTestArc(arcs: Arc[], mx: number, my: number, variant: PieChartConfig['variant']): number {\n for (let i = 0; i < arcs.length; i++) {\n const arc = arcs[i];\n const dx = mx - arc.centerX;\n const dy = my - arc.centerY;\n const dist = Math.sqrt(dx * dx + dy * dy);\n\n if (dist < arc.outerRadius && dist >= arc.innerRadius) {\n const rawAngle = Math.atan2(dx, -dy);\n\n if (variant === 'semi') {\n if (rawAngle >= arc.startAngle - 1e-9 && rawAngle <= arc.endAngle + 1e-9) return i;\n } else {\n const angle = rawAngle < 0 ? rawAngle + TWO_PI : rawAngle;\n\n if (angle >= arc.startAngle - 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AAO,CAAA,KAC5E,CACL,IAAM,EAAQ,EAAW,EAAI,EAAW,EAAS,EAEjD,GAAI,GAAS,EAAI,WAAa,MAAQ,GAAS,EAAI,SAAW,KAAM,OAAO,CAC7E,CACF,CACF,CAEA,MAAO,EACT"}
1
+ {"version":3,"file":"pie-chart.js","names":[],"sources":["../../../src/charts/pie/pie-chart.ts"],"sourcesContent":["import { resolveEasing } from '../../animation/easing';\nimport { resolveMotion } from '../../animation/motion';\nimport { startTween } from '../../animation/transition';\nimport { tweenNumber } from '../../animation/tween';\nimport type { ChartEventHandlers } from '../../core/chart-scaffold';\nimport { createRadialScaffold } from '../../core/chart-scaffold';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport { estimateTextWidth } from '../../svg/text';\nimport { seriesColor } from '../../theme';\nimport type { ChartHandle, PieChartConfig, PieSliceConfig } from '../../types';\nimport { type Arc, arcCentroid, arcPath, computeArcs } from './pie-renderer';\n\nconst TWO_PI = 2 * Math.PI;\n/** Default `--prism-pie-label-size` in px, used to decide whether a label fits its slice. */\nconst LABEL_FONT_SIZE = 12;\n\n/** A label fits when its slice is wide enough along the centroid arc and thick enough radially. */\nfunction labelFits(arc: Arc, label: string): boolean {\n const thickness = arc.outerRadius - arc.innerRadius;\n const midRadius = (arc.outerRadius + arc.innerRadius) / 2;\n const arcLength = (arc.endAngle - arc.startAngle - 2 * arc.padAngle) * midRadius;\n\n return thickness >= LABEL_FONT_SIZE * 1.4 && arcLength >= estimateTextWidth(label, LABEL_FONT_SIZE) + 8;\n}\n\nconst SEMI_START = -Math.PI / 2; // -90° = 9-o'clock (left)\nconst SEMI_END = Math.PI / 2; // +90° = 3-o'clock (right) → true 180° half-circle\n\nfunction semiAngles(variant: PieChartConfig['variant']): { end: number; start: number } {\n return variant === 'semi' ? { end: SEMI_END, start: SEMI_START } : { end: TWO_PI, start: 0 };\n}\n\nexport function createPieChart(container: HTMLElement, config: PieChartConfig): ChartHandle<PieSliceConfig[]> {\n const variant = config.variant ?? 'pie';\n const padPixels = config.padPixels ?? (variant === 'pie' ? 0 : 8);\n const cornerRadius = config.cornerRadius ?? (variant === 'pie' ? 0 : 8);\n let data = config.data;\n\n // Pie SVG elements live directly on the SVG (not inside chartArea groups).\n // We create them once and reuse across renders.\n const bgCircle = createSvgElement('circle', { class: 'prism-pie-bg', 'pointer-events': 'none' });\n const pieGroup = createSvgElement('g', {\n class: 'prism-pie-slices',\n 'shape-rendering': 'geometricPrecision',\n });\n const labelGroup = createSvgElement('g', { class: 'prism-pie-labels', 'pointer-events': 'none' });\n\n // Current arcs shared between renderFn and event handlers via closure.\n let currentArcs: Arc[] = [];\n // The geometry actually on screen right now (mid-tween included): the update\n // morph interpolates from this, so interrupting a tween never jumps.\n let drawnArcs: Arc[] = [];\n let activeTween: (() => void) | null = null;\n\n function renderLabels(slices: PieSliceConfig[]): void {\n labelGroup.replaceChildren();\n\n for (let i = 0; i < currentArcs.length; i++) {\n const arc = currentArcs[i];\n const slice = slices[i];\n\n if (!slice?.label || !labelFits(arc, slice.label)) continue;\n\n const { x, y } = arcCentroid(arc);\n const text = createSvgElement('text', { class: 'prism-pie-label' });\n\n setAttributes(text, {\n 'dominant-baseline': 'middle',\n fill: 'var(--prism-pie-label-color, #fff)',\n 'font-family': 'var(--prism-font-family, system-ui)',\n 'font-size': 'var(--prism-pie-label-size, 12px)',\n 'text-anchor': 'middle',\n x,\n y,\n });\n\n text.textContent = slice.label;\n labelGroup.appendChild(text);\n }\n }\n\n return createRadialScaffold(\n container,\n {\n a11y: config.a11y,\n legend: config.legend,\n tooltip: config.tooltip,\n },\n (ctx): ChartEventHandlers => {\n const { legend, svg, tooltip } = ctx;\n\n // Append pie groups to SVG on first render (idempotent).\n if (!svg.contains(bgCircle)) {\n svg.appendChild(bgCircle);\n svg.appendChild(pieGroup);\n svg.appendChild(labelGroup);\n }\n\n const { height: h, width: w } = ctx.dimensions;\n const isSemi = variant === 'semi';\n const cx = w / 2;\n const cy = isSemi ? h * 0.85 : h / 2;\n const padding = 8;\n const outer = isSemi ? Math.min(cx, cy) - padding : Math.min(w, h) / 2 - padding;\n const defaultInner = variant === 'pie' ? 0 : Math.round(outer * 0.55);\n const inner = config.innerRadius !== undefined ? config.innerRadius : defaultInner;\n const outerR = Math.max(inner + 1, outer);\n\n const slices = data;\n const { end, start } = semiAngles(variant);\n\n currentArcs = computeArcs(\n slices,\n cx,\n cy,\n outerR,\n inner,\n start,\n end,\n padPixels,\n cornerRadius,\n (i) => seriesColor(i),\n false,\n );\n\n setAttributes(bgCircle, { cx, cy, r: inner > 0 ? inner : 0 });\n bgCircle.setAttribute('style', 'fill:var(--prism-bg,#fff)');\n\n while (pieGroup.children.length > currentArcs.length) pieGroup.removeChild(pieGroup.lastChild!);\n\n labelGroup.replaceChildren();\n\n const motion = resolveMotion(config.transition);\n const dur = motion.duration;\n const easing = resolveEasing(motion.easing);\n\n for (let i = 0; i < currentArcs.length; i++) {\n const arc = currentArcs[i];\n let path = pieGroup.children[i] as SVGPathElement | undefined;\n\n if (!path) {\n path = createSvgElement('path', { class: 'prism-pie-slice' });\n pieGroup.appendChild(path);\n }\n\n path.setAttribute('fill', arc.color);\n path.setAttribute('stroke', 'none');\n path.style.cursor = config.onClick || config.onHover ? 'pointer' : '';\n }\n\n activeTween?.();\n\n // Mount sweeps the ring in once; an update morphs every slice from its\n // drawn angles to the new ones, which reads as the data changing rather\n // than the chart redrawing.\n const isMount = drawnArcs.length === 0;\n const fromArcs = drawnArcs;\n\n activeTween = startTween({\n count: 1,\n duration: dur,\n easing,\n onComplete: () => renderLabels(slices),\n onFrame: (progress) => {\n const e = progress(0);\n\n if (isMount) {\n const revealAngle = tweenNumber(start, end, e);\n\n drawnArcs = currentArcs.map((a, j) => {\n const el = pieGroup.children[j] as SVGPathElement | undefined;\n\n if (!el) return a;\n\n if (revealAngle <= a.startAngle) {\n setAttributes(el, { d: '' });\n\n return { ...a, endAngle: a.startAngle };\n }\n\n const visibleEnd = Math.min(a.endAngle, revealAngle);\n\n setAttributes(el, { d: arcPath({ ...a, endAngle: visibleEnd }) });\n\n return { ...a, endAngle: visibleEnd };\n });\n\n return;\n }\n\n drawnArcs = currentArcs.map((to, j) => {\n const el = pieGroup.children[j] as SVGPathElement | undefined;\n const lastDrawn = fromArcs.at(-1);\n // A slice that was not drawn before grows out of the end of the last drawn one.\n const from: Arc = fromArcs[j] ?? {\n ...to,\n endAngle: lastDrawn?.endAngle ?? start,\n startAngle: lastDrawn?.endAngle ?? start,\n };\n const morphed: Arc = {\n ...to,\n endAngle: tweenNumber(from.endAngle, to.endAngle, e),\n innerRadius: tweenNumber(from.innerRadius, to.innerRadius, e),\n outerRadius: tweenNumber(from.outerRadius, to.outerRadius, e),\n padAngle: tweenNumber(from.padAngle, to.padAngle, e),\n startAngle: tweenNumber(from.startAngle, to.startAngle, e),\n };\n\n if (!el) return morphed;\n\n setAttributes(el, {\n d: morphed.endAngle - morphed.startAngle <= 1e-6 ? '' : arcPath(morphed),\n });\n\n return morphed;\n });\n },\n signal: ctx.disposalSignal,\n });\n\n legend?.update(currentArcs.map((arc) => ({ color: arc.color, name: arc.slice.label ?? '' })));\n tooltip?.hide();\n\n const total = currentArcs.reduce((sum, arc) => sum + Math.max(0, arc.slice.value), 0);\n let activeIndex = -1;\n\n const describe = (arc: Arc): string => {\n const percent = total > 0 ? Math.round((Math.max(0, arc.slice.value) / total) * 1000) / 10 : 0;\n\n return `${arc.slice.label ?? `Slice ${arc.index + 1}`}: ${arc.slice.value} (${percent}%)`;\n };\n\n const setActive = (index: number): void => {\n activeIndex = index;\n pieGroup.classList.toggle('prism-pie-focused', index >= 0);\n for (const [i, el] of [...pieGroup.children].entries())\n el.classList.toggle('prism-pie-slice--active', i === index);\n };\n\n const activate = (index: number, originalEvent: Event): void => {\n const arc = currentArcs[index];\n\n if (!arc) return;\n\n setActive(index);\n config.onHover?.({ index, originalEvent, slice: arc.slice });\n\n const text = describe(arc);\n\n if (!tooltip) {\n ctx.announcer.announce(text);\n\n return;\n }\n\n const { x, y } = arcCentroid(arc);\n const svgRect = svg.getBoundingClientRect();\n const contR = container.getBoundingClientRect();\n\n tooltip.show(\n x + (svgRect.left - contR.left),\n y + (svgRect.top - contR.top),\n { key: index, value: arc.slice.value },\n { color: arc.color, data: [], name: arc.slice.label ?? '' },\n text,\n );\n };\n\n const deactivate = (): void => {\n setActive(-1);\n tooltip?.hide();\n ctx.announcer.clear();\n config.onHover?.(null);\n };\n\n const hitAt = (e: MouseEvent): number => {\n const svgRect = svg.getBoundingClientRect();\n\n return hitTestArc(currentArcs, e.clientX - svgRect.left, e.clientY - svgRect.top, variant);\n };\n\n const onMouseMove = (e: MouseEvent): void => {\n const hit = hitAt(e);\n\n if (hit >= 0) {\n if (hit !== activeIndex) activate(hit, e);\n } else if (activeIndex >= 0) {\n deactivate();\n }\n };\n\n const onClick = (e: MouseEvent): void => {\n if (!config.onClick) return;\n\n const hit = hitAt(e);\n\n if (hit >= 0) config.onClick({ index: hit, originalEvent: e, slice: currentArcs[hit].slice });\n };\n\n const onKeyDown = (e: KeyboardEvent): void => {\n const count = currentArcs.length;\n\n if (count === 0) return;\n\n const step: Record<string, number> = { ArrowDown: 1, ArrowLeft: -1, ArrowRight: 1, ArrowUp: -1 };\n\n if (e.key in step) {\n e.preventDefault();\n activate(\n activeIndex < 0 ? (step[e.key] > 0 ? 0 : count - 1) : (activeIndex + step[e.key] + count) % count,\n e,\n );\n } else if (e.key === 'Home' || e.key === 'End') {\n e.preventDefault();\n activate(e.key === 'Home' ? 0 : count - 1, e);\n } else if ((e.key === 'Enter' || e.key === ' ') && activeIndex >= 0 && config.onClick) {\n e.preventDefault();\n config.onClick({ index: activeIndex, originalEvent: e, slice: currentArcs[activeIndex].slice });\n } else if (e.key === 'Escape') {\n deactivate();\n }\n };\n\n return { onClick, onKeyDown, onMouseLeave: deactivate, onMouseMove };\n },\n (next) => {\n data = next;\n },\n );\n}\n\nfunction hitTestArc(arcs: Arc[], mx: number, my: number, variant: PieChartConfig['variant']): number {\n for (let i = 0; i < arcs.length; i++) {\n const arc = arcs[i];\n const dx = mx - arc.centerX;\n const dy = my - arc.centerY;\n const dist = Math.sqrt(dx * dx + dy * dy);\n\n if (dist < arc.outerRadius && dist >= arc.innerRadius) {\n const rawAngle = Math.atan2(dx, -dy);\n\n if (variant === 'semi') {\n if (rawAngle >= arc.startAngle - 1e-9 && rawAngle <= arc.endAngle + 1e-9) return i;\n } else {\n const angle = rawAngle < 0 ? rawAngle + TWO_PI : rawAngle;\n\n if (angle >= arc.startAngle - 1e-9 && angle <= arc.endAngle + 1e-9) return i;\n }\n }\n }\n\n return -1;\n}\n"],"mappings":"4iBAYA,IAAM,EAAS,EAAI,KAAK,GAElB,EAAkB,GAGxB,SAAS,UAAU,EAAU,EAAwB,CACnD,IAAM,EAAY,EAAI,YAAc,EAAI,YAClC,GAAa,EAAI,YAAc,EAAI,aAAe,EAClD,GAAa,EAAI,SAAW,EAAI,WAAa,EAAI,EAAI,UAAY,EAEvE,OAAO,GAAa,EAAkB,KAAO,GAAa,EAAkB,EAAO,CAAe,EAAI,CACxG,CAEA,IAAM,EAAa,CAAC,KAAK,GAAK,EACxB,EAAW,KAAK,GAAK,EAE3B,SAAS,WAAW,EAAoE,CACtF,OAAO,IAAY,OAAS,CAAE,IAAK,EAAU,MAAO,CAAW,EAAI,CAAE,IAAK,EAAQ,MAAO,CAAE,CAC7F,CAEA,SAAgB,eAAe,EAAwB,EAAuD,CAC5G,IAAM,EAAU,EAAO,SAAW,MAC5B,EAAY,EAAO,YAAc,IAAY,MAAQ,EAAI,GACzD,EAAe,EAAO,eAAiB,IAAY,MAAQ,EAAI,GACjE,EAAO,EAAO,KAIZ,EAAW,EAAiB,SAAU,CAAE,MAAO,eAAgB,iBAAkB,MAAO,CAAC,EACzF,EAAW,EAAiB,IAAK,CACrC,MAAO,mBACP,kBAAmB,oBACrB,CAAC,EACK,EAAa,EAAiB,IAAK,CAAE,MAAO,mBAAoB,iBAAkB,MAAO,CAAC,EAG5F,EAAqB,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CAEA,MAAO,EACT"}
@@ -1,2 +1,2 @@
1
- require("../../_dev.cjs");const e=require("../../svg/element.cjs"),t=require("../../interaction/announcer.cjs"),n=require("../../interaction/tooltip.cjs"),r=require("../../core/chart-scaffold.cjs"),i=require("../../core/series-id.cjs"),a=require("../../theme/index.cjs"),o=require("../../animation/easing.cjs"),s=require("../../animation/motion.cjs"),c=require("../../animation/tween.cjs"),l=require("../../animation/transition.cjs"),u=require("../../core/ids.cjs"),d=require("../../core/polar.cjs"),f=require("./radar-geometry.cjs");var p=11,m=12,h=10,g={ArrowDown:1,ArrowLeft:-1,ArrowRight:1,ArrowUp:-1};function resolveGrid(e){return e===!1?null:{bands:!0,labels:!1,levels:4,shape:`polygon`,...typeof e==`object`?e:{}}}function createRadarChart(_,v){let{axes:y}=v,b=v.curve??`linear`,x=v.fill??`solid`,S=v.showPoints??!0,C=resolveGrid(v.grid),w=f.toRadians(v.startAngle??0),T=f.axisAngles(y.length,w),E=m+(v.showValues?h:0),D=u.uniqueId(`prism-radar`),O=v.series,k=e.createSvgElement(`g`,{class:`prism-radar`}),A=e.createSvgElement(`defs`),j=e.createSvgElement(`g`,{"aria-hidden":`true`,class:`prism-radar-grid`}),M=e.createSvgElement(`g`,{class:`prism-radar-series-group`}),N=e.createSvgElement(`g`,{"aria-hidden":`true`,class:`prism-radar-labels`});k.append(A,j,M,N);let P=[],F=null,I=-1,L={cx:0,cy:0,radius:0},datumAt=(e,t)=>e.data.find(e=>e.key===y[t].key),valuesAt=e=>O.map(t=>({datum:datumAt(t,e),series:t})),formatValue=(e,t)=>y[e].format?.(t)??String(t),describe=e=>t.describeValues(y[e].label,valuesAt(e),t=>formatValue(e,t));function draw(t){let{cx:n,cy:r,radius:i}=L;t.forEach((t,a)=>{let o=M.children[a];if(!o)return;let s=f.radarPoints(t,n,r,i,T);o.querySelector(`.prism-radar-area`)?.setAttribute(`d`,f.closedPath(s,b)),o.querySelectorAll(`.prism-radar-point`).forEach((t,n)=>{e.setAttributes(t,{cx:s[n].x,cy:s[n].y})}),o.querySelectorAll(`.prism-radar-value`).forEach((a,o)=>{let s=i*t[o]+h;e.setAttributes(a,{x:d.polarX(n,s,T[o]),y:d.polarY(r,s,T[o])})})})}function renderGrid(t){if(j.replaceChildren(),!C)return;let{cx:n,cy:r,radius:i}=L,a=Math.max(1,Math.round(C.levels)),o=Array.from({length:a},(e,t)=>f.ringPath(C.shape,n,r,i*(t+1)/a,T));if(C.bands)for(let t=a-1;t>=0;t-=2)j.appendChild(e.createSvgElement(`path`,{class:`prism-radar-band`,d:`${o[t]}${o[t-1]??``}`,"fill-rule":`evenodd`}));for(let t of o)j.appendChild(e.createSvgElement(`path`,{class:`prism-radar-ring`,d:t,fill:`none`}));T.forEach((t,a)=>{j.appendChild(e.createSvgElement(`line`,{class:`prism-radar-spoke`,"data-axis":a,x1:n,x2:d.polarX(n,i,t),y1:r,y2:d.polarY(r,i,t)}))});let[s,c]=t[0],l=t.every(([e,t])=>e===s&&t===c);if(!C.labels||!l)return;let u=T[0]+Math.PI/T.length;for(let t=1;t<=a;t++){let o=i*t/a,l=e.createSvgElement(`text`,{class:`prism-radar-level`,"dominant-baseline":`middle`,"text-anchor":`middle`,x:d.polarX(n,o,u),y:d.polarY(r,o,u)});l.textContent=formatValue(0,Math.round((s+(c-s)*t/a)*100)/100),j.appendChild(l)}}function renderLabels(){N.replaceChildren();let{cx:t,cy:n,radius:r}=L;y.forEach((i,a)=>{let{anchor:o,baseline:s}=f.labelPlacement(T[a]),c=e.createSvgElement(`text`,{class:`prism-radar-axis-label`,"dominant-baseline":s,"text-anchor":o,x:d.polarX(t,r+E,T[a]),y:d.polarY(n,r+E,T[a])});c.textContent=i.label,N.appendChild(c)})}function renderSeries(){let{cx:t,cy:n,radius:r}=L;for(A.replaceChildren();M.children.length>O.length;)M.lastChild?.remove();O.forEach((o,s)=>{let c=o.color??a.seriesColor(s),l=M.children[s];l||(l=e.createSvgElement(`g`,{class:`prism-radar-series`}),M.appendChild(l)),l.setAttribute(`data-series-id`,i.seriesDomId(o,s)),l.replaceChildren();let u=e.createSvgElement(`path`,{class:`prism-radar-area prism-radar-area--${x}`,stroke:c,"stroke-linejoin":`round`,"stroke-width":2});if(x===`gradient`){let i=`${D}-fill-${s}`,a=e.createSvgElement(`radialGradient`,{cx:t,cy:n,gradientUnits:`userSpaceOnUse`,id:i,r});for(let[t,n]of[[0,.08],[1,.55]])a.appendChild(e.createSvgElement(`stop`,{offset:t,"stop-color":c,"stop-opacity":n,style:`stop-color:${c}`}));A.appendChild(a),e.setAttributes(u,{fill:`url(#${i})`})}else e.setAttributes(u,{fill:x===`none`?`none`:c,"fill-opacity":.25});l.appendChild(u),S&&y.forEach((t,n)=>{let r=!Number.isFinite(datumAt(o,n)?.value);l.appendChild(e.createSvgElement(`circle`,{class:`prism-radar-point${r?` prism-radar-point--missing`:``}`,"data-axis":n,fill:r?`none`:c,r:3,stroke:c}))}),v.showValues&&y.forEach((t,n)=>{let r=datumAt(o,n),{anchor:i,baseline:a}=f.labelPlacement(T[n]),s=e.createSvgElement(`text`,{"aria-hidden":`true`,class:`prism-radar-value`,"dominant-baseline":a,"text-anchor":i});s.textContent=r&&Number.isFinite(r.value)?formatValue(n,r.value):``,l.appendChild(s)})})}function setActive(e){I=e;for(let t of k.querySelectorAll(`[data-axis]`)){let n=Number(t.getAttribute(`data-axis`))===e;t.classList.toggle(t.tagName===`line`?`prism-radar-spoke--active`:`prism-radar-point--active`,n)}}function animateTo(e,t){F?.();let n=e.map((e,t)=>e.map((e,n)=>P[t]?.[n]??0)),r=s.resolveMotion(v.transition,400),i=o.resolveEasing(r.easing??`ease-out`),a=n.every((t,n)=>t.every((t,r)=>t===e[n][r]));if(r.duration===0||a){P=e,draw(e);return}F=l.startTween({count:e.length,duration:r.duration,easing:i,onFrame:t=>{P=e.map((e,r)=>{let i=t(r);return e.map((e,t)=>c.tweenNumber(n[r][t],e,i))}),draw(P)},signal:t,stagger:r.stagger})}return r.createRadialScaffold(_,{a11y:v.a11y,legend:v.legend,tooltip:v.tooltip},e=>{let{legend:t,svg:r,tooltip:i}=e;if(r.contains(k)||r.appendChild(k),i?.hide(),t?.update(O.map((e,t)=>({color:e.color??a.seriesColor(t),name:e.name}))),y.length<3){for(let e of[A,j,M,N])e.replaceChildren();P=[];return}let{height:o,width:s}=e.dimensions,c=f.fitRadius(s,o,y.map(e=>e.label),T,p,E);L={cx:s/2,cy:o/2,radius:c};let l=f.resolveAxisDomains(y,O,v.domain);renderGrid(l),renderLabels(),renderSeries(),animateTo(O.map(e=>y.map((t,n)=>{let r=datumAt(e,n)?.value;return r!==void 0&&Number.isFinite(r)?f.normalize(r,l[n]):0})),e.disposalSignal),setActive(I);let eventFor=(e,t)=>({axis:y[e],index:e,originalEvent:t,values:valuesAt(e)}),activate=(t,o)=>{setActive(t),v.onHover?.(eventFor(t,o));let s=describe(t);if(!i){e.announcer.announce(s);return}let c=Math.max(0,...P.map(e=>e[t]??0)),l=r.getBoundingClientRect(),u=_.getBoundingClientRect(),f=valuesAt(t),p=f.find(e=>e.datum)?.datum,m=f.flatMap(({datum:e,series:n})=>e?[{color:n.color??a.seriesColor(O.indexOf(n)),name:n.name,value:formatValue(t,e.value)}]:[]);i.show(d.polarX(L.cx,L.radius*c,T[t])+(l.left-u.left),d.polarY(L.cy,L.radius*c,T[t])+(l.top-u.top),{key:y[t].key,meta:{axis:y[t],text:s,values:f},value:p?.value??0},{color:O[0]?.color??a.seriesColor(0),data:[],name:y[t].label},n.comparisonContent(r.ownerDocument,y[t].label,m,s))},deactivate=()=>{setActive(-1),v.onHover?.(null),i?.hide(),e.announcer.clear()},hitIndex=e=>{let t=r.getBoundingClientRect(),n=e.clientX-t.left-L.cx,i=e.clientY-t.top-L.cy;return Math.hypot(n,i)>L.radius+E+22?-1:f.nearestAxis(n,i,y.length,w)};return{onClick(e){let t=hitIndex(e);t>=0&&v.onClick?.(eventFor(t,e))},onKeyDown(e){let t=g[e.key];t===void 0?(e.key===`Enter`||e.key===` `)&&I>=0&&v.onClick?(e.preventDefault(),v.onClick(eventFor(I,e))):e.key===`Escape`&&deactivate():(e.preventDefault(),activate(I<0?0:(I+t+y.length)%y.length,e))},onMouseLeave:deactivate,onMouseMove(e){let t=hitIndex(e);t<0?I>=0&&deactivate():t!==I&&activate(t,e)}}},e=>{O=e})}exports.createRadarChart=createRadarChart;
1
+ require("../../_dev.cjs");const e=require("../../svg/element.cjs"),t=require("../../interaction/announcer.cjs"),n=require("../../interaction/tooltip.cjs"),r=require("../../core/chart-scaffold.cjs"),i=require("../../core/series-id.cjs"),a=require("../../theme/index.cjs"),o=require("../../animation/easing.cjs"),s=require("../../animation/motion.cjs"),c=require("../../animation/tween.cjs"),l=require("../../animation/transition.cjs"),u=require("../../core/ids.cjs"),d=require("../../core/polar.cjs"),f=require("./radar-geometry.cjs");var p=11,m=12,h=10,g={ArrowDown:1,ArrowLeft:-1,ArrowRight:1,ArrowUp:-1};function resolveGrid(e){return e===!1?null:{bands:!0,labels:!1,levels:4,shape:`polygon`,...typeof e==`object`?e:{}}}function createRadarChart(_,v){let{axes:y}=v,b=v.curve??`linear`,x=v.fill??`solid`,S=v.showPoints??!0,C=resolveGrid(v.grid),w=f.toRadians(v.startAngle??0),T=f.axisAngles(y.length,w),E=m+(v.showValues?h:0),D=u.uniqueId(`prism-radar`),O=v.series,k=e.createSvgElement(`g`,{class:`prism-radar`}),A=e.createSvgElement(`defs`),j=e.createSvgElement(`g`,{"aria-hidden":`true`,class:`prism-radar-grid`}),M=e.createSvgElement(`g`,{class:`prism-radar-series-group`}),N=e.createSvgElement(`g`,{"aria-hidden":`true`,class:`prism-radar-labels`});k.append(A,j,M,N);let P=[],F=null,I=-1,L={cx:0,cy:0,radius:0},datumAt=(e,t)=>e.data.find(e=>e.key===y[t].key),valuesAt=e=>O.map(t=>({datum:datumAt(t,e),series:t})),formatValue=(e,t)=>y[e].format?.(t)??String(t),describe=e=>t.describeValues(y[e].label,valuesAt(e),t=>formatValue(e,t));function draw(t){let{cx:n,cy:r,radius:i}=L;t.forEach((t,a)=>{let o=M.children[a];if(!o)return;let s=f.radarPoints(t,n,r,i,T);o.querySelector(`.prism-radar-area`)?.setAttribute(`d`,f.closedPath(s,b)),o.querySelectorAll(`.prism-radar-point`).forEach((t,n)=>{e.setAttributes(t,{cx:s[n].x,cy:s[n].y})}),o.querySelectorAll(`.prism-radar-value`).forEach((a,o)=>{let s=i*t[o]+h;e.setAttributes(a,{x:d.polarX(n,s,T[o]),y:d.polarY(r,s,T[o])})})})}function renderGrid(t){if(j.replaceChildren(),!C)return;let{cx:n,cy:r,radius:i}=L,a=Math.max(1,Math.round(C.levels)),o=Array.from({length:a},(e,t)=>f.ringPath(C.shape,n,r,i*(t+1)/a,T));if(C.bands)for(let t=a-1;t>=0;t-=2)j.appendChild(e.createSvgElement(`path`,{class:`prism-radar-band`,d:`${o[t]}${o[t-1]??``}`,"fill-rule":`evenodd`}));for(let t of o)j.appendChild(e.createSvgElement(`path`,{class:`prism-radar-ring`,d:t,fill:`none`}));T.forEach((t,a)=>{j.appendChild(e.createSvgElement(`line`,{class:`prism-radar-spoke`,"data-axis":a,x1:n,x2:d.polarX(n,i,t),y1:r,y2:d.polarY(r,i,t)}))});let[s,c]=t[0],l=t.every(([e,t])=>e===s&&t===c);if(!C.labels||!l)return;let u=T[0]+Math.PI/T.length;for(let t=1;t<=a;t++){let o=i*t/a,l=e.createSvgElement(`text`,{class:`prism-radar-level`,"dominant-baseline":`middle`,"text-anchor":`middle`,x:d.polarX(n,o,u),y:d.polarY(r,o,u)});l.textContent=formatValue(0,Math.round((s+(c-s)*t/a)*100)/100),j.appendChild(l)}}function renderLabels(){N.replaceChildren();let{cx:t,cy:n,radius:r}=L;y.forEach((i,a)=>{let{anchor:o,baseline:s}=f.labelPlacement(T[a]),c=e.createSvgElement(`text`,{class:`prism-radar-axis-label`,"dominant-baseline":s,"text-anchor":o,x:d.polarX(t,r+E,T[a]),y:d.polarY(n,r+E,T[a])});c.textContent=i.label,N.appendChild(c)})}function renderSeries(){let{cx:t,cy:n,radius:r}=L;for(A.replaceChildren();M.children.length>O.length;)M.lastChild?.remove();O.forEach((o,s)=>{let c=o.color??a.seriesColor(s),l=M.children[s];l||(l=e.createSvgElement(`g`,{class:`prism-radar-series`}),M.appendChild(l)),l.setAttribute(`data-series-id`,i.seriesDomId(o,s)),l.replaceChildren();let u=e.createSvgElement(`path`,{class:`prism-radar-area prism-radar-area--${x}`,stroke:c,"stroke-linejoin":`round`,"stroke-width":2});if(x===`gradient`){let i=`${D}-fill-${s}`,a=e.createSvgElement(`radialGradient`,{cx:t,cy:n,gradientUnits:`userSpaceOnUse`,id:i,r});for(let[t,n]of[[0,.08],[1,.55]])a.appendChild(e.createSvgElement(`stop`,{offset:t,"stop-color":c,"stop-opacity":n,style:`stop-color:${c}`}));A.appendChild(a),e.setAttributes(u,{fill:`url(#${i})`})}else e.setAttributes(u,{fill:x===`none`?`none`:c,"fill-opacity":.25});l.appendChild(u),S&&y.forEach((t,n)=>{let r=!Number.isFinite(datumAt(o,n)?.value);l.appendChild(e.createSvgElement(`circle`,{class:`prism-radar-point${r?` prism-radar-point--missing`:``}`,"data-axis":n,fill:r?`none`:c,r:3,stroke:c}))}),v.showValues&&y.forEach((t,n)=>{let r=datumAt(o,n),{anchor:i,baseline:a}=f.labelPlacement(T[n]),s=e.createSvgElement(`text`,{"aria-hidden":`true`,class:`prism-radar-value`,"dominant-baseline":a,"text-anchor":i});s.textContent=r&&Number.isFinite(r.value)?formatValue(n,r.value):``,l.appendChild(s)})})}function setActive(e){I=e;for(let t of k.querySelectorAll(`[data-axis]`)){let n=Number(t.getAttribute(`data-axis`))===e;t.classList.toggle(t.tagName===`line`?`prism-radar-spoke--active`:`prism-radar-point--active`,n)}}function animateTo(e,t){F?.();let n=e.map((e,t)=>e.map((e,n)=>P[t]?.[n]??0)),r=s.resolveMotion(v.transition,{defaultDuration:400}),i=o.resolveEasing(r.easing??`ease-out`),a=n.every((t,n)=>t.every((t,r)=>t===e[n][r]));if(r.duration===0||a){P=e,draw(e);return}F=l.startTween({count:e.length,duration:r.duration,easing:i,onFrame:t=>{P=e.map((e,r)=>{let i=t(r);return e.map((e,t)=>c.tweenNumber(n[r][t],e,i))}),draw(P)},signal:t,stagger:r.stagger})}return r.createRadialScaffold(_,{a11y:v.a11y,legend:v.legend,tooltip:v.tooltip},e=>{let{legend:t,svg:r,tooltip:i}=e;if(r.contains(k)||r.appendChild(k),i?.hide(),t?.update(O.map((e,t)=>({color:e.color??a.seriesColor(t),name:e.name}))),y.length<3){for(let e of[A,j,M,N])e.replaceChildren();P=[];return}let{height:o,width:s}=e.dimensions,c=f.fitRadius(s,o,y.map(e=>e.label),T,p,E);L={cx:s/2,cy:o/2,radius:c};let l=f.resolveAxisDomains(y,O,v.domain);renderGrid(l),renderLabels(),renderSeries(),animateTo(O.map(e=>y.map((t,n)=>{let r=datumAt(e,n)?.value;return r!==void 0&&Number.isFinite(r)?f.normalize(r,l[n]):0})),e.disposalSignal),setActive(I);let eventFor=(e,t)=>({axis:y[e],index:e,originalEvent:t,values:valuesAt(e)}),activate=(t,o)=>{setActive(t),v.onHover?.(eventFor(t,o));let s=describe(t);if(!i){e.announcer.announce(s);return}let c=Math.max(0,...P.map(e=>e[t]??0)),l=r.getBoundingClientRect(),u=_.getBoundingClientRect(),f=valuesAt(t),p=f.find(e=>e.datum)?.datum,m=f.flatMap(({datum:e,series:n})=>e?[{color:n.color??a.seriesColor(O.indexOf(n)),name:n.name,value:formatValue(t,e.value)}]:[]);i.show(d.polarX(L.cx,L.radius*c,T[t])+(l.left-u.left),d.polarY(L.cy,L.radius*c,T[t])+(l.top-u.top),{key:y[t].key,meta:{axis:y[t],text:s,values:f},value:p?.value??0},{color:O[0]?.color??a.seriesColor(0),data:[],name:y[t].label},n.comparisonContent(r.ownerDocument,y[t].label,m,s))},deactivate=()=>{setActive(-1),v.onHover?.(null),i?.hide(),e.announcer.clear()},hitIndex=e=>{let t=r.getBoundingClientRect(),n=e.clientX-t.left-L.cx,i=e.clientY-t.top-L.cy;return Math.hypot(n,i)>L.radius+E+22?-1:f.nearestAxis(n,i,y.length,w)};return{onClick(e){let t=hitIndex(e);t>=0&&v.onClick?.(eventFor(t,e))},onKeyDown(e){let t=g[e.key];t===void 0?(e.key===`Enter`||e.key===` `)&&I>=0&&v.onClick?(e.preventDefault(),v.onClick(eventFor(I,e))):e.key===`Escape`&&deactivate():(e.preventDefault(),activate(I<0?0:(I+t+y.length)%y.length,e))},onMouseLeave:deactivate,onMouseMove(e){let t=hitIndex(e);t<0?I>=0&&deactivate():t!==I&&activate(t,e)}}},e=>{O=e})}exports.createRadarChart=createRadarChart;
2
2
  //# sourceMappingURL=radar-chart.cjs.map