@vielzeug/prism 2.2.6 → 26.10.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 -6
- package/dist/_dev.js.map +1 -1
- package/dist/animation/easing.cjs +1 -1
- package/dist/animation/easing.cjs.map +1 -1
- package/dist/animation/easing.js +1 -13
- package/dist/animation/easing.js.map +1 -1
- package/dist/animation/motion.cjs +1 -1
- package/dist/animation/motion.cjs.map +1 -1
- package/dist/animation/motion.js +1 -12
- package/dist/animation/motion.js.map +1 -1
- package/dist/animation/transition.cjs +1 -1
- package/dist/animation/transition.cjs.map +1 -1
- package/dist/animation/transition.js +1 -28
- package/dist/animation/transition.js.map +1 -1
- package/dist/animation/tween.cjs +1 -1
- package/dist/animation/tween.cjs.map +1 -1
- package/dist/animation/tween.js +1 -7
- package/dist/animation/tween.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 +1 -59
- package/dist/axes/axis.js.map +1 -1
- package/dist/axes/grid.cjs +1 -1
- package/dist/axes/grid.cjs.map +1 -1
- package/dist/axes/grid.js +1 -29
- package/dist/axes/grid.js.map +1 -1
- package/dist/axes/scale-utils.cjs +1 -1
- package/dist/axes/scale-utils.cjs.map +1 -1
- package/dist/axes/scale-utils.js +1 -10
- package/dist/axes/scale-utils.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 +1 -61
- 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 +1 -73
- 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 +1 -172
- 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 +1 -28
- package/dist/charts/bar/bar-hit-test.js.map +1 -1
- package/dist/charts/bar/bar-renderer.cjs +1 -1
- package/dist/charts/bar/bar-renderer.cjs.map +1 -1
- package/dist/charts/bar/bar-renderer.js +1 -106
- package/dist/charts/bar/bar-renderer.js.map +1 -1
- 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 +1 -62
- 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 +1 -100
- 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 +1 -160
- package/dist/charts/pie/pie-chart.js.map +1 -1
- package/dist/charts/pie/pie-renderer.cjs +1 -1
- package/dist/charts/pie/pie-renderer.cjs.map +1 -1
- package/dist/charts/pie/pie-renderer.js +1 -76
- package/dist/charts/pie/pie-renderer.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 +1 -192
- package/dist/charts/sparkline/sparkline.js.map +1 -1
- package/dist/core/cartesian-model.cjs +1 -1
- package/dist/core/cartesian-model.cjs.map +1 -1
- package/dist/core/cartesian-model.js +1 -30
- package/dist/core/cartesian-model.js.map +1 -1
- package/dist/core/cartesian-scales.cjs +1 -1
- package/dist/core/cartesian-scales.cjs.map +1 -1
- package/dist/core/cartesian-scales.js +1 -37
- package/dist/core/cartesian-scales.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 +1 -62
- 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 +1 -101
- 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 -22
- package/dist/core/layout.js.map +1 -1
- package/dist/core/responsive.cjs +1 -1
- package/dist/core/responsive.cjs.map +1 -1
- package/dist/core/responsive.js +1 -19
- package/dist/core/responsive.js.map +1 -1
- package/dist/devtools.cjs +1 -1
- package/dist/devtools.cjs.map +1 -1
- package/dist/devtools.js +1 -18
- package/dist/devtools.js.map +1 -1
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.js +1 -9
- package/dist/errors.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 +1 -12
- package/dist/interaction/crosshair.cjs +1 -1
- package/dist/interaction/crosshair.cjs.map +1 -1
- package/dist/interaction/crosshair.js +1 -45
- package/dist/interaction/crosshair.js.map +1 -1
- package/dist/interaction/events.cjs +1 -1
- package/dist/interaction/events.cjs.map +1 -1
- package/dist/interaction/events.js +1 -11
- package/dist/interaction/events.js.map +1 -1
- package/dist/interaction/legend.cjs +1 -1
- package/dist/interaction/legend.cjs.map +1 -1
- package/dist/interaction/legend.js +1 -30
- package/dist/interaction/legend.js.map +1 -1
- package/dist/interaction/series-interaction.cjs +1 -1
- package/dist/interaction/series-interaction.cjs.map +1 -1
- package/dist/interaction/series-interaction.js +1 -97
- package/dist/interaction/series-interaction.js.map +1 -1
- package/dist/interaction/tooltip.cjs +1 -1
- package/dist/interaction/tooltip.cjs.map +1 -1
- package/dist/interaction/tooltip.d.ts.map +1 -1
- package/dist/interaction/tooltip.js +1 -63
- 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/scales/band.cjs +1 -1
- package/dist/scales/band.cjs.map +1 -1
- package/dist/scales/band.js +1 -39
- package/dist/scales/band.js.map +1 -1
- package/dist/scales/linear.cjs +1 -1
- package/dist/scales/linear.cjs.map +1 -1
- package/dist/scales/linear.js +1 -43
- package/dist/scales/linear.js.map +1 -1
- package/dist/scales/time.cjs +1 -1
- package/dist/scales/time.cjs.map +1 -1
- package/dist/scales/time.js +1 -61
- package/dist/scales/time.js.map +1 -1
- package/dist/svg/element.cjs +1 -1
- package/dist/svg/element.cjs.map +1 -1
- package/dist/svg/element.js +1 -22
- package/dist/svg/element.js.map +1 -1
- package/dist/svg/path.cjs +1 -1
- package/dist/svg/path.cjs.map +1 -1
- package/dist/svg/path.js +1 -48
- package/dist/svg/path.js.map +1 -1
- package/dist/svg/text.cjs +1 -1
- package/dist/svg/text.cjs.map +1 -1
- package/dist/svg/text.js +1 -9
- package/dist/svg/text.js.map +1 -1
- package/dist/theme/index.cjs +1 -1
- package/dist/theme/index.cjs.map +1 -1
- package/dist/theme/index.js +1 -19
- package/dist/theme/index.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,173 +1,2 @@
|
|
|
1
|
-
import
|
|
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 { resolveMaybeSignal as c } from "../../core/resolve.js";
|
|
9
|
-
import { normalizeCartesianSeries as l } from "../../core/cartesian-model.js";
|
|
10
|
-
import { getMousePosition as u } from "../../interaction/events.js";
|
|
11
|
-
import { seriesColor as d } from "../../theme/index.js";
|
|
12
|
-
import { bandScale as f } from "../../scales/band.js";
|
|
13
|
-
import { findCatIdx as p, findSeriesIdx as m, isOutsideBars as h } from "./bar-hit-test.js";
|
|
14
|
-
import { renderBars as g } from "./bar-renderer.js";
|
|
15
|
-
//#region src/charts/bar/bar-chart.ts
|
|
16
|
-
function _(e) {
|
|
17
|
-
return {
|
|
18
|
-
horizontal: e === "grouped-horizontal" || e === "stacked-horizontal",
|
|
19
|
-
stacked: e === "stacked" || e === "stacked-horizontal"
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function v(v, y) {
|
|
23
|
-
let b = c(y.series), x;
|
|
24
|
-
try {
|
|
25
|
-
return x = s(v, y, (s) => {
|
|
26
|
-
let { groups: v, legend: x, tooltip: S } = s, C = s.dimensions.value, w = a(C.width, C.height, C.margin), T = b.value, E = T.map((e) => c(e.data).value), D = l(T, E), O = D.domain, k = D.series.map(({ byKey: e }) => O.map((t) => e.get(t))), A = (e) => {
|
|
27
|
-
if (e) return {
|
|
28
|
-
...e,
|
|
29
|
-
tickFormat: (t) => {
|
|
30
|
-
let n = String(t), r = D.labels.get(n) ?? t;
|
|
31
|
-
return e.tickFormat ? e.tickFormat(r) : String(r);
|
|
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
|
|
70
|
-
};
|
|
71
|
-
if (j) {
|
|
72
|
-
y.xAxis?.grid && r(v.grid, I, y.xAxis.grid, w.height, "vertical", n(y.xAxis, w.width, "bottom"));
|
|
73
|
-
let e = A(y.yAxis);
|
|
74
|
-
e && t(v.yAxis, F, e, w.height, "left"), y.xAxis && (v.xAxis.setAttribute("transform", `translate(0,${w.height})`), t(v.xAxis, I, y.xAxis, w.width, "bottom"));
|
|
75
|
-
} else {
|
|
76
|
-
y.yAxis?.grid && r(v.grid, I, y.yAxis.grid, w.width, "horizontal", n(y.yAxis, w.height, "left"));
|
|
77
|
-
let e = A(y.xAxis);
|
|
78
|
-
e && (v.xAxis.setAttribute("transform", `translate(0,${w.height})`), t(v.xAxis, F, e, w.width, "bottom")), y.yAxis && t(v.yAxis, I, y.yAxis, w.height, "left");
|
|
79
|
-
}
|
|
80
|
-
for (; v.series.children.length > T.length;) {
|
|
81
|
-
let e = v.series.lastElementChild;
|
|
82
|
-
e && v.series.removeChild(e);
|
|
83
|
-
}
|
|
84
|
-
for (let t = 0; t < T.length; t++) {
|
|
85
|
-
let n = T[t], r = v.series.children[t];
|
|
86
|
-
r || (r = e("g", { class: "prism-bar-series" }), v.series.appendChild(r));
|
|
87
|
-
let i = O.map((e, n) => {
|
|
88
|
-
let r = k[t]?.[n];
|
|
89
|
-
if (M) {
|
|
90
|
-
let t = R[e] ?? 0, n = t + Math.max(0, r?.value ?? 0);
|
|
91
|
-
return R[e] = n, {
|
|
92
|
-
base: t,
|
|
93
|
-
key: e,
|
|
94
|
-
present: r !== void 0,
|
|
95
|
-
y: n
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
return {
|
|
99
|
-
base: 0,
|
|
100
|
-
key: e,
|
|
101
|
-
present: r !== void 0,
|
|
102
|
-
y: r?.value ?? 0
|
|
103
|
-
};
|
|
104
|
-
});
|
|
105
|
-
L[t] = i.map((e) => e.y);
|
|
106
|
-
let a = M ? i.map((e) => I.map(e.base)) : void 0;
|
|
107
|
-
g(r, i, F, I, z.baselinePx, {
|
|
108
|
-
baselineYs: a,
|
|
109
|
-
borderRadius: n.borderRadius ?? 0,
|
|
110
|
-
color: d(t, n.color),
|
|
111
|
-
disposalSignal: s.disposalSignal,
|
|
112
|
-
horizontal: j,
|
|
113
|
-
seriesCount: T.length,
|
|
114
|
-
seriesIndex: t,
|
|
115
|
-
stacked: M,
|
|
116
|
-
transition: y.transition
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
return x?.update(T.map((e, t) => ({
|
|
120
|
-
color: d(t, e.color),
|
|
121
|
-
name: e.name
|
|
122
|
-
}))), S?.hide(), {
|
|
123
|
-
onClick: (e) => {
|
|
124
|
-
if (!y.onClick) return;
|
|
125
|
-
let t = s.dimensions.value, n = u(s.svg, e, t.margin.left, t.margin.top), r = a(t.width, t.height, t.margin);
|
|
126
|
-
if (n.x < 0 || n.x > r.width || n.y < 0 || n.y > r.height) return;
|
|
127
|
-
let i = j ? n.y : n.x, o = p(i, O, z);
|
|
128
|
-
if (o === -1) return;
|
|
129
|
-
let c = m(n, o, O, z, T.length), l = k[c]?.[o];
|
|
130
|
-
l && y.onClick({
|
|
131
|
-
datum: l,
|
|
132
|
-
originalEvent: e,
|
|
133
|
-
series: T[c]
|
|
134
|
-
});
|
|
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
|
-
}
|
|
164
|
-
};
|
|
165
|
-
}), x;
|
|
166
|
-
} catch (e) {
|
|
167
|
-
throw x?.dispose(), e;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
//#endregion
|
|
171
|
-
export { v as createBarChart };
|
|
172
|
-
|
|
1
|
+
import"../../_dev.js";import{createSvgElement as e}from"../../svg/element.js";import{positionAxis as t,renderAxis as n,resolveTickCount as r}from"../../axes/axis.js";import{renderGrid as i}from"../../axes/grid.js";import{linearScale as a}from"../../scales/linear.js";import{chartArea as o}from"../../core/layout.js";import{clearCartesianDom as s,createChartScaffold as c}from"../../core/chart-scaffold.js";import{normalizeCartesianSeries as l}from"../../core/cartesian-model.js";import{getMousePosition as u}from"../../interaction/events.js";import{seriesColor as d}from"../../theme/index.js";import{bandScale as f}from"../../scales/band.js";import{findCatIdx as p,findSeriesIdx as m,isOutsideBars as h}from"./bar-hit-test.js";import{renderBars as g}from"./bar-renderer.js";function variantFlags(e){return{horizontal:e===`grouped-horizontal`||e===`stacked-horizontal`,stacked:e===`stacked`||e===`stacked-horizontal`}}function createBarChart(_,v){let y=v.series;return c(_,v,c=>{let{groups:_,legend:b,tooltip:x}=c,S=c.dimensions,C=o(S.width,S.height,S.margin),w=y.map(e=>e.data),T=l(y,w),E=T.domain,D=T.series.map(({byKey:e})=>E.map(t=>e.get(t))),categoryAxis=e=>{if(e)return{...e,tickFormat:t=>{let n=String(t),r=T.labels.get(n)??t;return e.tickFormat?e.tickFormat(r):String(r)}}};if(E.length===0){s(_,b,x);return}let{horizontal:O,stacked:k}=variantFlags(v.variant??`grouped`),A,j;if(k){D.some(e=>e.some(e=>(e?.value??0)<0));let e=E.map((e,t)=>D.reduce((e,n)=>e+Math.max(0,n[t]?.value??0),0));A=Math.max(...e),j=0}else{let e=D.flatMap(e=>e.flatMap(e=>e?[e.value]:[]));A=Math.max(...e),j=Math.min(0,...e)}let M=f(O?{domain:E,range:[0,C.height]}:{domain:E,range:[0,C.width]}),N=a(O?{domain:[j,A],range:[0,C.width]}:{domain:[j,A],range:[C.height,0]}),P=[],F=Object.create(null);for(let e of E)F[e]=0;let I={bandCenter:e=>M.map(e)+M.bandwidth()/2,bandwidth:M.bandwidth(),baselinePx:N.map(0),horizontal:O,stacked:k,stackedTops:P,valueScale:N};if(O){v.xAxis?.grid&&i(_.grid,N,v.xAxis.grid,C.height,`vertical`,r(v.xAxis,C.width,`bottom`));let e=categoryAxis(v.yAxis);e&&(t(_.yAxis,e.position??`left`,C.width,C.height),n(_.yAxis,M,e,C.height,`left`)),v.xAxis&&(t(_.xAxis,v.xAxis.position??`bottom`,C.width,C.height),n(_.xAxis,N,v.xAxis,C.width,`bottom`))}else{v.yAxis?.grid&&i(_.grid,N,v.yAxis.grid,C.width,`horizontal`,r(v.yAxis,C.height,`left`));let e=categoryAxis(v.xAxis);e&&(t(_.xAxis,e.position??`bottom`,C.width,C.height),n(_.xAxis,M,e,C.width,`bottom`)),v.yAxis&&(t(_.yAxis,v.yAxis.position??`left`,C.width,C.height),n(_.yAxis,N,v.yAxis,C.height,`left`))}for(;_.series.children.length>y.length;){let e=_.series.lastElementChild;e&&_.series.removeChild(e)}for(let t=0;t<y.length;t++){let n=y[t],r=_.series.children[t];r||(r=e(`g`,{class:`prism-bar-series`}),_.series.appendChild(r));let i=E.map((e,n)=>{let r=D[t]?.[n];if(k){let t=F[e]??0,n=t+Math.max(0,r?.value??0);return F[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}});P[t]=i.map(e=>e.y);let a=k?i.map(e=>N.map(e.base)):void 0;g(r,i,M,N,I.baselinePx,{baselineYs:a,borderRadius:n.borderRadius??0,color:d(t,n.color),disposalSignal:c.disposalSignal,horizontal:O,seriesCount:y.length,seriesIndex:t,stacked:k,transition:v.transition})}b?.update(y.map((e,t)=>({color:d(t,e.color),name:e.name}))),x?.hide();let onMouseMove=e=>{let t=c.dimensions,n=u(c.svg,e,t.margin.left,t.margin.top),r=o(t.width,t.height,t.margin);if(n.x<0||n.x>r.width||n.y<0||n.y>r.height){x?.hide();return}let i=O?n.y:n.x,a=p(i,E,I);if(a===-1){x?.hide();return}if(h(n,a,D,I,y.length)){x?.hide();return}let s=m(n,a,E,I,y.length),l=D[s]?.[a];if(l){let n=I.bandCenter(E[a]),r=k?P[s]?.[a]??l.value:l.value,i=N.map(r),o=O?i+t.margin.left:n+t.margin.left,c=O?n+t.margin.top:i+t.margin.top;x?.show(o,c,l,y[s]),v.onHover?.({datum:l,originalEvent:e,series:y[s]})}},onMouseLeave=()=>{x?.hide(),v.onHover?.(null)},onClick=e=>{if(!v.onClick)return;let t=c.dimensions,n=u(c.svg,e,t.margin.left,t.margin.top),r=o(t.width,t.height,t.margin);if(n.x<0||n.x>r.width||n.y<0||n.y>r.height)return;let i=O?n.y:n.x,a=p(i,E,I);if(a===-1)return;let s=m(n,a,E,I,y.length),l=D[s]?.[a];l&&v.onClick({datum:l,originalEvent:e,series:y[s]})};return{onClick,onMouseLeave,onMouseMove}},e=>{y=e})}export{createBarChart};
|
|
173
2
|
//# sourceMappingURL=bar-chart.js.map
|
|
@@ -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,QACnB,IAAU,EAAM,OAAO,KAAK,EAAE,eAAY,EAAW,KAAK,MAAQ,EAAM,IAAI,CAAG,CAAC,CAAC,GACjF,KAAgB,MAA4D;IAC3E,OAEL,OAAO;KACL,GAAG;KACH,aAAa,MAAkC;MAC7C,IAAM,IAAM,OAAO,CAAK,GAClB,IAAQ,EAAM,OAAO,IAAI,CAAG,KAAK;MAEvC,OAAO,EAAK,aAAa,EAAK,WAAW,CAAK,IAAI,OAAO,CAAK;KAChE;IACF;GACF;GAEA,IAAI,EAAW,WAAW,GAAG;IAE3B,EAAkB,GAAQ,GAAQ,CAAO;IAEzC;GACF;GAEA,IAAM,EAAE,eAAY,eAAY,EAAa,EAAO,WAAW,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/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;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AAM,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,EAEM,iBAAqB,CACzB,GAAS,KAAK,EACd,EAAO,UAAU,IAAI,CACvB,EAEM,QAAW,GAAsB,CACrC,GAAI,CAAC,EAAO,QAAS,OAErB,IAAM,EAAI,EAAI,WACR,EAAM,EAAiB,EAAI,IAAK,EAAO,EAAE,OAAO,KAAM,EAAE,OAAO,GAAG,EAClE,EAAI,EAAU,EAAE,MAAO,EAAE,OAAQ,EAAE,MAAM,EAE/C,GAAI,EAAI,EAAI,GAAK,EAAI,EAAI,EAAE,OAAS,EAAI,EAAI,GAAK,EAAI,EAAI,EAAE,OAAQ,OAEnE,IAAM,EAAU,EAAa,EAAI,EAAI,EAAI,EACnC,EAAS,EAAW,EAAS,EAAY,CAAE,EAEjD,GAAI,IAAW,GAAI,OAEnB,IAAM,EAAY,EAAc,EAAK,EAAQ,EAAY,EAAI,EAAW,MAAM,EACxE,EAAQ,EAAQ,EAAU,GAAG,GAE/B,GACF,EAAO,QAAQ,CAAE,MAAO,EAAO,cAAe,EAAO,OAAQ,EAAW,EAAW,CAAC,CAExF,EAEA,MAAO,CAAE,QAAS,aAAc,WAAY,CAC9C,EACC,GAAS,CACR,EAAa,CACf,CACF,CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function
|
|
1
|
+
function findCatIdx(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 findSeriesIdx(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 isOutsideBars(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=findCatIdx,exports.findSeriesIdx=findSeriesIdx,exports.isOutsideBars=isOutsideBars;
|
|
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,
|
|
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,WAAW,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,cACd,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,cACd,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,29 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
function e(e, t, n) {
|
|
3
|
-
for (let r = 0; r < t.length; r++) {
|
|
4
|
-
let i = n.bandCenter(t[r]) - n.bandwidth / 2;
|
|
5
|
-
if (e >= i && e < i + n.bandwidth) return r;
|
|
6
|
-
}
|
|
7
|
-
return -1;
|
|
8
|
-
}
|
|
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 {
|
|
14
|
-
for (let n = 0; n < i; n++) if (r.valueScale.map(r.stackedTops[n]?.[t] ?? 0) <= e.y) return n;
|
|
15
|
-
return i - 1;
|
|
16
|
-
}
|
|
17
|
-
{
|
|
18
|
-
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);
|
|
19
|
-
return Math.max(0, Math.min(i - 1, c));
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
function n(e, t, n, r, i) {
|
|
23
|
-
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);
|
|
24
|
-
return r.horizontal ? e.x > s : e.y < s;
|
|
25
|
-
}
|
|
26
|
-
//#endregion
|
|
27
|
-
export { e as findCatIdx, t as findSeriesIdx, n as isOutsideBars };
|
|
28
|
-
|
|
1
|
+
function findCatIdx(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 findSeriesIdx(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 isOutsideBars(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}export{findCatIdx,findSeriesIdx,isOutsideBars};
|
|
29
2
|
//# sourceMappingURL=bar-hit-test.js.map
|
|
@@ -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":"
|
|
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,WAAW,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,cACd,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,cACd,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,2 +1,2 @@
|
|
|
1
|
-
const e=require("../../
|
|
1
|
+
const e=require("../../svg/element.cjs"),t=require("../../animation/transition.cjs");var n=new WeakMap;function renderBars(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=renderBars;
|
|
2
2
|
//# sourceMappingURL=bar-renderer.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bar-renderer.cjs","names":[],"sources":["../../../src/charts/bar/bar-renderer.ts"],"sourcesContent":["import type { AnimationTarget } from '../../animation/transition';\nimport { animate } from '../../animation/transition';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport type { BandScale, Scale, TransitionConfig } from '../../types';\n\nexport interface BarRenderOptions {\n baselineYs?: number[];\n borderRadius: number;\n color: string;\n /** Aborted when the owning chart is disposed — stops in-flight transitions from rescheduling. */\n disposalSignal?: AbortSignal;\n horizontal?: boolean;\n seriesCount: number;\n seriesIndex: number;\n stacked?: boolean;\n transition?: TransitionConfig;\n}\n\nconst activeBarAnimations = new WeakMap<SVGGElement, () => void>();\n\nexport function renderBars(\n parent: SVGGElement,\n data: { base: number; key: string; present: boolean; y: number }[],\n xScale: BandScale,\n yScale: Scale<number>,\n baselineY: number,\n options: BarRenderOptions,\n): void {\n while (parent.children.length > data.length) {\n const last = parent.lastElementChild;\n\n if (last) parent.removeChild(last);\n }\n\n const bandwidth = xScale.bandwidth();\n const barBand = options.stacked ? bandwidth : bandwidth / options.seriesCount;\n const offset = options.stacked ? 0 : barBand * options.seriesIndex;\n const horizontal = options.horizontal ?? false;\n\n const enterTargets: AnimationTarget[] = [];\n const updateTargets: AnimationTarget[] = [];\n\n for (let i = 0; i < data.length; i++) {\n const d = data[i];\n const bandPos = xScale.map(d.key) + offset;\n const barBaselineY = options.baselineYs ? options.baselineYs[i] : baselineY;\n const valuePx = yScale.map(d.y);\n\n let rect = parent.children[i] as SVGRectElement | undefined;\n\n const isNew = !rect;\n\n if (!rect) {\n rect = createSvgElement('rect', { class: 'prism-bar' });\n parent.appendChild(rect);\n }\n\n rect.style.display = d.present ? '' : 'none';\n\n if (horizontal) {\n // Horizontal: category on Y axis, value on X axis\n // baselineY here is actually the baseline X (yScale.map(0) in value-space mapped to screen X)\n const finalWidth = Math.max(0, Math.abs(barBaselineY - valuePx));\n const finalX = Math.min(valuePx, barBaselineY);\n\n setAttributes(rect, {\n fill: options.color,\n height: Math.max(0, barBand - 1),\n rx: options.borderRadius,\n ry: options.borderRadius,\n y: bandPos,\n });\n\n if (options.transition) {\n if (isNew) {\n setAttributes(rect, { width: 0, x: barBaselineY });\n enterTargets.push({\n attrs: { width: { from: 0, to: finalWidth }, x: { from: barBaselineY, to: finalX } },\n el: rect,\n });\n } else {\n updateTargets.push({\n attrs: {\n width: { from: Number(rect.getAttribute('width') ?? finalWidth), to: finalWidth },\n x: { from: Number(rect.getAttribute('x') ?? finalX), to: finalX },\n },\n el: rect,\n });\n }\n } else {\n setAttributes(rect, { width: finalWidth, x: finalX });\n }\n } else {\n // Vertical (default)\n const finalHeight = Math.max(0, Math.abs(barBaselineY - valuePx));\n const finalY = Math.min(valuePx, barBaselineY);\n\n setAttributes(rect, {\n fill: options.color,\n rx: options.borderRadius,\n ry: options.borderRadius,\n width: Math.max(0, barBand - 1),\n x: bandPos,\n });\n\n if (options.transition) {\n if (isNew) {\n setAttributes(rect, { height: 0, y: barBaselineY });\n enterTargets.push({\n attrs: { height: { from: 0, to: finalHeight }, y: { from: barBaselineY, to: finalY } },\n el: rect,\n });\n } else {\n updateTargets.push({\n attrs: {\n height: { from: Number(rect.getAttribute('height') ?? finalHeight), to: finalHeight },\n y: { from: Number(rect.getAttribute('y') ?? finalY), to: finalY },\n },\n el: rect,\n });\n }\n } else {\n setAttributes(rect, { height: finalHeight, y: finalY });\n }\n }\n }\n\n if (options.transition) {\n activeBarAnimations.get(parent)?.();\n\n const cancels: (() => void)[] = [];\n\n if (enterTargets.length > 0) {\n cancels.push(animate(enterTargets, options.transition, undefined, options.disposalSignal));\n }\n\n if (updateTargets.length > 0) {\n cancels.push(animate(updateTargets, { ...options.transition, stagger: 0 }, undefined, options.disposalSignal));\n }\n\n activeBarAnimations.set(parent, () => {\n for (const cancel of cancels) cancel();\n });\n }\n}\n"],"mappings":"qFAkBA,IAAM,EAAsB,IAAI,QAEhC,SAAgB,
|
|
1
|
+
{"version":3,"file":"bar-renderer.cjs","names":[],"sources":["../../../src/charts/bar/bar-renderer.ts"],"sourcesContent":["import type { AnimationTarget } from '../../animation/transition';\nimport { animate } from '../../animation/transition';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport type { BandScale, Scale, TransitionConfig } from '../../types';\n\nexport interface BarRenderOptions {\n baselineYs?: number[];\n borderRadius: number;\n color: string;\n /** Aborted when the owning chart is disposed — stops in-flight transitions from rescheduling. */\n disposalSignal?: AbortSignal;\n horizontal?: boolean;\n seriesCount: number;\n seriesIndex: number;\n stacked?: boolean;\n transition?: TransitionConfig;\n}\n\nconst activeBarAnimations = new WeakMap<SVGGElement, () => void>();\n\nexport function renderBars(\n parent: SVGGElement,\n data: { base: number; key: string; present: boolean; y: number }[],\n xScale: BandScale,\n yScale: Scale<number>,\n baselineY: number,\n options: BarRenderOptions,\n): void {\n while (parent.children.length > data.length) {\n const last = parent.lastElementChild;\n\n if (last) parent.removeChild(last);\n }\n\n const bandwidth = xScale.bandwidth();\n const barBand = options.stacked ? bandwidth : bandwidth / options.seriesCount;\n const offset = options.stacked ? 0 : barBand * options.seriesIndex;\n const horizontal = options.horizontal ?? false;\n\n const enterTargets: AnimationTarget[] = [];\n const updateTargets: AnimationTarget[] = [];\n\n for (let i = 0; i < data.length; i++) {\n const d = data[i];\n const bandPos = xScale.map(d.key) + offset;\n const barBaselineY = options.baselineYs ? options.baselineYs[i] : baselineY;\n const valuePx = yScale.map(d.y);\n\n let rect = parent.children[i] as SVGRectElement | undefined;\n\n const isNew = !rect;\n\n if (!rect) {\n rect = createSvgElement('rect', { class: 'prism-bar' });\n parent.appendChild(rect);\n }\n\n rect.style.display = d.present ? '' : 'none';\n\n if (horizontal) {\n // Horizontal: category on Y axis, value on X axis\n // baselineY here is actually the baseline X (yScale.map(0) in value-space mapped to screen X)\n const finalWidth = Math.max(0, Math.abs(barBaselineY - valuePx));\n const finalX = Math.min(valuePx, barBaselineY);\n\n setAttributes(rect, {\n fill: options.color,\n height: Math.max(0, barBand - 1),\n rx: options.borderRadius,\n ry: options.borderRadius,\n y: bandPos,\n });\n\n if (options.transition) {\n if (isNew) {\n setAttributes(rect, { width: 0, x: barBaselineY });\n enterTargets.push({\n attrs: { width: { from: 0, to: finalWidth }, x: { from: barBaselineY, to: finalX } },\n el: rect,\n });\n } else {\n updateTargets.push({\n attrs: {\n width: { from: Number(rect.getAttribute('width') ?? finalWidth), to: finalWidth },\n x: { from: Number(rect.getAttribute('x') ?? finalX), to: finalX },\n },\n el: rect,\n });\n }\n } else {\n setAttributes(rect, { width: finalWidth, x: finalX });\n }\n } else {\n // Vertical (default)\n const finalHeight = Math.max(0, Math.abs(barBaselineY - valuePx));\n const finalY = Math.min(valuePx, barBaselineY);\n\n setAttributes(rect, {\n fill: options.color,\n rx: options.borderRadius,\n ry: options.borderRadius,\n width: Math.max(0, barBand - 1),\n x: bandPos,\n });\n\n if (options.transition) {\n if (isNew) {\n setAttributes(rect, { height: 0, y: barBaselineY });\n enterTargets.push({\n attrs: { height: { from: 0, to: finalHeight }, y: { from: barBaselineY, to: finalY } },\n el: rect,\n });\n } else {\n updateTargets.push({\n attrs: {\n height: { from: Number(rect.getAttribute('height') ?? finalHeight), to: finalHeight },\n y: { from: Number(rect.getAttribute('y') ?? finalY), to: finalY },\n },\n el: rect,\n });\n }\n } else {\n setAttributes(rect, { height: finalHeight, y: finalY });\n }\n }\n }\n\n if (options.transition) {\n activeBarAnimations.get(parent)?.();\n\n const cancels: (() => void)[] = [];\n\n if (enterTargets.length > 0) {\n cancels.push(animate(enterTargets, options.transition, undefined, options.disposalSignal));\n }\n\n if (updateTargets.length > 0) {\n cancels.push(animate(updateTargets, { ...options.transition, stagger: 0 }, undefined, options.disposalSignal));\n }\n\n activeBarAnimations.set(parent, () => {\n for (const cancel of cancels) cancel();\n });\n }\n}\n"],"mappings":"qFAkBA,IAAM,EAAsB,IAAI,QAEhC,SAAgB,WACd,EACA,EACA,EACA,EACA,EACA,EACM,CACN,KAAO,EAAO,SAAS,OAAS,EAAK,QAAQ,CAC3C,IAAM,EAAO,EAAO,iBAEhB,GAAM,EAAO,YAAY,CAAI,CACnC,CAEA,IAAM,EAAY,EAAO,UAAU,EAC7B,EAAU,EAAQ,QAAU,EAAY,EAAY,EAAQ,YAC5D,EAAS,EAAQ,QAAU,EAAI,EAAU,EAAQ,YACjD,EAAa,EAAQ,YAAc,GAEnC,EAAkC,CAAC,EACnC,EAAmC,CAAC,EAE1C,IAAK,IAAI,EAAI,EAAG,EAAI,EAAK,OAAQ,IAAK,CACpC,IAAM,EAAI,EAAK,GACT,EAAU,EAAO,IAAI,EAAE,GAAG,EAAI,EAC9B,EAAe,EAAQ,WAAa,EAAQ,WAAW,GAAK,EAC5D,EAAU,EAAO,IAAI,EAAE,CAAC,EAE1B,EAAO,EAAO,SAAS,GAErB,EAAQ,CAAC,EASf,GAPK,IACH,EAA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AChB,MAAO,CAAE,OAAQ,CAAE,KAAM,EAAG,GAAI,CAAY,EAAG,EAAG,CAAE,KAAM,EAAc,GAAI,CAAO,CAAE,EACrF,GAAI,CACN,CAAC,GAED,EAAc,KAAK,CACjB,MAAO,CACL,OAAQ,CAAE,KAAM,OAAO,EAAK,aAAa,QAAQ,GAAK,CAAW,EAAG,GAAI,CAAY,EACpF,EAAG,CAAE,KAAM,OAAO,EAAK,aAAa,GAAG,GAAK,CAAM,EAAG,GAAI,CAAO,CAClE,EACA,GAAI,CACN,CAAC,EAGH,EAAA,cAAc,EAAM,CAAE,OAAQ,EAAa,EAAG,CAAO,CAAC,CAE1D,CACF,CAEA,GAAI,EAAQ,WAAY,CACtB,EAAoB,IAAI,CAAM,CAAC,GAAG,EAElC,IAAM,EAA0B,CAAC,EAE7B,EAAa,OAAS,GACxB,EAAQ,KAAK,EAAA,QAAQ,EAAc,EAAQ,WAAY,IAAA,GAAW,EAAQ,cAAc,CAAC,EAGvF,EAAc,OAAS,GACzB,EAAQ,KAAK,EAAA,QAAQ,EAAe,CAAE,GAAG,EAAQ,WAAY,QAAS,CAAE,EAAG,IAAA,GAAW,EAAQ,cAAc,CAAC,EAG/G,EAAoB,IAAI,MAAc,CACpC,IAAK,IAAM,KAAU,EAAS,EAAO,CACvC,CAAC,CACH,CACF"}
|
|
@@ -1,107 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createSvgElement as t, setAttributes as n } from "../../svg/element.js";
|
|
3
|
-
//#region src/charts/bar/bar-renderer.ts
|
|
4
|
-
var r = /* @__PURE__ */ new WeakMap();
|
|
5
|
-
function i(i, a, o, s, c, l) {
|
|
6
|
-
for (; i.children.length > a.length;) {
|
|
7
|
-
let e = i.lastElementChild;
|
|
8
|
-
e && i.removeChild(e);
|
|
9
|
-
}
|
|
10
|
-
let u = o.bandwidth(), d = l.stacked ? u : u / l.seriesCount, f = l.stacked ? 0 : d * l.seriesIndex, p = l.horizontal ?? !1, m = [], h = [];
|
|
11
|
-
for (let e = 0; e < a.length; e++) {
|
|
12
|
-
let r = a[e], u = o.map(r.key) + f, g = l.baselineYs ? l.baselineYs[e] : c, _ = s.map(r.y), v = i.children[e], y = !v;
|
|
13
|
-
if (v || (v = t("rect", { class: "prism-bar" }), i.appendChild(v)), v.style.display = r.present ? "" : "none", p) {
|
|
14
|
-
let e = Math.max(0, Math.abs(g - _)), t = Math.min(_, g);
|
|
15
|
-
n(v, {
|
|
16
|
-
fill: l.color,
|
|
17
|
-
height: Math.max(0, d - 1),
|
|
18
|
-
rx: l.borderRadius,
|
|
19
|
-
ry: l.borderRadius,
|
|
20
|
-
y: u
|
|
21
|
-
}), l.transition ? y ? (n(v, {
|
|
22
|
-
width: 0,
|
|
23
|
-
x: g
|
|
24
|
-
}), m.push({
|
|
25
|
-
attrs: {
|
|
26
|
-
width: {
|
|
27
|
-
from: 0,
|
|
28
|
-
to: e
|
|
29
|
-
},
|
|
30
|
-
x: {
|
|
31
|
-
from: g,
|
|
32
|
-
to: t
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
el: v
|
|
36
|
-
})) : h.push({
|
|
37
|
-
attrs: {
|
|
38
|
-
width: {
|
|
39
|
-
from: Number(v.getAttribute("width") ?? e),
|
|
40
|
-
to: e
|
|
41
|
-
},
|
|
42
|
-
x: {
|
|
43
|
-
from: Number(v.getAttribute("x") ?? t),
|
|
44
|
-
to: t
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
el: v
|
|
48
|
-
}) : n(v, {
|
|
49
|
-
width: e,
|
|
50
|
-
x: t
|
|
51
|
-
});
|
|
52
|
-
} else {
|
|
53
|
-
let e = Math.max(0, Math.abs(g - _)), t = Math.min(_, g);
|
|
54
|
-
n(v, {
|
|
55
|
-
fill: l.color,
|
|
56
|
-
rx: l.borderRadius,
|
|
57
|
-
ry: l.borderRadius,
|
|
58
|
-
width: Math.max(0, d - 1),
|
|
59
|
-
x: u
|
|
60
|
-
}), l.transition ? y ? (n(v, {
|
|
61
|
-
height: 0,
|
|
62
|
-
y: g
|
|
63
|
-
}), m.push({
|
|
64
|
-
attrs: {
|
|
65
|
-
height: {
|
|
66
|
-
from: 0,
|
|
67
|
-
to: e
|
|
68
|
-
},
|
|
69
|
-
y: {
|
|
70
|
-
from: g,
|
|
71
|
-
to: t
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
el: v
|
|
75
|
-
})) : h.push({
|
|
76
|
-
attrs: {
|
|
77
|
-
height: {
|
|
78
|
-
from: Number(v.getAttribute("height") ?? e),
|
|
79
|
-
to: e
|
|
80
|
-
},
|
|
81
|
-
y: {
|
|
82
|
-
from: Number(v.getAttribute("y") ?? t),
|
|
83
|
-
to: t
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
el: v
|
|
87
|
-
}) : n(v, {
|
|
88
|
-
height: e,
|
|
89
|
-
y: t
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (l.transition) {
|
|
94
|
-
r.get(i)?.();
|
|
95
|
-
let t = [];
|
|
96
|
-
m.length > 0 && t.push(e(m, l.transition, void 0, l.disposalSignal)), h.length > 0 && t.push(e(h, {
|
|
97
|
-
...l.transition,
|
|
98
|
-
stagger: 0
|
|
99
|
-
}, void 0, l.disposalSignal)), r.set(i, () => {
|
|
100
|
-
for (let e of t) e();
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
//#endregion
|
|
105
|
-
export { i as renderBars };
|
|
106
|
-
|
|
1
|
+
import{createSvgElement as e,setAttributes as t}from"../../svg/element.js";import{animate as n}from"../../animation/transition.js";var r=new WeakMap;function renderBars(i,a,o,s,c,l){for(;i.children.length>a.length;){let e=i.lastElementChild;e&&i.removeChild(e)}let u=o.bandwidth(),d=l.stacked?u:u/l.seriesCount,f=l.stacked?0:d*l.seriesIndex,p=l.horizontal??!1,m=[],h=[];for(let n=0;n<a.length;n++){let r=a[n],u=o.map(r.key)+f,g=l.baselineYs?l.baselineYs[n]:c,_=s.map(r.y),v=i.children[n],y=!v;if(v||(v=e(`rect`,{class:`prism-bar`}),i.appendChild(v)),v.style.display=r.present?``:`none`,p){let e=Math.max(0,Math.abs(g-_)),n=Math.min(_,g);t(v,{fill:l.color,height:Math.max(0,d-1),rx:l.borderRadius,ry:l.borderRadius,y:u}),l.transition?y?(t(v,{width:0,x:g}),m.push({attrs:{width:{from:0,to:e},x:{from:g,to:n}},el:v})):h.push({attrs:{width:{from:Number(v.getAttribute(`width`)??e),to:e},x:{from:Number(v.getAttribute(`x`)??n),to:n}},el:v}):t(v,{width:e,x:n})}else{let e=Math.max(0,Math.abs(g-_)),n=Math.min(_,g);t(v,{fill:l.color,rx:l.borderRadius,ry:l.borderRadius,width:Math.max(0,d-1),x:u}),l.transition?y?(t(v,{height:0,y:g}),m.push({attrs:{height:{from:0,to:e},y:{from:g,to:n}},el:v})):h.push({attrs:{height:{from:Number(v.getAttribute(`height`)??e),to:e},y:{from:Number(v.getAttribute(`y`)??n),to:n}},el:v}):t(v,{height:e,y:n})}}if(l.transition){r.get(i)?.();let e=[];m.length>0&&e.push(n(m,l.transition,void 0,l.disposalSignal)),h.length>0&&e.push(n(h,{...l.transition,stagger:0},void 0,l.disposalSignal)),r.set(i,()=>{for(let t of e)t()})}}export{renderBars};
|
|
107
2
|
//# sourceMappingURL=bar-renderer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bar-renderer.js","names":[],"sources":["../../../src/charts/bar/bar-renderer.ts"],"sourcesContent":["import type { AnimationTarget } from '../../animation/transition';\nimport { animate } from '../../animation/transition';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport type { BandScale, Scale, TransitionConfig } from '../../types';\n\nexport interface BarRenderOptions {\n baselineYs?: number[];\n borderRadius: number;\n color: string;\n /** Aborted when the owning chart is disposed — stops in-flight transitions from rescheduling. */\n disposalSignal?: AbortSignal;\n horizontal?: boolean;\n seriesCount: number;\n seriesIndex: number;\n stacked?: boolean;\n transition?: TransitionConfig;\n}\n\nconst activeBarAnimations = new WeakMap<SVGGElement, () => void>();\n\nexport function renderBars(\n parent: SVGGElement,\n data: { base: number; key: string; present: boolean; y: number }[],\n xScale: BandScale,\n yScale: Scale<number>,\n baselineY: number,\n options: BarRenderOptions,\n): void {\n while (parent.children.length > data.length) {\n const last = parent.lastElementChild;\n\n if (last) parent.removeChild(last);\n }\n\n const bandwidth = xScale.bandwidth();\n const barBand = options.stacked ? bandwidth : bandwidth / options.seriesCount;\n const offset = options.stacked ? 0 : barBand * options.seriesIndex;\n const horizontal = options.horizontal ?? false;\n\n const enterTargets: AnimationTarget[] = [];\n const updateTargets: AnimationTarget[] = [];\n\n for (let i = 0; i < data.length; i++) {\n const d = data[i];\n const bandPos = xScale.map(d.key) + offset;\n const barBaselineY = options.baselineYs ? options.baselineYs[i] : baselineY;\n const valuePx = yScale.map(d.y);\n\n let rect = parent.children[i] as SVGRectElement | undefined;\n\n const isNew = !rect;\n\n if (!rect) {\n rect = createSvgElement('rect', { class: 'prism-bar' });\n parent.appendChild(rect);\n }\n\n rect.style.display = d.present ? '' : 'none';\n\n if (horizontal) {\n // Horizontal: category on Y axis, value on X axis\n // baselineY here is actually the baseline X (yScale.map(0) in value-space mapped to screen X)\n const finalWidth = Math.max(0, Math.abs(barBaselineY - valuePx));\n const finalX = Math.min(valuePx, barBaselineY);\n\n setAttributes(rect, {\n fill: options.color,\n height: Math.max(0, barBand - 1),\n rx: options.borderRadius,\n ry: options.borderRadius,\n y: bandPos,\n });\n\n if (options.transition) {\n if (isNew) {\n setAttributes(rect, { width: 0, x: barBaselineY });\n enterTargets.push({\n attrs: { width: { from: 0, to: finalWidth }, x: { from: barBaselineY, to: finalX } },\n el: rect,\n });\n } else {\n updateTargets.push({\n attrs: {\n width: { from: Number(rect.getAttribute('width') ?? finalWidth), to: finalWidth },\n x: { from: Number(rect.getAttribute('x') ?? finalX), to: finalX },\n },\n el: rect,\n });\n }\n } else {\n setAttributes(rect, { width: finalWidth, x: finalX });\n }\n } else {\n // Vertical (default)\n const finalHeight = Math.max(0, Math.abs(barBaselineY - valuePx));\n const finalY = Math.min(valuePx, barBaselineY);\n\n setAttributes(rect, {\n fill: options.color,\n rx: options.borderRadius,\n ry: options.borderRadius,\n width: Math.max(0, barBand - 1),\n x: bandPos,\n });\n\n if (options.transition) {\n if (isNew) {\n setAttributes(rect, { height: 0, y: barBaselineY });\n enterTargets.push({\n attrs: { height: { from: 0, to: finalHeight }, y: { from: barBaselineY, to: finalY } },\n el: rect,\n });\n } else {\n updateTargets.push({\n attrs: {\n height: { from: Number(rect.getAttribute('height') ?? finalHeight), to: finalHeight },\n y: { from: Number(rect.getAttribute('y') ?? finalY), to: finalY },\n },\n el: rect,\n });\n }\n } else {\n setAttributes(rect, { height: finalHeight, y: finalY });\n }\n }\n }\n\n if (options.transition) {\n activeBarAnimations.get(parent)?.();\n\n const cancels: (() => void)[] = [];\n\n if (enterTargets.length > 0) {\n cancels.push(animate(enterTargets, options.transition, undefined, options.disposalSignal));\n }\n\n if (updateTargets.length > 0) {\n cancels.push(animate(updateTargets, { ...options.transition, stagger: 0 }, undefined, options.disposalSignal));\n }\n\n activeBarAnimations.set(parent, () => {\n for (const cancel of cancels) cancel();\n });\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"bar-renderer.js","names":[],"sources":["../../../src/charts/bar/bar-renderer.ts"],"sourcesContent":["import type { AnimationTarget } from '../../animation/transition';\nimport { animate } from '../../animation/transition';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport type { BandScale, Scale, TransitionConfig } from '../../types';\n\nexport interface BarRenderOptions {\n baselineYs?: number[];\n borderRadius: number;\n color: string;\n /** Aborted when the owning chart is disposed — stops in-flight transitions from rescheduling. */\n disposalSignal?: AbortSignal;\n horizontal?: boolean;\n seriesCount: number;\n seriesIndex: number;\n stacked?: boolean;\n transition?: TransitionConfig;\n}\n\nconst activeBarAnimations = new WeakMap<SVGGElement, () => void>();\n\nexport function renderBars(\n parent: SVGGElement,\n data: { base: number; key: string; present: boolean; y: number }[],\n xScale: BandScale,\n yScale: Scale<number>,\n baselineY: number,\n options: BarRenderOptions,\n): void {\n while (parent.children.length > data.length) {\n const last = parent.lastElementChild;\n\n if (last) parent.removeChild(last);\n }\n\n const bandwidth = xScale.bandwidth();\n const barBand = options.stacked ? bandwidth : bandwidth / options.seriesCount;\n const offset = options.stacked ? 0 : barBand * options.seriesIndex;\n const horizontal = options.horizontal ?? false;\n\n const enterTargets: AnimationTarget[] = [];\n const updateTargets: AnimationTarget[] = [];\n\n for (let i = 0; i < data.length; i++) {\n const d = data[i];\n const bandPos = xScale.map(d.key) + offset;\n const barBaselineY = options.baselineYs ? options.baselineYs[i] : baselineY;\n const valuePx = yScale.map(d.y);\n\n let rect = parent.children[i] as SVGRectElement | undefined;\n\n const isNew = !rect;\n\n if (!rect) {\n rect = createSvgElement('rect', { class: 'prism-bar' });\n parent.appendChild(rect);\n }\n\n rect.style.display = d.present ? '' : 'none';\n\n if (horizontal) {\n // Horizontal: category on Y axis, value on X axis\n // baselineY here is actually the baseline X (yScale.map(0) in value-space mapped to screen X)\n const finalWidth = Math.max(0, Math.abs(barBaselineY - valuePx));\n const finalX = Math.min(valuePx, barBaselineY);\n\n setAttributes(rect, {\n fill: options.color,\n height: Math.max(0, barBand - 1),\n rx: options.borderRadius,\n ry: options.borderRadius,\n y: bandPos,\n });\n\n if (options.transition) {\n if (isNew) {\n setAttributes(rect, { width: 0, x: barBaselineY });\n enterTargets.push({\n attrs: { width: { from: 0, to: finalWidth }, x: { from: barBaselineY, to: finalX } },\n el: rect,\n });\n } else {\n updateTargets.push({\n attrs: {\n width: { from: Number(rect.getAttribute('width') ?? finalWidth), to: finalWidth },\n x: { from: Number(rect.getAttribute('x') ?? finalX), to: finalX },\n },\n el: rect,\n });\n }\n } else {\n setAttributes(rect, { width: finalWidth, x: finalX });\n }\n } else {\n // Vertical (default)\n const finalHeight = Math.max(0, Math.abs(barBaselineY - valuePx));\n const finalY = Math.min(valuePx, barBaselineY);\n\n setAttributes(rect, {\n fill: options.color,\n rx: options.borderRadius,\n ry: options.borderRadius,\n width: Math.max(0, barBand - 1),\n x: bandPos,\n });\n\n if (options.transition) {\n if (isNew) {\n setAttributes(rect, { height: 0, y: barBaselineY });\n enterTargets.push({\n attrs: { height: { from: 0, to: finalHeight }, y: { from: barBaselineY, to: finalY } },\n el: rect,\n });\n } else {\n updateTargets.push({\n attrs: {\n height: { from: Number(rect.getAttribute('height') ?? finalHeight), to: finalHeight },\n y: { from: Number(rect.getAttribute('y') ?? finalY), to: finalY },\n },\n el: rect,\n });\n }\n } else {\n setAttributes(rect, { height: finalHeight, y: finalY });\n }\n }\n }\n\n if (options.transition) {\n activeBarAnimations.get(parent)?.();\n\n const cancels: (() => void)[] = [];\n\n if (enterTargets.length > 0) {\n cancels.push(animate(enterTargets, options.transition, undefined, options.disposalSignal));\n }\n\n if (updateTargets.length > 0) {\n cancels.push(animate(updateTargets, { ...options.transition, stagger: 0 }, undefined, options.disposalSignal));\n }\n\n activeBarAnimations.set(parent, () => {\n for (const cancel of cancels) cancel();\n });\n }\n}\n"],"mappings":"mIAkBA,IAAM,EAAsB,IAAI,QAEhC,SAAgB,WACd,EACA,EACA,EACA,EACA,EACA,EACM,CACN,KAAO,EAAO,SAAS,OAAS,EAAK,QAAQ,CAC3C,IAAM,EAAO,EAAO,iBAEhB,GAAM,EAAO,YAAY,CAAI,CACnC,CAEA,IAAM,EAAY,EAAO,UAAU,EAC7B,EAAU,EAAQ,QAAU,EAAY,EAAY,EAAQ,YAC5D,EAAS,EAAQ,QAAU,EAAI,EAAU,EAAQ,YACjD,EAAa,EAAQ,YAAc,GAEnC,EAAkC,CAAC,EACnC,EAAmC,CAAC,EAE1C,IAAK,IAAI,EAAI,EAAG,EAAI,EAAK,OAAQ,IAAK,CACpC,IAAM,EAAI,EAAK,GACT,EAAU,EAAO,IAAI,EAAE,GAAG,EAAI,EAC9B,EAAe,EAAQ,WAAa,EAA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,WACN,GACF,EAAc,EAAM,CAAE,OAAQ,EAAG,EAAG,CAAa,CAAC,EAClD,EAAa,KAAK,CAChB,MAAO,CAAE,OAAQ,CAAE,KAAM,EAAG,GAAI,CAAY,EAAG,EAAG,CAAE,KAAM,EAAc,GAAI,CAAO,CAAE,EACrF,GAAI,CACN,CAAC,GAED,EAAc,KAAK,CACjB,MAAO,CACL,OAAQ,CAAE,KAAM,OAAO,EAAK,aAAa,QAAQ,GAAK,CAAW,EAAG,GAAI,CAAY,EACpF,EAAG,CAAE,KAAM,OAAO,EAAK,aAAa,GAAG,GAAK,CAAM,EAAG,GAAI,CAAO,CAClE,EACA,GAAI,CACN,CAAC,EAGH,EAAc,EAAM,CAAE,OAAQ,EAAa,EAAG,CAAO,CAAC,CAE1D,CACF,CAEA,GAAI,EAAQ,WAAY,CACtB,EAAoB,IAAI,CAAM,CAAC,GAAG,EAElC,IAAM,EAA0B,CAAC,EAE7B,EAAa,OAAS,GACxB,EAAQ,KAAK,EAAQ,EAAc,EAAQ,WAAY,IAAA,GAAW,EAAQ,cAAc,CAAC,EAGvF,EAAc,OAAS,GACzB,EAAQ,KAAK,EAAQ,EAAe,CAAE,GAAG,EAAQ,WAAY,QAAS,CAAE,EAAG,IAAA,GAAW,EAAQ,cAAc,CAAC,EAG/G,EAAoB,IAAI,MAAc,CACpC,IAAK,IAAM,KAAU,EAAS,EAAO,CACvC,CAAC,CACH,CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
const e=require("../../svg/element.cjs"),t=require("../../axes/axis.cjs"),n=require("../../axes/grid.cjs"),r=require("../../core/cartesian-scales.cjs"),i=require("../../core/layout.cjs"),a=require("../../core/chart-scaffold.cjs"),o=require("../../interaction/crosshair.cjs"),s=require("../../interaction/series-interaction.cjs"),c=require("../../theme/index.cjs"),l=require("./line-renderer.cjs");function createLineChart(u,d){let f=null,p=d.series;return a.createChartScaffold(u,d,u=>{let{groups:m,legend:h,tooltip:g}=u,_=u.dimensions,v=i.chartArea(_.width,_.height,_.margin),y=p.map(e=>e.data),b=y.flat().map(e=>e.key),x=y.flat().map(e=>e.value);if(b.length===0){a.clearCartesianDom(m,h,g,f);return}d.crosshair&&!f&&(f=o.createCrosshair(u.chartArea,d.crosshair));let S=r.buildXScale(b,v.width),C=r.buildYScale(x,v.height);for(d.yAxis?.grid&&n.renderGrid(m.grid,C,d.yAxis.grid,v.width,`horizontal`,t.resolveTickCount(d.yAxis,v.height,`left`)),d.xAxis?.grid&&n.renderGrid(m.grid,S,d.xAxis.grid,v.height,`vertical`,t.resolveTickCount(d.xAxis,v.width,`bottom`)),d.xAxis&&(t.positionAxis(m.xAxis,d.xAxis.position??`bottom`,v.width,v.height),t.renderAxis(m.xAxis,S,d.xAxis,v.width,`bottom`)),d.yAxis&&(t.positionAxis(m.yAxis,d.yAxis.position??`left`,v.width,v.height),t.renderAxis(m.yAxis,C,d.yAxis,v.height,`left`));m.series.children.length>p.length;)m.series.removeChild(m.series.lastChild);let w=[];for(let t=0;t<p.length;t++){let n=p[t],r=m.series.children[t];r||(r=e.createSvgElement(`g`,{class:`prism-line-series`}),m.series.appendChild(r));let i=l.computePoints(y[t],S,C);w.push(i),l.renderLine(r,i,{color:c.seriesColor(t,n.color),curve:n.curve??`linear`,disposalSignal:u.disposalSignal,pointRadius:n.pointRadius??3,showPoints:n.showPoints??!1,strokeWidth:n.strokeWidth??2,transition:d.transition})}return h?.update(p.map((e,t)=>({color:c.seriesColor(t,e.color),name:e.name}))),g?.hide(),s.createSeriesInteraction({crosshair:f,dims:()=>u.dimensions,getData:()=>y,getPoints:()=>w,getSeriesList:()=>p,onClick:d.onClick,onHover:d.onHover,svg:u.svg,tooltip:g})},e=>{p=e})}exports.createLineChart=createLineChart;
|
|
2
2
|
//# sourceMappingURL=line-chart.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"line-chart.cjs","names":[],"sources":["../../../src/charts/line/line-chart.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"line-chart.cjs","names":[],"sources":["../../../src/charts/line/line-chart.ts"],"sourcesContent":["import { positionAxis, renderAxis, resolveTickCount } from '../../axes/axis';\nimport { renderGrid } from '../../axes/grid';\nimport { buildXScale, buildYScale } from '../../core/cartesian-scales';\nimport { clearCartesianDom, createChartScaffold } from '../../core/chart-scaffold';\nimport { chartArea } from '../../core/layout';\nimport { createCrosshair } from '../../interaction/crosshair';\nimport { createSeriesInteraction } from '../../interaction/series-interaction';\nimport { createSvgElement } from '../../svg/element';\nimport type { Point } from '../../svg/path';\nimport { seriesColor } from '../../theme';\nimport type { ChartHandle, LineChartConfig, LineSeriesConfig } from '../../types';\nimport { computePoints, renderLine } from './line-renderer';\n\nexport function createLineChart(container: HTMLElement, config: LineChartConfig): ChartHandle<LineSeriesConfig[]> {\n let crosshair: ReturnType<typeof createCrosshair> | null = null;\n let seriesList = config.series;\n\n return createChartScaffold(\n container,\n config,\n (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const allData = seriesList.map((series) => series.data);\n const allX = allData.flat().map((datum) => datum.key);\n const allY = allData.flat().map((d) => d.value);\n\n if (allX.length === 0) {\n clearCartesianDom(groups, legend, tooltip, crosshair);\n\n return;\n }\n\n if (config.crosshair && !crosshair) {\n crosshair = createCrosshair(ctx.chartArea, config.crosshair);\n }\n\n const xScale = buildXScale(allX, area.width);\n const yScale = buildYScale(allY, area.height);\n\n if (config.yAxis?.grid) {\n renderGrid(\n groups.grid,\n yScale,\n config.yAxis.grid,\n area.width,\n 'horizontal',\n resolveTickCount(config.yAxis, area.height, 'left'),\n );\n }\n\n if (config.xAxis?.grid) {\n renderGrid(\n groups.grid,\n xScale,\n config.xAxis.grid,\n area.height,\n 'vertical',\n resolveTickCount(config.xAxis, area.width, 'bottom'),\n );\n }\n\n if (config.xAxis) {\n positionAxis(groups.xAxis, config.xAxis.position ?? 'bottom', area.width, area.height);\n renderAxis(groups.xAxis, xScale, config.xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) {\n positionAxis(groups.yAxis, config.yAxis.position ?? 'left', area.width, area.height);\n renderAxis(groups.yAxis, yScale, config.yAxis, area.height, 'left');\n }\n\n while (groups.series.children.length > seriesList.length) {\n groups.series.removeChild(groups.series.lastChild!);\n }\n\n const allPoints: Point[][] = [];\n\n for (let i = 0; i < seriesList.length; i++) {\n const series = seriesList[i];\n let group = groups.series.children[i] as SVGGElement | undefined;\n\n if (!group) {\n group = createSvgElement('g', { class: 'prism-line-series' });\n groups.series.appendChild(group);\n }\n\n const points = computePoints(allData[i], xScale, yScale);\n\n allPoints.push(points);\n\n renderLine(group, points, {\n color: seriesColor(i, series.color),\n curve: series.curve ?? 'linear',\n disposalSignal: ctx.disposalSignal,\n pointRadius: series.pointRadius ?? 3,\n showPoints: series.showPoints ?? false,\n strokeWidth: series.strokeWidth ?? 2,\n transition: config.transition,\n });\n }\n\n legend?.update(seriesList.map((s, i) => ({ color: seriesColor(i, s.color), name: s.name })));\n tooltip?.hide();\n\n return createSeriesInteraction({\n crosshair,\n dims: () => ctx.dimensions,\n getData: () => allData,\n getPoints: () => allPoints,\n getSeriesList: () => seriesList,\n onClick: config.onClick,\n onHover: config.onHover,\n svg: ctx.svg,\n tooltip,\n });\n },\n (data) => {\n seriesList = data;\n },\n );\n}\n"],"mappings":"6YAaA,SAAgB,gBAAgB,EAAwB,EAA0D,CAChH,IAAI,EAAuD,KACvD,EAAa,EAAO,OAExB,OAAO,EAAA,oBACL,EACA,EACC,GAAQ,CACP,GAAM,CAAE,SAAQ,SAAQ,WAAY,EAC9B,EAAO,EAAI,WACX,EAAO,EAAA,UAAU,EAAK,MAAO,EAAK,OAAQ,EAAK,MAAM,EACrD,EAAU,EAAW,IAAK,GAAW,EAAO,IAAI,EAChD,EAAO,EAAQ,KAAK,CAAC,CAAC,IAAK,GAAU,EAAM,GAAG,EAC9C,EAAO,EAAQ,KAAK,CAAC,CAAC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,GAAI,EAAQ,CAAM,EAEvD,EAAU,KAAK,CAAM,EAErB,EAAA,WAAW,EAAO,EAAQ,CACxB,MAAO,EAAA,YAAY,EAAG,EAAO,KAAK,EAClC,MAAO,EAAO,OAAS,SACvB,eAAgB,EAAI,eACpB,YAAa,EAAO,aAAe,EACnC,WAAY,EAAO,YAAc,GACjC,YAAa,EAAO,aAAe,EACnC,WAAY,EAAO,UACrB,CAAC,CACH,CAKA,OAHA,GAAQ,OAAO,EAAW,KAAK,EAAG,KAAO,CAAE,MAAO,EAAA,YAAY,EAAG,EAAE,KAAK,EAAG,KAAM,EAAE,IAAK,EAAE,CAAC,EAC3F,GAAS,KAAK,EAEP,EAAA,wBAAwB,CAC7B,YACA,SAAY,EAAI,WAChB,YAAe,EACf,cAAiB,EACjB,kBAAqB,EACrB,QAAS,EAAO,QAChB,QAAS,EAAO,QAChB,IAAK,EAAI,IACT,SACF,CAAC,CACH,EACC,GAAS,CACR,EAAa,CACf,CACF,CACF"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { ChartHandle, LineChartConfig } from '../../types';
|
|
2
|
-
export declare function createLineChart(container: HTMLElement, config: LineChartConfig): ChartHandle
|
|
1
|
+
import type { ChartHandle, LineChartConfig, LineSeriesConfig } from '../../types';
|
|
2
|
+
export declare function createLineChart(container: HTMLElement, config: LineChartConfig): ChartHandle<LineSeriesConfig[]>;
|
|
3
3
|
//# sourceMappingURL=line-chart.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"line-chart.d.ts","sourceRoot":"","sources":["../../../src/charts/line/line-chart.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"line-chart.d.ts","sourceRoot":"","sources":["../../../src/charts/line/line-chart.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGlF,wBAAgB,eAAe,CAAC,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,eAAe,GAAG,WAAW,CAAC,gBAAgB,EAAE,CAAC,CA6GhH"}
|