@vielzeug/prism 2.2.5 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/README.md +19 -40
  2. package/dist/_dev.cjs +1 -1
  3. package/dist/_dev.cjs.map +1 -1
  4. package/dist/_dev.js +1 -2
  5. package/dist/_dev.js.map +1 -1
  6. package/dist/axes/axis.cjs +1 -1
  7. package/dist/axes/axis.cjs.map +1 -1
  8. package/dist/axes/axis.d.ts +1 -0
  9. package/dist/axes/axis.d.ts.map +1 -1
  10. package/dist/axes/axis.js +15 -11
  11. package/dist/axes/axis.js.map +1 -1
  12. package/dist/charts/area/area-chart.cjs +1 -1
  13. package/dist/charts/area/area-chart.cjs.map +1 -1
  14. package/dist/charts/area/area-chart.d.ts +2 -2
  15. package/dist/charts/area/area-chart.d.ts.map +1 -1
  16. package/dist/charts/area/area-chart.js +31 -31
  17. package/dist/charts/area/area-chart.js.map +1 -1
  18. package/dist/charts/area/area-renderer.cjs +1 -1
  19. package/dist/charts/area/area-renderer.cjs.map +1 -1
  20. package/dist/charts/area/area-renderer.d.ts +2 -2
  21. package/dist/charts/area/area-renderer.d.ts.map +1 -1
  22. package/dist/charts/area/area-renderer.js +14 -14
  23. package/dist/charts/area/area-renderer.js.map +1 -1
  24. package/dist/charts/bar/bar-chart.cjs +1 -1
  25. package/dist/charts/bar/bar-chart.cjs.map +1 -1
  26. package/dist/charts/bar/bar-chart.d.ts +2 -2
  27. package/dist/charts/bar/bar-chart.d.ts.map +1 -1
  28. package/dist/charts/bar/bar-chart.js +58 -56
  29. package/dist/charts/bar/bar-chart.js.map +1 -1
  30. package/dist/charts/bar/bar-hit-test.cjs +1 -1
  31. package/dist/charts/bar/bar-hit-test.cjs.map +1 -1
  32. package/dist/charts/bar/bar-hit-test.js +5 -4
  33. package/dist/charts/bar/bar-hit-test.js.map +1 -1
  34. package/dist/charts/bar/bar-renderer.cjs +1 -1
  35. package/dist/charts/bar/bar-renderer.js +24 -24
  36. package/dist/charts/line/line-chart.cjs +1 -1
  37. package/dist/charts/line/line-chart.cjs.map +1 -1
  38. package/dist/charts/line/line-chart.d.ts +2 -2
  39. package/dist/charts/line/line-chart.d.ts.map +1 -1
  40. package/dist/charts/line/line-chart.js +31 -31
  41. package/dist/charts/line/line-chart.js.map +1 -1
  42. package/dist/charts/line/line-renderer.cjs +1 -1
  43. package/dist/charts/line/line-renderer.cjs.map +1 -1
  44. package/dist/charts/line/line-renderer.d.ts +2 -2
  45. package/dist/charts/line/line-renderer.d.ts.map +1 -1
  46. package/dist/charts/line/line-renderer.js +34 -34
  47. package/dist/charts/line/line-renderer.js.map +1 -1
  48. package/dist/charts/pie/pie-chart.cjs +1 -1
  49. package/dist/charts/pie/pie-chart.cjs.map +1 -1
  50. package/dist/charts/pie/pie-chart.d.ts +2 -2
  51. package/dist/charts/pie/pie-chart.d.ts.map +1 -1
  52. package/dist/charts/pie/pie-chart.js +118 -109
  53. package/dist/charts/pie/pie-chart.js.map +1 -1
  54. package/dist/charts/sparkline/sparkline.cjs +1 -1
  55. package/dist/charts/sparkline/sparkline.cjs.map +1 -1
  56. package/dist/charts/sparkline/sparkline.d.ts +2 -2
  57. package/dist/charts/sparkline/sparkline.d.ts.map +1 -1
  58. package/dist/charts/sparkline/sparkline.js +119 -117
  59. package/dist/charts/sparkline/sparkline.js.map +1 -1
  60. package/dist/core/chart-base.cjs +1 -1
  61. package/dist/core/chart-base.cjs.map +1 -1
  62. package/dist/core/chart-base.d.ts +2 -4
  63. package/dist/core/chart-base.d.ts.map +1 -1
  64. package/dist/core/chart-base.js +21 -30
  65. package/dist/core/chart-base.js.map +1 -1
  66. package/dist/core/chart-scaffold.cjs +1 -1
  67. package/dist/core/chart-scaffold.cjs.map +1 -1
  68. package/dist/core/chart-scaffold.d.ts +9 -10
  69. package/dist/core/chart-scaffold.d.ts.map +1 -1
  70. package/dist/core/chart-scaffold.js +31 -43
  71. package/dist/core/chart-scaffold.js.map +1 -1
  72. package/dist/core/layout.cjs +1 -1
  73. package/dist/core/layout.cjs.map +1 -1
  74. package/dist/core/layout.js +1 -1
  75. package/dist/core/layout.js.map +1 -1
  76. package/dist/index.cjs +1 -1
  77. package/dist/index.d.ts +2 -6
  78. package/dist/index.d.ts.map +1 -1
  79. package/dist/index.js +11 -12
  80. package/dist/interaction/legend.cjs +1 -1
  81. package/dist/interaction/legend.cjs.map +1 -1
  82. package/dist/interaction/legend.js +1 -1
  83. package/dist/interaction/legend.js.map +1 -1
  84. package/dist/interaction/tooltip.cjs +1 -1
  85. package/dist/interaction/tooltip.cjs.map +1 -1
  86. package/dist/interaction/tooltip.d.ts.map +1 -1
  87. package/dist/interaction/tooltip.js +29 -29
  88. package/dist/interaction/tooltip.js.map +1 -1
  89. package/dist/prism.cjs +1 -1
  90. package/dist/prism.cjs.map +1 -1
  91. package/dist/prism.iife.js +1 -1
  92. package/dist/prism.iife.js.map +1 -1
  93. package/dist/prism.js +1 -1
  94. package/dist/prism.js.map +1 -1
  95. package/dist/types.d.ts +24 -48
  96. package/dist/types.d.ts.map +1 -1
  97. package/package.json +8 -9
@@ -1,8 +1,8 @@
1
- import { resolveEasing as e } from "../../animation/easing.js";
2
- import { resolveMotion as t } from "../../animation/motion.js";
3
- import { tweenNumber as n } from "../../animation/tween.js";
4
1
  import "../../_dev.js";
5
- import { createSvgElement as r, setAttributes as i } from "../../svg/element.js";
2
+ import { createSvgElement as e, setAttributes as t } from "../../svg/element.js";
3
+ import { resolveEasing as n } from "../../animation/easing.js";
4
+ import { resolveMotion as r } from "../../animation/motion.js";
5
+ import { tweenNumber as i } from "../../animation/tween.js";
6
6
  import { areaPath as a, linePath as o, monotonePath as s, stepPath as c } from "../../svg/path.js";
7
7
  //#region src/charts/area/area-renderer.ts
8
8
  var l = /* @__PURE__ */ new WeakMap(), u = /* @__PURE__ */ new WeakMap();
@@ -10,17 +10,17 @@ function d(e, t) {
10
10
  return t === "monotone" ? s(e) : t === "step" ? c(e) : o(e);
11
11
  }
12
12
  function f(o, s, c, f) {
13
- let p = t(f.transition, 0), m = p.duration, h = e(p.easing), g = o.querySelector(".prism-area-fill");
14
- g || (g = r("path", { class: "prism-area-fill" }), o.appendChild(g)), i(g, {
13
+ let p = r(f.transition, 0), m = p.duration, h = n(p.easing), g = o.querySelector(".prism-area-fill");
14
+ g || (g = e("path", { class: "prism-area-fill" }), o.appendChild(g)), t(g, {
15
15
  fill: f.color,
16
16
  "fill-opacity": f.fillOpacity,
17
17
  stroke: "none"
18
18
  });
19
19
  let _ = null;
20
- if (f.showLine ? (_ = o.querySelector(".prism-area-line"), _ || (_ = r("path", {
20
+ if (f.showLine ? (_ = o.querySelector(".prism-area-line"), _ || (_ = e("path", {
21
21
  class: "prism-area-line",
22
22
  fill: "none"
23
- }), o.appendChild(_)), i(_, {
23
+ }), o.appendChild(_)), t(_, {
24
24
  stroke: f.color,
25
25
  "stroke-width": 2
26
26
  })) : o.querySelector(".prism-area-line")?.remove(), m === 0) {
@@ -28,7 +28,7 @@ function f(o, s, c, f) {
28
28
  x: e.x,
29
29
  y: c
30
30
  }));
31
- i(g, { d: a(s, e, f.curve) }), _ && i(_, { d: d(s, f.curve) });
31
+ t(g, { d: a(s, e, f.curve) }), _ && t(_, { d: d(s, f.curve) });
32
32
  return;
33
33
  }
34
34
  if (l.get(o)?.(), !g.hasAttribute("d")) {
@@ -36,7 +36,7 @@ function f(o, s, c, f) {
36
36
  x: e.x,
37
37
  y: c
38
38
  }));
39
- i(g, { d: a(s, e, f.curve) }), _ && i(_, { d: d(s, f.curve) }), u.set(o, s);
39
+ t(g, { d: a(s, e, f.curve) }), _ && t(_, { d: d(s, f.curve) }), u.set(o, s);
40
40
  return;
41
41
  }
42
42
  let v = u.get(o) ?? s, y = s.map((e, t) => v[t] ?? v[v.length - 1] ?? s[t]), b = null;
@@ -46,14 +46,14 @@ function f(o, s, c, f) {
46
46
  return;
47
47
  }
48
48
  b === null && (b = e);
49
- let t = Math.min(1, (e - b) / m), r = h(t), p = s.map((e, t) => ({
50
- x: n(y[t].x, e.x, r),
51
- y: n(y[t].y, e.y, r)
49
+ let n = Math.min(1, (e - b) / m), r = h(n), p = s.map((e, t) => ({
50
+ x: i(y[t].x, e.x, r),
51
+ y: i(y[t].y, e.y, r)
52
52
  })), v = p.map((e) => ({
53
53
  x: e.x,
54
54
  y: c
55
55
  }));
56
- if (i(g, { d: a(p, v, f.curve) }), _ && i(_, { d: d(p, f.curve) }), t < 1) {
56
+ if (t(g, { d: a(p, v, f.curve) }), _ && t(_, { d: d(p, f.curve) }), n < 1) {
57
57
  let e = requestAnimationFrame(x);
58
58
  l.set(o, () => cancelAnimationFrame(e));
59
59
  } else l.delete(o), u.set(o, s);
@@ -1 +1 @@
1
- {"version":3,"file":"area-renderer.js","names":[],"sources":["../../../src/charts/area/area-renderer.ts"],"sourcesContent":["import { warn } from '../../_dev';\nimport { resolveEasing } from '../../animation/easing';\nimport { resolveMotion } from '../../animation/motion';\nimport { tweenNumber } from '../../animation/tween';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport type { Point } from '../../svg/path';\nimport { areaPath, linePath, monotonePath, stepPath } from '../../svg/path';\nimport type { Datum, Scale, TransitionConfig } from '../../types';\n\nexport interface AreaRenderOptions {\n color: string;\n curve: 'linear' | 'monotone' | 'step';\n /** Aborted when the owning chart is disposed — stops the transition's `requestAnimationFrame` loop from rescheduling. */\n disposalSignal?: AbortSignal;\n fillOpacity: number;\n showLine: boolean;\n transition?: TransitionConfig;\n}\n\nconst activeAreaAnimations = new WeakMap<SVGGElement, () => void>();\nconst previousPoints = new WeakMap<SVGGElement, Point[]>();\n\nfunction buildLinePath(pts: Point[], curve: AreaRenderOptions['curve']): string {\n return curve === 'monotone' ? monotonePath(pts) : curve === 'step' ? stepPath(pts) : linePath(pts);\n}\n\nexport function renderArea(parent: SVGGElement, points: Point[], baselineY: number, options: AreaRenderOptions): void {\n const motion = resolveMotion(options.transition, 0);\n const dur = motion.duration;\n const easing = resolveEasing(motion.easing);\n\n let fill = parent.querySelector<SVGPathElement>('.prism-area-fill');\n\n if (!fill) {\n fill = createSvgElement('path', { class: 'prism-area-fill' });\n parent.appendChild(fill);\n }\n\n setAttributes(fill, { fill: options.color, 'fill-opacity': options.fillOpacity, stroke: 'none' });\n\n let line: SVGPathElement | null = null;\n\n if (options.showLine) {\n line = parent.querySelector<SVGPathElement>('.prism-area-line');\n\n if (!line) {\n line = createSvgElement('path', { class: 'prism-area-line', fill: 'none' });\n parent.appendChild(line);\n }\n\n setAttributes(line, { stroke: options.color, 'stroke-width': 2 });\n } else {\n parent.querySelector('.prism-area-line')?.remove();\n }\n\n if (dur === 0) {\n const bottomPoints = points.map((p) => ({ x: p.x, y: baselineY }));\n\n setAttributes(fill, { d: areaPath(points, bottomPoints, options.curve) });\n\n if (line) setAttributes(line, { d: buildLinePath(points, options.curve) });\n\n return;\n }\n\n activeAreaAnimations.get(parent)?.();\n\n const hasExisting = fill.hasAttribute('d');\n\n if (!hasExisting) {\n const bottomPoints = points.map((p) => ({ x: p.x, y: baselineY }));\n\n setAttributes(fill, { d: areaPath(points, bottomPoints, options.curve) });\n\n if (line) setAttributes(line, { d: buildLinePath(points, options.curve) });\n\n previousPoints.set(parent, points);\n\n return;\n }\n\n const rawFrom = previousPoints.get(parent) ?? points;\n const fromPoints: Point[] = points.map((_, i) => rawFrom[i] ?? rawFrom[rawFrom.length - 1] ?? points[i]);\n\n let startTime: number | null = null;\n\n function frame(ts: number) {\n if (options.disposalSignal?.aborted) {\n activeAreaAnimations.delete(parent);\n\n return;\n }\n\n if (startTime === null) startTime = ts;\n\n const t = Math.min(1, (ts - startTime) / dur);\n const e = easing(t);\n const interpolated: Point[] = points.map((to, i) => ({\n x: tweenNumber(fromPoints[i].x, to.x, e),\n y: tweenNumber(fromPoints[i].y, to.y, e),\n }));\n const interpolatedBottom = interpolated.map((p) => ({ x: p.x, y: baselineY }));\n\n setAttributes(fill!, { d: areaPath(interpolated, interpolatedBottom, options.curve) });\n\n if (line) setAttributes(line, { d: buildLinePath(interpolated, options.curve) });\n\n if (t < 1) {\n const id = requestAnimationFrame(frame);\n\n activeAreaAnimations.set(parent, () => cancelAnimationFrame(id));\n } else {\n activeAreaAnimations.delete(parent);\n previousPoints.set(parent, points);\n }\n }\n\n previousPoints.set(parent, fromPoints);\n\n const id = requestAnimationFrame(frame);\n\n activeAreaAnimations.set(parent, () => cancelAnimationFrame(id));\n}\n\nexport function computeAreaPoints(data: Datum[], xScale: Scale<Date | number>, yScale: Scale<number>): Point[] {\n if (data.some((d) => d.key == null)) {\n warn(\n 'computeAreaPoints: datum.key is null or undefined — data must use the Datum shape { key, value }. Did you pass { x, y } instead?',\n );\n } else if (data.some((d) => typeof d.key === 'string')) {\n warn('computeAreaPoints: string keys are not supported for line/area charts — use numeric or Date keys.');\n }\n\n return data.map((d) => ({\n x: xScale.map(d.key as Date | number),\n y: yScale.map(d.value),\n }));\n}\n"],"mappings":";;;;;;;AAmBA,IAAM,oBAAuB,IAAI,QAAiC,GAC5D,oBAAiB,IAAI,QAA8B;AAEzD,SAAS,EAAc,GAAc,GAA2C;CAC9E,OAAO,MAAU,aAAa,EAAa,CAAG,IAAI,MAAU,SAAS,EAAS,CAAG,IAAI,EAAS,CAAG;AACnG;AAEA,SAAgB,EAAW,GAAqB,GAAiB,GAAmB,GAAkC;CACpH,IAAM,IAAS,EAAc,EAAQ,YAAY,CAAC,GAC5C,IAAM,EAAO,UACb,IAAS,EAAc,EAAO,MAAM,GAEtC,IAAO,EAAO,cAA8B,kBAAkB;CAOlE,AALK,MACH,IAAO,EAAiB,QAAQ,EAAE,OAAO,kBAAkB,CAAC,GAC5D,EAAO,YAAY,CAAI,IAGzB,EAAc,GAAM;EAAE,MAAM,EAAQ;EAAO,gBAAgB,EAAQ;EAAa,QAAQ;CAAO,CAAC;CAEhG,IAAI,IAA8B;CAelC,IAbI,EAAQ,YACV,IAAO,EAAO,cAA8B,kBAAkB,GAEzD,MACH,IAAO,EAAiB,QA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,GAAG,EAAG,GAAG,CAAC;GACvC,GAAG,EAAY,EAAW,EAAE,CAAC,GAAG,EAAG,GAAG,CAAC;EACzC,EAAE,GACI,IAAqB,EAAa,KAAK,OAAO;GAAE,GAAG,EAAE;GAAG,GAAG;EAAU,EAAE;EAM7E,IAJA,EAAc,GAAO,EAAE,GAAG,EAAS,GAAc,GAAoB,EAAQ,KAAK,EAAE,CAAC,GAEjF,KAAM,EAAc,GAAM,EAAE,GAAG,EAAc,GAAc,EAAQ,KAAK,EAAE,CAAC,GAE3E,IAAI,GAAG;GACT,IAAM,IAAK,sBAAsB,CAAK;GAEtC,EAAqB,IAAI,SAAc,qBAAqB,CAAE,CAAC;EACjE,OAEE,AADA,EAAqB,OAAO,CAAM,GAClC,EAAe,IAAI,GAAQ,CAAM;CAErC;CAEA,EAAe,IAAI,GAAQ,CAAU;CAErC,IAAM,IAAK,sBAAsB,CAAK;CAEtC,EAAqB,IAAI,SAAc,qBAAqB,CAAE,CAAC;AACjE;AAEA,SAAgB,EAAkB,GAAe,GAA8B,GAAgC;CAS7G,OARI,EAAK,MAAM,MAAM,EAAE,OAAO,IAAI,KAIvB,EAAK,MAAM,MAAM,OAAO,EAAE,OAAQ,QAAQ,GAI9C,EAAK,KAAK,OAAO;EACtB,GAAG,EAAO,IAAI,EAAE,GAAoB;EACpC,GAAG,EAAO,IAAI,EAAE,KAAK;CACvB,EAAE;AACJ"}
1
+ {"version":3,"file":"area-renderer.js","names":[],"sources":["../../../src/charts/area/area-renderer.ts"],"sourcesContent":["import { warn } from '../../_dev';\nimport { resolveEasing } from '../../animation/easing';\nimport { resolveMotion } from '../../animation/motion';\nimport { tweenNumber } from '../../animation/tween';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport type { Point } from '../../svg/path';\nimport { areaPath, linePath, monotonePath, stepPath } from '../../svg/path';\nimport type { ContinuousDatum, Scale, TransitionConfig } from '../../types';\n\nexport interface AreaRenderOptions {\n color: string;\n curve: 'linear' | 'monotone' | 'step';\n /** Aborted when the owning chart is disposed — stops the transition's `requestAnimationFrame` loop from rescheduling. */\n disposalSignal?: AbortSignal;\n fillOpacity: number;\n showLine: boolean;\n transition?: TransitionConfig;\n}\n\nconst activeAreaAnimations = new WeakMap<SVGGElement, () => void>();\nconst previousPoints = new WeakMap<SVGGElement, Point[]>();\n\nfunction buildLinePath(pts: Point[], curve: AreaRenderOptions['curve']): string {\n return curve === 'monotone' ? monotonePath(pts) : curve === 'step' ? stepPath(pts) : linePath(pts);\n}\n\nexport function renderArea(parent: SVGGElement, points: Point[], baselineY: number, options: AreaRenderOptions): void {\n const motion = resolveMotion(options.transition, 0);\n const dur = motion.duration;\n const easing = resolveEasing(motion.easing);\n\n let fill = parent.querySelector<SVGPathElement>('.prism-area-fill');\n\n if (!fill) {\n fill = createSvgElement('path', { class: 'prism-area-fill' });\n parent.appendChild(fill);\n }\n\n setAttributes(fill, { fill: options.color, 'fill-opacity': options.fillOpacity, stroke: 'none' });\n\n let line: SVGPathElement | null = null;\n\n if (options.showLine) {\n line = parent.querySelector<SVGPathElement>('.prism-area-line');\n\n if (!line) {\n line = createSvgElement('path', { class: 'prism-area-line', fill: 'none' });\n parent.appendChild(line);\n }\n\n setAttributes(line, { stroke: options.color, 'stroke-width': 2 });\n } else {\n parent.querySelector('.prism-area-line')?.remove();\n }\n\n if (dur === 0) {\n const bottomPoints = points.map((p) => ({ x: p.x, y: baselineY }));\n\n setAttributes(fill, { d: areaPath(points, bottomPoints, options.curve) });\n\n if (line) setAttributes(line, { d: buildLinePath(points, options.curve) });\n\n return;\n }\n\n activeAreaAnimations.get(parent)?.();\n\n const hasExisting = fill.hasAttribute('d');\n\n if (!hasExisting) {\n const bottomPoints = points.map((p) => ({ x: p.x, y: baselineY }));\n\n setAttributes(fill, { d: areaPath(points, bottomPoints, options.curve) });\n\n if (line) setAttributes(line, { d: buildLinePath(points, options.curve) });\n\n previousPoints.set(parent, points);\n\n return;\n }\n\n const rawFrom = previousPoints.get(parent) ?? points;\n const fromPoints: Point[] = points.map((_, i) => rawFrom[i] ?? rawFrom[rawFrom.length - 1] ?? points[i]);\n\n let startTime: number | null = null;\n\n function frame(ts: number) {\n if (options.disposalSignal?.aborted) {\n activeAreaAnimations.delete(parent);\n\n return;\n }\n\n if (startTime === null) startTime = ts;\n\n const t = Math.min(1, (ts - startTime) / dur);\n const e = easing(t);\n const interpolated: Point[] = points.map((to, i) => ({\n x: tweenNumber(fromPoints[i].x, to.x, e),\n y: tweenNumber(fromPoints[i].y, to.y, e),\n }));\n const interpolatedBottom = interpolated.map((p) => ({ x: p.x, y: baselineY }));\n\n setAttributes(fill!, { d: areaPath(interpolated, interpolatedBottom, options.curve) });\n\n if (line) setAttributes(line, { d: buildLinePath(interpolated, options.curve) });\n\n if (t < 1) {\n const id = requestAnimationFrame(frame);\n\n activeAreaAnimations.set(parent, () => cancelAnimationFrame(id));\n } else {\n activeAreaAnimations.delete(parent);\n previousPoints.set(parent, points);\n }\n }\n\n previousPoints.set(parent, fromPoints);\n\n const id = requestAnimationFrame(frame);\n\n activeAreaAnimations.set(parent, () => cancelAnimationFrame(id));\n}\n\nexport function computeAreaPoints(\n data: ContinuousDatum[],\n xScale: Scale<Date | number>,\n yScale: Scale<number>,\n): Point[] {\n if (data.some((d) => d.key == null)) {\n warn(\n 'computeAreaPoints: datum.key is null or undefined — data must use the Datum shape { key, value }. Did you pass { x, y } instead?',\n );\n } else if (data.some((d) => typeof d.key === 'string')) {\n warn('computeAreaPoints: string keys are not supported for line/area charts — use numeric or Date keys.');\n }\n\n return data.map((d) => ({\n x: xScale.map(d.key as Date | number),\n y: yScale.map(d.value),\n }));\n}\n"],"mappings":";;;;;;;AAmBA,IAAM,oBAAuB,IAAI,QAAiC,GAC5D,oBAAiB,IAAI,QAA8B;AAEzD,SAAS,EAAc,GAAc,GAA2C;CAC9E,OAAO,MAAU,aAAa,EAAa,CAAG,IAAI,MAAU,SAAS,EAAS,CAAG,IAAI,EAAS,CAAG;AACnG;AAEA,SAAgB,E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,GAAoB;EACpC,GAAG,EAAO,IAAI,EAAE,KAAK;CACvB,EAAE;AACJ"}
@@ -1,2 +1,2 @@
1
- require("../../_dev.cjs");const e=require("../../svg/element.cjs"),t=require("../../axes/axis.cjs"),n=require("../../axes/grid.cjs"),r=require("../../scales/linear.cjs"),i=require("../../core/layout.cjs"),a=require("../../core/chart-scaffold.cjs"),o=require("../../core/cartesian-model.cjs"),s=require("../../interaction/events.cjs"),c=require("../../theme/index.cjs"),l=require("../../scales/band.cjs"),u=require("./bar-hit-test.cjs"),d=require("./bar-renderer.cjs");let f=require("@vielzeug/ripple");function p(e){return{horizontal:e===`grouped-horizontal`||e===`stacked-horizontal`,stacked:e===`stacked`||e===`stacked-horizontal`}}function m(m,h){return a.createChartScaffold(m,h,m=>{let{groups:g,legend:_,tooltip:v}=m,y=m.dimensions.value,b=i.chartArea(y.width,y.height,y.margin),x=(0,f.isReactive)(h.series)?h.series.value:h.series,S=x.map(e=>(0,f.isReactive)(e.data)?e.data.value:e.data),C=o.normalizeCartesianSeries(x,S),w=C.domain,T=C.series.map(({byKey:e})=>w.map(t=>e.get(t))),E=e=>{if(e)return{...e,tickFormat:t=>{let n=String(t),r=C.labels.get(n)??t;return e.tickFormat?e.tickFormat(r):String(r)}}};if(w.length===0){a.clearCartesianDom(g,_,v);return}let{horizontal:D,stacked:O}=p(h.variant??`grouped`),k,A;if(O){T.some(e=>e.some(e=>(e?.value??0)<0));let e=w.map((e,t)=>T.reduce((e,n)=>e+Math.max(0,n[t]?.value??0),0));k=Math.max(...e),A=0}else{let e=T.flatMap(e=>e.flatMap(e=>e?[e.value]:[]));k=Math.max(...e),A=Math.min(0,...e)}let j=D?l.bandScale({domain:w,range:[0,b.height]}):l.bandScale({domain:w,range:[0,b.width]}),M=D?r.linearScale({domain:[A,k],range:[0,b.width]}):r.linearScale({domain:[A,k],range:[b.height,0]}),N=[],P=Object.create(null);for(let e of w)P[e]=0;let F={bandCenter:e=>j.map(e)+j.bandwidth()/2,bandwidth:j.bandwidth(),baselinePx:M.map(0),horizontal:D,stacked:O,stackedTops:N,valueScale:M};if(D){h.xAxis?.grid&&n.renderGrid(g.grid,M,h.xAxis.grid,b.height,`vertical`,t.resolveTickCount(h.xAxis,b.width,`bottom`));let e=E(h.yAxis);e&&t.renderAxis(g.yAxis,j,e,b.height,`left`),h.xAxis&&(g.xAxis.setAttribute(`transform`,`translate(0,${b.height})`),t.renderAxis(g.xAxis,M,h.xAxis,b.width,`bottom`))}else{h.yAxis?.grid&&n.renderGrid(g.grid,M,h.yAxis.grid,b.width,`horizontal`,t.resolveTickCount(h.yAxis,b.height,`left`));let e=E(h.xAxis);e&&(g.xAxis.setAttribute(`transform`,`translate(0,${b.height})`),t.renderAxis(g.xAxis,j,e,b.width,`bottom`)),h.yAxis&&t.renderAxis(g.yAxis,M,h.yAxis,b.height,`left`)}for(;g.series.children.length>x.length;){let e=g.series.lastElementChild;e&&g.series.removeChild(e)}for(let t=0;t<x.length;t++){let n=x[t],r=g.series.children[t];r||(r=e.createSvgElement(`g`,{class:`prism-bar-series`}),g.series.appendChild(r));let i=w.map((e,n)=>{let r=T[t]?.[n];if(O){let t=P[e]??0,n=t+Math.max(0,r?.value??0);return P[e]=n,{base:t,key:e,present:r!==void 0,y:n}}return{base:0,key:e,present:r!==void 0,y:r?.value??0}});N[t]=i.map(e=>e.y);let a=O?i.map(e=>M.map(e.base)):void 0;d.renderBars(r,i,j,M,F.baselinePx,{baselineYs:a,borderRadius:n.borderRadius??0,color:c.seriesColor(t,n.color),disposalSignal:m.disposalSignal,horizontal:D,seriesCount:x.length,seriesIndex:t,stacked:O,transition:h.transition})}return _?.update(x.map((e,t)=>({color:c.seriesColor(t,e.color),name:e.name}))),v?.hide(),{onClick:e=>{if(!h.onClick)return;let t=m.dimensions.value,n=s.getMousePosition(m.svg,e,t.margin.left,t.margin.top),r=i.chartArea(t.width,t.height,t.margin);if(n.x<0||n.x>r.width||n.y<0||n.y>r.height)return;let a=D?n.y:n.x,o=u.findCatIdx(a,w,F);if(o===-1)return;let c=u.findSeriesIdx(n,o,w,F,x.length),l=T[c]?.[o];l&&h.onClick({datum:l,originalEvent:e,series:x[c]})},onMouseLeave:()=>{v?.hide(),h.onHover?.(null)},onMouseMove:e=>{let t=m.dimensions.value,n=s.getMousePosition(m.svg,e,t.margin.left,t.margin.top),r=i.chartArea(t.width,t.height,t.margin);if(n.x<0||n.x>r.width||n.y<0||n.y>r.height){v?.hide();return}let a=D?n.y:n.x,o=u.findCatIdx(a,w,F);if(o===-1){v?.hide();return}if(u.isOutsideBars(n,o,T,F,x.length)){v?.hide();return}let c=u.findSeriesIdx(n,o,w,F,x.length),l=T[c]?.[o];if(l){let n=F.bandCenter(w[o]),r=O?N[c]?.[o]??l.value:l.value,i=M.map(r),a=D?i+t.margin.left:n+t.margin.left,s=D?n+t.margin.top:i+t.margin.top;v?.show(a,s,l,x[c]),h.onHover?.({datum:l,originalEvent:e,series:x[c]})}}}})}exports.createBarChart=m;
1
+ require("../../_dev.cjs");const e=require("../../svg/element.cjs"),t=require("../../axes/axis.cjs"),n=require("../../axes/grid.cjs"),r=require("../../scales/linear.cjs"),i=require("../../core/layout.cjs"),a=require("../../core/chart-scaffold.cjs"),o=require("../../core/cartesian-model.cjs"),s=require("../../interaction/events.cjs"),c=require("../../theme/index.cjs"),l=require("../../scales/band.cjs"),u=require("./bar-hit-test.cjs"),d=require("./bar-renderer.cjs");function f(e){return{horizontal:e===`grouped-horizontal`||e===`stacked-horizontal`,stacked:e===`stacked`||e===`stacked-horizontal`}}function p(p,m){let h=m.series;return a.createChartScaffold(p,m,p=>{let{groups:g,legend:_,tooltip:v}=p,y=p.dimensions,b=i.chartArea(y.width,y.height,y.margin),x=h.map(e=>e.data),S=o.normalizeCartesianSeries(h,x),C=S.domain,w=S.series.map(({byKey:e})=>C.map(t=>e.get(t))),T=e=>{if(e)return{...e,tickFormat:t=>{let n=String(t),r=S.labels.get(n)??t;return e.tickFormat?e.tickFormat(r):String(r)}}};if(C.length===0){a.clearCartesianDom(g,_,v);return}let{horizontal:E,stacked:D}=f(m.variant??`grouped`),O,k;if(D){w.some(e=>e.some(e=>(e?.value??0)<0));let e=C.map((e,t)=>w.reduce((e,n)=>e+Math.max(0,n[t]?.value??0),0));O=Math.max(...e),k=0}else{let e=w.flatMap(e=>e.flatMap(e=>e?[e.value]:[]));O=Math.max(...e),k=Math.min(0,...e)}let A=E?l.bandScale({domain:C,range:[0,b.height]}):l.bandScale({domain:C,range:[0,b.width]}),j=E?r.linearScale({domain:[k,O],range:[0,b.width]}):r.linearScale({domain:[k,O],range:[b.height,0]}),M=[],N=Object.create(null);for(let e of C)N[e]=0;let P={bandCenter:e=>A.map(e)+A.bandwidth()/2,bandwidth:A.bandwidth(),baselinePx:j.map(0),horizontal:E,stacked:D,stackedTops:M,valueScale:j};if(E){m.xAxis?.grid&&n.renderGrid(g.grid,j,m.xAxis.grid,b.height,`vertical`,t.resolveTickCount(m.xAxis,b.width,`bottom`));let e=T(m.yAxis);e&&(t.positionAxis(g.yAxis,e.position??`left`,b.width,b.height),t.renderAxis(g.yAxis,A,e,b.height,`left`)),m.xAxis&&(t.positionAxis(g.xAxis,m.xAxis.position??`bottom`,b.width,b.height),t.renderAxis(g.xAxis,j,m.xAxis,b.width,`bottom`))}else{m.yAxis?.grid&&n.renderGrid(g.grid,j,m.yAxis.grid,b.width,`horizontal`,t.resolveTickCount(m.yAxis,b.height,`left`));let e=T(m.xAxis);e&&(t.positionAxis(g.xAxis,e.position??`bottom`,b.width,b.height),t.renderAxis(g.xAxis,A,e,b.width,`bottom`)),m.yAxis&&(t.positionAxis(g.yAxis,m.yAxis.position??`left`,b.width,b.height),t.renderAxis(g.yAxis,j,m.yAxis,b.height,`left`))}for(;g.series.children.length>h.length;){let e=g.series.lastElementChild;e&&g.series.removeChild(e)}for(let t=0;t<h.length;t++){let n=h[t],r=g.series.children[t];r||(r=e.createSvgElement(`g`,{class:`prism-bar-series`}),g.series.appendChild(r));let i=C.map((e,n)=>{let r=w[t]?.[n];if(D){let t=N[e]??0,n=t+Math.max(0,r?.value??0);return N[e]=n,{base:t,key:e,present:r!==void 0,y:n}}return{base:0,key:e,present:r!==void 0,y:r?.value??0}});M[t]=i.map(e=>e.y);let a=D?i.map(e=>j.map(e.base)):void 0;d.renderBars(r,i,A,j,P.baselinePx,{baselineYs:a,borderRadius:n.borderRadius??0,color:c.seriesColor(t,n.color),disposalSignal:p.disposalSignal,horizontal:E,seriesCount:h.length,seriesIndex:t,stacked:D,transition:m.transition})}return _?.update(h.map((e,t)=>({color:c.seriesColor(t,e.color),name:e.name}))),v?.hide(),{onClick:e=>{if(!m.onClick)return;let t=p.dimensions,n=s.getMousePosition(p.svg,e,t.margin.left,t.margin.top),r=i.chartArea(t.width,t.height,t.margin);if(n.x<0||n.x>r.width||n.y<0||n.y>r.height)return;let a=E?n.y:n.x,o=u.findCatIdx(a,C,P);if(o===-1)return;let c=u.findSeriesIdx(n,o,C,P,h.length),l=w[c]?.[o];l&&m.onClick({datum:l,originalEvent:e,series:h[c]})},onMouseLeave:()=>{v?.hide(),m.onHover?.(null)},onMouseMove:e=>{let t=p.dimensions,n=s.getMousePosition(p.svg,e,t.margin.left,t.margin.top),r=i.chartArea(t.width,t.height,t.margin);if(n.x<0||n.x>r.width||n.y<0||n.y>r.height){v?.hide();return}let a=E?n.y:n.x,o=u.findCatIdx(a,C,P);if(o===-1){v?.hide();return}if(u.isOutsideBars(n,o,w,P,h.length)){v?.hide();return}let c=u.findSeriesIdx(n,o,C,P,h.length),l=w[c]?.[o];if(l){let n=P.bandCenter(C[o]),r=D?M[c]?.[o]??l.value:l.value,i=j.map(r),a=E?i+t.margin.left:n+t.margin.left,s=E?n+t.margin.top:i+t.margin.top;v?.show(a,s,l,h[c]),m.onHover?.({datum:l,originalEvent:e,series:h[c]})}}}},e=>{h=e})}exports.createBarChart=p;
2
2
  //# sourceMappingURL=bar-chart.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"bar-chart.cjs","names":[],"sources":["../../../src/charts/bar/bar-chart.ts"],"sourcesContent":["import { isReactive } from '@vielzeug/ripple';\nimport { warn } from '../../_dev';\nimport { renderAxis, resolveTickCount } from '../../axes/axis';\nimport { renderGrid } from '../../axes/grid';\nimport { normalizeCartesianSeries } from '../../core/cartesian-model';\nimport { clearCartesianDom, createChartScaffold } from '../../core/chart-scaffold';\nimport { chartArea } from '../../core/layout';\nimport { getMousePosition } from '../../interaction/events';\nimport { bandScale } from '../../scales/band';\nimport { linearScale } from '../../scales/linear';\nimport { createSvgElement } from '../../svg/element';\nimport { seriesColor } from '../../theme';\nimport type { BarChartConfig, BarVariant, ChartHandle } from '../../types';\nimport { findCatIdx, findSeriesIdx, isOutsideBars } from './bar-hit-test';\nimport { renderBars } from './bar-renderer';\nimport type { BarScaleContext } from './bar-scale-context';\n\nfunction variantFlags(variant: BarVariant): { horizontal: boolean; stacked: boolean } {\n return {\n horizontal: variant === 'grouped-horizontal' || variant === 'stacked-horizontal',\n stacked: variant === 'stacked' || variant === 'stacked-horizontal',\n };\n}\n\n// ─── Chart ────────────────────────────────────────────────────────────────────\n\nexport function createBarChart(container: HTMLElement, config: BarChartConfig): ChartHandle {\n return createChartScaffold(container, config, (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions.value;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const seriesList = isReactive(config.series) ? config.series.value : config.series;\n const sourceData = seriesList.map((series) => (isReactive(series.data) ? series.data.value : series.data));\n const model = normalizeCartesianSeries(seriesList, sourceData);\n const categories = model.domain;\n const allData = model.series.map(({ byKey }) => categories.map((key) => byKey.get(key)));\n const categoryAxis = (axis: BarChartConfig['xAxis'] | BarChartConfig['yAxis']) => {\n if (!axis) return undefined;\n\n return {\n ...axis,\n tickFormat: (value: Date | number | string) => {\n const key = String(value);\n const label = model.labels.get(key) ?? value;\n\n return axis.tickFormat ? axis.tickFormat(label) : String(label);\n },\n };\n };\n\n if (categories.length === 0) {\n warn('createBarChart: no data');\n clearCartesianDom(groups, legend, tooltip);\n\n return;\n }\n\n const { horizontal, stacked } = variantFlags(config.variant ?? 'grouped');\n\n // Value domain\n let vMax: number;\n let vMin: number;\n\n if (stacked) {\n if (allData.some((seriesData) => seriesData.some((datum) => (datum?.value ?? 0) < 0))) {\n warn(\n 'createBarChart: negative values in a stacked/stacked-horizontal series are clamped to 0 — stacking mixed-sign data is not supported.',\n );\n }\n\n const sums = categories.map((_, categoryIndex) =>\n allData.reduce((sum, seriesData) => sum + Math.max(0, seriesData[categoryIndex]?.value ?? 0), 0),\n );\n\n vMax = Math.max(...sums);\n vMin = 0;\n } else {\n const allY = allData.flatMap((seriesData) => seriesData.flatMap((datum) => (datum ? [datum.value] : [])));\n\n vMax = Math.max(...allY);\n vMin = Math.min(0, ...allY);\n }\n\n // Build uniform scale context\n const catScale = horizontal\n ? bandScale({ domain: categories, range: [0, area.height] })\n : bandScale({ domain: categories, range: [0, area.width] });\n\n const valScale = horizontal\n ? linearScale({ domain: [vMin, vMax], range: [0, area.width] })\n : linearScale({ domain: [vMin, vMax], range: [area.height, 0] });\n\n const stackedTops: number[][] = [];\n const stackTops = Object.create(null) as Record<string, number>;\n\n for (const cat of categories) stackTops[cat] = 0;\n\n const sc: BarScaleContext = {\n bandCenter: (cat) => catScale.map(cat) + catScale.bandwidth() / 2,\n bandwidth: catScale.bandwidth(),\n baselinePx: valScale.map(0),\n horizontal,\n stacked,\n stackedTops,\n valueScale: valScale,\n };\n\n // Axes & grid\n if (horizontal) {\n if (config.xAxis?.grid) {\n renderGrid(\n groups.grid,\n valScale,\n config.xAxis.grid,\n area.height,\n 'vertical',\n resolveTickCount(config.xAxis, area.width, 'bottom'),\n );\n }\n\n const yAxis = categoryAxis(config.yAxis);\n\n if (yAxis) renderAxis(groups.yAxis, catScale, yAxis, area.height, 'left');\n\n if (config.xAxis) {\n groups.xAxis.setAttribute('transform', `translate(0,${area.height})`);\n renderAxis(groups.xAxis, valScale, config.xAxis, area.width, 'bottom');\n }\n } else {\n if (config.yAxis?.grid) {\n renderGrid(\n groups.grid,\n valScale,\n config.yAxis.grid,\n area.width,\n 'horizontal',\n resolveTickCount(config.yAxis, area.height, 'left'),\n );\n }\n\n const xAxis = categoryAxis(config.xAxis);\n\n if (xAxis) {\n groups.xAxis.setAttribute('transform', `translate(0,${area.height})`);\n renderAxis(groups.xAxis, catScale, xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) renderAxis(groups.yAxis, valScale, config.yAxis, area.height, 'left');\n }\n\n // Series groups\n while (groups.series.children.length > seriesList.length) {\n const last = groups.series.lastElementChild;\n\n if (last) groups.series.removeChild(last);\n }\n\n for (let i = 0; i < seriesList.length; i++) {\n const series = seriesList[i];\n let group = groups.series.children[i] as SVGGElement | undefined;\n\n if (!group) {\n group = createSvgElement('g', { class: 'prism-bar-series' });\n groups.series.appendChild(group);\n }\n\n const barData = categories.map((key, categoryIndex) => {\n const datum = allData[i]?.[categoryIndex];\n\n if (stacked) {\n const base = stackTops[key] ?? 0;\n const top = base + Math.max(0, datum?.value ?? 0);\n\n stackTops[key] = top;\n\n return { base, key, present: datum !== undefined, y: top };\n }\n\n return { base: 0, key, present: datum !== undefined, y: datum?.value ?? 0 };\n });\n\n stackedTops[i] = barData.map((d) => d.y);\n\n const baselineYs = stacked ? barData.map((d) => valScale.map(d.base)) : undefined;\n\n renderBars(group, barData, catScale, valScale, sc.baselinePx, {\n baselineYs,\n borderRadius: series.borderRadius ?? 0,\n color: seriesColor(i, series.color),\n disposalSignal: ctx.disposalSignal,\n horizontal,\n seriesCount: seriesList.length,\n seriesIndex: i,\n stacked,\n transition: config.transition,\n });\n }\n\n legend?.update(seriesList.map((s, i) => ({ color: seriesColor(i, s.color), name: s.name })));\n tooltip?.hide();\n\n // ─── Event handlers (close over render-derived state) ─────────────────────\n\n const onMouseMove = (event: MouseEvent) => {\n const d = ctx.dimensions.value;\n const pos = getMousePosition(ctx.svg, event, d.margin.left, d.margin.top);\n const a = chartArea(d.width, d.height, d.margin);\n\n if (pos.x < 0 || pos.x > a.width || pos.y < 0 || pos.y > a.height) {\n tooltip?.hide();\n\n return;\n }\n\n const posBand = horizontal ? pos.y : pos.x;\n const catIdx = findCatIdx(posBand, categories, sc);\n\n if (catIdx === -1) {\n tooltip?.hide();\n\n return;\n }\n\n if (isOutsideBars(pos, catIdx, allData, sc, seriesList.length)) {\n tooltip?.hide();\n\n return;\n }\n\n const seriesIdx = findSeriesIdx(pos, catIdx, categories, sc, seriesList.length);\n const point = allData[seriesIdx]?.[catIdx];\n\n if (point) {\n const bandCenterPx = sc.bandCenter(categories[catIdx]);\n const stackedTop = stacked ? (stackedTops[seriesIdx]?.[catIdx] ?? point.value) : point.value;\n const valuePx = valScale.map(stackedTop);\n\n const tooltipX = horizontal ? valuePx + d.margin.left : bandCenterPx + d.margin.left;\n const tooltipY = horizontal ? bandCenterPx + d.margin.top : valuePx + d.margin.top;\n\n tooltip?.show(tooltipX, tooltipY, point, seriesList[seriesIdx]);\n config.onHover?.({ datum: point, originalEvent: event, series: seriesList[seriesIdx] });\n }\n };\n\n const onMouseLeave = () => {\n tooltip?.hide();\n config.onHover?.(null);\n };\n\n const onClick = (event: MouseEvent) => {\n if (!config.onClick) return;\n\n const d = ctx.dimensions.value;\n const pos = getMousePosition(ctx.svg, event, d.margin.left, d.margin.top);\n const a = chartArea(d.width, d.height, d.margin);\n\n if (pos.x < 0 || pos.x > a.width || pos.y < 0 || pos.y > a.height) return;\n\n const posBand = horizontal ? pos.y : pos.x;\n const catIdx = findCatIdx(posBand, categories, sc);\n\n if (catIdx === -1) return;\n\n const seriesIdx = findSeriesIdx(pos, catIdx, categories, sc, seriesList.length);\n const point = allData[seriesIdx]?.[catIdx];\n\n if (point) {\n config.onClick({ datum: point, originalEvent: event, series: seriesList[seriesIdx] });\n }\n };\n\n return { onClick, onMouseLeave, onMouseMove };\n });\n}\n"],"mappings":"sfAiBA,SAAS,EAAa,EAAgE,CACpF,MAAO,CACL,WAAY,IAAY,sBAAwB,IAA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UAAU,EAAE,MAAO,EAAE,OAAQ,EAAE,MAAM,EAE/C,GAAI,EAAI,EAAI,GAAK,EAAI,EAAI,EAAE,OAAS,EAAI,EAAI,GAAK,EAAI,EAAI,EAAE,OAAQ,CACjE,GAAS,KAAK,EAEd,MACF,CAEA,IAAM,EAAU,EAAa,EAAI,EAAI,EAAI,EACnC,EAAS,EAAA,WAAW,EAAS,EAAY,CAAE,EAEjD,GAAI,IAAW,GAAI,CACjB,GAAS,KAAK,EAEd,MACF,CAEA,GAAI,EAAA,cAAc,EAAK,EAAQ,EAAS,EAAI,EAAW,MAAM,EAAG,CAC9D,GAAS,KAAK,EAEd,MACF,CAEA,IAAM,EAAY,EAAA,cAAc,EAAK,EAAQ,EAAY,EAAI,EAAW,MAAM,EACxE,EAAQ,EAAQ,EAAU,GAAG,GAEnC,GAAI,EAAO,CACT,IAAM,EAAe,EAAG,WAAW,EAAW,EAAO,EAC/C,EAAa,EAAW,EAAY,EAAU,GAAG,IAAW,EAAM,MAAS,EAAM,MACjF,EAAU,EAAS,IAAI,CAAU,EAEjC,EAAW,EAAa,EAAU,EAAE,OAAO,KAAO,EAAe,EAAE,OAAO,KAC1E,EAAW,EAAa,EAAe,EAAE,OAAO,IAAM,EAAU,EAAE,OAAO,IAE/E,GAAS,KAAK,EAAU,EAAU,EAAO,EAAW,EAAU,EAC9D,EAAO,UAAU,CAAE,MAAO,EAAO,cAAe,EAAO,OAAQ,EAAW,EAAW,CAAC,CACxF,CACF,CA6B4C,CAC9C,CAAC,CACH"}
1
+ {"version":3,"file":"bar-chart.cjs","names":[],"sources":["../../../src/charts/bar/bar-chart.ts"],"sourcesContent":["import { warn } from '../../_dev';\nimport { positionAxis, renderAxis, resolveTickCount } from '../../axes/axis';\nimport { renderGrid } from '../../axes/grid';\nimport { normalizeCartesianSeries } from '../../core/cartesian-model';\nimport { clearCartesianDom, createChartScaffold } from '../../core/chart-scaffold';\nimport { chartArea } from '../../core/layout';\nimport { getMousePosition } from '../../interaction/events';\nimport { bandScale } from '../../scales/band';\nimport { linearScale } from '../../scales/linear';\nimport { createSvgElement } from '../../svg/element';\nimport { seriesColor } from '../../theme';\nimport type { BarChartConfig, BarSeriesConfig, BarVariant, ChartHandle } from '../../types';\nimport { findCatIdx, findSeriesIdx, isOutsideBars } from './bar-hit-test';\nimport { renderBars } from './bar-renderer';\nimport type { BarScaleContext } from './bar-scale-context';\n\nfunction variantFlags(variant: BarVariant): { horizontal: boolean; stacked: boolean } {\n return {\n horizontal: variant === 'grouped-horizontal' || variant === 'stacked-horizontal',\n stacked: variant === 'stacked' || variant === 'stacked-horizontal',\n };\n}\n\n// ─── Chart ────────────────────────────────────────────────────────────────────\n\nexport function createBarChart(container: HTMLElement, config: BarChartConfig): ChartHandle<BarSeriesConfig[]> {\n let seriesList = config.series;\n\n return createChartScaffold(\n container,\n config,\n (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const sourceData = seriesList.map((series) => series.data);\n const model = normalizeCartesianSeries(seriesList, sourceData);\n const categories = model.domain;\n const allData = model.series.map(({ byKey }) => categories.map((key) => byKey.get(key)));\n const categoryAxis = (axis: BarChartConfig['xAxis'] | BarChartConfig['yAxis']) => {\n if (!axis) return undefined;\n\n return {\n ...axis,\n tickFormat: (value: Date | number | string) => {\n const key = String(value);\n const label = model.labels.get(key) ?? value;\n\n return axis.tickFormat ? axis.tickFormat(label) : String(label);\n },\n };\n };\n\n if (categories.length === 0) {\n clearCartesianDom(groups, legend, tooltip);\n\n return;\n }\n\n const { horizontal, stacked } = variantFlags(config.variant ?? 'grouped');\n\n // Value domain\n let vMax: number;\n let vMin: number;\n\n if (stacked) {\n if (allData.some((seriesData) => seriesData.some((datum) => (datum?.value ?? 0) < 0))) {\n warn(\n 'createBarChart: negative values in a stacked/stacked-horizontal series are clamped to 0 — stacking mixed-sign data is not supported.',\n );\n }\n\n const sums = categories.map((_, categoryIndex) =>\n allData.reduce((sum, seriesData) => sum + Math.max(0, seriesData[categoryIndex]?.value ?? 0), 0),\n );\n\n vMax = Math.max(...sums);\n vMin = 0;\n } else {\n const allY = allData.flatMap((seriesData) => seriesData.flatMap((datum) => (datum ? [datum.value] : [])));\n\n vMax = Math.max(...allY);\n vMin = Math.min(0, ...allY);\n }\n\n // Build uniform scale context\n const catScale = horizontal\n ? bandScale({ domain: categories, range: [0, area.height] })\n : bandScale({ domain: categories, range: [0, area.width] });\n\n const valScale = horizontal\n ? linearScale({ domain: [vMin, vMax], range: [0, area.width] })\n : linearScale({ domain: [vMin, vMax], range: [area.height, 0] });\n\n const stackedTops: number[][] = [];\n const stackTops = Object.create(null) as Record<string, number>;\n\n for (const cat of categories) stackTops[cat] = 0;\n\n const sc: BarScaleContext = {\n bandCenter: (cat) => catScale.map(cat) + catScale.bandwidth() / 2,\n bandwidth: catScale.bandwidth(),\n baselinePx: valScale.map(0),\n horizontal,\n stacked,\n stackedTops,\n valueScale: valScale,\n };\n\n // Axes & grid\n if (horizontal) {\n if (config.xAxis?.grid) {\n renderGrid(\n groups.grid,\n valScale,\n config.xAxis.grid,\n area.height,\n 'vertical',\n resolveTickCount(config.xAxis, area.width, 'bottom'),\n );\n }\n\n const yAxis = categoryAxis(config.yAxis);\n\n if (yAxis) {\n positionAxis(groups.yAxis, yAxis.position ?? 'left', area.width, area.height);\n renderAxis(groups.yAxis, catScale, yAxis, area.height, 'left');\n }\n\n if (config.xAxis) {\n positionAxis(groups.xAxis, config.xAxis.position ?? 'bottom', area.width, area.height);\n renderAxis(groups.xAxis, valScale, config.xAxis, area.width, 'bottom');\n }\n } else {\n if (config.yAxis?.grid) {\n renderGrid(\n groups.grid,\n valScale,\n config.yAxis.grid,\n area.width,\n 'horizontal',\n resolveTickCount(config.yAxis, area.height, 'left'),\n );\n }\n\n const xAxis = categoryAxis(config.xAxis);\n\n if (xAxis) {\n positionAxis(groups.xAxis, xAxis.position ?? 'bottom', area.width, area.height);\n renderAxis(groups.xAxis, catScale, xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) {\n positionAxis(groups.yAxis, config.yAxis.position ?? 'left', area.width, area.height);\n renderAxis(groups.yAxis, valScale, config.yAxis, area.height, 'left');\n }\n }\n\n // Series groups\n while (groups.series.children.length > seriesList.length) {\n const last = groups.series.lastElementChild;\n\n if (last) groups.series.removeChild(last);\n }\n\n for (let i = 0; i < seriesList.length; i++) {\n const series = seriesList[i];\n let group = groups.series.children[i] as SVGGElement | undefined;\n\n if (!group) {\n group = createSvgElement('g', { class: 'prism-bar-series' });\n groups.series.appendChild(group);\n }\n\n const barData = categories.map((key, categoryIndex) => {\n const datum = allData[i]?.[categoryIndex];\n\n if (stacked) {\n const base = stackTops[key] ?? 0;\n const top = base + Math.max(0, datum?.value ?? 0);\n\n stackTops[key] = top;\n\n return { base, key, present: datum !== undefined, y: top };\n }\n\n return { base: 0, key, present: datum !== undefined, y: datum?.value ?? 0 };\n });\n\n stackedTops[i] = barData.map((d) => d.y);\n\n const baselineYs = stacked ? barData.map((d) => valScale.map(d.base)) : undefined;\n\n renderBars(group, barData, catScale, valScale, sc.baselinePx, {\n baselineYs,\n borderRadius: series.borderRadius ?? 0,\n color: seriesColor(i, series.color),\n disposalSignal: ctx.disposalSignal,\n horizontal,\n seriesCount: seriesList.length,\n seriesIndex: i,\n stacked,\n transition: config.transition,\n });\n }\n\n legend?.update(seriesList.map((s, i) => ({ color: seriesColor(i, s.color), name: s.name })));\n tooltip?.hide();\n\n // ─── Event handlers (close over render-derived state) ─────────────────────\n\n const onMouseMove = (event: MouseEvent) => {\n const d = ctx.dimensions;\n const pos = getMousePosition(ctx.svg, event, d.margin.left, d.margin.top);\n const a = chartArea(d.width, d.height, d.margin);\n\n if (pos.x < 0 || pos.x > a.width || pos.y < 0 || pos.y > a.height) {\n tooltip?.hide();\n\n return;\n }\n\n const posBand = horizontal ? pos.y : pos.x;\n const catIdx = findCatIdx(posBand, categories, sc);\n\n if (catIdx === -1) {\n tooltip?.hide();\n\n return;\n }\n\n if (isOutsideBars(pos, catIdx, allData, sc, seriesList.length)) {\n tooltip?.hide();\n\n return;\n }\n\n const seriesIdx = findSeriesIdx(pos, catIdx, categories, sc, seriesList.length);\n const point = allData[seriesIdx]?.[catIdx];\n\n if (point) {\n const bandCenterPx = sc.bandCenter(categories[catIdx]);\n const stackedTop = stacked ? (stackedTops[seriesIdx]?.[catIdx] ?? point.value) : point.value;\n const valuePx = valScale.map(stackedTop);\n\n const tooltipX = horizontal ? valuePx + d.margin.left : bandCenterPx + d.margin.left;\n const tooltipY = horizontal ? bandCenterPx + d.margin.top : valuePx + d.margin.top;\n\n tooltip?.show(tooltipX, tooltipY, point, seriesList[seriesIdx]);\n config.onHover?.({ datum: point, originalEvent: event, series: seriesList[seriesIdx] });\n }\n };\n\n const onMouseLeave = () => {\n tooltip?.hide();\n config.onHover?.(null);\n };\n\n const onClick = (event: MouseEvent) => {\n if (!config.onClick) return;\n\n const d = ctx.dimensions;\n const pos = getMousePosition(ctx.svg, event, d.margin.left, d.margin.top);\n const a = chartArea(d.width, d.height, d.margin);\n\n if (pos.x < 0 || pos.x > a.width || pos.y < 0 || pos.y > a.height) return;\n\n const posBand = horizontal ? pos.y : pos.x;\n const catIdx = findCatIdx(posBand, categories, sc);\n\n if (catIdx === -1) return;\n\n const seriesIdx = findSeriesIdx(pos, catIdx, categories, sc, seriesList.length);\n const point = allData[seriesIdx]?.[catIdx];\n\n if (point) {\n config.onClick({ datum: point, originalEvent: event, series: seriesList[seriesIdx] });\n }\n };\n\n return { onClick, onMouseLeave, onMouseMove };\n },\n (data) => {\n seriesList = data;\n },\n );\n}\n"],"mappings":"odAgBA,SAAS,EAAa,EAAgE,CACpF,MAAO,CACL,WAAY,IAAY,sBAAwB,IAAY,qBAC5D,QAAS,IAAY,WAAa,IAAY,oBAChD,CACF,CAIA,SAAgB,EAAe,EAAwB,EAAwD,CAC7G,IAAI,EAAa,EAAO,OAExB,OAAO,EAAA,oBACL,EACA,EACC,GAAQ,CACP,G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I,EAAI,GAAK,EAAI,EAAI,EAAE,OAAQ,CACjE,GAAS,KAAK,EAEd,MACF,CAEA,IAAM,EAAU,EAAa,EAAI,EAAI,EAAI,EACnC,EAAS,EAAA,WAAW,EAAS,EAAY,CAAE,EAEjD,GAAI,IAAW,GAAI,CACjB,GAAS,KAAK,EAEd,MACF,CAEA,GAAI,EAAA,cAAc,EAAK,EAAQ,EAAS,EAAI,EAAW,MAAM,EAAG,CAC9D,GAAS,KAAK,EAEd,MACF,CAEA,IAAM,EAAY,EAAA,cAAc,EAAK,EAAQ,EAAY,EAAI,EAAW,MAAM,EACxE,EAAQ,EAAQ,EAAU,GAAG,GAEnC,GAAI,EAAO,CACT,IAAM,EAAe,EAAG,WAAW,EAAW,EAAO,EAC/C,EAAa,EAAW,EAAY,EAAU,GAAG,IAAW,EAAM,MAAS,EAAM,MACjF,EAAU,EAAS,IAAI,CAAU,EAEjC,EAAW,EAAa,EAAU,EAAE,OAAO,KAAO,EAAe,EAAE,OAAO,KAC1E,EAAW,EAAa,EAAe,EAAE,OAAO,IAAM,EAAU,EAAE,OAAO,IAE/E,GAAS,KAAK,EAAU,EAAU,EAAO,EAAW,EAAU,EAC9D,EAAO,UAAU,CAAE,MAAO,EAAO,cAAe,EAAO,OAAQ,EAAW,EAAW,CAAC,CACxF,CACF,CA6B4C,CAC9C,EACC,GAAS,CACR,EAAa,CACf,CACF,CACF"}
@@ -1,3 +1,3 @@
1
- import type { BarChartConfig, ChartHandle } from '../../types';
2
- export declare function createBarChart(container: HTMLElement, config: BarChartConfig): ChartHandle;
1
+ import type { BarChartConfig, BarSeriesConfig, ChartHandle } from '../../types';
2
+ export declare function createBarChart(container: HTMLElement, config: BarChartConfig): ChartHandle<BarSeriesConfig[]>;
3
3
  //# sourceMappingURL=bar-chart.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bar-chart.d.ts","sourceRoot":"","sources":["../../../src/charts/bar/bar-chart.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,cAAc,EAAc,WAAW,EAAE,MAAM,aAAa,CAAC;AAc3E,wBAAgB,cAAc,CAAC,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,GAAG,WAAW,CAwP1F"}
1
+ {"version":3,"file":"bar-chart.d.ts","sourceRoot":"","sources":["../../../src/charts/bar/bar-chart.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAc,WAAW,EAAE,MAAM,aAAa,CAAC;AAc5F,wBAAgB,cAAc,CAAC,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,GAAG,WAAW,CAAC,eAAe,EAAE,CAAC,CAqQ7G"}
@@ -1,17 +1,16 @@
1
1
  import "../../_dev.js";
2
2
  import { createSvgElement as e } from "../../svg/element.js";
3
- import { renderAxis as t, resolveTickCount as n } from "../../axes/axis.js";
4
- import { renderGrid as r } from "../../axes/grid.js";
5
- import { linearScale as i } from "../../scales/linear.js";
6
- import { chartArea as a } from "../../core/layout.js";
7
- import { clearCartesianDom as o, createChartScaffold as s } from "../../core/chart-scaffold.js";
8
- import { normalizeCartesianSeries as c } from "../../core/cartesian-model.js";
9
- import { getMousePosition as l } from "../../interaction/events.js";
10
- import { seriesColor as u } from "../../theme/index.js";
11
- import { bandScale as d } from "../../scales/band.js";
12
- import { findCatIdx as f, findSeriesIdx as p, isOutsideBars as m } from "./bar-hit-test.js";
13
- import { renderBars as h } from "./bar-renderer.js";
14
- import { isReactive as g } from "@vielzeug/ripple";
3
+ import { positionAxis as t, renderAxis as n, resolveTickCount as r } from "../../axes/axis.js";
4
+ import { renderGrid as i } from "../../axes/grid.js";
5
+ import { linearScale as a } from "../../scales/linear.js";
6
+ import { chartArea as o } from "../../core/layout.js";
7
+ import { clearCartesianDom as s, createChartScaffold as c } from "../../core/chart-scaffold.js";
8
+ import { normalizeCartesianSeries as l } from "../../core/cartesian-model.js";
9
+ import { getMousePosition as u } from "../../interaction/events.js";
10
+ import { seriesColor as d } from "../../theme/index.js";
11
+ import { bandScale as f } from "../../scales/band.js";
12
+ import { findCatIdx as p, findSeriesIdx as m, isOutsideBars as h } from "./bar-hit-test.js";
13
+ import { renderBars as g } from "./bar-renderer.js";
15
14
  //#region src/charts/bar/bar-chart.ts
16
15
  function _(e) {
17
16
  return {
@@ -20,8 +19,9 @@ function _(e) {
20
19
  };
21
20
  }
22
21
  function v(v, y) {
23
- return s(v, y, (s) => {
24
- let { groups: v, legend: b, tooltip: x } = s, S = s.dimensions.value, C = a(S.width, S.height, S.margin), w = g(y.series) ? y.series.value : y.series, T = w.map((e) => g(e.data) ? e.data.value : e.data), E = c(w, T), D = E.domain, O = E.series.map(({ byKey: e }) => D.map((t) => e.get(t))), k = (e) => {
22
+ let b = y.series;
23
+ return c(v, y, (c) => {
24
+ let { groups: v, legend: x, tooltip: S } = c, C = c.dimensions, w = o(C.width, C.height, C.margin), T = b.map((e) => e.data), E = l(b, T), D = E.domain, O = E.series.map(({ byKey: e }) => D.map((t) => e.get(t))), k = (e) => {
25
25
  if (e) return {
26
26
  ...e,
27
27
  tickFormat: (t) => {
@@ -31,7 +31,7 @@ function v(v, y) {
31
31
  };
32
32
  };
33
33
  if (D.length === 0) {
34
- o(v, b, x);
34
+ s(v, x, S);
35
35
  return;
36
36
  }
37
37
  let { horizontal: A, stacked: j } = _(y.variant ?? "grouped"), M, N;
@@ -43,18 +43,18 @@ function v(v, y) {
43
43
  let e = O.flatMap((e) => e.flatMap((e) => e ? [e.value] : []));
44
44
  M = Math.max(...e), N = Math.min(0, ...e);
45
45
  }
46
- let P = d(A ? {
46
+ let P = f(A ? {
47
47
  domain: D,
48
- range: [0, C.height]
48
+ range: [0, w.height]
49
49
  } : {
50
50
  domain: D,
51
- range: [0, C.width]
52
- }), F = i(A ? {
51
+ range: [0, w.width]
52
+ }), F = a(A ? {
53
53
  domain: [N, M],
54
- range: [0, C.width]
54
+ range: [0, w.width]
55
55
  } : {
56
56
  domain: [N, M],
57
- range: [C.height, 0]
57
+ range: [w.height, 0]
58
58
  }), I = [], L = Object.create(null);
59
59
  for (let e of D) L[e] = 0;
60
60
  let R = {
@@ -67,20 +67,20 @@ function v(v, y) {
67
67
  valueScale: F
68
68
  };
69
69
  if (A) {
70
- y.xAxis?.grid && r(v.grid, F, y.xAxis.grid, C.height, "vertical", n(y.xAxis, C.width, "bottom"));
70
+ y.xAxis?.grid && i(v.grid, F, y.xAxis.grid, w.height, "vertical", r(y.xAxis, w.width, "bottom"));
71
71
  let e = k(y.yAxis);
72
- e && t(v.yAxis, P, e, C.height, "left"), y.xAxis && (v.xAxis.setAttribute("transform", `translate(0,${C.height})`), t(v.xAxis, F, y.xAxis, C.width, "bottom"));
72
+ e && (t(v.yAxis, e.position ?? "left", w.width, w.height), n(v.yAxis, P, e, w.height, "left")), y.xAxis && (t(v.xAxis, y.xAxis.position ?? "bottom", w.width, w.height), n(v.xAxis, F, y.xAxis, w.width, "bottom"));
73
73
  } else {
74
- y.yAxis?.grid && r(v.grid, F, y.yAxis.grid, C.width, "horizontal", n(y.yAxis, C.height, "left"));
74
+ y.yAxis?.grid && i(v.grid, F, y.yAxis.grid, w.width, "horizontal", r(y.yAxis, w.height, "left"));
75
75
  let e = k(y.xAxis);
76
- e && (v.xAxis.setAttribute("transform", `translate(0,${C.height})`), t(v.xAxis, P, e, C.width, "bottom")), y.yAxis && t(v.yAxis, F, y.yAxis, C.height, "left");
76
+ e && (t(v.xAxis, e.position ?? "bottom", w.width, w.height), n(v.xAxis, P, e, w.width, "bottom")), y.yAxis && (t(v.yAxis, y.yAxis.position ?? "left", w.width, w.height), n(v.yAxis, F, y.yAxis, w.height, "left"));
77
77
  }
78
- for (; v.series.children.length > w.length;) {
78
+ for (; v.series.children.length > b.length;) {
79
79
  let e = v.series.lastElementChild;
80
80
  e && v.series.removeChild(e);
81
81
  }
82
- for (let t = 0; t < w.length; t++) {
83
- let n = w[t], r = v.series.children[t];
82
+ for (let t = 0; t < b.length; t++) {
83
+ let n = b[t], r = v.series.children[t];
84
84
  r || (r = e("g", { class: "prism-bar-series" }), v.series.appendChild(r));
85
85
  let i = D.map((e, n) => {
86
86
  let r = O[t]?.[n];
@@ -102,64 +102,66 @@ function v(v, y) {
102
102
  });
103
103
  I[t] = i.map((e) => e.y);
104
104
  let a = j ? i.map((e) => F.map(e.base)) : void 0;
105
- h(r, i, P, F, R.baselinePx, {
105
+ g(r, i, P, F, R.baselinePx, {
106
106
  baselineYs: a,
107
107
  borderRadius: n.borderRadius ?? 0,
108
- color: u(t, n.color),
109
- disposalSignal: s.disposalSignal,
108
+ color: d(t, n.color),
109
+ disposalSignal: c.disposalSignal,
110
110
  horizontal: A,
111
- seriesCount: w.length,
111
+ seriesCount: b.length,
112
112
  seriesIndex: t,
113
113
  stacked: j,
114
114
  transition: y.transition
115
115
  });
116
116
  }
117
- return b?.update(w.map((e, t) => ({
118
- color: u(t, e.color),
117
+ return x?.update(b.map((e, t) => ({
118
+ color: d(t, e.color),
119
119
  name: e.name
120
- }))), x?.hide(), {
120
+ }))), S?.hide(), {
121
121
  onClick: (e) => {
122
122
  if (!y.onClick) return;
123
- let t = s.dimensions.value, n = l(s.svg, e, t.margin.left, t.margin.top), r = a(t.width, t.height, t.margin);
123
+ let t = c.dimensions, n = u(c.svg, e, t.margin.left, t.margin.top), r = o(t.width, t.height, t.margin);
124
124
  if (n.x < 0 || n.x > r.width || n.y < 0 || n.y > r.height) return;
125
- let i = A ? n.y : n.x, o = f(i, D, R);
126
- if (o === -1) return;
127
- let c = p(n, o, D, R, w.length), u = O[c]?.[o];
128
- u && y.onClick({
129
- datum: u,
125
+ let i = A ? n.y : n.x, a = p(i, D, R);
126
+ if (a === -1) return;
127
+ let s = m(n, a, D, R, b.length), l = O[s]?.[a];
128
+ l && y.onClick({
129
+ datum: l,
130
130
  originalEvent: e,
131
- series: w[c]
131
+ series: b[s]
132
132
  });
133
133
  },
134
134
  onMouseLeave: () => {
135
- x?.hide(), y.onHover?.(null);
135
+ S?.hide(), y.onHover?.(null);
136
136
  },
137
137
  onMouseMove: (e) => {
138
- let t = s.dimensions.value, n = l(s.svg, e, t.margin.left, t.margin.top), r = a(t.width, t.height, t.margin);
138
+ let t = c.dimensions, n = u(c.svg, e, t.margin.left, t.margin.top), r = o(t.width, t.height, t.margin);
139
139
  if (n.x < 0 || n.x > r.width || n.y < 0 || n.y > r.height) {
140
- x?.hide();
140
+ S?.hide();
141
141
  return;
142
142
  }
143
- let i = A ? n.y : n.x, o = f(i, D, R);
144
- if (o === -1) {
145
- x?.hide();
143
+ let i = A ? n.y : n.x, a = p(i, D, R);
144
+ if (a === -1) {
145
+ S?.hide();
146
146
  return;
147
147
  }
148
- if (m(n, o, O, R, w.length)) {
149
- x?.hide();
148
+ if (h(n, a, O, R, b.length)) {
149
+ S?.hide();
150
150
  return;
151
151
  }
152
- let c = p(n, o, D, R, w.length), u = O[c]?.[o];
153
- if (u) {
154
- let n = R.bandCenter(D[o]), r = j ? I[c]?.[o] ?? u.value : u.value, i = F.map(r), a = A ? i + t.margin.left : n + t.margin.left, s = A ? n + t.margin.top : i + t.margin.top;
155
- x?.show(a, s, u, w[c]), y.onHover?.({
156
- datum: u,
152
+ let s = m(n, a, D, R, b.length), l = O[s]?.[a];
153
+ if (l) {
154
+ let n = R.bandCenter(D[a]), r = j ? I[s]?.[a] ?? l.value : l.value, i = F.map(r), o = A ? i + t.margin.left : n + t.margin.left, c = A ? n + t.margin.top : i + t.margin.top;
155
+ S?.show(o, c, l, b[s]), y.onHover?.({
156
+ datum: l,
157
157
  originalEvent: e,
158
- series: w[c]
158
+ series: b[s]
159
159
  });
160
160
  }
161
161
  }
162
162
  };
163
+ }, (e) => {
164
+ b = e;
163
165
  });
164
166
  }
165
167
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"bar-chart.js","names":[],"sources":["../../../src/charts/bar/bar-chart.ts"],"sourcesContent":["import { isReactive } from '@vielzeug/ripple';\nimport { warn } from '../../_dev';\nimport { renderAxis, resolveTickCount } from '../../axes/axis';\nimport { renderGrid } from '../../axes/grid';\nimport { normalizeCartesianSeries } from '../../core/cartesian-model';\nimport { clearCartesianDom, createChartScaffold } from '../../core/chart-scaffold';\nimport { chartArea } from '../../core/layout';\nimport { getMousePosition } from '../../interaction/events';\nimport { bandScale } from '../../scales/band';\nimport { linearScale } from '../../scales/linear';\nimport { createSvgElement } from '../../svg/element';\nimport { seriesColor } from '../../theme';\nimport type { BarChartConfig, BarVariant, ChartHandle } from '../../types';\nimport { findCatIdx, findSeriesIdx, isOutsideBars } from './bar-hit-test';\nimport { renderBars } from './bar-renderer';\nimport type { BarScaleContext } from './bar-scale-context';\n\nfunction variantFlags(variant: BarVariant): { horizontal: boolean; stacked: boolean } {\n return {\n horizontal: variant === 'grouped-horizontal' || variant === 'stacked-horizontal',\n stacked: variant === 'stacked' || variant === 'stacked-horizontal',\n };\n}\n\n// ─── Chart ────────────────────────────────────────────────────────────────────\n\nexport function createBarChart(container: HTMLElement, config: BarChartConfig): ChartHandle {\n return createChartScaffold(container, config, (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions.value;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const seriesList = isReactive(config.series) ? config.series.value : config.series;\n const sourceData = seriesList.map((series) => (isReactive(series.data) ? series.data.value : series.data));\n const model = normalizeCartesianSeries(seriesList, sourceData);\n const categories = model.domain;\n const allData = model.series.map(({ byKey }) => categories.map((key) => byKey.get(key)));\n const categoryAxis = (axis: BarChartConfig['xAxis'] | BarChartConfig['yAxis']) => {\n if (!axis) return undefined;\n\n return {\n ...axis,\n tickFormat: (value: Date | number | string) => {\n const key = String(value);\n const label = model.labels.get(key) ?? value;\n\n return axis.tickFormat ? axis.tickFormat(label) : String(label);\n },\n };\n };\n\n if (categories.length === 0) {\n warn('createBarChart: no data');\n clearCartesianDom(groups, legend, tooltip);\n\n return;\n }\n\n const { horizontal, stacked } = variantFlags(config.variant ?? 'grouped');\n\n // Value domain\n let vMax: number;\n let vMin: number;\n\n if (stacked) {\n if (allData.some((seriesData) => seriesData.some((datum) => (datum?.value ?? 0) < 0))) {\n warn(\n 'createBarChart: negative values in a stacked/stacked-horizontal series are clamped to 0 — stacking mixed-sign data is not supported.',\n );\n }\n\n const sums = categories.map((_, categoryIndex) =>\n allData.reduce((sum, seriesData) => sum + Math.max(0, seriesData[categoryIndex]?.value ?? 0), 0),\n );\n\n vMax = Math.max(...sums);\n vMin = 0;\n } else {\n const allY = allData.flatMap((seriesData) => seriesData.flatMap((datum) => (datum ? [datum.value] : [])));\n\n vMax = Math.max(...allY);\n vMin = Math.min(0, ...allY);\n }\n\n // Build uniform scale context\n const catScale = horizontal\n ? bandScale({ domain: categories, range: [0, area.height] })\n : bandScale({ domain: categories, range: [0, area.width] });\n\n const valScale = horizontal\n ? linearScale({ domain: [vMin, vMax], range: [0, area.width] })\n : linearScale({ domain: [vMin, vMax], range: [area.height, 0] });\n\n const stackedTops: number[][] = [];\n const stackTops = Object.create(null) as Record<string, number>;\n\n for (const cat of categories) stackTops[cat] = 0;\n\n const sc: BarScaleContext = {\n bandCenter: (cat) => catScale.map(cat) + catScale.bandwidth() / 2,\n bandwidth: catScale.bandwidth(),\n baselinePx: valScale.map(0),\n horizontal,\n stacked,\n stackedTops,\n valueScale: valScale,\n };\n\n // Axes & grid\n if (horizontal) {\n if (config.xAxis?.grid) {\n renderGrid(\n groups.grid,\n valScale,\n config.xAxis.grid,\n area.height,\n 'vertical',\n resolveTickCount(config.xAxis, area.width, 'bottom'),\n );\n }\n\n const yAxis = categoryAxis(config.yAxis);\n\n if (yAxis) renderAxis(groups.yAxis, catScale, yAxis, area.height, 'left');\n\n if (config.xAxis) {\n groups.xAxis.setAttribute('transform', `translate(0,${area.height})`);\n renderAxis(groups.xAxis, valScale, config.xAxis, area.width, 'bottom');\n }\n } else {\n if (config.yAxis?.grid) {\n renderGrid(\n groups.grid,\n valScale,\n config.yAxis.grid,\n area.width,\n 'horizontal',\n resolveTickCount(config.yAxis, area.height, 'left'),\n );\n }\n\n const xAxis = categoryAxis(config.xAxis);\n\n if (xAxis) {\n groups.xAxis.setAttribute('transform', `translate(0,${area.height})`);\n renderAxis(groups.xAxis, catScale, xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) renderAxis(groups.yAxis, valScale, config.yAxis, area.height, 'left');\n }\n\n // Series groups\n while (groups.series.children.length > seriesList.length) {\n const last = groups.series.lastElementChild;\n\n if (last) groups.series.removeChild(last);\n }\n\n for (let i = 0; i < seriesList.length; i++) {\n const series = seriesList[i];\n let group = groups.series.children[i] as SVGGElement | undefined;\n\n if (!group) {\n group = createSvgElement('g', { class: 'prism-bar-series' });\n groups.series.appendChild(group);\n }\n\n const barData = categories.map((key, categoryIndex) => {\n const datum = allData[i]?.[categoryIndex];\n\n if (stacked) {\n const base = stackTops[key] ?? 0;\n const top = base + Math.max(0, datum?.value ?? 0);\n\n stackTops[key] = top;\n\n return { base, key, present: datum !== undefined, y: top };\n }\n\n return { base: 0, key, present: datum !== undefined, y: datum?.value ?? 0 };\n });\n\n stackedTops[i] = barData.map((d) => d.y);\n\n const baselineYs = stacked ? barData.map((d) => valScale.map(d.base)) : undefined;\n\n renderBars(group, barData, catScale, valScale, sc.baselinePx, {\n baselineYs,\n borderRadius: series.borderRadius ?? 0,\n color: seriesColor(i, series.color),\n disposalSignal: ctx.disposalSignal,\n horizontal,\n seriesCount: seriesList.length,\n seriesIndex: i,\n stacked,\n transition: config.transition,\n });\n }\n\n legend?.update(seriesList.map((s, i) => ({ color: seriesColor(i, s.color), name: s.name })));\n tooltip?.hide();\n\n // ─── Event handlers (close over render-derived state) ─────────────────────\n\n const onMouseMove = (event: MouseEvent) => {\n const d = ctx.dimensions.value;\n const pos = getMousePosition(ctx.svg, event, d.margin.left, d.margin.top);\n const a = chartArea(d.width, d.height, d.margin);\n\n if (pos.x < 0 || pos.x > a.width || pos.y < 0 || pos.y > a.height) {\n tooltip?.hide();\n\n return;\n }\n\n const posBand = horizontal ? pos.y : pos.x;\n const catIdx = findCatIdx(posBand, categories, sc);\n\n if (catIdx === -1) {\n tooltip?.hide();\n\n return;\n }\n\n if (isOutsideBars(pos, catIdx, allData, sc, seriesList.length)) {\n tooltip?.hide();\n\n return;\n }\n\n const seriesIdx = findSeriesIdx(pos, catIdx, categories, sc, seriesList.length);\n const point = allData[seriesIdx]?.[catIdx];\n\n if (point) {\n const bandCenterPx = sc.bandCenter(categories[catIdx]);\n const stackedTop = stacked ? (stackedTops[seriesIdx]?.[catIdx] ?? point.value) : point.value;\n const valuePx = valScale.map(stackedTop);\n\n const tooltipX = horizontal ? valuePx + d.margin.left : bandCenterPx + d.margin.left;\n const tooltipY = horizontal ? bandCenterPx + d.margin.top : valuePx + d.margin.top;\n\n tooltip?.show(tooltipX, tooltipY, point, seriesList[seriesIdx]);\n config.onHover?.({ datum: point, originalEvent: event, series: seriesList[seriesIdx] });\n }\n };\n\n const onMouseLeave = () => {\n tooltip?.hide();\n config.onHover?.(null);\n };\n\n const onClick = (event: MouseEvent) => {\n if (!config.onClick) return;\n\n const d = ctx.dimensions.value;\n const pos = getMousePosition(ctx.svg, event, d.margin.left, d.margin.top);\n const a = chartArea(d.width, d.height, d.margin);\n\n if (pos.x < 0 || pos.x > a.width || pos.y < 0 || pos.y > a.height) return;\n\n const posBand = horizontal ? pos.y : pos.x;\n const catIdx = findCatIdx(posBand, categories, sc);\n\n if (catIdx === -1) return;\n\n const seriesIdx = findSeriesIdx(pos, catIdx, categories, sc, seriesList.length);\n const point = allData[seriesIdx]?.[catIdx];\n\n if (point) {\n config.onClick({ datum: point, originalEvent: event, series: seriesList[seriesIdx] });\n }\n };\n\n return { onClick, onMouseLeave, onMouseMove };\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,SAAS,EAAa,GAAgE;CACpF,OAAO;EACL,YAAY,MAAY,wBAAwB,MAAY;EAC5D,SAAS,MAAY,aAAa,MAAY;CAChD;AACF;AAIA,SAAgB,EAAe,GAAwB,GAAqC;CAC1F,OAAO,EAAoB,GAAW,IAAS,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B,GAAS,KAAK;KAEd;IACF;IAEA,IAAI,EAAc,GAAK,GAAQ,GAAS,GAAI,EAAW,MAAM,GAAG;KAC9D,GAAS,KAAK;KAEd;IACF;IAEA,IAAM,IAAY,EAAc,GAAK,GAAQ,GAAY,GAAI,EAAW,MAAM,GACxE,IAAQ,EAAQ,EAAU,GAAG;IAEnC,IAAI,GAAO;KACT,IAAM,IAAe,EAAG,WAAW,EAAW,EAAO,GAC/C,IAAa,IAAW,EAAY,EAAU,GAAG,MAAW,EAAM,QAAS,EAAM,OACjF,IAAU,EAAS,IAAI,CAAU,GAEjC,IAAW,IAAa,IAAU,EAAE,OAAO,OAAO,IAAe,EAAE,OAAO,MAC1E,IAAW,IAAa,IAAe,EAAE,OAAO,MAAM,IAAU,EAAE,OAAO;KAG/E,AADA,GAAS,KAAK,GAAU,GAAU,GAAO,EAAW,EAAU,GAC9D,EAAO,UAAU;MAAE,OAAO;MAAO,eAAe;MAAO,QAAQ,EAAW;KAAW,CAAC;IACxF;GACF;EA6B4C;CAC9C,CAAC;AACH"}
1
+ {"version":3,"file":"bar-chart.js","names":[],"sources":["../../../src/charts/bar/bar-chart.ts"],"sourcesContent":["import { warn } from '../../_dev';\nimport { positionAxis, renderAxis, resolveTickCount } from '../../axes/axis';\nimport { renderGrid } from '../../axes/grid';\nimport { normalizeCartesianSeries } from '../../core/cartesian-model';\nimport { clearCartesianDom, createChartScaffold } from '../../core/chart-scaffold';\nimport { chartArea } from '../../core/layout';\nimport { getMousePosition } from '../../interaction/events';\nimport { bandScale } from '../../scales/band';\nimport { linearScale } from '../../scales/linear';\nimport { createSvgElement } from '../../svg/element';\nimport { seriesColor } from '../../theme';\nimport type { BarChartConfig, BarSeriesConfig, BarVariant, ChartHandle } from '../../types';\nimport { findCatIdx, findSeriesIdx, isOutsideBars } from './bar-hit-test';\nimport { renderBars } from './bar-renderer';\nimport type { BarScaleContext } from './bar-scale-context';\n\nfunction variantFlags(variant: BarVariant): { horizontal: boolean; stacked: boolean } {\n return {\n horizontal: variant === 'grouped-horizontal' || variant === 'stacked-horizontal',\n stacked: variant === 'stacked' || variant === 'stacked-horizontal',\n };\n}\n\n// ─── Chart ────────────────────────────────────────────────────────────────────\n\nexport function createBarChart(container: HTMLElement, config: BarChartConfig): ChartHandle<BarSeriesConfig[]> {\n let seriesList = config.series;\n\n return createChartScaffold(\n container,\n config,\n (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const sourceData = seriesList.map((series) => series.data);\n const model = normalizeCartesianSeries(seriesList, sourceData);\n const categories = model.domain;\n const allData = model.series.map(({ byKey }) => categories.map((key) => byKey.get(key)));\n const categoryAxis = (axis: BarChartConfig['xAxis'] | BarChartConfig['yAxis']) => {\n if (!axis) return undefined;\n\n return {\n ...axis,\n tickFormat: (value: Date | number | string) => {\n const key = String(value);\n const label = model.labels.get(key) ?? value;\n\n return axis.tickFormat ? axis.tickFormat(label) : String(label);\n },\n };\n };\n\n if (categories.length === 0) {\n clearCartesianDom(groups, legend, tooltip);\n\n return;\n }\n\n const { horizontal, stacked } = variantFlags(config.variant ?? 'grouped');\n\n // Value domain\n let vMax: number;\n let vMin: number;\n\n if (stacked) {\n if (allData.some((seriesData) => seriesData.some((datum) => (datum?.value ?? 0) < 0))) {\n warn(\n 'createBarChart: negative values in a stacked/stacked-horizontal series are clamped to 0 — stacking mixed-sign data is not supported.',\n );\n }\n\n const sums = categories.map((_, categoryIndex) =>\n allData.reduce((sum, seriesData) => sum + Math.max(0, seriesData[categoryIndex]?.value ?? 0), 0),\n );\n\n vMax = Math.max(...sums);\n vMin = 0;\n } else {\n const allY = allData.flatMap((seriesData) => seriesData.flatMap((datum) => (datum ? [datum.value] : [])));\n\n vMax = Math.max(...allY);\n vMin = Math.min(0, ...allY);\n }\n\n // Build uniform scale context\n const catScale = horizontal\n ? bandScale({ domain: categories, range: [0, area.height] })\n : bandScale({ domain: categories, range: [0, area.width] });\n\n const valScale = horizontal\n ? linearScale({ domain: [vMin, vMax], range: [0, area.width] })\n : linearScale({ domain: [vMin, vMax], range: [area.height, 0] });\n\n const stackedTops: number[][] = [];\n const stackTops = Object.create(null) as Record<string, number>;\n\n for (const cat of categories) stackTops[cat] = 0;\n\n const sc: BarScaleContext = {\n bandCenter: (cat) => catScale.map(cat) + catScale.bandwidth() / 2,\n bandwidth: catScale.bandwidth(),\n baselinePx: valScale.map(0),\n horizontal,\n stacked,\n stackedTops,\n valueScale: valScale,\n };\n\n // Axes & grid\n if (horizontal) {\n if (config.xAxis?.grid) {\n renderGrid(\n groups.grid,\n valScale,\n config.xAxis.grid,\n area.height,\n 'vertical',\n resolveTickCount(config.xAxis, area.width, 'bottom'),\n );\n }\n\n const yAxis = categoryAxis(config.yAxis);\n\n if (yAxis) {\n positionAxis(groups.yAxis, yAxis.position ?? 'left', area.width, area.height);\n renderAxis(groups.yAxis, catScale, yAxis, area.height, 'left');\n }\n\n if (config.xAxis) {\n positionAxis(groups.xAxis, config.xAxis.position ?? 'bottom', area.width, area.height);\n renderAxis(groups.xAxis, valScale, config.xAxis, area.width, 'bottom');\n }\n } else {\n if (config.yAxis?.grid) {\n renderGrid(\n groups.grid,\n valScale,\n config.yAxis.grid,\n area.width,\n 'horizontal',\n resolveTickCount(config.yAxis, area.height, 'left'),\n );\n }\n\n const xAxis = categoryAxis(config.xAxis);\n\n if (xAxis) {\n positionAxis(groups.xAxis, xAxis.position ?? 'bottom', area.width, area.height);\n renderAxis(groups.xAxis, catScale, xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) {\n positionAxis(groups.yAxis, config.yAxis.position ?? 'left', area.width, area.height);\n renderAxis(groups.yAxis, valScale, config.yAxis, area.height, 'left');\n }\n }\n\n // Series groups\n while (groups.series.children.length > seriesList.length) {\n const last = groups.series.lastElementChild;\n\n if (last) groups.series.removeChild(last);\n }\n\n for (let i = 0; i < seriesList.length; i++) {\n const series = seriesList[i];\n let group = groups.series.children[i] as SVGGElement | undefined;\n\n if (!group) {\n group = createSvgElement('g', { class: 'prism-bar-series' });\n groups.series.appendChild(group);\n }\n\n const barData = categories.map((key, categoryIndex) => {\n const datum = allData[i]?.[categoryIndex];\n\n if (stacked) {\n const base = stackTops[key] ?? 0;\n const top = base + Math.max(0, datum?.value ?? 0);\n\n stackTops[key] = top;\n\n return { base, key, present: datum !== undefined, y: top };\n }\n\n return { base: 0, key, present: datum !== undefined, y: datum?.value ?? 0 };\n });\n\n stackedTops[i] = barData.map((d) => d.y);\n\n const baselineYs = stacked ? barData.map((d) => valScale.map(d.base)) : undefined;\n\n renderBars(group, barData, catScale, valScale, sc.baselinePx, {\n baselineYs,\n borderRadius: series.borderRadius ?? 0,\n color: seriesColor(i, series.color),\n disposalSignal: ctx.disposalSignal,\n horizontal,\n seriesCount: seriesList.length,\n seriesIndex: i,\n stacked,\n transition: config.transition,\n });\n }\n\n legend?.update(seriesList.map((s, i) => ({ color: seriesColor(i, s.color), name: s.name })));\n tooltip?.hide();\n\n // ─── Event handlers (close over render-derived state) ─────────────────────\n\n const onMouseMove = (event: MouseEvent) => {\n const d = ctx.dimensions;\n const pos = getMousePosition(ctx.svg, event, d.margin.left, d.margin.top);\n const a = chartArea(d.width, d.height, d.margin);\n\n if (pos.x < 0 || pos.x > a.width || pos.y < 0 || pos.y > a.height) {\n tooltip?.hide();\n\n return;\n }\n\n const posBand = horizontal ? pos.y : pos.x;\n const catIdx = findCatIdx(posBand, categories, sc);\n\n if (catIdx === -1) {\n tooltip?.hide();\n\n return;\n }\n\n if (isOutsideBars(pos, catIdx, allData, sc, seriesList.length)) {\n tooltip?.hide();\n\n return;\n }\n\n const seriesIdx = findSeriesIdx(pos, catIdx, categories, sc, seriesList.length);\n const point = allData[seriesIdx]?.[catIdx];\n\n if (point) {\n const bandCenterPx = sc.bandCenter(categories[catIdx]);\n const stackedTop = stacked ? (stackedTops[seriesIdx]?.[catIdx] ?? point.value) : point.value;\n const valuePx = valScale.map(stackedTop);\n\n const tooltipX = horizontal ? valuePx + d.margin.left : bandCenterPx + d.margin.left;\n const tooltipY = horizontal ? bandCenterPx + d.margin.top : valuePx + d.margin.top;\n\n tooltip?.show(tooltipX, tooltipY, point, seriesList[seriesIdx]);\n config.onHover?.({ datum: point, originalEvent: event, series: seriesList[seriesIdx] });\n }\n };\n\n const onMouseLeave = () => {\n tooltip?.hide();\n config.onHover?.(null);\n };\n\n const onClick = (event: MouseEvent) => {\n if (!config.onClick) return;\n\n const d = ctx.dimensions;\n const pos = getMousePosition(ctx.svg, event, d.margin.left, d.margin.top);\n const a = chartArea(d.width, d.height, d.margin);\n\n if (pos.x < 0 || pos.x > a.width || pos.y < 0 || pos.y > a.height) return;\n\n const posBand = horizontal ? pos.y : pos.x;\n const catIdx = findCatIdx(posBand, categories, sc);\n\n if (catIdx === -1) return;\n\n const seriesIdx = findSeriesIdx(pos, catIdx, categories, sc, seriesList.length);\n const point = allData[seriesIdx]?.[catIdx];\n\n if (point) {\n config.onClick({ datum: point, originalEvent: event, series: seriesList[seriesIdx] });\n }\n };\n\n return { onClick, onMouseLeave, onMouseMove };\n },\n (data) => {\n seriesList = data;\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AAgBA,SAAS,EAAa,GAAgE;CACpF,OAAO;EACL,YAAY,MAAY,wBAAwB,MAAY;EAC5D,SAAS,MAAY,aAAa,MAAY;CAChD;AACF;AAIA,SAAgB,EAAe,GAAwB,GAAwD;CAC7G,IAAI,IAAa,EAAO;CAExB,OAAO,EACL,GACA,IACC,MAAQ;EACP,IAAM,EAAE,WAAQ,WAAQ,eAAY,GAC9B,IAAO,EAAI,YACX,IAAO,EAAU,EAAK,OAAO,EAAK,QAAQ,EAAK,MAAM,GACrD,IAAa,EAAW,KAAK,MAAW,EAAO,IAAI,GACnD,IAAQ,EAAyB,GAAY,CAAU,GACvD,IAAa,EAAM,QACnB,IAAU,EAAM,OAAO,KAAK,EAAE,eAAY,EAAW,KAAK,MAAQ,EAAM,IAAI,CAAG,CAAC,CAAC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EAAW,EAAO,GAC/C,IAAa,IAAW,EAAY,EAAU,GAAG,MAAW,EAAM,QAAS,EAAM,OACjF,IAAU,EAAS,IAAI,CAAU,GAEjC,IAAW,IAAa,IAAU,EAAE,OAAO,OAAO,IAAe,EAAE,OAAO,MAC1E,IAAW,IAAa,IAAe,EAAE,OAAO,MAAM,IAAU,EAAE,OAAO;KAG/E,AADA,GAAS,KAAK,GAAU,GAAU,GAAO,EAAW,EAAU,GAC9D,EAAO,UAAU;MAAE,OAAO;MAAO,eAAe;MAAO,QAAQ,EAAW;KAAW,CAAC;IACxF;GACF;EA6B4C;CAC9C,IACC,MAAS;EACR,IAAa;CACf,CACF;AACF"}
@@ -1,2 +1,2 @@
1
- function e(e,t,n){for(let r=0;r<t.length;r++){let i=n.bandCenter(t[r])-n.bandwidth/2;if(e>=i&&e<i+n.bandwidth)return r}return-1}function t(e,t,n,r,i){if(r.stacked)if(r.horizontal){for(let n=0;n<i;n++)if(r.valueScale.map(r.stackedTops[n]?.[t]??0)>=e.x)return n;return i-1}else{for(let n=0;n<i;n++)if(r.valueScale.map(r.stackedTops[n]?.[t]??0)<=e.y)return n;return i-1}{let a=r.bandwidth/i,o=r.bandCenter(n[t])-r.bandwidth/2,s=r.horizontal?e.y-o:e.x-o,c=Math.floor(s/a);return Math.max(0,Math.min(i-1,c))}}function n(e,t,n,r,i){let a=i-1,o=r.stacked?r.stackedTops[a]?.[t]??0:Math.max(...Array.from({length:i},(e,r)=>n[r]?.[t]?.value??0)),s=r.valueScale.map(o);return r.horizontal?e.x>s:e.y<s}exports.findCatIdx=e,exports.findSeriesIdx=t,exports.isOutsideBars=n;
1
+ function e(e,t,n){for(let r=0;r<t.length;r++){let i=n.bandCenter(t[r])-n.bandwidth/2;if(e>=i&&e<i+n.bandwidth)return r}return-1}function t(e,t,n,r,i){if(r.stacked){if(r.horizontal){for(let n=0;n<i;n++)if(r.valueScale.map(r.stackedTops[n]?.[t]??0)>=e.x)return n;return i-1}for(let n=0;n<i;n++)if(r.valueScale.map(r.stackedTops[n]?.[t]??0)<=e.y)return n;return i-1}{let a=r.bandwidth/i,o=r.bandCenter(n[t])-r.bandwidth/2,s=r.horizontal?e.y-o:e.x-o,c=Math.floor(s/a);return Math.max(0,Math.min(i-1,c))}}function n(e,t,n,r,i){let a=i-1,o=r.stacked?r.stackedTops[a]?.[t]??0:Math.max(...Array.from({length:i},(e,r)=>n[r]?.[t]?.value??0)),s=r.valueScale.map(o);return r.horizontal?e.x>s:e.y<s}exports.findCatIdx=e,exports.findSeriesIdx=t,exports.isOutsideBars=n;
2
2
  //# sourceMappingURL=bar-hit-test.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"bar-hit-test.cjs","names":[],"sources":["../../../src/charts/bar/bar-hit-test.ts"],"sourcesContent":["import type { Datum } from '../../types';\nimport type { BarScaleContext } from './bar-scale-context';\n\nexport function findCatIdx(pos: number, categories: string[], sc: BarScaleContext): number {\n for (let i = 0; i < categories.length; i++) {\n const center = sc.bandCenter(categories[i]);\n const start = center - sc.bandwidth / 2;\n\n if (pos >= start && pos < start + sc.bandwidth) return i;\n }\n\n return -1;\n}\n\nexport function findSeriesIdx(\n pos: { x: number; y: number },\n catIdx: number,\n categories: string[],\n sc: BarScaleContext,\n seriesCount: number,\n): number {\n if (sc.stacked) {\n if (sc.horizontal) {\n for (let si = 0; si < seriesCount; si++) {\n const rightX = sc.valueScale.map(sc.stackedTops[si]?.[catIdx] ?? 0);\n\n if (rightX >= pos.x) return si;\n }\n\n return seriesCount - 1;\n } else {\n for (let si = 0; si < seriesCount; si++) {\n const topY = sc.valueScale.map(sc.stackedTops[si]?.[catIdx] ?? 0);\n\n if (topY <= pos.y) return si;\n }\n\n return seriesCount - 1;\n }\n } else {\n const subSize = sc.bandwidth / seriesCount;\n const bandStart = sc.bandCenter(categories[catIdx]) - sc.bandwidth / 2;\n const offset = sc.horizontal ? pos.y - bandStart : pos.x - bandStart;\n const subIdx = Math.floor(offset / subSize);\n\n return Math.max(0, Math.min(seriesCount - 1, subIdx));\n }\n}\n\nexport function isOutsideBars(\n pos: { x: number; y: number },\n catIdx: number,\n allData: (Datum | undefined)[][],\n sc: BarScaleContext,\n seriesCount: number,\n): boolean {\n const lastSi = seriesCount - 1;\n const maxVal = sc.stacked\n ? (sc.stackedTops[lastSi]?.[catIdx] ?? 0)\n : Math.max(...Array.from({ length: seriesCount }, (_, si) => allData[si]?.[catIdx]?.value ?? 0));\n const maxPx = sc.valueScale.map(maxVal);\n\n return sc.horizontal ? pos.x > maxPx : pos.y < maxPx;\n}\n"],"mappings":"AAGA,SAAgB,EAAW,EAAa,EAAsB,EAA6B,CACzF,IAAK,IAAI,EAAI,EAAG,EAAI,EAAW,OAAQ,IAAK,CAE1C,IAAM,EADS,EAAG,WAAW,EAAW,EAC1B,EAAS,EAAG,UAAY,EAEtC,GAAI,GAAO,GAAS,EAAM,EAAQ,EAAG,UAAW,OAAO,CACzD,CAEA,MAAO,EACT,CAEA,SAAgB,EACd,EACA,EACA,EACA,EACA,EACQ,CACR,GAAI,EAAG,QACL,GAAI,EAAG,WAAY,CACjB,IAAK,IAAI,EAAK,EAAG,EAAK,EAAa,IAGjC,GAFe,EAAG,WAAW,IAAI,EAAG,YAAY,EAAG,GAAG,IAAW,CAE7D,GAAU,EAAI,EAAG,OAAO,EAG9B,OAAO,EAAc,CACvB,KAAO,CACL,IAAK,IAAI,EAAK,EAAG,EAAK,EAAa,IAGjC,GAFa,EAAG,WAAW,IAAI,EAAG,YAAY,EAAG,GAAG,IAAW,CAE3D,GAAQ,EAAI,EAAG,OAAO,EAG5B,OAAO,EAAc,CACvB,CACK,CACL,IAAM,EAAU,EAAG,UAAY,EACzB,EAAY,EAAG,WAAW,EAAW,EAAO,EAAI,EAAG,UAAY,EAC/D,EAAS,EAAG,WAAa,EAAI,EAAI,EAAY,EAAI,EAAI,EACrD,EAAS,KAAK,MAAM,EAAS,CAAO,EAE1C,OAAO,KAAK,IAAI,EAAG,KAAK,IAAI,EAAc,EAAG,CAAM,CAAC,CACtD,CACF,CAEA,SAAgB,EACd,EACA,EACA,EACA,EACA,EACS,CACT,IAAM,EAAS,EAAc,EACvB,EAAS,EAAG,QACb,EAAG,YAAY,EAAO,GAAG,IAAW,EACrC,KAAK,IAAI,GAAG,MAAM,KAAK,CAAE,OAAQ,CAAY,GAAI,EAAG,IAAO,EAAQ,EAAG,GAAG,EAAO,EAAE,OAAS,CAAC,CAAC,EAC3F,EAAQ,EAAG,WAAW,IAAI,CAAM,EAEtC,OAAO,EAAG,WAAa,EAAI,EAAI,EAAQ,EAAI,EAAI,CACjD"}
1
+ {"version":3,"file":"bar-hit-test.cjs","names":[],"sources":["../../../src/charts/bar/bar-hit-test.ts"],"sourcesContent":["import type { Datum } from '../../types';\nimport type { BarScaleContext } from './bar-scale-context';\n\nexport function findCatIdx(pos: number, categories: string[], sc: BarScaleContext): number {\n for (let i = 0; i < categories.length; i++) {\n const center = sc.bandCenter(categories[i]);\n const start = center - sc.bandwidth / 2;\n\n if (pos >= start && pos < start + sc.bandwidth) return i;\n }\n\n return -1;\n}\n\nexport function findSeriesIdx(\n pos: { x: number; y: number },\n catIdx: number,\n categories: string[],\n sc: BarScaleContext,\n seriesCount: number,\n): number {\n if (sc.stacked) {\n if (sc.horizontal) {\n for (let si = 0; si < seriesCount; si++) {\n const rightX = sc.valueScale.map(sc.stackedTops[si]?.[catIdx] ?? 0);\n\n if (rightX >= pos.x) return si;\n }\n\n return seriesCount - 1;\n } else {\n for (let si = 0; si < seriesCount; si++) {\n const topY = sc.valueScale.map(sc.stackedTops[si]?.[catIdx] ?? 0);\n\n if (topY <= pos.y) return si;\n }\n\n return seriesCount - 1;\n }\n } else {\n const subSize = sc.bandwidth / seriesCount;\n const bandStart = sc.bandCenter(categories[catIdx]) - sc.bandwidth / 2;\n const offset = sc.horizontal ? pos.y - bandStart : pos.x - bandStart;\n const subIdx = Math.floor(offset / subSize);\n\n return Math.max(0, Math.min(seriesCount - 1, subIdx));\n }\n}\n\nexport function isOutsideBars(\n pos: { x: number; y: number },\n catIdx: number,\n allData: (Datum | undefined)[][],\n sc: BarScaleContext,\n seriesCount: number,\n): boolean {\n const lastSi = seriesCount - 1;\n const maxVal = sc.stacked\n ? (sc.stackedTops[lastSi]?.[catIdx] ?? 0)\n : Math.max(...Array.from({ length: seriesCount }, (_, si) => allData[si]?.[catIdx]?.value ?? 0));\n const maxPx = sc.valueScale.map(maxVal);\n\n return sc.horizontal ? pos.x > maxPx : pos.y < maxPx;\n}\n"],"mappings":"AAGA,SAAgB,EAAW,EAAa,EAAsB,EAA6B,CACzF,IAAK,IAAI,EAAI,EAAG,EAAI,EAAW,OAAQ,IAAK,CAE1C,IAAM,EADS,EAAG,WAAW,EAAW,EAC1B,EAAS,EAAG,UAAY,EAEtC,GAAI,GAAO,GAAS,EAAM,EAAQ,EAAG,UAAW,OAAO,CACzD,CAEA,MAAO,EACT,CAEA,SAAgB,EACd,EACA,EACA,EACA,EACA,EACQ,CACR,GAAI,EAAG,QAAS,CACd,GAAI,EAAG,WAAY,CACjB,IAAK,IAAI,EAAK,EAAG,EAAK,EAAa,IAGjC,GAFe,EAAG,WAAW,IAAI,EAAG,YAAY,EAAG,GAAG,IAAW,CAE7D,GAAU,EAAI,EAAG,OAAO,EAG9B,OAAO,EAAc,CACvB,CACE,IAAK,IAAI,EAAK,EAAG,EAAK,EAAa,IAGjC,GAFa,EAAG,WAAW,IAAI,EAAG,YAAY,EAAG,GAAG,IAAW,CAE3D,GAAQ,EAAI,EAAG,OAAO,EAG5B,OAAO,EAAc,CAEzB,CAAO,CACL,IAAM,EAAU,EAAG,UAAY,EACzB,EAAY,EAAG,WAAW,EAAW,EAAO,EAAI,EAAG,UAAY,EAC/D,EAAS,EAAG,WAAa,EAAI,EAAI,EAAY,EAAI,EAAI,EACrD,EAAS,KAAK,MAAM,EAAS,CAAO,EAE1C,OAAO,KAAK,IAAI,EAAG,KAAK,IAAI,EAAc,EAAG,CAAM,CAAC,CACtD,CACF,CAEA,SAAgB,EACd,EACA,EACA,EACA,EACA,EACS,CACT,IAAM,EAAS,EAAc,EACvB,EAAS,EAAG,QACb,EAAG,YAAY,EAAO,GAAG,IAAW,EACrC,KAAK,IAAI,GAAG,MAAM,KAAK,CAAE,OAAQ,CAAY,GAAI,EAAG,IAAO,EAAQ,EAAG,GAAG,EAAO,EAAE,OAAS,CAAC,CAAC,EAC3F,EAAQ,EAAG,WAAW,IAAI,CAAM,EAEtC,OAAO,EAAG,WAAa,EAAI,EAAI,EAAQ,EAAI,EAAI,CACjD"}
@@ -7,10 +7,11 @@ function e(e, t, n) {
7
7
  return -1;
8
8
  }
9
9
  function t(e, t, n, r, i) {
10
- if (r.stacked) if (r.horizontal) {
11
- for (let n = 0; n < i; n++) if (r.valueScale.map(r.stackedTops[n]?.[t] ?? 0) >= e.x) return n;
12
- return i - 1;
13
- } else {
10
+ if (r.stacked) {
11
+ if (r.horizontal) {
12
+ for (let n = 0; n < i; n++) if (r.valueScale.map(r.stackedTops[n]?.[t] ?? 0) >= e.x) return n;
13
+ return i - 1;
14
+ }
14
15
  for (let n = 0; n < i; n++) if (r.valueScale.map(r.stackedTops[n]?.[t] ?? 0) <= e.y) return n;
15
16
  return i - 1;
16
17
  }
@@ -1 +1 @@
1
- {"version":3,"file":"bar-hit-test.js","names":[],"sources":["../../../src/charts/bar/bar-hit-test.ts"],"sourcesContent":["import type { Datum } from '../../types';\nimport type { BarScaleContext } from './bar-scale-context';\n\nexport function findCatIdx(pos: number, categories: string[], sc: BarScaleContext): number {\n for (let i = 0; i < categories.length; i++) {\n const center = sc.bandCenter(categories[i]);\n const start = center - sc.bandwidth / 2;\n\n if (pos >= start && pos < start + sc.bandwidth) return i;\n }\n\n return -1;\n}\n\nexport function findSeriesIdx(\n pos: { x: number; y: number },\n catIdx: number,\n categories: string[],\n sc: BarScaleContext,\n seriesCount: number,\n): number {\n if (sc.stacked) {\n if (sc.horizontal) {\n for (let si = 0; si < seriesCount; si++) {\n const rightX = sc.valueScale.map(sc.stackedTops[si]?.[catIdx] ?? 0);\n\n if (rightX >= pos.x) return si;\n }\n\n return seriesCount - 1;\n } else {\n for (let si = 0; si < seriesCount; si++) {\n const topY = sc.valueScale.map(sc.stackedTops[si]?.[catIdx] ?? 0);\n\n if (topY <= pos.y) return si;\n }\n\n return seriesCount - 1;\n }\n } else {\n const subSize = sc.bandwidth / seriesCount;\n const bandStart = sc.bandCenter(categories[catIdx]) - sc.bandwidth / 2;\n const offset = sc.horizontal ? pos.y - bandStart : pos.x - bandStart;\n const subIdx = Math.floor(offset / subSize);\n\n return Math.max(0, Math.min(seriesCount - 1, subIdx));\n }\n}\n\nexport function isOutsideBars(\n pos: { x: number; y: number },\n catIdx: number,\n allData: (Datum | undefined)[][],\n sc: BarScaleContext,\n seriesCount: number,\n): boolean {\n const lastSi = seriesCount - 1;\n const maxVal = sc.stacked\n ? (sc.stackedTops[lastSi]?.[catIdx] ?? 0)\n : Math.max(...Array.from({ length: seriesCount }, (_, si) => allData[si]?.[catIdx]?.value ?? 0));\n const maxPx = sc.valueScale.map(maxVal);\n\n return sc.horizontal ? pos.x > maxPx : pos.y < maxPx;\n}\n"],"mappings":";AAGA,SAAgB,EAAW,GAAa,GAAsB,GAA6B;CACzF,KAAK,IAAI,IAAI,GAAG,IAAI,EAAW,QAAQ,KAAK;EAE1C,IAAM,IADS,EAAG,WAAW,EAAW,EAC1B,IAAS,EAAG,YAAY;EAEtC,IAAI,KAAO,KAAS,IAAM,IAAQ,EAAG,WAAW,OAAO;CACzD;CAEA,OAAO;AACT;AAEA,SAAgB,EACd,GACA,GACA,GACA,GACA,GACQ;CACR,IAAI,EAAG,SACL,IAAI,EAAG,YAAY;EACjB,KAAK,IAAI,IAAK,GAAG,IAAK,GAAa,KAGjC,IAFe,EAAG,WAAW,IAAI,EAAG,YAAY,EAAG,GAAG,MAAW,CAE7D,KAAU,EAAI,GAAG,OAAO;EAG9B,OAAO,IAAc;CACvB,OAAO;EACL,KAAK,IAAI,IAAK,GAAG,IAAK,GAAa,KAGjC,IAFa,EAAG,WAAW,IAAI,EAAG,YAAY,EAAG,GAAG,MAAW,CAE3D,KAAQ,EAAI,GAAG,OAAO;EAG5B,OAAO,IAAc;CACvB;CACK;EACL,IAAM,IAAU,EAAG,YAAY,GACzB,IAAY,EAAG,WAAW,EAAW,EAAO,IAAI,EAAG,YAAY,GAC/D,IAAS,EAAG,aAAa,EAAI,IAAI,IAAY,EAAI,IAAI,GACrD,IAAS,KAAK,MAAM,IAAS,CAAO;EAE1C,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,IAAc,GAAG,CAAM,CAAC;CACtD;AACF;AAEA,SAAgB,EACd,GACA,GACA,GACA,GACA,GACS;CACT,IAAM,IAAS,IAAc,GACvB,IAAS,EAAG,UACb,EAAG,YAAY,EAAO,GAAG,MAAW,IACrC,KAAK,IAAI,GAAG,MAAM,KAAK,EAAE,QAAQ,EAAY,IAAI,GAAG,MAAO,EAAQ,EAAG,GAAG,EAAO,EAAE,SAAS,CAAC,CAAC,GAC3F,IAAQ,EAAG,WAAW,IAAI,CAAM;CAEtC,OAAO,EAAG,aAAa,EAAI,IAAI,IAAQ,EAAI,IAAI;AACjD"}
1
+ {"version":3,"file":"bar-hit-test.js","names":[],"sources":["../../../src/charts/bar/bar-hit-test.ts"],"sourcesContent":["import type { Datum } from '../../types';\nimport type { BarScaleContext } from './bar-scale-context';\n\nexport function findCatIdx(pos: number, categories: string[], sc: BarScaleContext): number {\n for (let i = 0; i < categories.length; i++) {\n const center = sc.bandCenter(categories[i]);\n const start = center - sc.bandwidth / 2;\n\n if (pos >= start && pos < start + sc.bandwidth) return i;\n }\n\n return -1;\n}\n\nexport function findSeriesIdx(\n pos: { x: number; y: number },\n catIdx: number,\n categories: string[],\n sc: BarScaleContext,\n seriesCount: number,\n): number {\n if (sc.stacked) {\n if (sc.horizontal) {\n for (let si = 0; si < seriesCount; si++) {\n const rightX = sc.valueScale.map(sc.stackedTops[si]?.[catIdx] ?? 0);\n\n if (rightX >= pos.x) return si;\n }\n\n return seriesCount - 1;\n } else {\n for (let si = 0; si < seriesCount; si++) {\n const topY = sc.valueScale.map(sc.stackedTops[si]?.[catIdx] ?? 0);\n\n if (topY <= pos.y) return si;\n }\n\n return seriesCount - 1;\n }\n } else {\n const subSize = sc.bandwidth / seriesCount;\n const bandStart = sc.bandCenter(categories[catIdx]) - sc.bandwidth / 2;\n const offset = sc.horizontal ? pos.y - bandStart : pos.x - bandStart;\n const subIdx = Math.floor(offset / subSize);\n\n return Math.max(0, Math.min(seriesCount - 1, subIdx));\n }\n}\n\nexport function isOutsideBars(\n pos: { x: number; y: number },\n catIdx: number,\n allData: (Datum | undefined)[][],\n sc: BarScaleContext,\n seriesCount: number,\n): boolean {\n const lastSi = seriesCount - 1;\n const maxVal = sc.stacked\n ? (sc.stackedTops[lastSi]?.[catIdx] ?? 0)\n : Math.max(...Array.from({ length: seriesCount }, (_, si) => allData[si]?.[catIdx]?.value ?? 0));\n const maxPx = sc.valueScale.map(maxVal);\n\n return sc.horizontal ? pos.x > maxPx : pos.y < maxPx;\n}\n"],"mappings":";AAGA,SAAgB,EAAW,GAAa,GAAsB,GAA6B;CACzF,KAAK,IAAI,IAAI,GAAG,IAAI,EAAW,QAAQ,KAAK;EAE1C,IAAM,IADS,EAAG,WAAW,EAAW,EAC1B,IAAS,EAAG,YAAY;EAEtC,IAAI,KAAO,KAAS,IAAM,IAAQ,EAAG,WAAW,OAAO;CACzD;CAEA,OAAO;AACT;AAEA,SAAgB,EACd,GACA,GACA,GACA,GACA,GACQ;CACR,IAAI,EAAG,SAAS;EACd,IAAI,EAAG,YAAY;GACjB,KAAK,IAAI,IAAK,GAAG,IAAK,GAAa,KAGjC,IAFe,EAAG,WAAW,IAAI,EAAG,YAAY,EAAG,GAAG,MAAW,CAE7D,KAAU,EAAI,GAAG,OAAO;GAG9B,OAAO,IAAc;EACvB;EACE,KAAK,IAAI,IAAK,GAAG,IAAK,GAAa,KAGjC,IAFa,EAAG,WAAW,IAAI,EAAG,YAAY,EAAG,GAAG,MAAW,CAE3D,KAAQ,EAAI,GAAG,OAAO;EAG5B,OAAO,IAAc;CAEzB;CAAO;EACL,IAAM,IAAU,EAAG,YAAY,GACzB,IAAY,EAAG,WAAW,EAAW,EAAO,IAAI,EAAG,YAAY,GAC/D,IAAS,EAAG,aAAa,EAAI,IAAI,IAAY,EAAI,IAAI,GACrD,IAAS,KAAK,MAAM,IAAS,CAAO;EAE1C,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,IAAc,GAAG,CAAM,CAAC;CACtD;AACF;AAEA,SAAgB,EACd,GACA,GACA,GACA,GACA,GACS;CACT,IAAM,IAAS,IAAc,GACvB,IAAS,EAAG,UACb,EAAG,YAAY,EAAO,GAAG,MAAW,IACrC,KAAK,IAAI,GAAG,MAAM,KAAK,EAAE,QAAQ,EAAY,IAAI,GAAG,MAAO,EAAQ,EAAG,GAAG,EAAO,EAAE,SAAS,CAAC,CAAC,GAC3F,IAAQ,EAAG,WAAW,IAAI,CAAM;CAEtC,OAAO,EAAG,aAAa,EAAI,IAAI,IAAQ,EAAI,IAAI;AACjD"}
@@ -1,2 +1,2 @@
1
- const e=require("../../animation/transition.cjs"),t=require("../../svg/element.cjs");var n=new WeakMap;function r(r,i,a,o,s,c){for(;r.children.length>i.length;){let e=r.lastElementChild;e&&r.removeChild(e)}let l=a.bandwidth(),u=c.stacked?l:l/c.seriesCount,d=c.stacked?0:u*c.seriesIndex,f=c.horizontal??!1,p=[],m=[];for(let e=0;e<i.length;e++){let n=i[e],l=a.map(n.key)+d,h=c.baselineYs?c.baselineYs[e]:s,g=o.map(n.y),_=r.children[e],v=!_;if(_||(_=t.createSvgElement(`rect`,{class:`prism-bar`}),r.appendChild(_)),_.style.display=n.present?``:`none`,f){let e=Math.max(0,Math.abs(h-g)),n=Math.min(g,h);t.setAttributes(_,{fill:c.color,height:Math.max(0,u-1),rx:c.borderRadius,ry:c.borderRadius,y:l}),c.transition?v?(t.setAttributes(_,{width:0,x:h}),p.push({attrs:{width:{from:0,to:e},x:{from:h,to:n}},el:_})):m.push({attrs:{width:{from:Number(_.getAttribute(`width`)??e),to:e},x:{from:Number(_.getAttribute(`x`)??n),to:n}},el:_}):t.setAttributes(_,{width:e,x:n})}else{let e=Math.max(0,Math.abs(h-g)),n=Math.min(g,h);t.setAttributes(_,{fill:c.color,rx:c.borderRadius,ry:c.borderRadius,width:Math.max(0,u-1),x:l}),c.transition?v?(t.setAttributes(_,{height:0,y:h}),p.push({attrs:{height:{from:0,to:e},y:{from:h,to:n}},el:_})):m.push({attrs:{height:{from:Number(_.getAttribute(`height`)??e),to:e},y:{from:Number(_.getAttribute(`y`)??n),to:n}},el:_}):t.setAttributes(_,{height:e,y:n})}}if(c.transition){n.get(r)?.();let t=[];p.length>0&&t.push(e.animate(p,c.transition,void 0,c.disposalSignal)),m.length>0&&t.push(e.animate(m,{...c.transition,stagger:0},void 0,c.disposalSignal)),n.set(r,()=>{for(let e of t)e()})}}exports.renderBars=r;
1
+ const e=require("../../svg/element.cjs"),t=require("../../animation/transition.cjs");var n=new WeakMap;function r(r,i,a,o,s,c){for(;r.children.length>i.length;){let e=r.lastElementChild;e&&r.removeChild(e)}let l=a.bandwidth(),u=c.stacked?l:l/c.seriesCount,d=c.stacked?0:u*c.seriesIndex,f=c.horizontal??!1,p=[],m=[];for(let t=0;t<i.length;t++){let n=i[t],l=a.map(n.key)+d,h=c.baselineYs?c.baselineYs[t]:s,g=o.map(n.y),_=r.children[t],v=!_;if(_||(_=e.createSvgElement(`rect`,{class:`prism-bar`}),r.appendChild(_)),_.style.display=n.present?``:`none`,f){let t=Math.max(0,Math.abs(h-g)),n=Math.min(g,h);e.setAttributes(_,{fill:c.color,height:Math.max(0,u-1),rx:c.borderRadius,ry:c.borderRadius,y:l}),c.transition?v?(e.setAttributes(_,{width:0,x:h}),p.push({attrs:{width:{from:0,to:t},x:{from:h,to:n}},el:_})):m.push({attrs:{width:{from:Number(_.getAttribute(`width`)??t),to:t},x:{from:Number(_.getAttribute(`x`)??n),to:n}},el:_}):e.setAttributes(_,{width:t,x:n})}else{let t=Math.max(0,Math.abs(h-g)),n=Math.min(g,h);e.setAttributes(_,{fill:c.color,rx:c.borderRadius,ry:c.borderRadius,width:Math.max(0,u-1),x:l}),c.transition?v?(e.setAttributes(_,{height:0,y:h}),p.push({attrs:{height:{from:0,to:t},y:{from:h,to:n}},el:_})):m.push({attrs:{height:{from:Number(_.getAttribute(`height`)??t),to:t},y:{from:Number(_.getAttribute(`y`)??n),to:n}},el:_}):e.setAttributes(_,{height:t,y:n})}}if(c.transition){n.get(r)?.();let e=[];p.length>0&&e.push(t.animate(p,c.transition,void 0,c.disposalSignal)),m.length>0&&e.push(t.animate(m,{...c.transition,stagger:0},void 0,c.disposalSignal)),n.set(r,()=>{for(let t of e)t()})}}exports.renderBars=r;
2
2
  //# sourceMappingURL=bar-renderer.cjs.map