insomni-plot 0.1.0-alpha.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/LICENSE.md +674 -0
- package/README.md +81 -0
- package/dist/core.d.mts +340 -0
- package/dist/core.mjs +1047 -0
- package/dist/index.d.mts +3426 -0
- package/dist/index.mjs +12762 -0
- package/dist/interactions-DEFL_F4E.mjs +5395 -0
- package/dist/range-presets-CzECsu3V.d.mts +1523 -0
- package/package.json +34 -0
- package/src/annotations.d.ts +121 -0
- package/src/annotations.ts +438 -0
- package/src/axis.d.ts +184 -0
- package/src/axis.test.ts +131 -0
- package/src/axis.ts +765 -0
- package/src/colorbar.d.ts +69 -0
- package/src/colorbar.ts +294 -0
- package/src/colors.d.ts +57 -0
- package/src/colors.test.ts +28 -0
- package/src/colors.ts +486 -0
- package/src/core.ts +299 -0
- package/src/format.d.ts +54 -0
- package/src/format.ts +138 -0
- package/src/grammar/accessibility.d.ts +147 -0
- package/src/grammar/accessibility.test.ts +199 -0
- package/src/grammar/accessibility.ts +443 -0
- package/src/grammar/aes.d.ts +35 -0
- package/src/grammar/aes.test.ts +75 -0
- package/src/grammar/aes.ts +120 -0
- package/src/grammar/annotations.d.ts +86 -0
- package/src/grammar/annotations.test.ts +68 -0
- package/src/grammar/annotations.ts +336 -0
- package/src/grammar/attach-brush.d.ts +44 -0
- package/src/grammar/attach-brush.test.ts +214 -0
- package/src/grammar/attach-brush.ts +111 -0
- package/src/grammar/attach-presets.d.ts +33 -0
- package/src/grammar/attach-presets.test.ts +106 -0
- package/src/grammar/attach-presets.ts +215 -0
- package/src/grammar/chart.d.ts +952 -0
- package/src/grammar/chart.test.ts +118 -0
- package/src/grammar/chart.ts +1172 -0
- package/src/grammar/color-utils.d.ts +29 -0
- package/src/grammar/color-utils.test.ts +53 -0
- package/src/grammar/color-utils.ts +66 -0
- package/src/grammar/constants.d.ts +45 -0
- package/src/grammar/constants.ts +61 -0
- package/src/grammar/coord.d.ts +183 -0
- package/src/grammar/coord.test.ts +355 -0
- package/src/grammar/coord.ts +619 -0
- package/src/grammar/data/pivot.d.ts +57 -0
- package/src/grammar/data/pivot.ts +107 -0
- package/src/grammar/emphasis-driver.d.ts +69 -0
- package/src/grammar/emphasis-driver.test.ts +199 -0
- package/src/grammar/emphasis-driver.ts +205 -0
- package/src/grammar/equality.d.ts +3 -0
- package/src/grammar/equality.ts +40 -0
- package/src/grammar/facet.d.ts +63 -0
- package/src/grammar/facet.test.ts +60 -0
- package/src/grammar/facet.ts +175 -0
- package/src/grammar/geoms/_categorical.d.ts +94 -0
- package/src/grammar/geoms/_categorical.ts +0 -0
- package/src/grammar/geoms/_distribution.d.ts +52 -0
- package/src/grammar/geoms/_distribution.ts +125 -0
- package/src/grammar/geoms/_mark.d.ts +69 -0
- package/src/grammar/geoms/_mark.ts +136 -0
- package/src/grammar/geoms/_shape.d.ts +41 -0
- package/src/grammar/geoms/_shape.ts +74 -0
- package/src/grammar/geoms/aggregate.d.ts +95 -0
- package/src/grammar/geoms/aggregate.test.ts +554 -0
- package/src/grammar/geoms/aggregate.ts +840 -0
- package/src/grammar/geoms/area.d.ts +32 -0
- package/src/grammar/geoms/area.test.ts +165 -0
- package/src/grammar/geoms/area.ts +578 -0
- package/src/grammar/geoms/band.d.ts +27 -0
- package/src/grammar/geoms/band.test.ts +57 -0
- package/src/grammar/geoms/band.ts +126 -0
- package/src/grammar/geoms/bar.d.ts +56 -0
- package/src/grammar/geoms/bar.test.ts +367 -0
- package/src/grammar/geoms/bar.ts +1054 -0
- package/src/grammar/geoms/boxplot.d.ts +129 -0
- package/src/grammar/geoms/boxplot.test.ts +299 -0
- package/src/grammar/geoms/boxplot.ts +834 -0
- package/src/grammar/geoms/connected-scatter.d.ts +27 -0
- package/src/grammar/geoms/connected-scatter.test.ts +157 -0
- package/src/grammar/geoms/connected-scatter.ts +63 -0
- package/src/grammar/geoms/emphasis.d.ts +76 -0
- package/src/grammar/geoms/emphasis.test.ts +135 -0
- package/src/grammar/geoms/emphasis.ts +162 -0
- package/src/grammar/geoms/histogram.d.ts +75 -0
- package/src/grammar/geoms/histogram.test.ts +262 -0
- package/src/grammar/geoms/histogram.ts +740 -0
- package/src/grammar/geoms/index.d.ts +20 -0
- package/src/grammar/geoms/index.ts +77 -0
- package/src/grammar/geoms/interval.d.ts +31 -0
- package/src/grammar/geoms/interval.test.ts +154 -0
- package/src/grammar/geoms/interval.ts +342 -0
- package/src/grammar/geoms/line.d.ts +38 -0
- package/src/grammar/geoms/line.test.ts +247 -0
- package/src/grammar/geoms/line.ts +659 -0
- package/src/grammar/geoms/point.d.ts +57 -0
- package/src/grammar/geoms/point.test.ts +163 -0
- package/src/grammar/geoms/point.ts +545 -0
- package/src/grammar/geoms/polar.test.ts +216 -0
- package/src/grammar/geoms/ribbon.d.ts +21 -0
- package/src/grammar/geoms/ribbon.test.ts +170 -0
- package/src/grammar/geoms/ribbon.ts +87 -0
- package/src/grammar/geoms/ridgeline.d.ts +89 -0
- package/src/grammar/geoms/ridgeline.test.ts +247 -0
- package/src/grammar/geoms/ridgeline.ts +1164 -0
- package/src/grammar/geoms/rolling.d.ts +43 -0
- package/src/grammar/geoms/rolling.test.ts +217 -0
- package/src/grammar/geoms/rolling.ts +387 -0
- package/src/grammar/geoms/rug.d.ts +28 -0
- package/src/grammar/geoms/rug.test.ts +126 -0
- package/src/grammar/geoms/rug.ts +214 -0
- package/src/grammar/geoms/rule.d.ts +23 -0
- package/src/grammar/geoms/rule.test.ts +69 -0
- package/src/grammar/geoms/rule.ts +212 -0
- package/src/grammar/geoms/smooth.d.ts +54 -0
- package/src/grammar/geoms/smooth.test.ts +78 -0
- package/src/grammar/geoms/smooth.ts +337 -0
- package/src/grammar/geoms/text.d.ts +29 -0
- package/src/grammar/geoms/text.test.ts +64 -0
- package/src/grammar/geoms/text.ts +234 -0
- package/src/grammar/geoms/tile.d.ts +61 -0
- package/src/grammar/geoms/tile.test.ts +157 -0
- package/src/grammar/geoms/tile.ts +621 -0
- package/src/grammar/geoms/types.d.ts +319 -0
- package/src/grammar/geoms/types.ts +362 -0
- package/src/grammar/geoms/violin.d.ts +85 -0
- package/src/grammar/geoms/violin.test.ts +187 -0
- package/src/grammar/geoms/violin.ts +672 -0
- package/src/grammar/index.d.ts +22 -0
- package/src/grammar/index.ts +269 -0
- package/src/grammar/interactions/_disposable.d.ts +5 -0
- package/src/grammar/interactions/_disposable.ts +23 -0
- package/src/grammar/interactions/_z.d.ts +4 -0
- package/src/grammar/interactions/_z.ts +16 -0
- package/src/grammar/interactions/brush-selection.test.ts +262 -0
- package/src/grammar/interactions/brush.d.ts +63 -0
- package/src/grammar/interactions/brush.test.ts +483 -0
- package/src/grammar/interactions/brush.ts +452 -0
- package/src/grammar/interactions/crosshair.d.ts +19 -0
- package/src/grammar/interactions/crosshair.test.ts +127 -0
- package/src/grammar/interactions/crosshair.ts +76 -0
- package/src/grammar/interactions/hit-layer.d.ts +64 -0
- package/src/grammar/interactions/hit-layer.ts +246 -0
- package/src/grammar/interactions/legend.d.ts +19 -0
- package/src/grammar/interactions/legend.ts +101 -0
- package/src/grammar/interactions/menu.d.ts +93 -0
- package/src/grammar/interactions/menu.test.ts +373 -0
- package/src/grammar/interactions/menu.ts +342 -0
- package/src/grammar/interactions/selection.d.ts +25 -0
- package/src/grammar/interactions/selection.test.ts +289 -0
- package/src/grammar/interactions/selection.ts +142 -0
- package/src/grammar/interactions/series-readout.d.ts +91 -0
- package/src/grammar/interactions/series-readout.test.ts +668 -0
- package/src/grammar/interactions/series-readout.ts +422 -0
- package/src/grammar/interactions/series-snap.d.ts +70 -0
- package/src/grammar/interactions/series-snap.test.ts +214 -0
- package/src/grammar/interactions/series-snap.ts +218 -0
- package/src/grammar/interactions/tooltip-axis.test.ts +176 -0
- package/src/grammar/interactions/tooltip-touch.browser.test.ts +49 -0
- package/src/grammar/interactions/tooltip-touch.test.ts +161 -0
- package/src/grammar/interactions/tooltip.d.ts +140 -0
- package/src/grammar/interactions/tooltip.test.ts +406 -0
- package/src/grammar/interactions/tooltip.ts +622 -0
- package/src/grammar/interactions/transitions.d.ts +34 -0
- package/src/grammar/interactions/transitions.test.ts +172 -0
- package/src/grammar/interactions/transitions.ts +160 -0
- package/src/grammar/layout.d.ts +68 -0
- package/src/grammar/layout.ts +186 -0
- package/src/grammar/legend-merge.test.ts +332 -0
- package/src/grammar/mount.d.ts +78 -0
- package/src/grammar/mount.test.ts +479 -0
- package/src/grammar/mount.ts +2112 -0
- package/src/grammar/palettes.d.ts +54 -0
- package/src/grammar/palettes.test.ts +80 -0
- package/src/grammar/palettes.ts +167 -0
- package/src/grammar/pan-zoom.test.ts +398 -0
- package/src/grammar/phylo.d.ts +65 -0
- package/src/grammar/phylo.test.ts +59 -0
- package/src/grammar/phylo.ts +112 -0
- package/src/grammar/pipeline.auto-ticks.test.ts +40 -0
- package/src/grammar/pipeline.d.ts +158 -0
- package/src/grammar/pipeline.test.ts +463 -0
- package/src/grammar/pipeline.ts +1233 -0
- package/src/grammar/profiling.d.ts +8 -0
- package/src/grammar/profiling.ts +24 -0
- package/src/grammar/scales.d.ts +188 -0
- package/src/grammar/scales.test.ts +181 -0
- package/src/grammar/scales.ts +800 -0
- package/src/grammar/svg.d.ts +3 -0
- package/src/grammar/svg.ts +39 -0
- package/src/grammar/theme.d.ts +261 -0
- package/src/grammar/theme.test.ts +105 -0
- package/src/grammar/theme.ts +490 -0
- package/src/heatmap/cpu.ts +109 -0
- package/src/heatmap/gpu.ts +565 -0
- package/src/heatmap/types.ts +177 -0
- package/src/heatmap.browser.test.ts +308 -0
- package/src/heatmap.test.ts +320 -0
- package/src/heatmap.ts +123 -0
- package/src/index.d.ts +1 -0
- package/src/index.ts +8 -0
- package/src/interactions.d.ts +48 -0
- package/src/interactions.test.ts +226 -0
- package/src/interactions.ts +394 -0
- package/src/layout/box.d.ts +48 -0
- package/src/layout/box.test.ts +107 -0
- package/src/layout/box.ts +143 -0
- package/src/legend.d.ts +115 -0
- package/src/legend.ts +422 -0
- package/src/marks/curve.d.ts +43 -0
- package/src/marks/curve.ts +244 -0
- package/src/marks/stack.d.ts +53 -0
- package/src/marks/stack.ts +184 -0
- package/src/marks.d.ts +273 -0
- package/src/marks.test.ts +541 -0
- package/src/marks.ts +1292 -0
- package/src/navigator.test.ts +174 -0
- package/src/navigator.ts +393 -0
- package/src/range-presets.d.ts +113 -0
- package/src/range-presets.test.ts +345 -0
- package/src/range-presets.ts +349 -0
- package/src/scales.d.ts +98 -0
- package/src/scales.test.ts +103 -0
- package/src/scales.ts +695 -0
- package/src/stats/index.d.ts +200 -0
- package/src/stats/index.test.ts +349 -0
- package/src/stats/index.ts +740 -0
- package/src/stats/regression.d.ts +38 -0
- package/src/stats/regression.test.ts +56 -0
- package/src/stats/regression.ts +396 -0
- package/src/stats/rolling-window.d.ts +55 -0
- package/src/stats/rolling-window.test.ts +237 -0
- package/src/stats/rolling-window.ts +256 -0
- package/src/test-setup.ts +19 -0
- package/src/viewport/axis-state.d.ts +72 -0
- package/src/viewport/axis-state.ts +476 -0
- package/src/viewport.d.ts +170 -0
- package/src/viewport.test.ts +363 -0
- package/src/viewport.ts +510 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { createFrame } from "insomni";
|
|
3
|
+
import { describe, expect, test } from "vite-plus/test";
|
|
4
|
+
import { plot } from "../chart.ts";
|
|
5
|
+
import { resolveAes } from "../aes.ts";
|
|
6
|
+
import { buildPositionScale, type ScaleBundle } from "../scales.ts";
|
|
7
|
+
import { themeDefault } from "../theme.ts";
|
|
8
|
+
import { ridgeline } from "./ridgeline.ts";
|
|
9
|
+
import { emphasisKeyFor, geomEmphasisBase } from "./emphasis.ts";
|
|
10
|
+
import type { CompileContext } from "./types.ts";
|
|
11
|
+
|
|
12
|
+
// Fake Layer recording the emphasisKey of every primitive a ridge composites
|
|
13
|
+
// (KDE/hist polygon + silhouette polyline + baseline polyline + inner dot/line).
|
|
14
|
+
function makeKeyCapture() {
|
|
15
|
+
const keys: (number | undefined)[] = [];
|
|
16
|
+
const record = (s: { emphasisKey?: number }) => keys.push(s.emphasisKey);
|
|
17
|
+
const layer = {
|
|
18
|
+
pushRect: record,
|
|
19
|
+
pushCircle: record,
|
|
20
|
+
pushEllipse: record,
|
|
21
|
+
pushSegment: record,
|
|
22
|
+
pushLine: record,
|
|
23
|
+
pushPolyline: record,
|
|
24
|
+
pushPolygon: record,
|
|
25
|
+
pushText: () => layer,
|
|
26
|
+
pushString: () => layer,
|
|
27
|
+
};
|
|
28
|
+
return { layer, keys };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface Obs {
|
|
32
|
+
group: string;
|
|
33
|
+
value: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const fixture = {
|
|
37
|
+
threeGroups: (): Obs[] => {
|
|
38
|
+
const out: Obs[] = [];
|
|
39
|
+
const seeds = { A: 0.1, B: 0.5, C: 0.9 };
|
|
40
|
+
let r = 0;
|
|
41
|
+
const rand = () => {
|
|
42
|
+
r = (r * 9301 + 49297) % 233280;
|
|
43
|
+
return r / 233280;
|
|
44
|
+
};
|
|
45
|
+
for (const [name, mu] of Object.entries(seeds)) {
|
|
46
|
+
for (let i = 0; i < 50; i++) {
|
|
47
|
+
out.push({ group: name, value: mu + (rand() - 0.5) * 0.3 });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return out;
|
|
51
|
+
},
|
|
52
|
+
bimodal: (): Obs[] => {
|
|
53
|
+
const out: Obs[] = [];
|
|
54
|
+
for (let i = 0; i < 30; i++) out.push({ group: "A", value: 0.2 + i * 0.005 });
|
|
55
|
+
for (let i = 0; i < 30; i++) out.push({ group: "A", value: 0.8 + i * 0.005 });
|
|
56
|
+
return out;
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
describe("ridgeline()", () => {
|
|
61
|
+
test("renders one closed silhouette per category in KDE mode", () => {
|
|
62
|
+
const svg = plot({ data: fixture.threeGroups(), width: 480, height: 320 })
|
|
63
|
+
.layer(ridgeline({ x: "value", y: "group" }))
|
|
64
|
+
.toSVG();
|
|
65
|
+
expect(svg).toBeInstanceOf(SVGSVGElement);
|
|
66
|
+
expect(svg.querySelectorAll("polygon").length).toBeGreaterThan(0);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("histogram mode emits a step polygon per row", () => {
|
|
70
|
+
const svg = plot({ data: fixture.threeGroups(), width: 480, height: 320 })
|
|
71
|
+
.layer(
|
|
72
|
+
ridgeline(
|
|
73
|
+
{ x: "value", y: "group" },
|
|
74
|
+
{ geom: "histogram", bins: 12, baseline: false, inner: "none" },
|
|
75
|
+
),
|
|
76
|
+
)
|
|
77
|
+
.toSVG();
|
|
78
|
+
expect(svg.querySelectorAll("polygon").length).toBeGreaterThan(0);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("gradient fill renders alongside solid fill (both produce output)", () => {
|
|
82
|
+
// The SVG renderer tessellates each `pushPolygon` into many triangles, so
|
|
83
|
+
// probing exact element counts is fragile. Verify both modes render
|
|
84
|
+
// without throwing and produce non-empty SVG output.
|
|
85
|
+
const svgSolid = plot({ data: fixture.threeGroups(), width: 320, height: 240 })
|
|
86
|
+
.layer(
|
|
87
|
+
ridgeline(
|
|
88
|
+
{ x: "value", y: "group" },
|
|
89
|
+
{ fillMode: "solid", baseline: false, inner: "none", gridSize: 32 },
|
|
90
|
+
),
|
|
91
|
+
)
|
|
92
|
+
.toSVG();
|
|
93
|
+
const svgGrad = plot({ data: fixture.threeGroups(), width: 320, height: 240 })
|
|
94
|
+
.layer(
|
|
95
|
+
ridgeline(
|
|
96
|
+
{ x: "value", y: "group" },
|
|
97
|
+
{ fillMode: "gradient", baseline: false, inner: "none", gridSize: 32 },
|
|
98
|
+
),
|
|
99
|
+
)
|
|
100
|
+
.toSVG();
|
|
101
|
+
expect(svgSolid.querySelectorAll("polygon").length).toBeGreaterThan(0);
|
|
102
|
+
expect(svgGrad.querySelectorAll("polygon").length).toBeGreaterThan(0);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("does not throw on degenerate samples (n=1, all-equal)", () => {
|
|
106
|
+
expect(() =>
|
|
107
|
+
plot({ data: [{ group: "A", value: 5 }] as Obs[] })
|
|
108
|
+
.layer(ridgeline({ x: "value", y: "group" }))
|
|
109
|
+
.toSVG({ width: 200, height: 200 }),
|
|
110
|
+
).not.toThrow();
|
|
111
|
+
expect(() =>
|
|
112
|
+
plot({ data: [3, 3, 3, 3].map((v) => ({ group: "A", value: v })) as Obs[] })
|
|
113
|
+
.layer(ridgeline({ x: "value", y: "group" }))
|
|
114
|
+
.toSVG({ width: 200, height: 200 }),
|
|
115
|
+
).not.toThrow();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("scale: 'count' / 'area' / 'width' all render", () => {
|
|
119
|
+
for (const mode of ["width", "area", "count"] as const) {
|
|
120
|
+
const svg = plot({ data: fixture.threeGroups(), width: 400, height: 300 })
|
|
121
|
+
.layer(ridgeline({ x: "value", y: "group" }, { scale: mode }))
|
|
122
|
+
.toSVG();
|
|
123
|
+
expect(svg).toBeInstanceOf(SVGSVGElement);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test("inner: 'median' / 'quartile' / 'mean' all render without throwing", () => {
|
|
128
|
+
for (const inner of ["median", "quartile", "mean"] as const) {
|
|
129
|
+
const svg = plot({ data: fixture.threeGroups(), width: 320, height: 240 })
|
|
130
|
+
.layer(ridgeline({ x: "value", y: "group" }, { inner }))
|
|
131
|
+
.toSVG();
|
|
132
|
+
expect(svg).toBeInstanceOf(SVGSVGElement);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("orientation auto-detect: y-band vs x-band", () => {
|
|
137
|
+
const svgYBand = plot({ data: fixture.threeGroups(), width: 320, height: 240 })
|
|
138
|
+
.layer(ridgeline({ x: "value", y: "group" }))
|
|
139
|
+
.toSVG();
|
|
140
|
+
const svgXBand = plot({ data: fixture.threeGroups(), width: 320, height: 240 })
|
|
141
|
+
.layer(ridgeline({ x: "group", y: "value" }))
|
|
142
|
+
.toSVG();
|
|
143
|
+
expect(svgYBand.querySelectorAll("polygon").length).toBeGreaterThan(0);
|
|
144
|
+
expect(svgXBand.querySelectorAll("polygon").length).toBeGreaterThan(0);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test("overlap factor scales row height (3x produces measurably taller silhouettes)", () => {
|
|
148
|
+
const svgFlat = plot({ data: fixture.bimodal(), width: 320, height: 240 })
|
|
149
|
+
.layer(ridgeline({ x: "value", y: "group" }, { overlap: 1, baseline: false }))
|
|
150
|
+
.toSVG();
|
|
151
|
+
const svgTall = plot({ data: fixture.bimodal(), width: 320, height: 240 })
|
|
152
|
+
.layer(ridgeline({ x: "value", y: "group" }, { overlap: 3, baseline: false }))
|
|
153
|
+
.toSVG();
|
|
154
|
+
// Both should produce polygons; we don't probe geometry directly, but we
|
|
155
|
+
// confirm both render without error.
|
|
156
|
+
expect(svgFlat.querySelectorAll("polygon").length).toBeGreaterThan(0);
|
|
157
|
+
expect(svgTall.querySelectorAll("polygon").length).toBeGreaterThan(0);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test("baseline: true draws an additional polygon per row vs. baseline: false", () => {
|
|
161
|
+
// `pushPolyline` is tessellated into triangles → emitted as <polygon>.
|
|
162
|
+
// Each row's baseline polyline contributes a couple of triangles, so the
|
|
163
|
+
// baseline-on chart emits strictly more <polygon> elements.
|
|
164
|
+
const data = fixture.threeGroups();
|
|
165
|
+
const withBase = plot({ data, width: 320, height: 240 })
|
|
166
|
+
.layer(ridgeline({ x: "value", y: "group" }, { baseline: true, inner: "none" }))
|
|
167
|
+
.toSVG();
|
|
168
|
+
const noBase = plot({ data, width: 320, height: 240 })
|
|
169
|
+
.layer(ridgeline({ x: "value", y: "group" }, { baseline: false, inner: "none" }))
|
|
170
|
+
.toSVG();
|
|
171
|
+
const polysWith = withBase.querySelectorAll("polygon").length;
|
|
172
|
+
const polysNo = noBase.querySelectorAll("polygon").length;
|
|
173
|
+
expect(polysWith).toBeGreaterThan(polysNo);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("compileHitTest emits one hit per row at (median, bandCenter)", () => {
|
|
177
|
+
const data = fixture.threeGroups();
|
|
178
|
+
const xAes = resolveAes<Obs, unknown>("value");
|
|
179
|
+
const yAes = resolveAes<Obs, unknown>("group");
|
|
180
|
+
const xScale = buildPositionScale(xAes, data, [0, 300]);
|
|
181
|
+
const yScale = buildPositionScale(yAes, data, [200, 0], { type: "band", padding: 0 });
|
|
182
|
+
const scales: ScaleBundle = { x: xScale, y: yScale };
|
|
183
|
+
const ctx: CompileContext<Obs> = {
|
|
184
|
+
data,
|
|
185
|
+
scales,
|
|
186
|
+
plot: createFrame({ x: 50, y: 30, width: 300, height: 200 }),
|
|
187
|
+
theme: themeDefault,
|
|
188
|
+
atlas: undefined,
|
|
189
|
+
};
|
|
190
|
+
const geom = ridgeline<Obs>({ x: "value", y: "group" });
|
|
191
|
+
const hits = geom.compileHitTest!(ctx)!;
|
|
192
|
+
expect(hits.geomKind).toBe("ridgeline");
|
|
193
|
+
expect(hits.dataIndex.length).toBe(3);
|
|
194
|
+
expect(new Set(hits.seriesKey)).toEqual(new Set(["A", "B", "C"]));
|
|
195
|
+
// size channel surfaces sample size per row.
|
|
196
|
+
expect(hits.channels.size!.fn(data[0]!, 0)).toBe(50);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
describe("ridgeline() — GPU hover emphasis (P5-T3 Gap 1)", () => {
|
|
201
|
+
function makeCtx(data: Obs[], emphasis = true): CompileContext<Obs> {
|
|
202
|
+
const xAes = resolveAes<Obs, unknown>("value");
|
|
203
|
+
const yAes = resolveAes<Obs, unknown>("group");
|
|
204
|
+
const xScale = buildPositionScale(xAes, data, [0, 300]);
|
|
205
|
+
const yScale = buildPositionScale(yAes, data, [200, 0], { type: "band", padding: 0 });
|
|
206
|
+
const scales: ScaleBundle = { x: xScale, y: yScale };
|
|
207
|
+
return {
|
|
208
|
+
data,
|
|
209
|
+
scales,
|
|
210
|
+
plot: createFrame({ x: 50, y: 30, width: 300, height: 200 }),
|
|
211
|
+
theme: themeDefault,
|
|
212
|
+
atlas: undefined,
|
|
213
|
+
emphasisBase: emphasis ? geomEmphasisBase(0) : undefined,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
test("tagging present + every primitive of a single row shares ONE key", () => {
|
|
218
|
+
const data = fixture.bimodal(); // one row "A"
|
|
219
|
+
const geom = ridgeline<Obs>({ x: "value", y: "group" }, { inner: "quartile", baseline: true });
|
|
220
|
+
const { layer, keys } = makeKeyCapture();
|
|
221
|
+
for (const b of geom.compile(makeCtx(data))) b.addTo(layer as never);
|
|
222
|
+
const nonzero = keys.filter((k): k is number => k !== undefined && k >= 1);
|
|
223
|
+
expect(nonzero.length).toBeGreaterThan(0);
|
|
224
|
+
const expected = emphasisKeyFor(geomEmphasisBase(0), 0);
|
|
225
|
+
expect(new Set(nonzero)).toEqual(new Set([expected]));
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test("emphasisResolution maps a hit's dataIndex (bucketIndex) to the tagged key", () => {
|
|
229
|
+
const data = fixture.threeGroups();
|
|
230
|
+
const geom = ridgeline<Obs>({ x: "value", y: "group" });
|
|
231
|
+
const res = geom.emphasisResolution!(makeCtx(data))!;
|
|
232
|
+
expect(res.geomKind).toBe("ridgeline");
|
|
233
|
+
expect(res.resolve({ geomKind: "ridgeline", dataIndex: 2, data, x: 0, y: 0 })).toBe(
|
|
234
|
+
emphasisKeyFor(geomEmphasisBase(0), 2),
|
|
235
|
+
);
|
|
236
|
+
expect(res.resolve({ geomKind: "violin", dataIndex: 0, data, x: 0, y: 0 })).toBeNull();
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test("no emphasisBase (SSR/SVG) → rows untagged, no resolver key", () => {
|
|
240
|
+
const data = fixture.threeGroups();
|
|
241
|
+
const geom = ridgeline<Obs>({ x: "value", y: "group" });
|
|
242
|
+
const { layer, keys } = makeKeyCapture();
|
|
243
|
+
for (const b of geom.compile(makeCtx(data, false))) b.addTo(layer as never);
|
|
244
|
+
expect(keys.every((k) => k === undefined)).toBe(true);
|
|
245
|
+
expect(geom.emphasisResolution!(makeCtx(data, false))).toBeNull();
|
|
246
|
+
});
|
|
247
|
+
});
|