@vielzeug/prism 3.0.0 → 26.10.1
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 +2 -2
- package/dist/_dev.cjs +1 -1
- package/dist/_dev.cjs.map +1 -1
- package/dist/_dev.js +1 -5
- 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 +2 -2
- package/dist/axes/axis.d.ts.map +1 -1
- package/dist/axes/axis.js +1 -63
- 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.d.ts +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.map +1 -1
- package/dist/charts/area/area-chart.js +1 -57
- 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 +4 -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.map +1 -1
- package/dist/charts/bar/bar-chart.js +1 -169
- 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.d.ts +0 -5
- package/dist/charts/bar/bar-hit-test.d.ts.map +1 -1
- package/dist/charts/bar/bar-hit-test.js +1 -29
- package/dist/charts/bar/bar-hit-test.js.map +1 -1
- package/dist/charts/bar/bar-renderer.cjs +1 -1
- package/dist/charts/bar/bar-renderer.cjs.map +1 -1
- package/dist/charts/bar/bar-renderer.d.ts +1 -1
- package/dist/charts/bar/bar-renderer.d.ts.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.map +1 -1
- package/dist/charts/line/line-chart.js +1 -58
- 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 +3 -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.map +1 -1
- package/dist/charts/pie/pie-chart.js +1 -165
- 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.d.ts.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/radar/index.d.ts +2 -0
- package/dist/charts/radar/index.d.ts.map +1 -0
- package/dist/charts/radar/radar-chart.cjs +2 -0
- package/dist/charts/radar/radar-chart.cjs.map +1 -0
- package/dist/charts/radar/radar-chart.d.ts +3 -0
- package/dist/charts/radar/radar-chart.d.ts.map +1 -0
- package/dist/charts/radar/radar-chart.js +2 -0
- package/dist/charts/radar/radar-chart.js.map +1 -0
- package/dist/charts/radar/radar-geometry.cjs +2 -0
- package/dist/charts/radar/radar-geometry.cjs.map +1 -0
- package/dist/charts/radar/radar-geometry.d.ts +22 -0
- package/dist/charts/radar/radar-geometry.d.ts.map +1 -0
- package/dist/charts/radar/radar-geometry.js +2 -0
- package/dist/charts/radar/radar-geometry.js.map +1 -0
- package/dist/charts/sparkline/sparkline.cjs +1 -1
- package/dist/charts/sparkline/sparkline.cjs.map +1 -1
- package/dist/charts/sparkline/sparkline.d.ts.map +1 -1
- package/dist/charts/sparkline/sparkline.js +1 -191
- 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 +9 -0
- package/dist/core/chart-base.d.ts.map +1 -1
- package/dist/core/chart-base.js +1 -53
- 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 +7 -3
- package/dist/core/chart-scaffold.d.ts.map +1 -1
- package/dist/core/chart-scaffold.js +1 -89
- package/dist/core/chart-scaffold.js.map +1 -1
- package/dist/core/ids.cjs +2 -0
- package/dist/core/ids.cjs.map +1 -0
- package/dist/core/ids.d.ts +3 -0
- package/dist/core/ids.d.ts.map +1 -0
- package/dist/core/ids.js +2 -0
- package/dist/core/ids.js.map +1 -0
- 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/polar.cjs +2 -0
- package/dist/core/polar.cjs.map +1 -0
- package/dist/core/polar.d.ts +5 -0
- package/dist/core/polar.d.ts.map +1 -0
- package/dist/core/polar.js +2 -0
- package/dist/core/polar.js.map +1 -0
- 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/index.d.ts +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.d.ts +1 -1
- package/dist/errors.d.ts.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 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -11
- package/dist/interaction/announcer.cjs +2 -0
- package/dist/interaction/announcer.cjs.map +1 -0
- package/dist/interaction/announcer.d.ts +13 -0
- package/dist/interaction/announcer.d.ts.map +1 -0
- package/dist/interaction/announcer.js +2 -0
- package/dist/interaction/announcer.js.map +1 -0
- package/dist/interaction/crosshair.cjs +1 -1
- package/dist/interaction/crosshair.cjs.map +1 -1
- package/dist/interaction/crosshair.d.ts +1 -5
- package/dist/interaction/crosshair.d.ts.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.d.ts +11 -1
- package/dist/interaction/series-interaction.d.ts.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 +12 -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.d.ts +1 -0
- package/dist/svg/text.d.ts.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/theme/prism.css +214 -7
- package/dist/types.d.ts +65 -5
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -5
|
@@ -1,170 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createSvgElement as e } from "../../svg/element.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";
|
|
8
|
-
import { normalizeCartesianSeries as l } from "../../core/cartesian-model.js";
|
|
9
|
-
import { getMousePosition as u } from "../../interaction/events.js";
|
|
10
|
-
import { seriesColor as d } from "../../theme/index.js";
|
|
11
|
-
import { bandScale as f } from "../../scales/band.js";
|
|
12
|
-
import { findCatIdx as p, findSeriesIdx as m, isOutsideBars as h } from "./bar-hit-test.js";
|
|
13
|
-
import { renderBars as g } from "./bar-renderer.js";
|
|
14
|
-
//#region src/charts/bar/bar-chart.ts
|
|
15
|
-
function _(e) {
|
|
16
|
-
return {
|
|
17
|
-
horizontal: e === "grouped-horizontal" || e === "stacked-horizontal",
|
|
18
|
-
stacked: e === "stacked" || e === "stacked-horizontal"
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
function v(v, y) {
|
|
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
|
-
}
|
|
31
|
-
};
|
|
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,
|
|
91
|
-
key: e,
|
|
92
|
-
present: r !== void 0,
|
|
93
|
-
y: n
|
|
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]
|
|
132
|
-
});
|
|
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?.({
|
|
156
|
-
datum: l,
|
|
157
|
-
originalEvent: e,
|
|
158
|
-
series: b[s]
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
}, (e) => {
|
|
164
|
-
b = e;
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
//#endregion
|
|
168
|
-
export { v as createBarChart };
|
|
169
|
-
|
|
1
|
+
import"../../_dev.js";import{createSvgElement as e,setAttributes as t}from"../../svg/element.js";import{positionAxis as n,renderAxis as r,resolveTickCount as i}from"../../axes/axis.js";import{renderGrid as a}from"../../axes/grid.js";import{linearScale as o}from"../../scales/linear.js";import{describeValues as s}from"../../interaction/announcer.js";import{comparisonContent as c}from"../../interaction/tooltip.js";import{chartArea as l}from"../../core/layout.js";import{clearCartesianDom as u,createChartScaffold as d}from"../../core/chart-scaffold.js";import{normalizeCartesianSeries as f}from"../../core/cartesian-model.js";import{getMousePosition as p}from"../../interaction/events.js";import{seriesColor as m}from"../../theme/index.js";import{bandScale as h}from"../../scales/band.js";import{findCatIdx as g,findSeriesIdx as _}from"./bar-hit-test.js";import{renderBars as v}from"./bar-renderer.js";function variantFlags(e){return{horizontal:e===`grouped-horizontal`||e===`stacked-horizontal`,stacked:e===`stacked`||e===`stacked-horizontal`}}function createBarChart(y,b){let x=b.series,S=null;return d(y,b,d=>{let{groups:y,legend:C,tooltip:w}=d,T=d.dimensions,E=l(T.width,T.height,T.margin),D=x.map(e=>e.data),O=f(x,D),k=O.domain,A=O.series.map(({byKey:e})=>k.map(t=>e.get(t))),categoryAxis=e=>{if(e)return{...e,tickFormat:t=>{let n=String(t),r=O.labels.get(n)??t;return e.tickFormat?e.tickFormat(r):String(r)}}};if(k.length===0){u(y,C,w),S?.remove(),S=null;return}let{horizontal:j,stacked:M}=variantFlags(b.variant??`grouped`),N,P;if(M){A.some(e=>e.some(e=>(e?.value??0)<0));let e=k.map((e,t)=>A.reduce((e,n)=>e+Math.max(0,n[t]?.value??0),0));N=Math.max(...e),P=0}else{let e=A.flatMap(e=>e.flatMap(e=>e?[e.value]:[]));N=Math.max(...e),P=Math.min(0,...e)}let F=h(j?{domain:k,range:[0,E.height]}:{domain:k,range:[0,E.width]}),I=o(j?{domain:[P,N],range:[0,E.width]}:{domain:[P,N],range:[E.height,0]}),L=[],R=Object.create(null);for(let e of k)R[e]=0;let z={bandCenter:e=>F.map(e)+F.bandwidth()/2,bandwidth:F.bandwidth(),baselinePx:I.map(0),horizontal:j,stacked:M,stackedTops:L,valueScale:I};if(j){b.xAxis?.grid&&a(y.grid,I,b.xAxis.grid,E.height,`vertical`,i(b.xAxis,E.width,`bottom`));let e=categoryAxis(b.yAxis);e&&(n(y.yAxis,e.position??`left`,E.width,E.height),r(y.yAxis,F,e,E.height,`left`)),b.xAxis&&(n(y.xAxis,b.xAxis.position??`bottom`,E.width,E.height),r(y.xAxis,I,b.xAxis,E.width,`bottom`))}else{b.yAxis?.grid&&a(y.grid,I,b.yAxis.grid,E.width,`horizontal`,i(b.yAxis,E.height,`left`));let e=categoryAxis(b.xAxis);e&&(n(y.xAxis,e.position??`bottom`,E.width,E.height),r(y.xAxis,F,e,E.width,`bottom`)),b.yAxis&&(n(y.yAxis,b.yAxis.position??`left`,E.width,E.height),r(y.yAxis,I,b.yAxis,E.height,`left`))}let B=M?0:Number.parseFloat(getComputedStyle(d.svg).getPropertyValue(`--prism-bar-radius`))||0;for(;y.series.children.length>x.length;){let e=y.series.lastElementChild;e&&y.series.removeChild(e)}for(let t=0;t<x.length;t++){let n=x[t],r=y.series.children[t];r||(r=e(`g`,{class:`prism-bar-series`}),y.series.appendChild(r));let i=k.map((e,n)=>{let r=A[t]?.[n];if(M){let t=R[e]??0,n=t+Math.max(0,r?.value??0);return R[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}});L[t]=i.map(e=>e.y);let a=M?i.map(e=>I.map(e.base)):void 0;v(r,i,F,I,z.baselinePx,{baselineYs:a,borderRadius:n.borderRadius??B,color:m(t,n.color),disposalSignal:d.disposalSignal,horizontal:j,seriesCount:x.length,seriesIndex:t,stacked:M,transition:b.transition})}C?.update(x.map((e,t)=>({color:m(t,e.color),name:e.name}))),w?.hide(),y.series.classList.toggle(`prism-bars-stacked`,M),(!S||!d.chartArea.contains(S))&&(S=e(`rect`,{"aria-hidden":`true`,class:`prism-bar-band`,"pointer-events":`none`}),d.chartArea.insertBefore(S,y.series)),S.style.display=`none`;let V=x.map((e,t)=>m(t,e.color)),labelOf=e=>String(O.labels.get(k[e])??k[e]),H=-1,valuesAt=e=>x.map((t,n)=>({datum:A[n]?.[e],series:t})),eventAt=(e,t,n)=>{let r=valuesAt(e),i=r[t]?.datum?t:r.findIndex(e=>e.datum),a=r[i]?.datum;return a?{datum:a,originalEvent:n,series:x[i],values:r}:null},setActive=e=>{H=e,y.series.classList.toggle(`prism-bars-focused`,e>=0);for(let t of y.series.children)for(let[n,r]of[...t.children].entries())r.classList.toggle(`prism-bar--active`,n===e);if(!S||(S.style.display=e<0?`none`:``,e<0))return;let n=z.bandCenter(k[e])-F.bandwidth()/2-F.gap()/2,r=F.bandwidth()+F.gap(),i=l(d.dimensions.width,d.dimensions.height,d.dimensions.margin);t(S,j?{height:r,width:i.width,x:0,y:n}:{height:i.height,width:r,x:n,y:0})},activate=(e,t,n)=>{let r=eventAt(e,t,n);if(!r)return;setActive(e);let i=r.values??[],a=s(labelOf(e),i);if(w){let t=i.map((t,n)=>M?L[n]?.[e]??0:Math.max(0,t.datum?.value??0)),n=I.map(Math.max(...t)),o=z.bandCenter(k[e]),{margin:s}=d.dimensions,l=i.flatMap((e,t)=>e.datum?[{color:V[t],name:e.series.name,value:String(e.datum.value)}]:[]);w.show((j?n:o)+s.left,(j?o:n)+s.top,r.datum,r.series,c(d.svg.ownerDocument,labelOf(e),l,a))}else d.announcer.announce(a);b.onHover?.(r)},deactivate=()=>{setActive(-1),w?.hide(),d.announcer.clear(),b.onHover?.(null)},hit=e=>{let t=d.dimensions,n=p(d.svg,e,t.margin.left,t.margin.top),r=l(t.width,t.height,t.margin);if(n.x<0||n.x>r.width||n.y<0||n.y>r.height)return null;let i=g(j?n.y:n.x,k,z);return i===-1?null:{catIdx:i,seriesIdx:_(n,i,k,z,x.length)}},onMouseMove=e=>{let t=hit(e);t?activate(t.catIdx,t.seriesIdx,e):H>=0&&deactivate()},onClick=e=>{let t=b.onClick&&hit(e),n=t&&eventAt(t.catIdx,t.seriesIdx,e);n&&b.onClick?.(n)},onKeyDown=e=>{let t=k.length-1,n=H<0?t:Math.max(0,H-1),r=H<0?0:Math.min(t,H+1),i={ArrowDown:r,ArrowLeft:n,ArrowRight:r,ArrowUp:n,End:t,Home:0};if(e.key in i)e.preventDefault(),activate(i[e.key],0,e);else if((e.key===`Enter`||e.key===` `)&&H>=0&&b.onClick){e.preventDefault();let t=eventAt(H,0,e);t&&b.onClick(t)}else e.key===`Escape`&&deactivate()};return{onClick,onKeyDown,onMouseLeave:deactivate,onMouseMove}},e=>{x=e})}export{createBarChart};
|
|
170
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 { 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 );\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AE,OAAO,EAAE,QAAQ,EAAE,MAAM;IAE/C,IAAI,EAAI,IAAI,KAAK,EAAI,IAAI,EAAE,SAAS,EAAI,IAAI,KAAK,EAAI,IAAI,EAAE,QAAQ;KACjE,GAAS,KAAK;KAEd;IACF;IAEA,IAAM,IAAU,IAAa,EAAI,IAAI,EAAI,GACnC,IAAS,EAAW,GAAS,GAAY,CAAE;IAEjD,IAAI,MAAW,IAAI;KACjB,GAAS,KAAK;KAEd;IACF;IAEA,IAAI,EAAc,GAAK,GAAQ,GAAS,GAAI,EAAW,MAAM,GAAG;KAC9D,GAAS,KAAK;KAEd;IACF;IAEA,IAAM,IAAY,EAAc,GAAK,GAAQ,GAAY,GAAI,EAAW,MAAM,GACxE,IAAQ,EAAQ,EAAU,GAAG;IAEnC,IAAI,GAAO;KACT,IAAM,IAAe,EAAG,WAAW,EAAW,EAAO,GAC/C,IAAa,IAAW,EAAY,EAAU,GAAG,MAAW,EAAM,QAAS,EAAM,OACjF,IAAU,EAAS,IAAI,CAAU,GAEjC,IAAW,IAAa,IAAU,EAAE,OAAO,OAAO,IAAe,EAAE,OAAO,MAC1E,IAAW,IAAa,IAAe,EAAE,OAAO,MAAM,IAAU,EAAE,OAAO;KAG/E,AADA,GAAS,KAAK,GAAU,GAAU,GAAO,EAAW,EAAU,GAC9D,EAAO,UAAU;MAAE,OAAO;MAAO,eAAe;MAAO,QAAQ,EAAW;KAAW,CAAC;IACxF;GACF;EA6B4C;CAC9C,IACC,MAAS;EACR,IAAa;CACf,CACF;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 { describeValues } from '../../interaction/announcer';\nimport { getMousePosition } from '../../interaction/events';\nimport { comparisonContent } from '../../interaction/tooltip';\nimport { bandScale } from '../../scales/band';\nimport { linearScale } from '../../scales/linear';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport { seriesColor } from '../../theme';\nimport type { BarChartConfig, BarSeriesConfig, BarVariant, ChartEvent, ChartHandle, SeriesValue } from '../../types';\nimport { findCatIdx, findSeriesIdx } 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 let band: SVGRectElement | null = null;\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 band?.remove();\n band = null;\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 // Stacked segments stay square so they join cleanly.\n const themeRadius = stacked\n ? 0\n : Number.parseFloat(getComputedStyle(ctx.svg).getPropertyValue('--prism-bar-radius')) || 0;\n\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 ?? themeRadius,\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 groups.series.classList.toggle('prism-bars-stacked', stacked);\n\n if (!band || !ctx.chartArea.contains(band)) {\n band = createSvgElement('rect', { 'aria-hidden': 'true', class: 'prism-bar-band', 'pointer-events': 'none' });\n ctx.chartArea.insertBefore(band, groups.series);\n }\n\n band.style.display = 'none';\n\n // ─── Event handlers (close over render-derived state) ─────────────────────\n\n const colors = seriesList.map((s, i) => seriesColor(i, s.color));\n const labelOf = (catIdx: number): string => String(model.labels.get(categories[catIdx]) ?? categories[catIdx]);\n let activeCat = -1;\n\n const valuesAt = (catIdx: number): SeriesValue[] =>\n seriesList.map((series, si) => ({ datum: allData[si]?.[catIdx], series }));\n\n const eventAt = (catIdx: number, seriesIdx: number, originalEvent: Event): ChartEvent | null => {\n const values = valuesAt(catIdx);\n const preferred = values[seriesIdx]?.datum ? seriesIdx : values.findIndex((v) => v.datum);\n const datum = values[preferred]?.datum;\n\n return datum ? { datum, originalEvent, series: seriesList[preferred], values } : null;\n };\n\n const setActive = (catIdx: number): void => {\n activeCat = catIdx;\n groups.series.classList.toggle('prism-bars-focused', catIdx >= 0);\n\n for (const group of groups.series.children) {\n for (const [i, rect] of [...group.children].entries())\n rect.classList.toggle('prism-bar--active', i === catIdx);\n }\n\n if (!band) return;\n\n band.style.display = catIdx < 0 ? 'none' : '';\n\n if (catIdx < 0) return;\n\n const start = sc.bandCenter(categories[catIdx]) - catScale.bandwidth() / 2 - catScale.gap() / 2;\n const size = catScale.bandwidth() + catScale.gap();\n const a = chartArea(ctx.dimensions.width, ctx.dimensions.height, ctx.dimensions.margin);\n\n setAttributes(\n band,\n horizontal\n ? { height: size, width: a.width, x: 0, y: start }\n : { height: a.height, width: size, x: start, y: 0 },\n );\n };\n\n const activate = (catIdx: number, seriesIdx: number, originalEvent: Event): void => {\n const event = eventAt(catIdx, seriesIdx, originalEvent);\n\n if (!event) return;\n\n setActive(catIdx);\n\n const values = event.values ?? [];\n const spoken = describeValues(labelOf(catIdx), values);\n\n if (tooltip) {\n const tops = values.map((v, si) =>\n stacked ? (stackedTops[si]?.[catIdx] ?? 0) : Math.max(0, v.datum?.value ?? 0),\n );\n const valuePx = valScale.map(Math.max(...tops));\n const bandCenterPx = sc.bandCenter(categories[catIdx]);\n const { margin } = ctx.dimensions;\n const rows = values.flatMap((v, si) =>\n v.datum ? [{ color: colors[si], name: v.series.name, value: String(v.datum.value) }] : [],\n );\n\n tooltip.show(\n (horizontal ? valuePx : bandCenterPx) + margin.left,\n (horizontal ? bandCenterPx : valuePx) + margin.top,\n event.datum,\n event.series,\n comparisonContent(ctx.svg.ownerDocument, labelOf(catIdx), rows, spoken),\n );\n } else {\n ctx.announcer.announce(spoken);\n }\n\n config.onHover?.(event);\n };\n\n const deactivate = (): void => {\n setActive(-1);\n tooltip?.hide();\n ctx.announcer.clear();\n config.onHover?.(null);\n };\n\n const hit = (event: MouseEvent): { catIdx: number; seriesIdx: number } | null => {\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 null;\n\n const catIdx = findCatIdx(horizontal ? pos.y : pos.x, categories, sc);\n\n return catIdx === -1\n ? null\n : { catIdx, seriesIdx: findSeriesIdx(pos, catIdx, categories, sc, seriesList.length) };\n };\n\n const onMouseMove = (event: MouseEvent) => {\n const target = hit(event);\n\n if (target) activate(target.catIdx, target.seriesIdx, event);\n else if (activeCat >= 0) deactivate();\n };\n\n const onClick = (event: MouseEvent) => {\n const target = config.onClick && hit(event);\n const chartEvent = target && eventAt(target.catIdx, target.seriesIdx, event);\n\n if (chartEvent) config.onClick?.(chartEvent);\n };\n\n const onKeyDown = (event: KeyboardEvent) => {\n const last = categories.length - 1;\n const prev = activeCat < 0 ? last : Math.max(0, activeCat - 1);\n const next = activeCat < 0 ? 0 : Math.min(last, activeCat + 1);\n const target: Record<string, number> = {\n ArrowDown: next,\n ArrowLeft: prev,\n ArrowRight: next,\n ArrowUp: prev,\n End: last,\n Home: 0,\n };\n\n if (event.key in target) {\n event.preventDefault();\n activate(target[event.key], 0, event);\n } else if ((event.key === 'Enter' || event.key === ' ') && activeCat >= 0 && config.onClick) {\n event.preventDefault();\n\n const chartEvent = eventAt(activeCat, 0, event);\n\n if (chartEvent) config.onClick(chartEvent);\n } else if (event.key === 'Escape') {\n deactivate();\n }\n };\n\n return { onClick, onKeyDown, onMouseLeave: deactivate, onMouseMove };\n },\n (data) => {\n seriesList = data;\n },\n );\n}\n"],"mappings":"u4BAkBA,SAAS,aAAa,EAAgE,CACpF,MAAO,CACL,WAAY,IAAY,sBAAwB,IAAY,qBAC5D,QAAS,IAAY,WAAa,IAAY,oBAChD,CACF,CAIA,SAAgB,eAAe,EAAwB,EAAwD,CAC7G,IAAI,EAAa,EAAO,OACpB,EAA8B,KAElC,OAAO,EACL,EACA,EACC,GAAQ,CACP,GAAM,CAAE,SAAQ,SAAQ,WAAY,EAC9B,EAAO,EAAI,WACX,EAAO,EAAU,EAAK,MAAO,EAAK,OAAQ,EAAK,MAAM,EACrD,EAAa,EAAW,IAAK,GAAW,EAAO,IAAI,EACnD,EAAQ,EAAyB,EAAY,CAAU,EACvD,EAAa,EAAM,OACnB,EAAU,EAAM,OAAO,KAAK,CAAE,WAAY,EAAW,IAAK,GAAQ,EAAM,IAAI,CAAG,CAAC,CAAC,EACjF,aAAgB,GAA4D,CAC3E,KAEL,MAAO,CACL,GAAG,EACH,WAAa,GAAkC,CAC7C,IAAM,EAAM,OAAO,CAAK,EAClB,EAAQ,EAAM,OAAO,IAAI,CAAG,GAAK,EAEvC,OAAO,EAAK,WAAa,EAAK,WAAW,CAAK,EAAI,OAAO,CAAK,CAChE,CACF,CACF,EAEA,GAAI,EAAW,SAAW,EAAG,CAC3B,EAAkB,EAAQ,EAAQ,CAAO,EACzC,GAAM,OAAO,EACb,EAAO,KAEP,MACF,CAEA,GAAM,CAAE,aAAY,WAAY,aAAa,EAAO,SAAW,SAAS,EAGpE,EACA,EAEJ,GAAI,EAAS,CACP,EAAQ,KAAM,GAAe,EAAW,KAAM,IAAW,GAAO,OAAS,GAAK,CAAC,CAAC,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tC,EAEM,QAAW,GAAsB,CACrC,IAAM,EAAS,EAAO,SAAW,IAAI,CAAK,EACpC,EAAa,GAAU,QAAQ,EAAO,OAAQ,EAAO,UAAW,CAAK,EAEvE,GAAY,EAAO,UAAU,CAAU,CAC7C,EAEM,UAAa,GAAyB,CAC1C,IAAM,EAAO,EAAW,OAAS,EAC3B,EAAO,EAAY,EAAI,EAAO,KAAK,IAAI,EAAG,EAAY,CAAC,EACvD,EAAO,EAAY,EAAI,EAAI,KAAK,IAAI,EAAM,EAAY,CAAC,EACvD,EAAiC,CACrC,UAAW,EACX,UAAW,EACX,WAAY,EACZ,QAAS,EACT,IAAK,EACL,KAAM,CACR,EAEA,GAAI,EAAM,OAAO,EACf,EAAM,eAAe,EACrB,SAAS,EAAO,EAAM,KAAM,EAAG,CAAK,OAC/B,IAAK,EAAM,MAAQ,SAAW,EAAM,MAAQ,MAAQ,GAAa,GAAK,EAAO,QAAS,CAC3F,EAAM,eAAe,EAErB,IAAM,EAAa,QAAQ,EAAW,EAAG,CAAK,EAE1C,GAAY,EAAO,QAAQ,CAAU,CAC3C,MAAW,EAAM,MAAQ,UACvB,WAAW,CAEf,EAEA,MAAO,CAAE,QAAS,UAAW,aAAc,WAAY,WAAY,CACrE,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))}}exports.findCatIdx=findCatIdx,exports.findSeriesIdx=findSeriesIdx;
|
|
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 {
|
|
1
|
+
{"version":3,"file":"bar-hit-test.cjs","names":[],"sources":["../../../src/charts/bar/bar-hit-test.ts"],"sourcesContent":["import 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"],"mappings":"AAEA,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"}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import type { Datum } from '../../types';
|
|
2
1
|
import type { BarScaleContext } from './bar-scale-context';
|
|
3
2
|
export declare function findCatIdx(pos: number, categories: string[], sc: BarScaleContext): number;
|
|
4
3
|
export declare function findSeriesIdx(pos: {
|
|
5
4
|
x: number;
|
|
6
5
|
y: number;
|
|
7
6
|
}, catIdx: number, categories: string[], sc: BarScaleContext, seriesCount: number): number;
|
|
8
|
-
export declare function isOutsideBars(pos: {
|
|
9
|
-
x: number;
|
|
10
|
-
y: number;
|
|
11
|
-
}, catIdx: number, allData: (Datum | undefined)[][], sc: BarScaleContext, seriesCount: number): boolean;
|
|
12
7
|
//# sourceMappingURL=bar-hit-test.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bar-hit-test.d.ts","sourceRoot":"","sources":["../../../src/charts/bar/bar-hit-test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"bar-hit-test.d.ts","sourceRoot":"","sources":["../../../src/charts/bar/bar-hit-test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3D,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,eAAe,GAAG,MAAM,CASzF;AAED,wBAAgB,aAAa,CAC3B,GAAG,EAAE;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,EAC7B,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAAE,EACpB,EAAE,EAAE,eAAe,EACnB,WAAW,EAAE,MAAM,GAClB,MAAM,CA2BR"}
|
|
@@ -1,30 +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) {
|
|
11
|
-
if (r.horizontal) {
|
|
12
|
-
for (let n = 0; n < i; n++) if (r.valueScale.map(r.stackedTops[n]?.[t] ?? 0) >= e.x) return n;
|
|
13
|
-
return i - 1;
|
|
14
|
-
}
|
|
15
|
-
for (let n = 0; n < i; n++) if (r.valueScale.map(r.stackedTops[n]?.[t] ?? 0) <= e.y) return n;
|
|
16
|
-
return i - 1;
|
|
17
|
-
}
|
|
18
|
-
{
|
|
19
|
-
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);
|
|
20
|
-
return Math.max(0, Math.min(i - 1, c));
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function n(e, t, n, r, i) {
|
|
24
|
-
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);
|
|
25
|
-
return r.horizontal ? e.x > s : e.y < s;
|
|
26
|
-
}
|
|
27
|
-
//#endregion
|
|
28
|
-
export { e as findCatIdx, t as findSeriesIdx, n as isOutsideBars };
|
|
29
|
-
|
|
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))}}export{findCatIdx,findSeriesIdx};
|
|
30
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 {
|
|
1
|
+
{"version":3,"file":"bar-hit-test.js","names":[],"sources":["../../../src/charts/bar/bar-hit-test.ts"],"sourcesContent":["import 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"],"mappings":"AAEA,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"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../../svg/element.cjs"),t=require("../../animation/transition.cjs");var n=new WeakMap;function
|
|
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
|
|
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,EAAO,EAAA,iBAAiB,OAAQ,CAAE,MAA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M,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"}
|
|
@@ -3,7 +3,7 @@ export interface BarRenderOptions {
|
|
|
3
3
|
baselineYs?: number[];
|
|
4
4
|
borderRadius: number;
|
|
5
5
|
color: string;
|
|
6
|
-
/** Aborted when the owning chart is disposed
|
|
6
|
+
/** Aborted when the owning chart is disposed: stops in-flight transitions from rescheduling. */
|
|
7
7
|
disposalSignal?: AbortSignal;
|
|
8
8
|
horizontal?: boolean;
|
|
9
9
|
seriesCount: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bar-renderer.d.ts","sourceRoot":"","sources":["../../../src/charts/bar/bar-renderer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEtE,MAAM,WAAW,gBAAgB;IAC/B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,
|
|
1
|
+
{"version":3,"file":"bar-renderer.d.ts","sourceRoot":"","sources":["../../../src/charts/bar/bar-renderer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEtE,MAAM,WAAW,gBAAgB;IAC/B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,gGAAgG;IAChG,cAAc,CAAC,EAAE,WAAW,CAAC;IAC7B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC/B;AAID,wBAAgB,UAAU,CACxB,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,EAClE,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,EACrB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,gBAAgB,GACxB,IAAI,CAqHN"}
|
|
@@ -1,107 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { animate as n } from "../../animation/transition.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 n = 0; n < a.length; n++) {
|
|
12
|
-
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;
|
|
13
|
-
if (v || (v = e("rect", { class: "prism-bar" }), i.appendChild(v)), v.style.display = r.present ? "" : "none", p) {
|
|
14
|
-
let e = Math.max(0, Math.abs(g - _)), n = Math.min(_, g);
|
|
15
|
-
t(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 ? (t(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: n
|
|
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") ?? n),
|
|
44
|
-
to: n
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
el: v
|
|
48
|
-
}) : t(v, {
|
|
49
|
-
width: e,
|
|
50
|
-
x: n
|
|
51
|
-
});
|
|
52
|
-
} else {
|
|
53
|
-
let e = Math.max(0, Math.abs(g - _)), n = Math.min(_, g);
|
|
54
|
-
t(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 ? (t(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: n
|
|
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") ?? n),
|
|
83
|
-
to: n
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
el: v
|
|
87
|
-
}) : t(v, {
|
|
88
|
-
height: e,
|
|
89
|
-
y: n
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (l.transition) {
|
|
94
|
-
r.get(i)?.();
|
|
95
|
-
let e = [];
|
|
96
|
-
m.length > 0 && e.push(n(m, l.transition, void 0, l.disposalSignal)), h.length > 0 && e.push(n(h, {
|
|
97
|
-
...l.transition,
|
|
98
|
-
stagger: 0
|
|
99
|
-
}, void 0, l.disposalSignal)), r.set(i, () => {
|
|
100
|
-
for (let t of e) t();
|
|
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
|
|
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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,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
|
-
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
|
|
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=null,m=null,h=d.series;return a.createChartScaffold(u,d,u=>{let{groups:g,legend:_,tooltip:v}=u,y=u.dimensions,b=h.some(e=>e.yAxis===`right`),x=h.some(e=>e.yAxis!==`right`&&e.data.length>0);y.margin.right=d.margin?.right??(b?d.rightYAxis?.label?72:50:i.resolveMargin(d.margin).right);let S=i.chartArea(y.width,y.height,y.margin),C=h.map(e=>e.data),w=C.flat().map(e=>e.key),T=h.filter(e=>e.yAxis!==`right`).flatMap(e=>e.data.map(e=>e.value)),E=h.filter(e=>e.yAxis===`right`).flatMap(e=>e.data.map(e=>e.value));if(w.length===0){a.clearCartesianDom(g,_,v,f),p?.replaceChildren(),m?.replaceChildren();return}d.crosshair&&!f&&(f=o.createCrosshair(u.chartArea,d.crosshair));let D=r.buildXScale(w,S.width),O=r.buildYScale(T,S.height),k=r.buildYScale(E,S.height);if(d.yAxis?.grid&&(!b||x)?n.renderGrid(g.grid,O,d.yAxis.grid,S.width,`horizontal`,t.resolveTickCount(d.yAxis,S.height,`left`)):g.grid.replaceChildren(),d.xAxis?.grid&&n.renderGrid(g.grid,D,d.xAxis.grid,S.height,`vertical`,t.resolveTickCount(d.xAxis,S.width,`bottom`)),d.xAxis&&(t.positionAxis(g.xAxis,d.xAxis.position??`bottom`,S.width,S.height),t.renderAxis(g.xAxis,D,d.xAxis,S.width,`bottom`)),d.yAxis&&(!b||x)){let e={...d.yAxis,position:b?`left`:d.yAxis.position??`left`};t.positionAxis(g.yAxis,e.position,S.width,S.height),t.renderAxis(g.yAxis,O,e,S.height,`left`)}else g.yAxis.replaceChildren();if(b){m||(m=e.createSvgElement(`g`,{class:`prism-y-axis-right`}),u.chartArea.appendChild(m));let n={...d.rightYAxis,position:`right`};t.positionAxis(m,`right`,S.width,S.height),t.renderAxis(m,k,n,S.height,`right`)}else m?.replaceChildren();for(;g.series.children.length>h.length;)g.series.removeChild(g.series.lastChild);let A=[];for(let t=0;t<h.length;t++){let n=h[t],r=g.series.children[t];r||(r=e.createSvgElement(`g`,{class:`prism-line-series`}),g.series.appendChild(r));let i=l.computePoints(C[t],D,n.yAxis===`right`?k:O);A.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,transition:d.transition})}return _?.update(h.map((e,t)=>({color:c.seriesColor(t,e.color),name:e.name}))),v?.hide(),p=s.ensureMarkerGroup(u.chartArea,p),s.createSeriesInteraction({announcer:u.announcer,colors:()=>h.map((e,t)=>c.seriesColor(t,e.color)),crosshair:f,dims:()=>u.dimensions,getData:()=>C,getPoints:()=>A,getSeriesList:()=>h,markers:p,onClick:d.onClick,onHover:d.onHover,seriesGroup:g.series,svg:u.svg,tooltip:v})},e=>{h=e})}exports.createLineChart=createLineChart;
|
|
2
2
|
//# sourceMappingURL=line-chart.cjs.map
|