@vielzeug/prism 2.2.6 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -40
- package/dist/_dev.cjs +1 -1
- package/dist/_dev.cjs.map +1 -1
- package/dist/_dev.js +1 -2
- package/dist/_dev.js.map +1 -1
- package/dist/axes/axis.cjs +1 -1
- package/dist/axes/axis.cjs.map +1 -1
- package/dist/axes/axis.d.ts +1 -0
- package/dist/axes/axis.d.ts.map +1 -1
- package/dist/axes/axis.js +15 -11
- package/dist/axes/axis.js.map +1 -1
- package/dist/charts/area/area-chart.cjs +1 -1
- package/dist/charts/area/area-chart.cjs.map +1 -1
- package/dist/charts/area/area-chart.d.ts +2 -2
- package/dist/charts/area/area-chart.d.ts.map +1 -1
- package/dist/charts/area/area-chart.js +45 -49
- package/dist/charts/area/area-chart.js.map +1 -1
- package/dist/charts/area/area-renderer.cjs +1 -1
- package/dist/charts/area/area-renderer.cjs.map +1 -1
- package/dist/charts/area/area-renderer.d.ts +2 -2
- package/dist/charts/area/area-renderer.d.ts.map +1 -1
- package/dist/charts/area/area-renderer.js +14 -14
- package/dist/charts/area/area-renderer.js.map +1 -1
- package/dist/charts/bar/bar-chart.cjs +1 -1
- package/dist/charts/bar/bar-chart.cjs.map +1 -1
- package/dist/charts/bar/bar-chart.d.ts +2 -2
- package/dist/charts/bar/bar-chart.d.ts.map +1 -1
- package/dist/charts/bar/bar-chart.js +140 -143
- package/dist/charts/bar/bar-chart.js.map +1 -1
- package/dist/charts/bar/bar-hit-test.cjs +1 -1
- package/dist/charts/bar/bar-hit-test.cjs.map +1 -1
- package/dist/charts/bar/bar-hit-test.js +5 -4
- package/dist/charts/bar/bar-hit-test.js.map +1 -1
- package/dist/charts/bar/bar-renderer.cjs +1 -1
- package/dist/charts/bar/bar-renderer.js +24 -24
- package/dist/charts/line/line-chart.cjs +1 -1
- package/dist/charts/line/line-chart.cjs.map +1 -1
- package/dist/charts/line/line-chart.d.ts +2 -2
- package/dist/charts/line/line-chart.d.ts.map +1 -1
- package/dist/charts/line/line-chart.js +46 -50
- package/dist/charts/line/line-chart.js.map +1 -1
- package/dist/charts/line/line-renderer.cjs +1 -1
- package/dist/charts/line/line-renderer.cjs.map +1 -1
- package/dist/charts/line/line-renderer.d.ts +2 -2
- package/dist/charts/line/line-renderer.d.ts.map +1 -1
- package/dist/charts/line/line-renderer.js +34 -34
- package/dist/charts/line/line-renderer.js.map +1 -1
- package/dist/charts/pie/pie-chart.cjs +1 -1
- package/dist/charts/pie/pie-chart.cjs.map +1 -1
- package/dist/charts/pie/pie-chart.d.ts +2 -2
- package/dist/charts/pie/pie-chart.d.ts.map +1 -1
- package/dist/charts/pie/pie-chart.js +84 -79
- package/dist/charts/pie/pie-chart.js.map +1 -1
- package/dist/charts/sparkline/sparkline.cjs +1 -1
- package/dist/charts/sparkline/sparkline.cjs.map +1 -1
- package/dist/charts/sparkline/sparkline.d.ts +2 -2
- package/dist/charts/sparkline/sparkline.d.ts.map +1 -1
- package/dist/charts/sparkline/sparkline.js +100 -101
- package/dist/charts/sparkline/sparkline.js.map +1 -1
- package/dist/core/chart-base.cjs +1 -1
- package/dist/core/chart-base.cjs.map +1 -1
- package/dist/core/chart-base.d.ts +2 -4
- package/dist/core/chart-base.d.ts.map +1 -1
- package/dist/core/chart-base.js +21 -30
- package/dist/core/chart-base.js.map +1 -1
- package/dist/core/chart-scaffold.cjs +1 -1
- package/dist/core/chart-scaffold.cjs.map +1 -1
- package/dist/core/chart-scaffold.d.ts +9 -10
- package/dist/core/chart-scaffold.d.ts.map +1 -1
- package/dist/core/chart-scaffold.js +31 -43
- package/dist/core/chart-scaffold.js.map +1 -1
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/layout.cjs +1 -1
- package/dist/core/layout.cjs.map +1 -1
- package/dist/core/layout.js +1 -1
- package/dist/core/layout.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -12
- package/dist/interaction/legend.cjs +1 -1
- package/dist/interaction/legend.cjs.map +1 -1
- package/dist/interaction/legend.js +1 -1
- package/dist/interaction/legend.js.map +1 -1
- package/dist/interaction/tooltip.cjs +1 -1
- package/dist/interaction/tooltip.cjs.map +1 -1
- package/dist/interaction/tooltip.d.ts.map +1 -1
- package/dist/interaction/tooltip.js +29 -29
- package/dist/interaction/tooltip.js.map +1 -1
- package/dist/prism.cjs +1 -1
- package/dist/prism.cjs.map +1 -1
- package/dist/prism.iife.js +1 -1
- package/dist/prism.iife.js.map +1 -1
- package/dist/prism.js +1 -1
- package/dist/prism.js.map +1 -1
- package/dist/types.d.ts +24 -48
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -9
- package/dist/core/resolve.cjs +0 -2
- package/dist/core/resolve.cjs.map +0 -1
- package/dist/core/resolve.d.ts +0 -9
- package/dist/core/resolve.d.ts.map +0 -1
- package/dist/core/resolve.js +0 -15
- package/dist/core/resolve.js.map +0 -1
|
@@ -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
|
|
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 =
|
|
14
|
-
g || (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"), _ || (_ =
|
|
20
|
+
if (f.showLine ? (_ = o.querySelector(".prism-area-line"), _ || (_ = e("path", {
|
|
21
21
|
class: "prism-area-line",
|
|
22
22
|
fill: "none"
|
|
23
|
-
}), o.appendChild(_)),
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
50
|
-
x:
|
|
51
|
-
y:
|
|
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 (
|
|
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 {
|
|
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,EAAW,GAAqB,GAAiB,GAAmB,GAAkC;CACpH,IAA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;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/
|
|
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 { 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 { resolveMaybeSignal } from '../../core/resolve';\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 const seriesSignal = resolveMaybeSignal(config.series);\n\n let scaffold: ChartHandle | undefined;\n\n try {\n scaffold = createChartScaffold(container, config, (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions.value;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const seriesList = seriesSignal.value;\n const sourceData = seriesList.map((series) => resolveMaybeSignal(series.data).value);\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 return scaffold;\n } catch (error) {\n scaffold?.dispose();\n throw error;\n }\n}\n"],"mappings":"wfAiBA,SAAS,EAAa,EAAgE,CACpF,MAAO,CACL,WAAY,IAAY,sBAAwB,IAAY,qBAC5D,QAAS,IAAY,WAAa,IAAY,oBAChD,CACF,CAIA,SAAgB,EAAe,EAAwB,EAAqC,CAC1F,IAAM,EAAe,EAAA,mBAAmB,EAAO,MAAM,EAEjD,EAEJ,GAAI,CAyPF,MAxPA,GAAW,EAAA,oBAAoB,EAAW,EAAS,GAAQ,CACzD,GAAM,CAAE,SAAQ,SAAQ,WAAY,EAC9B,EAAO,EAAI,WAAW,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,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,EAEM,CACT,OAAS,EAAO,CAEd,MADA,GAAU,QAAQ,EACZ,CACR,CACF"}
|
|
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,GAAM,CAAE,SAAQ,SAAQ,WAAY,EAC9B,EAAO,EAAI,WACX,EAAO,EAAA,UAAU,EAAK,MAAO,EAAK,OAAQ,EAAK,MAAM,EACrD,EAAa,EAAW,IAAK,GAAW,EAAO,IAAI,EACnD,EAAQ,EAAA,yBAAyB,EAAY,CAAU,EACvD,EAAa,EAAM,OACn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AAI,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":"
|
|
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,11 +1,10 @@
|
|
|
1
1
|
import "../../_dev.js";
|
|
2
2
|
import { createSvgElement as e } from "../../svg/element.js";
|
|
3
|
-
import {
|
|
4
|
-
import { renderGrid as
|
|
5
|
-
import { linearScale as
|
|
6
|
-
import { chartArea as
|
|
7
|
-
import { clearCartesianDom as
|
|
8
|
-
import { resolveMaybeSignal as c } from "../../core/resolve.js";
|
|
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";
|
|
9
8
|
import { normalizeCartesianSeries as l } from "../../core/cartesian-model.js";
|
|
10
9
|
import { getMousePosition as u } from "../../interaction/events.js";
|
|
11
10
|
import { seriesColor as d } from "../../theme/index.js";
|
|
@@ -20,152 +19,150 @@ function _(e) {
|
|
|
20
19
|
};
|
|
21
20
|
}
|
|
22
21
|
function v(v, y) {
|
|
23
|
-
let b =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
if (O.length === 0) {
|
|
36
|
-
o(v, x, S);
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
let { horizontal: j, stacked: M } = _(y.variant ?? "grouped"), N, P;
|
|
40
|
-
if (M) {
|
|
41
|
-
k.some((e) => e.some((e) => (e?.value ?? 0) < 0));
|
|
42
|
-
let e = O.map((e, t) => k.reduce((e, n) => e + Math.max(0, n[t]?.value ?? 0), 0));
|
|
43
|
-
N = Math.max(...e), P = 0;
|
|
44
|
-
} else {
|
|
45
|
-
let e = k.flatMap((e) => e.flatMap((e) => e ? [e.value] : []));
|
|
46
|
-
N = Math.max(...e), P = Math.min(0, ...e);
|
|
47
|
-
}
|
|
48
|
-
let F = f(j ? {
|
|
49
|
-
domain: O,
|
|
50
|
-
range: [0, w.height]
|
|
51
|
-
} : {
|
|
52
|
-
domain: O,
|
|
53
|
-
range: [0, w.width]
|
|
54
|
-
}), I = i(j ? {
|
|
55
|
-
domain: [P, N],
|
|
56
|
-
range: [0, w.width]
|
|
57
|
-
} : {
|
|
58
|
-
domain: [P, N],
|
|
59
|
-
range: [w.height, 0]
|
|
60
|
-
}), L = [], R = Object.create(null);
|
|
61
|
-
for (let e of O) R[e] = 0;
|
|
62
|
-
let z = {
|
|
63
|
-
bandCenter: (e) => F.map(e) + F.bandwidth() / 2,
|
|
64
|
-
bandwidth: F.bandwidth(),
|
|
65
|
-
baselinePx: I.map(0),
|
|
66
|
-
horizontal: j,
|
|
67
|
-
stacked: M,
|
|
68
|
-
stackedTops: L,
|
|
69
|
-
valueScale: I
|
|
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
|
+
if (e) return {
|
|
26
|
+
...e,
|
|
27
|
+
tickFormat: (t) => {
|
|
28
|
+
let n = String(t), r = E.labels.get(n) ?? t;
|
|
29
|
+
return e.tickFormat ? e.tickFormat(r) : String(r);
|
|
30
|
+
}
|
|
70
31
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
32
|
+
};
|
|
33
|
+
if (D.length === 0) {
|
|
34
|
+
s(v, x, S);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
let { horizontal: A, stacked: j } = _(y.variant ?? "grouped"), M, N;
|
|
38
|
+
if (j) {
|
|
39
|
+
O.some((e) => e.some((e) => (e?.value ?? 0) < 0));
|
|
40
|
+
let e = D.map((e, t) => O.reduce((e, n) => e + Math.max(0, n[t]?.value ?? 0), 0));
|
|
41
|
+
M = Math.max(...e), N = 0;
|
|
42
|
+
} else {
|
|
43
|
+
let e = O.flatMap((e) => e.flatMap((e) => e ? [e.value] : []));
|
|
44
|
+
M = Math.max(...e), N = Math.min(0, ...e);
|
|
45
|
+
}
|
|
46
|
+
let P = f(A ? {
|
|
47
|
+
domain: D,
|
|
48
|
+
range: [0, w.height]
|
|
49
|
+
} : {
|
|
50
|
+
domain: D,
|
|
51
|
+
range: [0, w.width]
|
|
52
|
+
}), F = a(A ? {
|
|
53
|
+
domain: [N, M],
|
|
54
|
+
range: [0, w.width]
|
|
55
|
+
} : {
|
|
56
|
+
domain: [N, M],
|
|
57
|
+
range: [w.height, 0]
|
|
58
|
+
}), I = [], L = Object.create(null);
|
|
59
|
+
for (let e of D) L[e] = 0;
|
|
60
|
+
let R = {
|
|
61
|
+
bandCenter: (e) => P.map(e) + P.bandwidth() / 2,
|
|
62
|
+
bandwidth: P.bandwidth(),
|
|
63
|
+
baselinePx: F.map(0),
|
|
64
|
+
horizontal: A,
|
|
65
|
+
stacked: j,
|
|
66
|
+
stackedTops: I,
|
|
67
|
+
valueScale: F
|
|
68
|
+
};
|
|
69
|
+
if (A) {
|
|
70
|
+
y.xAxis?.grid && i(v.grid, F, y.xAxis.grid, w.height, "vertical", r(y.xAxis, w.width, "bottom"));
|
|
71
|
+
let e = k(y.yAxis);
|
|
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
|
+
} else {
|
|
74
|
+
y.yAxis?.grid && i(v.grid, F, y.yAxis.grid, w.width, "horizontal", r(y.yAxis, w.height, "left"));
|
|
75
|
+
let e = k(y.xAxis);
|
|
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
|
+
}
|
|
78
|
+
for (; v.series.children.length > b.length;) {
|
|
79
|
+
let e = v.series.lastElementChild;
|
|
80
|
+
e && v.series.removeChild(e);
|
|
81
|
+
}
|
|
82
|
+
for (let t = 0; t < b.length; t++) {
|
|
83
|
+
let n = b[t], r = v.series.children[t];
|
|
84
|
+
r || (r = e("g", { class: "prism-bar-series" }), v.series.appendChild(r));
|
|
85
|
+
let i = D.map((e, n) => {
|
|
86
|
+
let r = O[t]?.[n];
|
|
87
|
+
if (j) {
|
|
88
|
+
let t = L[e] ?? 0, n = t + Math.max(0, r?.value ?? 0);
|
|
89
|
+
return L[e] = n, {
|
|
90
|
+
base: t,
|
|
100
91
|
key: e,
|
|
101
92
|
present: r !== void 0,
|
|
102
|
-
y:
|
|
93
|
+
y: n
|
|
103
94
|
};
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
base: 0,
|
|
98
|
+
key: e,
|
|
99
|
+
present: r !== void 0,
|
|
100
|
+
y: r?.value ?? 0
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
I[t] = i.map((e) => e.y);
|
|
104
|
+
let a = j ? i.map((e) => F.map(e.base)) : void 0;
|
|
105
|
+
g(r, i, P, F, R.baselinePx, {
|
|
106
|
+
baselineYs: a,
|
|
107
|
+
borderRadius: n.borderRadius ?? 0,
|
|
108
|
+
color: d(t, n.color),
|
|
109
|
+
disposalSignal: c.disposalSignal,
|
|
110
|
+
horizontal: A,
|
|
111
|
+
seriesCount: b.length,
|
|
112
|
+
seriesIndex: t,
|
|
113
|
+
stacked: j,
|
|
114
|
+
transition: y.transition
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return x?.update(b.map((e, t) => ({
|
|
118
|
+
color: d(t, e.color),
|
|
119
|
+
name: e.name
|
|
120
|
+
}))), S?.hide(), {
|
|
121
|
+
onClick: (e) => {
|
|
122
|
+
if (!y.onClick) return;
|
|
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
|
+
if (n.x < 0 || n.x > r.width || n.y < 0 || n.y > r.height) return;
|
|
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
|
+
originalEvent: e,
|
|
131
|
+
series: b[s]
|
|
104
132
|
});
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if (o === -1) return;
|
|
129
|
-
let c = m(n, o, O, z, T.length), l = k[c]?.[o];
|
|
130
|
-
l && y.onClick({
|
|
133
|
+
},
|
|
134
|
+
onMouseLeave: () => {
|
|
135
|
+
S?.hide(), y.onHover?.(null);
|
|
136
|
+
},
|
|
137
|
+
onMouseMove: (e) => {
|
|
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
|
+
if (n.x < 0 || n.x > r.width || n.y < 0 || n.y > r.height) {
|
|
140
|
+
S?.hide();
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
let i = A ? n.y : n.x, a = p(i, D, R);
|
|
144
|
+
if (a === -1) {
|
|
145
|
+
S?.hide();
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (h(n, a, O, R, b.length)) {
|
|
149
|
+
S?.hide();
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
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?.({
|
|
131
156
|
datum: l,
|
|
132
157
|
originalEvent: e,
|
|
133
|
-
series:
|
|
158
|
+
series: b[s]
|
|
134
159
|
});
|
|
135
|
-
},
|
|
136
|
-
onMouseLeave: () => {
|
|
137
|
-
S?.hide(), y.onHover?.(null);
|
|
138
|
-
},
|
|
139
|
-
onMouseMove: (e) => {
|
|
140
|
-
let t = s.dimensions.value, n = u(s.svg, e, t.margin.left, t.margin.top), r = a(t.width, t.height, t.margin);
|
|
141
|
-
if (n.x < 0 || n.x > r.width || n.y < 0 || n.y > r.height) {
|
|
142
|
-
S?.hide();
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
let i = j ? n.y : n.x, o = p(i, O, z);
|
|
146
|
-
if (o === -1) {
|
|
147
|
-
S?.hide();
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
if (h(n, o, k, z, T.length)) {
|
|
151
|
-
S?.hide();
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
let c = m(n, o, O, z, T.length), l = k[c]?.[o];
|
|
155
|
-
if (l) {
|
|
156
|
-
let n = z.bandCenter(O[o]), r = M ? L[c]?.[o] ?? l.value : l.value, i = I.map(r), a = j ? i + t.margin.left : n + t.margin.left, s = j ? n + t.margin.top : i + t.margin.top;
|
|
157
|
-
S?.show(a, s, l, T[c]), y.onHover?.({
|
|
158
|
-
datum: l,
|
|
159
|
-
originalEvent: e,
|
|
160
|
-
series: T[c]
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
160
|
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
}
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}, (e) => {
|
|
164
|
+
b = e;
|
|
165
|
+
});
|
|
169
166
|
}
|
|
170
167
|
//#endregion
|
|
171
168
|
export { v as createBarChart };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bar-chart.js","names":[],"sources":["../../../src/charts/bar/bar-chart.ts"],"sourcesContent":["import { 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 { resolveMaybeSignal } from '../../core/resolve';\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 const seriesSignal = resolveMaybeSignal(config.series);\n\n let scaffold: ChartHandle | undefined;\n\n try {\n scaffold = createChartScaffold(container, config, (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions.value;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const seriesList = seriesSignal.value;\n const sourceData = seriesList.map((series) => resolveMaybeSignal(series.data).value);\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 return scaffold;\n } catch (error) {\n scaffold?.dispose();\n throw error;\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,IAAM,IAAe,EAAmB,EAAO,MAAM,GAEjD;CAEJ,IAAI;EAyPF,OAxPA,IAAW,EAAoB,GAAW,IAAS,MAAQ;GACzD,IAAM,EAAE,WAAQ,WAAQ,eAAY,GAC9B,IAAO,EAAI,WAAW,OACtB,IAAO,EAAU,EAAK,OAAO,EAAK,QAAQ,EAAK,MAAM,GACrD,IAAa,EAAa,OAC1B,IAAa,EAAW,KAAK,MAAW,EAAmB,EAAO,IAAI,CAAC,CAAC,KAAK,GAC7E,IAAQ,EAAyB,GAAY,CAAU,GACvD,IAAa,EAAM,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S,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;MAG/E,AADA,GAAS,KAAK,GAAU,GAAU,GAAO,EAAW,EAAU,GAC9D,EAAO,UAAU;OAAE,OAAO;OAAO,eAAe;OAAO,QAAQ,EAAW;MAAW,CAAC;KACxF;IACF;GA6B4C;EAC9C,CAAC,GAEM;CACT,SAAS,GAAO;EAEd,MADA,GAAU,QAAQ,GACZ;CACR;AACF"}
|
|
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,GACjF,KAAgB,MAA4D;GAC3E,OAEL,OAAO;IACL,GAAG;IACH,aAAa,MAAkC;KAC7C,IAAM,IAAM,OAAO,CAAK,GAClB,IAAQ,EAAM,OAAO,IAAI,CAAG,KAAK;KAEvC,OAAO,EAAK,aAAa,EAAK,WAAW,CAAK,IAAI,OAAO,CAAK;IAChE;GACF;EACF;EAEA,IAAI,EAAW,WAAW,GAAG;GAC3B,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AU,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}
|
|
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
|