@vielzeug/prism 2.0.0 → 2.1.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 +3 -2
- package/dist/animation/motion.cjs +2 -0
- package/dist/animation/motion.cjs.map +1 -0
- package/dist/animation/motion.d.ts +3 -0
- package/dist/animation/motion.d.ts.map +1 -0
- package/dist/animation/motion.js +13 -0
- package/dist/animation/motion.js.map +1 -0
- package/dist/animation/transition.cjs +1 -1
- package/dist/animation/transition.cjs.map +1 -1
- package/dist/animation/transition.d.ts.map +1 -1
- package/dist/animation/transition.js +19 -18
- package/dist/animation/transition.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.map +1 -1
- package/dist/charts/area/area-renderer.js +42 -41
- 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 +104 -87
- package/dist/charts/bar/bar-chart.js.map +1 -1
- package/dist/charts/bar/bar-hit-test.cjs.map +1 -1
- package/dist/charts/bar/bar-hit-test.d.ts +1 -1
- package/dist/charts/bar/bar-hit-test.d.ts.map +1 -1
- 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 -0
- package/dist/charts/bar/bar-renderer.d.ts.map +1 -1
- package/dist/charts/bar/bar-renderer.js +1 -1
- package/dist/charts/bar/bar-renderer.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.map +1 -1
- package/dist/charts/line/line-renderer.js +58 -57
- 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 +72 -70
- package/dist/charts/pie/pie-chart.js.map +1 -1
- package/dist/charts/sparkline/sparkline.cjs +1 -1
- package/dist/charts/sparkline/sparkline.cjs.map +1 -1
- package/dist/charts/sparkline/sparkline.d.ts.map +1 -1
- package/dist/charts/sparkline/sparkline.js +63 -62
- package/dist/charts/sparkline/sparkline.js.map +1 -1
- package/dist/core/cartesian-model.cjs +2 -0
- package/dist/core/cartesian-model.cjs.map +1 -0
- package/dist/core/cartesian-model.d.ts +14 -0
- package/dist/core/cartesian-model.d.ts.map +1 -0
- package/dist/core/cartesian-model.js +31 -0
- package/dist/core/cartesian-model.js.map +1 -0
- 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 -1
- package/dist/core/chart-base.d.ts.map +1 -1
- package/dist/core/chart-base.js +28 -25
- 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 +1 -0
- package/dist/core/chart-scaffold.d.ts.map +1 -1
- package/dist/core/chart-scaffold.js +2 -1
- package/dist/core/chart-scaffold.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.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.map +1 -1
- package/dist/interaction/series-interaction.js +73 -34
- 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 +28 -15
- 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/theme/prism.css +1 -0
- package/dist/types.d.ts +13 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +10 -6
- package/dist/interaction/hit-test.cjs +0 -2
- package/dist/interaction/hit-test.cjs.map +0 -1
- package/dist/interaction/hit-test.js +0 -14
- package/dist/interaction/hit-test.js.map +0 -1
|
@@ -5,140 +5,157 @@ import { renderGrid as r } from "../../axes/grid.js";
|
|
|
5
5
|
import { linearScale as i } from "../../scales/linear.js";
|
|
6
6
|
import { chartArea as a } from "../../core/layout.js";
|
|
7
7
|
import { clearCartesianDom as o, createChartScaffold as s } from "../../core/chart-scaffold.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
8
|
+
import { normalizeCartesianSeries as c } from "../../core/cartesian-model.js";
|
|
9
|
+
import { getMousePosition as l } from "../../interaction/events.js";
|
|
10
|
+
import { seriesColor as u } from "../../theme/index.js";
|
|
11
|
+
import { bandScale as d } from "../../scales/band.js";
|
|
12
|
+
import { findCatIdx as f, findSeriesIdx as p, isOutsideBars as m } from "./bar-hit-test.js";
|
|
13
|
+
import { renderBars as h } from "./bar-renderer.js";
|
|
14
|
+
import { isReactive as g } from "@vielzeug/ripple";
|
|
14
15
|
//#region src/charts/bar/bar-chart.ts
|
|
15
|
-
function
|
|
16
|
+
function _(e) {
|
|
16
17
|
return {
|
|
17
18
|
horizontal: e === "grouped-horizontal" || e === "stacked-horizontal",
|
|
18
19
|
stacked: e === "stacked" || e === "stacked-horizontal"
|
|
19
20
|
};
|
|
20
21
|
}
|
|
21
|
-
function
|
|
22
|
-
return s(
|
|
23
|
-
let { groups:
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
function v(v, y) {
|
|
23
|
+
return s(v, y, (s) => {
|
|
24
|
+
let { groups: v, legend: b, tooltip: x } = s, S = s.dimensions.value, C = a(S.width, S.height, S.margin), w = g(y.series) ? y.series.value : y.series, T = w.map((e) => g(e.data) ? e.data.value : e.data), E = c(w, T), D = E.domain, O = E.series.map(({ byKey: e }) => D.map((t) => e.get(t))), k = (e) => {
|
|
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
|
+
o(v, b, x);
|
|
26
35
|
return;
|
|
27
36
|
}
|
|
28
|
-
let { horizontal:
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
let e =
|
|
32
|
-
|
|
33
|
-
return t + (r ? Math.max(0, r.value) : 0);
|
|
34
|
-
}, 0));
|
|
35
|
-
O = Math.max(...e), k = 0;
|
|
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;
|
|
36
42
|
} else {
|
|
37
|
-
let e =
|
|
38
|
-
|
|
43
|
+
let e = O.flatMap((e) => e.flatMap((e) => e ? [e.value] : []));
|
|
44
|
+
M = Math.max(...e), N = Math.min(0, ...e);
|
|
39
45
|
}
|
|
40
|
-
let
|
|
41
|
-
domain:
|
|
42
|
-
range: [0,
|
|
46
|
+
let P = d(A ? {
|
|
47
|
+
domain: D,
|
|
48
|
+
range: [0, C.height]
|
|
43
49
|
} : {
|
|
44
|
-
domain:
|
|
45
|
-
range: [0,
|
|
46
|
-
}),
|
|
47
|
-
domain: [
|
|
48
|
-
range: [0,
|
|
50
|
+
domain: D,
|
|
51
|
+
range: [0, C.width]
|
|
52
|
+
}), F = i(A ? {
|
|
53
|
+
domain: [N, M],
|
|
54
|
+
range: [0, C.width]
|
|
49
55
|
} : {
|
|
50
|
-
domain: [
|
|
51
|
-
range: [
|
|
52
|
-
}),
|
|
53
|
-
for (let e of
|
|
54
|
-
let
|
|
55
|
-
bandCenter: (e) =>
|
|
56
|
-
bandwidth:
|
|
57
|
-
baselinePx:
|
|
58
|
-
horizontal:
|
|
59
|
-
stacked:
|
|
60
|
-
stackedTops:
|
|
61
|
-
valueScale:
|
|
56
|
+
domain: [N, M],
|
|
57
|
+
range: [C.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
|
|
62
68
|
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
e
|
|
69
|
+
if (A) {
|
|
70
|
+
y.xAxis?.grid && r(v.grid, F, y.xAxis.grid, C.height, "vertical", n(y.xAxis, C.width, "bottom"));
|
|
71
|
+
let e = k(y.yAxis);
|
|
72
|
+
e && t(v.yAxis, P, e, C.height, "left"), y.xAxis && (v.xAxis.setAttribute("transform", `translate(0,${C.height})`), t(v.xAxis, F, y.xAxis, C.width, "bottom"));
|
|
73
|
+
} else {
|
|
74
|
+
y.yAxis?.grid && r(v.grid, F, y.yAxis.grid, C.width, "horizontal", n(y.yAxis, C.height, "left"));
|
|
75
|
+
let e = k(y.xAxis);
|
|
76
|
+
e && (v.xAxis.setAttribute("transform", `translate(0,${C.height})`), t(v.xAxis, P, e, C.width, "bottom")), y.yAxis && t(v.yAxis, F, y.yAxis, C.height, "left");
|
|
77
|
+
}
|
|
78
|
+
for (; v.series.children.length > w.length;) {
|
|
79
|
+
let e = v.series.lastElementChild;
|
|
80
|
+
e && v.series.removeChild(e);
|
|
66
81
|
}
|
|
67
|
-
for (let t = 0; t <
|
|
68
|
-
let n =
|
|
69
|
-
r || (r = e("g", { class: "prism-bar-series" }),
|
|
70
|
-
let i =
|
|
71
|
-
let
|
|
72
|
-
if (
|
|
73
|
-
let
|
|
74
|
-
return
|
|
75
|
-
base:
|
|
76
|
-
key:
|
|
77
|
-
|
|
82
|
+
for (let t = 0; t < w.length; t++) {
|
|
83
|
+
let n = w[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
|
|
78
94
|
};
|
|
79
95
|
}
|
|
80
96
|
return {
|
|
81
97
|
base: 0,
|
|
82
|
-
key:
|
|
83
|
-
|
|
98
|
+
key: e,
|
|
99
|
+
present: r !== void 0,
|
|
100
|
+
y: r?.value ?? 0
|
|
84
101
|
};
|
|
85
102
|
});
|
|
86
|
-
|
|
87
|
-
let a =
|
|
88
|
-
|
|
103
|
+
I[t] = i.map((e) => e.y);
|
|
104
|
+
let a = j ? i.map((e) => F.map(e.base)) : void 0;
|
|
105
|
+
h(r, i, P, F, R.baselinePx, {
|
|
89
106
|
baselineYs: a,
|
|
90
107
|
borderRadius: n.borderRadius ?? 0,
|
|
91
|
-
color:
|
|
108
|
+
color: u(t, n.color),
|
|
92
109
|
disposalSignal: s.disposalSignal,
|
|
93
|
-
horizontal:
|
|
94
|
-
seriesCount:
|
|
110
|
+
horizontal: A,
|
|
111
|
+
seriesCount: w.length,
|
|
95
112
|
seriesIndex: t,
|
|
96
|
-
stacked:
|
|
97
|
-
transition:
|
|
113
|
+
stacked: j,
|
|
114
|
+
transition: y.transition
|
|
98
115
|
});
|
|
99
116
|
}
|
|
100
|
-
return
|
|
101
|
-
color:
|
|
117
|
+
return b?.update(w.map((e, t) => ({
|
|
118
|
+
color: u(t, e.color),
|
|
102
119
|
name: e.name
|
|
103
|
-
}))),
|
|
120
|
+
}))), x?.hide(), {
|
|
104
121
|
onClick: (e) => {
|
|
105
|
-
if (!
|
|
106
|
-
let t = s.dimensions.value, n =
|
|
122
|
+
if (!y.onClick) return;
|
|
123
|
+
let t = s.dimensions.value, n = l(s.svg, e, t.margin.left, t.margin.top), r = a(t.width, t.height, t.margin);
|
|
107
124
|
if (n.x < 0 || n.x > r.width || n.y < 0 || n.y > r.height) return;
|
|
108
|
-
let i =
|
|
125
|
+
let i = A ? n.y : n.x, o = f(i, D, R);
|
|
109
126
|
if (o === -1) return;
|
|
110
|
-
let
|
|
111
|
-
u &&
|
|
127
|
+
let c = p(n, o, D, R, w.length), u = O[c]?.[o];
|
|
128
|
+
u && y.onClick({
|
|
112
129
|
datum: u,
|
|
113
130
|
originalEvent: e,
|
|
114
|
-
series:
|
|
131
|
+
series: w[c]
|
|
115
132
|
});
|
|
116
133
|
},
|
|
117
134
|
onMouseLeave: () => {
|
|
118
|
-
|
|
135
|
+
x?.hide(), y.onHover?.(null);
|
|
119
136
|
},
|
|
120
137
|
onMouseMove: (e) => {
|
|
121
|
-
let t = s.dimensions.value, n =
|
|
138
|
+
let t = s.dimensions.value, n = l(s.svg, e, t.margin.left, t.margin.top), r = a(t.width, t.height, t.margin);
|
|
122
139
|
if (n.x < 0 || n.x > r.width || n.y < 0 || n.y > r.height) {
|
|
123
|
-
|
|
140
|
+
x?.hide();
|
|
124
141
|
return;
|
|
125
142
|
}
|
|
126
|
-
let i =
|
|
143
|
+
let i = A ? n.y : n.x, o = f(i, D, R);
|
|
127
144
|
if (o === -1) {
|
|
128
|
-
|
|
145
|
+
x?.hide();
|
|
129
146
|
return;
|
|
130
147
|
}
|
|
131
|
-
if (
|
|
132
|
-
|
|
148
|
+
if (m(n, o, O, R, w.length)) {
|
|
149
|
+
x?.hide();
|
|
133
150
|
return;
|
|
134
151
|
}
|
|
135
|
-
let
|
|
152
|
+
let c = p(n, o, D, R, w.length), u = O[c]?.[o];
|
|
136
153
|
if (u) {
|
|
137
|
-
let n =
|
|
138
|
-
|
|
154
|
+
let n = R.bandCenter(D[o]), r = j ? I[c]?.[o] ?? u.value : u.value, i = F.map(r), a = A ? i + t.margin.left : n + t.margin.left, s = A ? n + t.margin.top : i + t.margin.top;
|
|
155
|
+
x?.show(a, s, u, w[c]), y.onHover?.({
|
|
139
156
|
datum: u,
|
|
140
157
|
originalEvent: e,
|
|
141
|
-
series:
|
|
158
|
+
series: w[c]
|
|
142
159
|
});
|
|
143
160
|
}
|
|
144
161
|
}
|
|
@@ -146,6 +163,6 @@ function _(_, v) {
|
|
|
146
163
|
});
|
|
147
164
|
}
|
|
148
165
|
//#endregion
|
|
149
|
-
export {
|
|
166
|
+
export { v as createBarChart };
|
|
150
167
|
|
|
151
168
|
//# sourceMappingURL=bar-chart.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bar-chart.js","names":[],"sources":["../../../src/charts/bar/bar-chart.ts"],"sourcesContent":["import { isReactive } from '@vielzeug/ripple';\n\nimport type { BarChartConfig, BarVariant, ChartHandle } from '../../types';\nimport type { BarScaleContext } from './bar-scale-context';\n\nimport { warn } from '../../_dev';\nimport { renderAxis, resolveTickCount } from '../../axes/axis';\nimport { renderGrid } from '../../axes/grid';\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 { findCatIdx, findSeriesIdx, isOutsideBars } from './bar-hit-test';\nimport { renderBars } from './bar-renderer';\n\nfunction variantFlags(variant: BarVariant): { horizontal: boolean; stacked: boolean } {\n return {\n horizontal: variant === 'grouped-horizontal' || variant === 'stacked-horizontal',\n stacked: variant === 'stacked' || variant === 'stacked-horizontal',\n };\n}\n\n// ─── Chart ────────────────────────────────────────────────────────────────────\n\nexport function createBarChart(container: HTMLElement, config: BarChartConfig): ChartHandle {\n return createChartScaffold(container, config, (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions.value;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const seriesList = isReactive(config.series) ? config.series.value : config.series;\n const allData = seriesList.map((s) => (isReactive(s.data) ? s.data.value : s.data));\n const categories = [...new Set(allData.flat().map((d) => String(d.key)))];\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((sd) => sd.some((d) => d.value < 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((cat) =>\n allData.reduce((sum, sd) => {\n const pt = sd.find((d) => String(d.key) === cat);\n\n return sum + (pt ? Math.max(0, pt.value) : 0);\n }, 0),\n );\n\n vMax = Math.max(...sums);\n vMin = 0;\n } else {\n const allY = allData.flat().map((d) => d.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 if (config.yAxis) renderAxis(groups.yAxis, catScale, config.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 if (config.xAxis) {\n groups.xAxis.setAttribute('transform', `translate(0,${area.height})`);\n renderAxis(groups.xAxis, catScale, config.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 = allData[i].map((d) => {\n const key = String(d.key);\n\n if (stacked) {\n const base = stackTops[key] ?? 0;\n const top = base + Math.max(0, d.value);\n\n stackTops[key] = top;\n\n return { base, key, y: top };\n }\n\n return { base: 0, key, y: d.value };\n });\n\n stackedTops[i] = barData.map((d) => d.y);\n\n const baselineYs = stacked ? barData.map((d) => valScale.map(d.base)) : undefined;\n\n renderBars(group, barData, catScale, valScale, sc.baselinePx, {\n baselineYs,\n borderRadius: series.borderRadius ?? 0,\n color: seriesColor(i, series.color),\n disposalSignal: ctx.disposalSignal,\n horizontal,\n seriesCount: seriesList.length,\n seriesIndex: i,\n stacked,\n transition: config.transition,\n });\n }\n\n legend?.update(seriesList.map((s, i) => ({ color: seriesColor(i, s.color), name: s.name })));\n tooltip?.hide();\n\n // ─── Event handlers (close over render-derived state) ─────────────────────\n\n const onMouseMove = (event: MouseEvent) => {\n const d = ctx.dimensions.value;\n const pos = getMousePosition(ctx.svg, event, d.margin.left, d.margin.top);\n const a = chartArea(d.width, d.height, d.margin);\n\n if (pos.x < 0 || pos.x > a.width || pos.y < 0 || pos.y > a.height) {\n tooltip?.hide();\n\n return;\n }\n\n const posBand = horizontal ? pos.y : pos.x;\n const catIdx = findCatIdx(posBand, categories, sc);\n\n if (catIdx === -1) {\n tooltip?.hide();\n\n return;\n }\n\n if (isOutsideBars(pos, catIdx, allData, sc, seriesList.length)) {\n tooltip?.hide();\n\n return;\n }\n\n const seriesIdx = findSeriesIdx(pos, catIdx, categories, sc, seriesList.length);\n const point = allData[seriesIdx]?.[catIdx];\n\n if (point) {\n const bandCenterPx = sc.bandCenter(categories[catIdx]);\n const stackedTop = stacked ? (stackedTops[seriesIdx]?.[catIdx] ?? point.value) : point.value;\n const valuePx = valScale.map(stackedTop);\n\n const tooltipX = horizontal ? valuePx + d.margin.left : bandCenterPx + d.margin.left;\n const tooltipY = horizontal ? bandCenterPx + d.margin.top : valuePx + d.margin.top;\n\n tooltip?.show(tooltipX, tooltipY, point, seriesList[seriesIdx]);\n config.onHover?.({ datum: point, originalEvent: event, series: seriesList[seriesIdx] });\n }\n };\n\n const onMouseLeave = () => {\n tooltip?.hide();\n config.onHover?.(null);\n };\n\n const onClick = (event: MouseEvent) => {\n if (!config.onClick) return;\n\n const d = ctx.dimensions.value;\n const pos = getMousePosition(ctx.svg, event, d.margin.left, d.margin.top);\n const a = chartArea(d.width, d.height, d.margin);\n\n if (pos.x < 0 || pos.x > a.width || pos.y < 0 || pos.y > a.height) return;\n\n const posBand = horizontal ? pos.y : pos.x;\n const catIdx = findCatIdx(posBand, categories, sc);\n\n if (catIdx === -1) return;\n\n const seriesIdx = findSeriesIdx(pos, catIdx, categories, sc, seriesList.length);\n const point = allData[seriesIdx]?.[catIdx];\n\n if (point) {\n config.onClick({ datum: point, originalEvent: event, series: seriesList[seriesIdx] });\n }\n };\n\n return { onClick, onMouseLeave, onMouseMove };\n });\n}\n"],"mappings":";;;;;;;;;;;;;;AAkBA,SAAS,EAAa,GAAgE;CACpF,OAAO;EACL,YAAY,MAAY,wBAAwB,MAAY;EAC5D,SAAS,MAAY,aAAa,MAAY;CAChD;AACF;AAIA,SAAgB,EAAe,GAAwB,GAAqC;CAC1F,OAAO,EAAoB,GAAW,IAAS,MAAQ;EACrD,IAAM,EAAE,WAAQ,WAAQ,eAAY,GAC9B,IAAO,EAAI,WAAW,OACtB,IAAO,EAAU,EAAK,OAAO,EAAK,QAAQ,EAAK,MAAM,GACrD,IAAa,EAAW,EAAO,MAAM,IAAI,EAAO,OAAO,QAAQ,EAAO,QACtE,IAAU,EAAW,KAAK,MAAO,EAAW,EAAE,IAAI,IAAI,EAAE,KAAK,QAAQ,EAAE,IAAK,GAC5E,IAAa,CAAC,GAAG,IAAI,IAAI,EAAQ,KAAK,CAAC,CAAC,KAAK,MAAM,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;EAExE,IAAI,EAAW,WAAW,GAAG;GAE3B,EAAkB,GAAQ,GAAQ,CAAO;GAEzC;EACF;EAEA,IAAM,EAAE,eAAY,eAAY,EAAa,EAAO,WAAW,SAAS,GAGpE,GACA;EAEJ,IAAI,GAAS;GACX,AAAI,EAAQ,MAAM,MAAO,EAAG,MAAM,MAAM,EAAE,QAAQ,CAAC,CAAC;GAMpD,IAAM,IAAO,EAAW,KAAK,MAC3B,EAAQ,QAAQ,GA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I,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,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"bar-chart.js","names":[],"sources":["../../../src/charts/bar/bar-chart.ts"],"sourcesContent":["import { isReactive } from '@vielzeug/ripple';\n\nimport type { BarChartConfig, BarVariant, ChartHandle } from '../../types';\nimport type { BarScaleContext } from './bar-scale-context';\n\nimport { warn } from '../../_dev';\nimport { renderAxis, resolveTickCount } from '../../axes/axis';\nimport { renderGrid } from '../../axes/grid';\nimport { normalizeCartesianSeries } from '../../core/cartesian-model';\nimport { clearCartesianDom, createChartScaffold } from '../../core/chart-scaffold';\nimport { chartArea } from '../../core/layout';\nimport { getMousePosition } from '../../interaction/events';\nimport { bandScale } from '../../scales/band';\nimport { linearScale } from '../../scales/linear';\nimport { createSvgElement } from '../../svg/element';\nimport { seriesColor } from '../../theme';\nimport { findCatIdx, findSeriesIdx, isOutsideBars } from './bar-hit-test';\nimport { renderBars } from './bar-renderer';\n\nfunction variantFlags(variant: BarVariant): { horizontal: boolean; stacked: boolean } {\n return {\n horizontal: variant === 'grouped-horizontal' || variant === 'stacked-horizontal',\n stacked: variant === 'stacked' || variant === 'stacked-horizontal',\n };\n}\n\n// ─── Chart ────────────────────────────────────────────────────────────────────\n\nexport function createBarChart(container: HTMLElement, config: BarChartConfig): ChartHandle {\n return createChartScaffold(container, config, (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions.value;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const seriesList = isReactive(config.series) ? config.series.value : config.series;\n const sourceData = seriesList.map((series) => (isReactive(series.data) ? series.data.value : series.data));\n const model = normalizeCartesianSeries(seriesList, sourceData);\n const categories = model.domain;\n const allData = model.series.map(({ byKey }) => categories.map((key) => byKey.get(key)));\n const categoryAxis = (axis: BarChartConfig['xAxis'] | BarChartConfig['yAxis']) => {\n if (!axis) return undefined;\n\n return {\n ...axis,\n tickFormat: (value: Date | number | string) => {\n const key = String(value);\n const label = model.labels.get(key) ?? value;\n\n return axis.tickFormat ? axis.tickFormat(label) : String(label);\n },\n };\n };\n\n if (categories.length === 0) {\n warn('createBarChart: no data');\n clearCartesianDom(groups, legend, tooltip);\n\n return;\n }\n\n const { horizontal, stacked } = variantFlags(config.variant ?? 'grouped');\n\n // Value domain\n let vMax: number;\n let vMin: number;\n\n if (stacked) {\n if (allData.some((seriesData) => seriesData.some((datum) => (datum?.value ?? 0) < 0))) {\n warn(\n 'createBarChart: negative values in a stacked/stacked-horizontal series are clamped to 0 — stacking mixed-sign data is not supported.',\n );\n }\n\n const sums = categories.map((_, categoryIndex) =>\n allData.reduce((sum, seriesData) => sum + Math.max(0, seriesData[categoryIndex]?.value ?? 0), 0),\n );\n\n vMax = Math.max(...sums);\n vMin = 0;\n } else {\n const allY = allData.flatMap((seriesData) => seriesData.flatMap((datum) => (datum ? [datum.value] : [])));\n\n vMax = Math.max(...allY);\n vMin = Math.min(0, ...allY);\n }\n\n // Build uniform scale context\n const catScale = horizontal\n ? bandScale({ domain: categories, range: [0, area.height] })\n : bandScale({ domain: categories, range: [0, area.width] });\n\n const valScale = horizontal\n ? linearScale({ domain: [vMin, vMax], range: [0, area.width] })\n : linearScale({ domain: [vMin, vMax], range: [area.height, 0] });\n\n const stackedTops: number[][] = [];\n const stackTops = Object.create(null) as Record<string, number>;\n\n for (const cat of categories) stackTops[cat] = 0;\n\n const sc: BarScaleContext = {\n bandCenter: (cat) => catScale.map(cat) + catScale.bandwidth() / 2,\n bandwidth: catScale.bandwidth(),\n baselinePx: valScale.map(0),\n horizontal,\n stacked,\n stackedTops,\n valueScale: valScale,\n };\n\n // Axes & grid\n if (horizontal) {\n if (config.xAxis?.grid) {\n renderGrid(\n groups.grid,\n valScale,\n config.xAxis.grid,\n area.height,\n 'vertical',\n resolveTickCount(config.xAxis, area.width, 'bottom'),\n );\n }\n\n const yAxis = categoryAxis(config.yAxis);\n\n if (yAxis) renderAxis(groups.yAxis, catScale, yAxis, area.height, 'left');\n\n if (config.xAxis) {\n groups.xAxis.setAttribute('transform', `translate(0,${area.height})`);\n renderAxis(groups.xAxis, valScale, config.xAxis, area.width, 'bottom');\n }\n } else {\n if (config.yAxis?.grid) {\n renderGrid(\n groups.grid,\n valScale,\n config.yAxis.grid,\n area.width,\n 'horizontal',\n resolveTickCount(config.yAxis, area.height, 'left'),\n );\n }\n\n const xAxis = categoryAxis(config.xAxis);\n\n if (xAxis) {\n groups.xAxis.setAttribute('transform', `translate(0,${area.height})`);\n renderAxis(groups.xAxis, catScale, xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) renderAxis(groups.yAxis, valScale, config.yAxis, area.height, 'left');\n }\n\n // Series groups\n while (groups.series.children.length > seriesList.length) {\n const last = groups.series.lastElementChild;\n\n if (last) groups.series.removeChild(last);\n }\n\n for (let i = 0; i < seriesList.length; i++) {\n const series = seriesList[i];\n let group = groups.series.children[i] as SVGGElement | undefined;\n\n if (!group) {\n group = createSvgElement('g', { class: 'prism-bar-series' });\n groups.series.appendChild(group);\n }\n\n const barData = categories.map((key, categoryIndex) => {\n const datum = allData[i]?.[categoryIndex];\n\n if (stacked) {\n const base = stackTops[key] ?? 0;\n const top = base + Math.max(0, datum?.value ?? 0);\n\n stackTops[key] = top;\n\n return { base, key, present: datum !== undefined, y: top };\n }\n\n return { base: 0, key, present: datum !== undefined, y: datum?.value ?? 0 };\n });\n\n stackedTops[i] = barData.map((d) => d.y);\n\n const baselineYs = stacked ? barData.map((d) => valScale.map(d.base)) : undefined;\n\n renderBars(group, barData, catScale, valScale, sc.baselinePx, {\n baselineYs,\n borderRadius: series.borderRadius ?? 0,\n color: seriesColor(i, series.color),\n disposalSignal: ctx.disposalSignal,\n horizontal,\n seriesCount: seriesList.length,\n seriesIndex: i,\n stacked,\n transition: config.transition,\n });\n }\n\n legend?.update(seriesList.map((s, i) => ({ color: seriesColor(i, s.color), name: s.name })));\n tooltip?.hide();\n\n // ─── Event handlers (close over render-derived state) ─────────────────────\n\n const onMouseMove = (event: MouseEvent) => {\n const d = ctx.dimensions.value;\n const pos = getMousePosition(ctx.svg, event, d.margin.left, d.margin.top);\n const a = chartArea(d.width, d.height, d.margin);\n\n if (pos.x < 0 || pos.x > a.width || pos.y < 0 || pos.y > a.height) {\n tooltip?.hide();\n\n return;\n }\n\n const posBand = horizontal ? pos.y : pos.x;\n const catIdx = findCatIdx(posBand, categories, sc);\n\n if (catIdx === -1) {\n tooltip?.hide();\n\n return;\n }\n\n if (isOutsideBars(pos, catIdx, allData, sc, seriesList.length)) {\n tooltip?.hide();\n\n return;\n }\n\n const seriesIdx = findSeriesIdx(pos, catIdx, categories, sc, seriesList.length);\n const point = allData[seriesIdx]?.[catIdx];\n\n if (point) {\n const bandCenterPx = sc.bandCenter(categories[catIdx]);\n const stackedTop = stacked ? (stackedTops[seriesIdx]?.[catIdx] ?? point.value) : point.value;\n const valuePx = valScale.map(stackedTop);\n\n const tooltipX = horizontal ? valuePx + d.margin.left : bandCenterPx + d.margin.left;\n const tooltipY = horizontal ? bandCenterPx + d.margin.top : valuePx + d.margin.top;\n\n tooltip?.show(tooltipX, tooltipY, point, seriesList[seriesIdx]);\n config.onHover?.({ datum: point, originalEvent: event, series: seriesList[seriesIdx] });\n }\n };\n\n const onMouseLeave = () => {\n tooltip?.hide();\n config.onHover?.(null);\n };\n\n const onClick = (event: MouseEvent) => {\n if (!config.onClick) return;\n\n const d = ctx.dimensions.value;\n const pos = getMousePosition(ctx.svg, event, d.margin.left, d.margin.top);\n const a = chartArea(d.width, d.height, d.margin);\n\n if (pos.x < 0 || pos.x > a.width || pos.y < 0 || pos.y > a.height) return;\n\n const posBand = horizontal ? pos.y : pos.x;\n const catIdx = findCatIdx(posBand, categories, sc);\n\n if (catIdx === -1) return;\n\n const seriesIdx = findSeriesIdx(pos, catIdx, categories, sc, seriesList.length);\n const point = allData[seriesIdx]?.[catIdx];\n\n if (point) {\n config.onClick({ datum: point, originalEvent: event, series: seriesList[seriesIdx] });\n }\n };\n\n return { onClick, onMouseLeave, onMouseMove };\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,SAAS,EAAa,GAAgE;CACpF,OAAO;EACL,YAAY,MAAY,wBAAwB,MAAY;EAC5D,SAAS,MAAY,aAAa,MAAY;CAChD;AACF;AAIA,SAAgB,EAAe,GAAwB,GAAqC;CAC1F,OAAO,EAAoB,GAAW,IAAS,MAAQ;EACrD,IAAM,EAAE,WAAQ,WAAQ,eAAY,GAC9B,IAAO,EAAI,WAAW,OACtB,IAAO,EAAU,EAAK,OAAO,EAAK,QAAQ,EAAK,MAAM,GACrD,IAAa,EAAW,EAAO,MAAM,IAAI,EAAO,OAAO,QAAQ,EAAO,QACtE,IAAa,EAAW,KAAK,MAAY,EAAW,EAAO,IAA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,IAAM,IAAe,EAAG,WAAW,EAAW,EAAO,GAC/C,IAAa,IAAW,EAAY,EAAU,GAAG,MAAW,EAAM,QAAS,EAAM,OACjF,IAAU,EAAS,IAAI,CAAU,GAEjC,IAAW,IAAa,IAAU,EAAE,OAAO,OAAO,IAAe,EAAE,OAAO,MAC1E,IAAW,IAAa,IAAe,EAAE,OAAO,MAAM,IAAU,EAAE,OAAO;KAG/E,AADA,GAAS,KAAK,GAAU,GAAU,GAAO,EAAW,EAAU,GAC9D,EAAO,UAAU;MAAE,OAAO;MAAO,eAAe;MAAO,QAAQ,EAAW;KAAW,CAAC;IACxF;GACF;EA6B4C;CAC9C,CAAC;AACH"}
|
|
@@ -1 +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[][],\n sc: BarScaleContext,\n seriesCount: number,\n): boolean {\n const lastSi = seriesCount - 1;\n const maxVal = sc.stacked\n ? (sc.stackedTops[lastSi]?.[catIdx] ?? 0)\n : Math.max(...Array.from({ length: seriesCount }, (_, si) => allData[si]?.[catIdx]?.value ?? 0));\n const maxPx = sc.valueScale.map(maxVal);\n\n return sc.horizontal ? pos.x > maxPx : pos.y < maxPx;\n}\n"],"mappings":"AAGA,SAAgB,EAAW,EAAa,EAAsB,EAA6B,CACzF,IAAK,IAAI,EAAI,EAAG,EAAI,EAAW,OAAQ,IAAK,CAE1C,IAAM,EADS,EAAG,WAAW,EAAW,EAC1B,EAAS,EAAG,UAAY,EAEtC,GAAI,GAAO,GAAS,EAAM,EAAQ,EAAG,UAAW,OAAO,CACzD,CAEA,MAAO,EACT,CAEA,SAAgB,EACd,EACA,EACA,EACA,EACA,EACQ,CACR,GAAI,EAAG,QACL,GAAI,EAAG,WAAY,CACjB,IAAK,IAAI,EAAK,EAAG,EAAK,EAAa,IAGjC,GAFe,EAAG,WAAW,IAAI,EAAG,YAAY,EAAG,GAAG,IAAW,CAE7D,GAAU,EAAI,EAAG,OAAO,EAG9B,OAAO,EAAc,CACvB,KAAO,CACL,IAAK,IAAI,EAAK,EAAG,EAAK,EAAa,IAGjC,GAFa,EAAG,WAAW,IAAI,EAAG,YAAY,EAAG,GAAG,IAAW,CAE3D,GAAQ,EAAI,EAAG,OAAO,EAG5B,OAAO,EAAc,CACvB,CACK,CACL,IAAM,EAAU,EAAG,UAAY,EACzB,EAAY,EAAG,WAAW,EAAW,EAAO,EAAI,EAAG,UAAY,EAC/D,EAAS,EAAG,WAAa,EAAI,EAAI,EAAY,EAAI,EAAI,EACrD,EAAS,KAAK,MAAM,EAAS,CAAO,EAE1C,OAAO,KAAK,IAAI,EAAG,KAAK,IAAI,EAAc,EAAG,CAAM,CAAC,CACtD,CACF,CAEA,SAAgB,EACd,EACA,EACA,EACA,EACA,EACS,CACT,IAAM,EAAS,EAAc,EACvB,EAAS,EAAG,QACb,EAAG,YAAY,EAAO,GAAG,IAAW,EACrC,KAAK,IAAI,GAAG,MAAM,KAAK,CAAE,OAAQ,CAAY,GAAI,EAAG,IAAO,EAAQ,EAAG,GAAG,EAAO,EAAE,OAAS,CAAC,CAAC,EAC3F,EAAQ,EAAG,WAAW,IAAI,CAAM,EAEtC,OAAO,EAAG,WAAa,EAAI,EAAI,EAAQ,EAAI,EAAI,CACjD"}
|
|
1
|
+
{"version":3,"file":"bar-hit-test.cjs","names":[],"sources":["../../../src/charts/bar/bar-hit-test.ts"],"sourcesContent":["import type { Datum } from '../../types';\nimport type { BarScaleContext } from './bar-scale-context';\n\nexport function findCatIdx(pos: number, categories: string[], sc: BarScaleContext): number {\n for (let i = 0; i < categories.length; i++) {\n const center = sc.bandCenter(categories[i]);\n const start = center - sc.bandwidth / 2;\n\n if (pos >= start && pos < start + sc.bandwidth) return i;\n }\n\n return -1;\n}\n\nexport function findSeriesIdx(\n pos: { x: number; y: number },\n catIdx: number,\n categories: string[],\n sc: BarScaleContext,\n seriesCount: number,\n): number {\n if (sc.stacked) {\n if (sc.horizontal) {\n for (let si = 0; si < seriesCount; si++) {\n const rightX = sc.valueScale.map(sc.stackedTops[si]?.[catIdx] ?? 0);\n\n if (rightX >= pos.x) return si;\n }\n\n return seriesCount - 1;\n } else {\n for (let si = 0; si < seriesCount; si++) {\n const topY = sc.valueScale.map(sc.stackedTops[si]?.[catIdx] ?? 0);\n\n if (topY <= pos.y) return si;\n }\n\n return seriesCount - 1;\n }\n } else {\n const subSize = sc.bandwidth / seriesCount;\n const bandStart = sc.bandCenter(categories[catIdx]) - sc.bandwidth / 2;\n const offset = sc.horizontal ? pos.y - bandStart : pos.x - bandStart;\n const subIdx = Math.floor(offset / subSize);\n\n return Math.max(0, Math.min(seriesCount - 1, subIdx));\n }\n}\n\nexport function isOutsideBars(\n pos: { x: number; y: number },\n catIdx: number,\n allData: (Datum | undefined)[][],\n sc: BarScaleContext,\n seriesCount: number,\n): boolean {\n const lastSi = seriesCount - 1;\n const maxVal = sc.stacked\n ? (sc.stackedTops[lastSi]?.[catIdx] ?? 0)\n : Math.max(...Array.from({ length: seriesCount }, (_, si) => allData[si]?.[catIdx]?.value ?? 0));\n const maxPx = sc.valueScale.map(maxVal);\n\n return sc.horizontal ? pos.x > maxPx : pos.y < maxPx;\n}\n"],"mappings":"AAGA,SAAgB,EAAW,EAAa,EAAsB,EAA6B,CACzF,IAAK,IAAI,EAAI,EAAG,EAAI,EAAW,OAAQ,IAAK,CAE1C,IAAM,EADS,EAAG,WAAW,EAAW,EAC1B,EAAS,EAAG,UAAY,EAEtC,GAAI,GAAO,GAAS,EAAM,EAAQ,EAAG,UAAW,OAAO,CACzD,CAEA,MAAO,EACT,CAEA,SAAgB,EACd,EACA,EACA,EACA,EACA,EACQ,CACR,GAAI,EAAG,QACL,GAAI,EAAG,WAAY,CACjB,IAAK,IAAI,EAAK,EAAG,EAAK,EAAa,IAGjC,GAFe,EAAG,WAAW,IAAI,EAAG,YAAY,EAAG,GAAG,IAAW,CAE7D,GAAU,EAAI,EAAG,OAAO,EAG9B,OAAO,EAAc,CACvB,KAAO,CACL,IAAK,IAAI,EAAK,EAAG,EAAK,EAAa,IAGjC,GAFa,EAAG,WAAW,IAAI,EAAG,YAAY,EAAG,GAAG,IAAW,CAE3D,GAAQ,EAAI,EAAG,OAAO,EAG5B,OAAO,EAAc,CACvB,CACK,CACL,IAAM,EAAU,EAAG,UAAY,EACzB,EAAY,EAAG,WAAW,EAAW,EAAO,EAAI,EAAG,UAAY,EAC/D,EAAS,EAAG,WAAa,EAAI,EAAI,EAAY,EAAI,EAAI,EACrD,EAAS,KAAK,MAAM,EAAS,CAAO,EAE1C,OAAO,KAAK,IAAI,EAAG,KAAK,IAAI,EAAc,EAAG,CAAM,CAAC,CACtD,CACF,CAEA,SAAgB,EACd,EACA,EACA,EACA,EACA,EACS,CACT,IAAM,EAAS,EAAc,EACvB,EAAS,EAAG,QACb,EAAG,YAAY,EAAO,GAAG,IAAW,EACrC,KAAK,IAAI,GAAG,MAAM,KAAK,CAAE,OAAQ,CAAY,GAAI,EAAG,IAAO,EAAQ,EAAG,GAAG,EAAO,EAAE,OAAS,CAAC,CAAC,EAC3F,EAAQ,EAAG,WAAW,IAAI,CAAM,EAEtC,OAAO,EAAG,WAAa,EAAI,EAAI,EAAQ,EAAI,EAAI,CACjD"}
|
|
@@ -8,5 +8,5 @@ export declare function findSeriesIdx(pos: {
|
|
|
8
8
|
export declare function isOutsideBars(pos: {
|
|
9
9
|
x: number;
|
|
10
10
|
y: number;
|
|
11
|
-
}, catIdx: number, allData: Datum[][], sc: BarScaleContext, seriesCount: number): boolean;
|
|
11
|
+
}, catIdx: number, allData: (Datum | undefined)[][], sc: BarScaleContext, seriesCount: number): boolean;
|
|
12
12
|
//# 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,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,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;AAED,wBAAgB,aAAa,CAC3B,GAAG,EAAE;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,EAC7B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,KAAK,EAAE,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,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,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;AAED,wBAAgB,aAAa,CAC3B,GAAG,EAAE;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,EAC7B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,CAAC,KAAK,GAAG,SAAS,CAAC,EAAE,EAAE,EAChC,EAAE,EAAE,eAAe,EACnB,WAAW,EAAE,MAAM,GAClB,OAAO,CAQT"}
|
|
@@ -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[][],\n sc: BarScaleContext,\n seriesCount: number,\n): boolean {\n const lastSi = seriesCount - 1;\n const maxVal = sc.stacked\n ? (sc.stackedTops[lastSi]?.[catIdx] ?? 0)\n : Math.max(...Array.from({ length: seriesCount }, (_, si) => allData[si]?.[catIdx]?.value ?? 0));\n const maxPx = sc.valueScale.map(maxVal);\n\n return sc.horizontal ? pos.x > maxPx : pos.y < maxPx;\n}\n"],"mappings":";AAGA,SAAgB,EAAW,GAAa,GAAsB,GAA6B;CACzF,KAAK,IAAI,IAAI,GAAG,IAAI,EAAW,QAAQ,KAAK;EAE1C,IAAM,IADS,EAAG,WAAW,EAAW,EAC1B,IAAS,EAAG,YAAY;EAEtC,IAAI,KAAO,KAAS,IAAM,IAAQ,EAAG,WAAW,OAAO;CACzD;CAEA,OAAO;AACT;AAEA,SAAgB,EACd,GACA,GACA,GACA,GACA,GACQ;CACR,IAAI,EAAG,SACL,IAAI,EAAG,YAAY;EACjB,KAAK,IAAI,IAAK,GAAG,IAAK,GAAa,KAGjC,IAFe,EAAG,WAAW,IAAI,EAAG,YAAY,EAAG,GAAG,MAAW,CAE7D,KAAU,EAAI,GAAG,OAAO;EAG9B,OAAO,IAAc;CACvB,OAAO;EACL,KAAK,IAAI,IAAK,GAAG,IAAK,GAAa,KAGjC,IAFa,EAAG,WAAW,IAAI,EAAG,YAAY,EAAG,GAAG,MAAW,CAE3D,KAAQ,EAAI,GAAG,OAAO;EAG5B,OAAO,IAAc;CACvB;CACK;EACL,IAAM,IAAU,EAAG,YAAY,GACzB,IAAY,EAAG,WAAW,EAAW,EAAO,IAAI,EAAG,YAAY,GAC/D,IAAS,EAAG,aAAa,EAAI,IAAI,IAAY,EAAI,IAAI,GACrD,IAAS,KAAK,MAAM,IAAS,CAAO;EAE1C,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,IAAc,GAAG,CAAM,CAAC;CACtD;AACF;AAEA,SAAgB,EACd,GACA,GACA,GACA,GACA,GACS;CACT,IAAM,IAAS,IAAc,GACvB,IAAS,EAAG,UACb,EAAG,YAAY,EAAO,GAAG,MAAW,IACrC,KAAK,IAAI,GAAG,MAAM,KAAK,EAAE,QAAQ,EAAY,IAAI,GAAG,MAAO,EAAQ,EAAG,GAAG,EAAO,EAAE,SAAS,CAAC,CAAC,GAC3F,IAAQ,EAAG,WAAW,IAAI,CAAM;CAEtC,OAAO,EAAG,aAAa,EAAI,IAAI,IAAQ,EAAI,IAAI;AACjD"}
|
|
1
|
+
{"version":3,"file":"bar-hit-test.js","names":[],"sources":["../../../src/charts/bar/bar-hit-test.ts"],"sourcesContent":["import type { Datum } from '../../types';\nimport type { BarScaleContext } from './bar-scale-context';\n\nexport function findCatIdx(pos: number, categories: string[], sc: BarScaleContext): number {\n for (let i = 0; i < categories.length; i++) {\n const center = sc.bandCenter(categories[i]);\n const start = center - sc.bandwidth / 2;\n\n if (pos >= start && pos < start + sc.bandwidth) return i;\n }\n\n return -1;\n}\n\nexport function findSeriesIdx(\n pos: { x: number; y: number },\n catIdx: number,\n categories: string[],\n sc: BarScaleContext,\n seriesCount: number,\n): number {\n if (sc.stacked) {\n if (sc.horizontal) {\n for (let si = 0; si < seriesCount; si++) {\n const rightX = sc.valueScale.map(sc.stackedTops[si]?.[catIdx] ?? 0);\n\n if (rightX >= pos.x) return si;\n }\n\n return seriesCount - 1;\n } else {\n for (let si = 0; si < seriesCount; si++) {\n const topY = sc.valueScale.map(sc.stackedTops[si]?.[catIdx] ?? 0);\n\n if (topY <= pos.y) return si;\n }\n\n return seriesCount - 1;\n }\n } else {\n const subSize = sc.bandwidth / seriesCount;\n const bandStart = sc.bandCenter(categories[catIdx]) - sc.bandwidth / 2;\n const offset = sc.horizontal ? pos.y - bandStart : pos.x - bandStart;\n const subIdx = Math.floor(offset / subSize);\n\n return Math.max(0, Math.min(seriesCount - 1, subIdx));\n }\n}\n\nexport function isOutsideBars(\n pos: { x: number; y: number },\n catIdx: number,\n allData: (Datum | undefined)[][],\n sc: BarScaleContext,\n seriesCount: number,\n): boolean {\n const lastSi = seriesCount - 1;\n const maxVal = sc.stacked\n ? (sc.stackedTops[lastSi]?.[catIdx] ?? 0)\n : Math.max(...Array.from({ length: seriesCount }, (_, si) => allData[si]?.[catIdx]?.value ?? 0));\n const maxPx = sc.valueScale.map(maxVal);\n\n return sc.horizontal ? pos.x > maxPx : pos.y < maxPx;\n}\n"],"mappings":";AAGA,SAAgB,EAAW,GAAa,GAAsB,GAA6B;CACzF,KAAK,IAAI,IAAI,GAAG,IAAI,EAAW,QAAQ,KAAK;EAE1C,IAAM,IADS,EAAG,WAAW,EAAW,EAC1B,IAAS,EAAG,YAAY;EAEtC,IAAI,KAAO,KAAS,IAAM,IAAQ,EAAG,WAAW,OAAO;CACzD;CAEA,OAAO;AACT;AAEA,SAAgB,EACd,GACA,GACA,GACA,GACA,GACQ;CACR,IAAI,EAAG,SACL,IAAI,EAAG,YAAY;EACjB,KAAK,IAAI,IAAK,GAAG,IAAK,GAAa,KAGjC,IAFe,EAAG,WAAW,IAAI,EAAG,YAAY,EAAG,GAAG,MAAW,CAE7D,KAAU,EAAI,GAAG,OAAO;EAG9B,OAAO,IAAc;CACvB,OAAO;EACL,KAAK,IAAI,IAAK,GAAG,IAAK,GAAa,KAGjC,IAFa,EAAG,WAAW,IAAI,EAAG,YAAY,EAAG,GAAG,MAAW,CAE3D,KAAQ,EAAI,GAAG,OAAO;EAG5B,OAAO,IAAc;CACvB;CACK;EACL,IAAM,IAAU,EAAG,YAAY,GACzB,IAAY,EAAG,WAAW,EAAW,EAAO,IAAI,EAAG,YAAY,GAC/D,IAAS,EAAG,aAAa,EAAI,IAAI,IAAY,EAAI,IAAI,GACrD,IAAS,KAAK,MAAM,IAAS,CAAO;EAE1C,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,IAAc,GAAG,CAAM,CAAC;CACtD;AACF;AAEA,SAAgB,EACd,GACA,GACA,GACA,GACA,GACS;CACT,IAAM,IAAS,IAAc,GACvB,IAAS,EAAG,UACb,EAAG,YAAY,EAAO,GAAG,MAAW,IACrC,KAAK,IAAI,GAAG,MAAM,KAAK,EAAE,QAAQ,EAAY,IAAI,GAAG,MAAO,EAAQ,EAAG,GAAG,EAAO,EAAE,SAAS,CAAC,CAAC,GAC3F,IAAQ,EAAG,WAAW,IAAI,CAAM;CAEtC,OAAO,EAAG,aAAa,EAAI,IAAI,IAAQ,EAAI,IAAI;AACjD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../../svg/element.cjs"),t=require("../../animation/transition.cjs");var n=new WeakMap;function r(r,i,a,o,s,c){for(;r.children.length>i.length;){let e=r.lastElementChild;e&&r.removeChild(e)}let l=a.bandwidth(),u=c.stacked?l:l/c.seriesCount,d=c.stacked?0:u*c.seriesIndex,f=c.horizontal??!1,p=[],m=[];for(let t=0;t<i.length;t++){let n=i[t],l=a.map(n.key)+d,h=c.baselineYs?c.baselineYs[t]:s,g=o.map(n.y),_=r.children[t],v=!_;if(_||(_=e.createSvgElement(`rect`,{class:`prism-bar`}),r.appendChild(_)),f){let t=Math.max(0,Math.abs(h-g)),n=Math.min(g,h);e.setAttributes(_,{fill:c.color,height:Math.max(0,u-1),rx:c.borderRadius,ry:c.borderRadius,y:l}),c.transition?v?(e.setAttributes(_,{width:0,x:h}),p.push({attrs:{width:{from:0,to:t},x:{from:h,to:n}},el:_})):m.push({attrs:{width:{from:Number(_.getAttribute(`width`)??t),to:t},x:{from:Number(_.getAttribute(`x`)??n),to:n}},el:_}):e.setAttributes(_,{width:t,x:n})}else{let t=Math.max(0,Math.abs(h-g)),n=Math.min(g,h);e.setAttributes(_,{fill:c.color,rx:c.borderRadius,ry:c.borderRadius,width:Math.max(0,u-1),x:l}),c.transition?v?(e.setAttributes(_,{height:0,y:h}),p.push({attrs:{height:{from:0,to:t},y:{from:h,to:n}},el:_})):m.push({attrs:{height:{from:Number(_.getAttribute(`height`)??t),to:t},y:{from:Number(_.getAttribute(`y`)??n),to:n}},el:_}):e.setAttributes(_,{height:t,y:n})}}if(c.transition){n.get(r)?.();let e=[];p.length>0&&e.push(t.animate(p,c.transition,void 0,c.disposalSignal)),m.length>0&&e.push(t.animate(m,{...c.transition,stagger:0},void 0,c.disposalSignal)),n.set(r,()=>{for(let t of e)t()})}}exports.renderBars=r;
|
|
1
|
+
const e=require("../../svg/element.cjs"),t=require("../../animation/transition.cjs");var n=new WeakMap;function r(r,i,a,o,s,c){for(;r.children.length>i.length;){let e=r.lastElementChild;e&&r.removeChild(e)}let l=a.bandwidth(),u=c.stacked?l:l/c.seriesCount,d=c.stacked?0:u*c.seriesIndex,f=c.horizontal??!1,p=[],m=[];for(let t=0;t<i.length;t++){let n=i[t],l=a.map(n.key)+d,h=c.baselineYs?c.baselineYs[t]:s,g=o.map(n.y),_=r.children[t],v=!_;if(_||(_=e.createSvgElement(`rect`,{class:`prism-bar`}),r.appendChild(_)),_.style.display=n.present?``:`none`,f){let t=Math.max(0,Math.abs(h-g)),n=Math.min(g,h);e.setAttributes(_,{fill:c.color,height:Math.max(0,u-1),rx:c.borderRadius,ry:c.borderRadius,y:l}),c.transition?v?(e.setAttributes(_,{width:0,x:h}),p.push({attrs:{width:{from:0,to:t},x:{from:h,to:n}},el:_})):m.push({attrs:{width:{from:Number(_.getAttribute(`width`)??t),to:t},x:{from:Number(_.getAttribute(`x`)??n),to:n}},el:_}):e.setAttributes(_,{width:t,x:n})}else{let t=Math.max(0,Math.abs(h-g)),n=Math.min(g,h);e.setAttributes(_,{fill:c.color,rx:c.borderRadius,ry:c.borderRadius,width:Math.max(0,u-1),x:l}),c.transition?v?(e.setAttributes(_,{height:0,y:h}),p.push({attrs:{height:{from:0,to:t},y:{from:h,to:n}},el:_})):m.push({attrs:{height:{from:Number(_.getAttribute(`height`)??t),to:t},y:{from:Number(_.getAttribute(`y`)??n),to:n}},el:_}):e.setAttributes(_,{height:t,y:n})}}if(c.transition){n.get(r)?.();let e=[];p.length>0&&e.push(t.animate(p,c.transition,void 0,c.disposalSignal)),m.length>0&&e.push(t.animate(m,{...c.transition,stagger:0},void 0,c.disposalSignal)),n.set(r,()=>{for(let t of e)t()})}}exports.renderBars=r;
|
|
2
2
|
//# sourceMappingURL=bar-renderer.cjs.map
|
|
@@ -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 type { BandScale, Scale, TransitionConfig } from '../../types';\n\nimport { animate } from '../../animation/transition';\nimport { createSvgElement, setAttributes } from '../../svg/element';\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; 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 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":"qFAmBA,IAAM,EAAsB,IAAI,QAEhC,SAAgB,EACd,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,
|
|
1
|
+
{"version":3,"file":"bar-renderer.cjs","names":[],"sources":["../../../src/charts/bar/bar-renderer.ts"],"sourcesContent":["import type { AnimationTarget } from '../../animation/transition';\nimport type { BandScale, Scale, TransitionConfig } from '../../types';\n\nimport { animate } from '../../animation/transition';\nimport { createSvgElement, setAttributes } from '../../svg/element';\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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,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"}
|
|
@@ -14,6 +14,7 @@ export interface BarRenderOptions {
|
|
|
14
14
|
export declare function renderBars(parent: SVGGElement, data: {
|
|
15
15
|
base: number;
|
|
16
16
|
key: string;
|
|
17
|
+
present: boolean;
|
|
17
18
|
y: number;
|
|
18
19
|
}[], xScale: BandScale, yScale: Scale<number>, baselineY: number, options: BarRenderOptions): void;
|
|
19
20
|
//# sourceMappingURL=bar-renderer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bar-renderer.d.ts","sourceRoot":"","sources":["../../../src/charts/bar/bar-renderer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAKtE,MAAM,WAAW,gBAAgB;IAC/B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,iGAAiG;IACjG,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,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"bar-renderer.d.ts","sourceRoot":"","sources":["../../../src/charts/bar/bar-renderer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAKtE,MAAM,WAAW,gBAAgB;IAC/B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,iGAAiG;IACjG,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"}
|
|
@@ -10,7 +10,7 @@ function i(i, a, o, s, c, l) {
|
|
|
10
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
11
|
for (let n = 0; n < a.length; n++) {
|
|
12
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)), p) {
|
|
13
|
+
if (v || (v = e("rect", { class: "prism-bar" }), i.appendChild(v)), v.style.display = r.present ? "" : "none", p) {
|
|
14
14
|
let e = Math.max(0, Math.abs(g - _)), n = Math.min(_, g);
|
|
15
15
|
t(v, {
|
|
16
16
|
fill: l.color,
|
|
@@ -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 type { BandScale, Scale, TransitionConfig } from '../../types';\n\nimport { animate } from '../../animation/transition';\nimport { createSvgElement, setAttributes } from '../../svg/element';\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; 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 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":";;;AAmBA,IAAM,oBAAsB,IAAI,QAAiC;AAEjE,SAAgB,EACd,GACA,GACA,GACA,GACA,GACA,GACM;CACN,OAAO,EAAO,SAAS,SAAS,EAAK,SAAQ;EAC3C,IAAM,IAAO,EAAO;EAEpB,AAAI,KAAM,EAAO,YAAY,CAAI;CACnC;CAEA,IAAM,IAAY,EAAO,UAAU,GAC7B,IAAU,EAAQ,UAAU,IAAY,IAAY,EAAQ,aAC5D,IAAS,EAAQ,UAAU,IAAI,IAAU,EAAQ,aACjD,IAAa,EAAQ,cAAc,IAEnC,IAAkC,CAAC,GACnC,IAAmC,CAAC;CAE1C,KAAK,IAAI,IAAI,GAAG,IAAI,EAAK,QAAQ,KAAK;EACpC,IAAM,IAAI,EAAK,IACT,IAAU,EAAO,IAAI,EAAE,GAAG,IAAI,GAC9B,IAAe,EAAQ,aAAa,EAAQ,WAAW,KAAK,GAC5D,IAAU,EAAO,IAAI,EAAE,CAAC,GAE1B,IAAO,EAAO,SAAS,IAErB,IAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"bar-renderer.js","names":[],"sources":["../../../src/charts/bar/bar-renderer.ts"],"sourcesContent":["import type { AnimationTarget } from '../../animation/transition';\nimport type { BandScale, Scale, TransitionConfig } from '../../types';\n\nimport { animate } from '../../animation/transition';\nimport { createSvgElement, setAttributes } from '../../svg/element';\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":";;;AAmBA,IAAM,oBAAsB,IAAI,QAAiC;AAEjE,SAAgB,EACd,GACA,GACA,GACA,GACA,GACA,GACM;CACN,OAAO,EAAO,SAAS,SAAS,EAAK,SAAQ;EAC3C,IAAM,IAAO,EAAO;EAEpB,AAAI,KAAM,EAAO,YAAY,CAAI;CACnC;CAEA,IAAM,IAAY,EAAO,UAAU,GAC7B,IAAU,EAAQ,UAAU,IAAY,IAAY,EAAQ,aAC5D,IAAS,EAAQ,UAAU,IAAI,IAAU,EAAQ,aACjD,IAAa,EAAQ,cAAc,IAEnC,IAAkC,CAAC,GACnC,IAAmC,CAAC;CAE1C,KAAK,IAAI,IAAI,GAAG,IAAI,EAAK,QAAQ,KAAK;EACpC,IAAM,IAAI,EAAK,IACT,IAAU,EAAO,IAAI,EAAE,GAAG,IAAI,GAC9B,IAAe,EAAQ,aAAa,EAAQ,WAAW,KAAK,GAC5D,IAAU,EAAO,IAAI,EAAE,CAAC,GAE1B,IAAO,EA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,GAClD,EAAa,KAAK;IAChB,OAAO;KAAE,QAAQ;MAAE,MAAM;MAAG,IAAI;KAAY;KAAG,GAAG;MAAE,MAAM;MAAc,IAAI;KAAO;IAAE;IACrF,IAAI;GACN,CAAC,KAED,EAAc,KAAK;IACjB,OAAO;KACL,QAAQ;MAAE,MAAM,OAAO,EAAK,aAAa,QAAQ,KAAK,CAAW;MAAG,IAAI;KAAY;KACpF,GAAG;MAAE,MAAM,OAAO,EAAK,aAAa,GAAG,KAAK,CAAM;MAAG,IAAI;KAAO;IAClE;IACA,IAAI;GACN,CAAC,IAGH,EAAc,GAAM;IAAE,QAAQ;IAAa,GAAG;GAAO,CAAC;EAE1D;CACF;CAEA,IAAI,EAAQ,YAAY;EACtB,EAAoB,IAAI,CAAM,CAAC,GAAG;EAElC,IAAM,IAA0B,CAAC;EAUjC,AARI,EAAa,SAAS,KACxB,EAAQ,KAAK,EAAQ,GAAc,EAAQ,YAAY,KAAA,GAAW,EAAQ,cAAc,CAAC,GAGvF,EAAc,SAAS,KACzB,EAAQ,KAAK,EAAQ,GAAe;GAAE,GAAG,EAAQ;GAAY,SAAS;EAAE,GAAG,KAAA,GAAW,EAAQ,cAAc,CAAC,GAG/G,EAAoB,IAAI,SAAc;GACpC,KAAK,IAAM,KAAU,GAAS,EAAO;EACvC,CAAC;CACH;AACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
require("../../_dev.cjs");const e=require("../../svg/element.cjs"),t=require("../../animation/easing.cjs"),n=require("../../animation/
|
|
1
|
+
require("../../_dev.cjs");const e=require("../../svg/element.cjs"),t=require("../../animation/easing.cjs"),n=require("../../animation/motion.cjs"),r=require("../../animation/tween.cjs"),i=require("../../svg/path.cjs");var a=new WeakMap;function o(e,t){return t===`monotone`?i.monotonePath(e):t===`step`?i.stepPath(e):i.linePath(e)}function s(i,s,c){let l=n.resolveMotion(c.transition,0),u=l.duration,d=t.resolveEasing(l.easing),f=i.querySelector(`.prism-line-path`);f||(f=e.createSvgElement(`path`,{class:`prism-line-path`,fill:`none`}),i.appendChild(f)),e.setAttributes(f,{stroke:c.color,"stroke-width":c.strokeWidth});let p=i.querySelector(`.prism-line-dots`);if(c.showPoints?p||(p=e.createSvgElement(`g`,{class:`prism-line-dots`}),i.appendChild(p)):p&&=(p.remove(),null),u===0){if(e.setAttributes(f,{d:o(s,c.curve)}),p){for(;p.children.length>s.length;)p.removeChild(p.lastChild);for(let t=0;t<s.length;t++){let n=p.children[t];n||(n=e.createSvgElement(`circle`,{class:`prism-line-dot`}),p.appendChild(n)),e.setAttributes(n,{cx:s[t].x,cy:s[t].y,fill:c.color,r:c.pointRadius})}}return}a.get(i)?.();let m=!!f.getAttribute(`d`),h=[],g=null;if(p){let t=p.children.length;for(let e=0;e<t;e++){let t=p.children[e],n={x:Number(t.getAttribute(`cx`)),y:Number(t.getAttribute(`cy`))};h.push(n),g=n}for(;p.children.length>s.length;)p.removeChild(p.lastChild);for(let t=p.children.length;t<s.length;t++){let n=e.createSvgElement(`circle`,{class:`prism-line-dot`});e.setAttributes(n,{cx:s[t].x,cy:s[t].y,fill:c.color,r:c.pointRadius}),p.appendChild(n)}}for(let e=h.length;e<s.length;e++)h.push(g??s[e]);let _=null;function v(t){if(c.disposalSignal?.aborted){a.delete(i);return}_===null&&(_=t);let n=Math.min(1,(t-_)/u),l=d(n),m=s.map((e,t)=>{let n=h[t]??e;return{x:r.tweenNumber(n.x,e.x,l),y:r.tweenNumber(n.y,e.y,l)}});if(e.setAttributes(f,{d:o(m,c.curve)}),p)for(let t=0;t<s.length;t++){let n=p.children[t];n&&e.setAttributes(n,{cx:m[t].x,cy:m[t].y})}if(n<1){let e=requestAnimationFrame(v);a.set(i,()=>cancelAnimationFrame(e))}else a.delete(i)}if(!m)e.setAttributes(f,{d:o(s,c.curve)});else{let e=requestAnimationFrame(v);a.set(i,()=>cancelAnimationFrame(e))}}function c(e,t,n){return e.some(e=>e.key==null)||e.some(e=>typeof e.key==`string`),e.map(e=>({x:t.map(e.key),y:n.map(e.value)}))}exports.computePoints=c,exports.renderLine=s;
|
|
2
2
|
//# sourceMappingURL=line-renderer.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"line-renderer.cjs","names":[],"sources":["../../../src/charts/line/line-renderer.ts"],"sourcesContent":["import type { Point } from '../../svg/path';\nimport type { Datum, Scale, TransitionConfig } from '../../types';\n\nimport { warn } from '../../_dev';\nimport { resolveEasing } from '../../animation/easing';\nimport { tweenNumber } from '../../animation/tween';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport { linePath, monotonePath, stepPath } from '../../svg/path';\n\nexport interface LineRenderOptions {\n color: string;\n curve: 'linear' | 'monotone' | 'step';\n /** Aborted when the owning chart is disposed — stops the transition's `requestAnimationFrame` loop from rescheduling. */\n disposalSignal?: AbortSignal;\n pointRadius: number;\n showPoints: boolean;\n strokeWidth: number;\n transition?: TransitionConfig;\n}\n\nconst activeAnimations = new WeakMap<SVGGElement, () => void>();\n\nfunction buildPath(pts: Point[], curve: LineRenderOptions['curve']): string {\n return curve === 'monotone' ? monotonePath(pts) : curve === 'step' ? stepPath(pts) : linePath(pts);\n}\n\nexport function renderLine(parent: SVGGElement, points: Point[], options: LineRenderOptions): void {\n const
|
|
1
|
+
{"version":3,"file":"line-renderer.cjs","names":[],"sources":["../../../src/charts/line/line-renderer.ts"],"sourcesContent":["import type { Point } from '../../svg/path';\nimport type { Datum, Scale, TransitionConfig } from '../../types';\n\nimport { warn } from '../../_dev';\nimport { resolveEasing } from '../../animation/easing';\nimport { resolveMotion } from '../../animation/motion';\nimport { tweenNumber } from '../../animation/tween';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport { linePath, monotonePath, stepPath } from '../../svg/path';\n\nexport interface LineRenderOptions {\n color: string;\n curve: 'linear' | 'monotone' | 'step';\n /** Aborted when the owning chart is disposed — stops the transition's `requestAnimationFrame` loop from rescheduling. */\n disposalSignal?: AbortSignal;\n pointRadius: number;\n showPoints: boolean;\n strokeWidth: number;\n transition?: TransitionConfig;\n}\n\nconst activeAnimations = new WeakMap<SVGGElement, () => void>();\n\nfunction buildPath(pts: Point[], curve: LineRenderOptions['curve']): string {\n return curve === 'monotone' ? monotonePath(pts) : curve === 'step' ? stepPath(pts) : linePath(pts);\n}\n\nexport function renderLine(parent: SVGGElement, points: Point[], options: LineRenderOptions): void {\n const motion = resolveMotion(options.transition, 0);\n const dur = motion.duration;\n const easing = resolveEasing(motion.easing);\n\n let path = parent.querySelector<SVGPathElement>('.prism-line-path');\n\n if (!path) {\n path = createSvgElement('path', { class: 'prism-line-path', fill: 'none' });\n parent.appendChild(path);\n }\n\n setAttributes(path, { stroke: options.color, 'stroke-width': options.strokeWidth });\n\n let dotsGroup = parent.querySelector<SVGGElement>('.prism-line-dots');\n\n if (options.showPoints) {\n if (!dotsGroup) {\n dotsGroup = createSvgElement('g', { class: 'prism-line-dots' });\n parent.appendChild(dotsGroup);\n }\n } else if (dotsGroup) {\n dotsGroup.remove();\n dotsGroup = null;\n }\n\n if (dur === 0) {\n setAttributes(path, { d: buildPath(points, options.curve) });\n\n if (dotsGroup) {\n while (dotsGroup.children.length > points.length) dotsGroup.removeChild(dotsGroup.lastChild!);\n\n for (let i = 0; i < points.length; i++) {\n let c = dotsGroup.children[i] as SVGCircleElement | undefined;\n\n if (!c) {\n c = createSvgElement('circle', { class: 'prism-line-dot' });\n dotsGroup.appendChild(c);\n }\n\n setAttributes(c, { cx: points[i].x, cy: points[i].y, fill: options.color, r: options.pointRadius });\n }\n }\n\n return;\n }\n\n activeAnimations.get(parent)?.();\n\n const hasExisting = !!path.getAttribute('d');\n\n const fromPts: Point[] = [];\n let lastKnown: Point | null = null;\n\n if (dotsGroup) {\n const existingCount = dotsGroup.children.length;\n\n for (let i = 0; i < existingCount; i++) {\n const c = dotsGroup.children[i] as SVGCircleElement;\n const pt = { x: Number(c.getAttribute('cx')), y: Number(c.getAttribute('cy')) };\n\n fromPts.push(pt);\n lastKnown = pt;\n }\n\n while (dotsGroup.children.length > points.length) dotsGroup.removeChild(dotsGroup.lastChild!);\n\n for (let i = dotsGroup.children.length; i < points.length; i++) {\n const c = createSvgElement('circle', { class: 'prism-line-dot' });\n\n setAttributes(c, { cx: points[i].x, cy: points[i].y, fill: options.color, r: options.pointRadius });\n dotsGroup.appendChild(c);\n }\n }\n\n for (let i = fromPts.length; i < points.length; i++) {\n fromPts.push(lastKnown ?? points[i]);\n }\n\n let startTime: number | null = null;\n\n function frame(ts: number) {\n if (options.disposalSignal?.aborted) {\n activeAnimations.delete(parent);\n\n return;\n }\n\n if (startTime === null) startTime = ts;\n\n const t = Math.min(1, (ts - startTime) / dur);\n const e = easing(t);\n const interpolated: Point[] = points.map((to, i) => {\n const from = fromPts[i] ?? to;\n\n return { x: tweenNumber(from.x, to.x, e), y: tweenNumber(from.y, to.y, e) };\n });\n\n setAttributes(path!, { d: buildPath(interpolated, options.curve) });\n\n if (dotsGroup) {\n for (let i = 0; i < points.length; i++) {\n const c = dotsGroup.children[i] as SVGCircleElement | undefined;\n\n if (c) setAttributes(c, { cx: interpolated[i].x, cy: interpolated[i].y });\n }\n }\n\n if (t < 1) {\n const id = requestAnimationFrame(frame);\n\n activeAnimations.set(parent, () => cancelAnimationFrame(id));\n } else {\n activeAnimations.delete(parent);\n }\n }\n\n if (!hasExisting) {\n setAttributes(path, { d: buildPath(points, options.curve) });\n } else {\n const id = requestAnimationFrame(frame);\n\n activeAnimations.set(parent, () => cancelAnimationFrame(id));\n }\n}\n\nexport function computePoints(data: Datum[], xScale: Scale<Date | number>, yScale: Scale<number>): Point[] {\n if (data.some((d) => d.key == null)) {\n warn(\n 'computePoints: datum.key is null or undefined — data must use the Datum shape { key, value }. Did you pass { x, y } instead?',\n );\n } else if (data.some((d) => typeof d.key === 'string')) {\n warn('computePoints: string keys are not supported for line/area charts — use numeric or Date keys.');\n }\n\n return data.map((d) => ({\n x: xScale.map(d.key as Date | number),\n y: yScale.map(d.value),\n }));\n}\n"],"mappings":"0NAqBA,I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K,EAAG,EAAG,EAAG,CAAC,CAAE,CAC5E,CAAC,EAID,GAFA,EAAA,cAAc,EAAO,CAAE,EAAG,EAAU,EAAc,EAAQ,KAAK,CAAE,CAAC,EAE9D,EACF,IAAK,IAAI,EAAI,EAAG,EAAI,EAAO,OAAQ,IAAK,CACtC,IAAM,EAAI,EAAU,SAAS,GAEzB,GAAG,EAAA,cAAc,EAAG,CAAE,GAAI,EAAa,EAAE,CAAC,EAAG,GAAI,EAAa,EAAE,CAAC,CAAE,CAAC,CAC1E,CAGF,GAAI,EAAI,EAAG,CACT,IAAM,EAAK,sBAAsB,CAAK,EAEtC,EAAiB,IAAI,MAAc,qBAAqB,CAAE,CAAC,CAC7D,MACE,EAAiB,OAAO,CAAM,CAElC,CAEA,GAAI,CAAC,EACH,EAAA,cAAc,EAAM,CAAE,EAAG,EAAU,EAAQ,EAAQ,KAAK,CAAE,CAAC,MACtD,CACL,IAAM,EAAK,sBAAsB,CAAK,EAEtC,EAAiB,IAAI,MAAc,qBAAqB,CAAE,CAAC,CAC7D,CACF,CAEA,SAAgB,EAAc,EAAe,EAA8B,EAAgC,CASzG,OARI,EAAK,KAAM,GAAM,EAAE,KAAO,IAAI,GAIvB,EAAK,KAAM,GAAM,OAAO,EAAE,KAAQ,QAAQ,EAI9C,EAAK,IAAK,IAAO,CACtB,EAAG,EAAO,IAAI,EAAE,GAAoB,EACpC,EAAG,EAAO,IAAI,EAAE,KAAK,CACvB,EAAE,CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"line-renderer.d.ts","sourceRoot":"","sources":["../../../src/charts/line/line-renderer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"line-renderer.d.ts","sourceRoot":"","sources":["../../../src/charts/line/line-renderer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AASlE,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAC;IACtC,yHAAyH;IACzH,cAAc,CAAC,EAAE,WAAW,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC/B;AAQD,wBAAgB,UAAU,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,iBAAiB,GAAG,IAAI,CA4HjG;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,IAAI,GAAG,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,EAAE,CAazG"}
|