@tetrascience-npm/ts-lib-viz 0.0.0-stage → 0.1.5
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 +202 -0
- package/README.md +2171 -2
- package/dist/src/builder/PlotPanel.d.ts +42 -0
- package/dist/src/builder/PlotPanel.js +433 -0
- package/dist/src/builder/Popover.d.ts +37 -0
- package/dist/src/builder/Popover.js +32 -0
- package/dist/src/builder/Stepper.d.ts +21 -0
- package/dist/src/builder/Stepper.js +41 -0
- package/dist/src/builder/index.d.ts +10 -0
- package/dist/src/builder/index.js +10 -0
- package/dist/src/core/adapters.d.ts +86 -0
- package/dist/src/core/adapters.js +219 -0
- package/dist/src/core/aggregate.d.ts +74 -0
- package/dist/src/core/aggregate.js +102 -0
- package/dist/src/core/annotations.d.ts +34 -0
- package/dist/src/core/annotations.js +71 -0
- package/dist/src/core/band-order.d.ts +86 -0
- package/dist/src/core/band-order.js +132 -0
- package/dist/src/core/binning.d.ts +123 -0
- package/dist/src/core/binning.js +193 -0
- package/dist/src/core/bounds.d.ts +40 -0
- package/dist/src/core/bounds.js +107 -0
- package/dist/src/core/brush.d.ts +73 -0
- package/dist/src/core/brush.js +102 -0
- package/dist/src/core/build.d.ts +322 -0
- package/dist/src/core/build.js +496 -0
- package/dist/src/core/camera.d.ts +152 -0
- package/dist/src/core/camera.js +303 -0
- package/dist/src/core/capabilities.d.ts +24 -0
- package/dist/src/core/capabilities.js +307 -0
- package/dist/src/core/chord.d.ts +49 -0
- package/dist/src/core/chord.js +57 -0
- package/dist/src/core/circular.d.ts +83 -0
- package/dist/src/core/circular.js +63 -0
- package/dist/src/core/cluster.d.ts +136 -0
- package/dist/src/core/cluster.js +607 -0
- package/dist/src/core/critique.d.ts +92 -0
- package/dist/src/core/critique.js +905 -0
- package/dist/src/core/density.d.ts +38 -0
- package/dist/src/core/density.js +82 -0
- package/dist/src/core/figure-set.d.ts +34 -0
- package/dist/src/core/figure-set.js +55 -0
- package/dist/src/core/finding-codes.d.ts +10 -0
- package/dist/src/core/finding-codes.js +1 -0
- package/dist/src/core/fit-types.d.ts +46 -0
- package/dist/src/core/fit-types.js +7 -0
- package/dist/src/core/fitter.d.ts +62 -0
- package/dist/src/core/fitter.js +102 -0
- package/dist/src/core/frame-geometry.d.ts +407 -0
- package/dist/src/core/frame-geometry.js +612 -0
- package/dist/src/core/frame.d.ts +329 -0
- package/dist/src/core/frame.js +1432 -0
- package/dist/src/core/geom-table.d.ts +503 -0
- package/dist/src/core/geom-table.js +484 -0
- package/dist/src/core/geom-types.d.ts +182 -0
- package/dist/src/core/geom-types.js +17 -0
- package/dist/src/core/grammar.d.ts +359 -0
- package/dist/src/core/grammar.js +397 -0
- package/dist/src/core/heat-reductions.d.ts +36 -0
- package/dist/src/core/heat-reductions.js +133 -0
- package/dist/src/core/hexbin.d.ts +84 -0
- package/dist/src/core/hexbin.js +168 -0
- package/dist/src/core/hierarchy.d.ts +59 -0
- package/dist/src/core/hierarchy.js +248 -0
- package/dist/src/core/hit.d.ts +75 -0
- package/dist/src/core/hit.js +37 -0
- package/dist/src/core/index.d.ts +33 -0
- package/dist/src/core/index.js +18 -0
- package/dist/src/core/internal.d.ts +58 -0
- package/dist/src/core/internal.js +58 -0
- package/dist/src/core/labels.d.ts +37 -0
- package/dist/src/core/labels.js +54 -0
- package/dist/src/core/layers.d.ts +594 -0
- package/dist/src/core/layers.js +2892 -0
- package/dist/src/core/load.d.ts +17 -0
- package/dist/src/core/load.js +356 -0
- package/dist/src/core/marginal.d.ts +65 -0
- package/dist/src/core/marginal.js +116 -0
- package/dist/src/core/mesh.d.ts +69 -0
- package/dist/src/core/mesh.js +237 -0
- package/dist/src/core/omission.d.ts +41 -0
- package/dist/src/core/omission.js +62 -0
- package/dist/src/core/palette-sets.d.ts +623 -0
- package/dist/src/core/palette-sets.js +1058 -0
- package/dist/src/core/palette.d.ts +871 -0
- package/dist/src/core/palette.js +511 -0
- package/dist/src/core/plot-data.d.ts +71 -0
- package/dist/src/core/plot-data.js +82 -0
- package/dist/src/core/predicate.d.ts +50 -0
- package/dist/src/core/predicate.js +20 -0
- package/dist/src/core/profile.d.ts +111 -0
- package/dist/src/core/profile.js +221 -0
- package/dist/src/core/readout.d.ts +108 -0
- package/dist/src/core/readout.js +215 -0
- package/dist/src/core/region.d.ts +56 -0
- package/dist/src/core/region.js +101 -0
- package/dist/src/core/rings.d.ts +96 -0
- package/dist/src/core/rings.js +171 -0
- package/dist/src/core/rules.d.ts +45 -0
- package/dist/src/core/rules.js +69 -0
- package/dist/src/core/sankey.d.ts +49 -0
- package/dist/src/core/sankey.js +96 -0
- package/dist/src/core/select.d.ts +52 -0
- package/dist/src/core/select.js +216 -0
- package/dist/src/core/side-track.d.ts +98 -0
- package/dist/src/core/side-track.js +197 -0
- package/dist/src/core/sizing.d.ts +54 -0
- package/dist/src/core/sizing.js +37 -0
- package/dist/src/core/spec-edit.d.ts +68 -0
- package/dist/src/core/spec-edit.js +105 -0
- package/dist/src/core/spec.d.ts +1111 -0
- package/dist/src/core/spec.js +39 -0
- package/dist/src/core/stats.d.ts +161 -0
- package/dist/src/core/stats.js +318 -0
- package/dist/src/core/tick-format.d.ts +21 -0
- package/dist/src/core/tick-format.js +87 -0
- package/dist/src/core/tokens.d.ts +47 -0
- package/dist/src/core/tokens.js +138 -0
- package/dist/src/core/transform.d.ts +21 -0
- package/dist/src/core/transform.js +19 -0
- package/dist/src/core/voxels.d.ts +53 -0
- package/dist/src/core/voxels.js +129 -0
- package/dist/src/core/zoom.d.ts +76 -0
- package/dist/src/core/zoom.js +103 -0
- package/dist/src/graph/GraphSurface.d.ts +127 -0
- package/dist/src/graph/GraphSurface.js +423 -0
- package/dist/src/graph/data.d.ts +103 -0
- package/dist/src/graph/data.js +140 -0
- package/dist/src/graph/index.d.ts +7 -0
- package/dist/src/graph/index.js +7 -0
- package/dist/src/mcp/data.d.ts +28 -0
- package/dist/src/mcp/data.js +131 -0
- package/dist/src/mcp/index.d.ts +7 -0
- package/dist/src/mcp/index.js +7 -0
- package/dist/src/mcp/paths.d.ts +12 -0
- package/dist/src/mcp/paths.js +30 -0
- package/dist/src/mcp/render.d.ts +67 -0
- package/dist/src/mcp/render.js +189 -0
- package/dist/src/mcp/server.d.ts +7 -0
- package/dist/src/mcp/server.js +25 -0
- package/dist/src/mcp/tools.d.ts +82 -0
- package/dist/src/mcp/tools.js +412 -0
- package/dist/src/react/BrushLayer.d.ts +20 -0
- package/dist/src/react/BrushLayer.js +98 -0
- package/dist/src/react/ColorLegend.d.ts +45 -0
- package/dist/src/react/ColorLegend.js +64 -0
- package/dist/src/react/Figure.d.ts +19 -0
- package/dist/src/react/Figure.js +6 -0
- package/dist/src/react/Frame.d.ts +87 -0
- package/dist/src/react/Frame.js +192 -0
- package/dist/src/react/MarkLegend.d.ts +32 -0
- package/dist/src/react/MarkLegend.js +24 -0
- package/dist/src/react/SeriesLegend.d.ts +38 -0
- package/dist/src/react/SeriesLegend.js +27 -0
- package/dist/src/react/SizeLegend.d.ts +24 -0
- package/dist/src/react/SizeLegend.js +25 -0
- package/dist/src/react/Toolbar.d.ts +109 -0
- package/dist/src/react/Toolbar.js +483 -0
- package/dist/src/react/Tooltip.d.ts +37 -0
- package/dist/src/react/Tooltip.js +59 -0
- package/dist/src/react/Viz.d.ts +112 -0
- package/dist/src/react/Viz.js +1311 -0
- package/dist/src/react/export.d.ts +32 -0
- package/dist/src/react/export.js +181 -0
- package/dist/src/react/geoms/Area.d.ts +38 -0
- package/dist/src/react/geoms/Area.js +48 -0
- package/dist/src/react/geoms/Bars.d.ts +130 -0
- package/dist/src/react/geoms/Bars.js +164 -0
- package/dist/src/react/geoms/Box.d.ts +50 -0
- package/dist/src/react/geoms/Box.js +32 -0
- package/dist/src/react/geoms/Chord.d.ts +60 -0
- package/dist/src/react/geoms/Chord.js +78 -0
- package/dist/src/react/geoms/Contour.d.ts +44 -0
- package/dist/src/react/geoms/Contour.js +78 -0
- package/dist/src/react/geoms/DensityCurve.d.ts +30 -0
- package/dist/src/react/geoms/DensityCurve.js +38 -0
- package/dist/src/react/geoms/FitCurve.d.ts +26 -0
- package/dist/src/react/geoms/FitCurve.js +52 -0
- package/dist/src/react/geoms/Freqpoly.d.ts +30 -0
- package/dist/src/react/geoms/Freqpoly.js +45 -0
- package/dist/src/react/geoms/Gauge.d.ts +42 -0
- package/dist/src/react/geoms/Gauge.js +90 -0
- package/dist/src/react/geoms/Heatmap.d.ts +79 -0
- package/dist/src/react/geoms/Heatmap.js +51 -0
- package/dist/src/react/geoms/Hexbin.d.ts +74 -0
- package/dist/src/react/geoms/Hexbin.js +89 -0
- package/dist/src/react/geoms/Icicle.d.ts +38 -0
- package/dist/src/react/geoms/Icicle.js +9 -0
- package/dist/src/react/geoms/Ideogram.d.ts +58 -0
- package/dist/src/react/geoms/Ideogram.js +77 -0
- package/dist/src/react/geoms/Interval.d.ts +30 -0
- package/dist/src/react/geoms/Interval.js +39 -0
- package/dist/src/react/geoms/Line.d.ts +39 -0
- package/dist/src/react/geoms/Line.js +52 -0
- package/dist/src/react/geoms/Parallel.d.ts +38 -0
- package/dist/src/react/geoms/Parallel.js +131 -0
- package/dist/src/react/geoms/Pie.d.ts +62 -0
- package/dist/src/react/geoms/Pie.js +59 -0
- package/dist/src/react/geoms/Points.d.ts +84 -0
- package/dist/src/react/geoms/Points.js +207 -0
- package/dist/src/react/geoms/Points3d.d.ts +49 -0
- package/dist/src/react/geoms/Points3d.js +58 -0
- package/dist/src/react/geoms/Radar.d.ts +39 -0
- package/dist/src/react/geoms/Radar.js +59 -0
- package/dist/src/react/geoms/Range.d.ts +31 -0
- package/dist/src/react/geoms/Range.js +20 -0
- package/dist/src/react/geoms/RingStack.d.ts +39 -0
- package/dist/src/react/geoms/RingStack.js +65 -0
- package/dist/src/react/geoms/Rule.d.ts +29 -0
- package/dist/src/react/geoms/Rule.js +51 -0
- package/dist/src/react/geoms/Sankey.d.ts +24 -0
- package/dist/src/react/geoms/Sankey.js +51 -0
- package/dist/src/react/geoms/Segment.d.ts +36 -0
- package/dist/src/react/geoms/Segment.js +39 -0
- package/dist/src/react/geoms/Sunburst.d.ts +46 -0
- package/dist/src/react/geoms/Sunburst.js +64 -0
- package/dist/src/react/geoms/Surface.d.ts +32 -0
- package/dist/src/react/geoms/Surface.js +49 -0
- package/dist/src/react/geoms/Text.d.ts +35 -0
- package/dist/src/react/geoms/Text.js +40 -0
- package/dist/src/react/geoms/Treemap.d.ts +39 -0
- package/dist/src/react/geoms/Treemap.js +16 -0
- package/dist/src/react/geoms/Violin.d.ts +56 -0
- package/dist/src/react/geoms/Violin.js +60 -0
- package/dist/src/react/geoms/Volume.d.ts +37 -0
- package/dist/src/react/geoms/Volume.js +40 -0
- package/dist/src/react/geoms/Waterfall.d.ts +43 -0
- package/dist/src/react/geoms/Waterfall.js +18 -0
- package/dist/src/react/geoms/cube-stage.d.ts +39 -0
- package/dist/src/react/geoms/cube-stage.js +85 -0
- package/dist/src/react/geoms/hierarchy-cells.d.ts +42 -0
- package/dist/src/react/geoms/hierarchy-cells.js +59 -0
- package/dist/src/react/geoms/sector-axis.d.ts +66 -0
- package/dist/src/react/geoms/sector-axis.js +99 -0
- package/dist/src/react/gl/GlMesh.d.ts +22 -0
- package/dist/src/react/gl/GlMesh.js +78 -0
- package/dist/src/react/gl/GlPoints.d.ts +45 -0
- package/dist/src/react/gl/GlPoints.js +117 -0
- package/dist/src/react/gl/GlVolume.d.ts +28 -0
- package/dist/src/react/gl/GlVolume.js +112 -0
- package/dist/src/react/gl/GlWalls.d.ts +24 -0
- package/dist/src/react/gl/GlWalls.js +55 -0
- package/dist/src/react/gl/context.d.ts +71 -0
- package/dist/src/react/gl/context.js +98 -0
- package/dist/src/react/gl/encode.d.ts +120 -0
- package/dist/src/react/gl/encode.js +215 -0
- package/dist/src/react/gl/index.d.ts +10 -0
- package/dist/src/react/gl/index.js +8 -0
- package/dist/src/react/gl/refresh.d.ts +7 -0
- package/dist/src/react/gl/refresh.js +19 -0
- package/dist/src/react/gl/renderer.d.ts +377 -0
- package/dist/src/react/gl/renderer.js +1081 -0
- package/dist/src/react/gl/shaders.d.ts +92 -0
- package/dist/src/react/gl/shaders.js +405 -0
- package/dist/src/react/gl/surface.d.ts +31 -0
- package/dist/src/react/gl/surface.js +73 -0
- package/dist/src/react/index.d.ts +12 -0
- package/dist/src/react/index.js +11 -0
- package/dist/src/react/orbit.d.ts +38 -0
- package/dist/src/react/orbit.js +81 -0
- package/dist/src/react/sides/DendrogramPanel.d.ts +32 -0
- package/dist/src/react/sides/DendrogramPanel.js +39 -0
- package/dist/src/react/sides/DensityPanel.d.ts +31 -0
- package/dist/src/react/sides/DensityPanel.js +37 -0
- package/dist/src/react/sides/HistogramPanel.d.ts +30 -0
- package/dist/src/react/sides/HistogramPanel.js +18 -0
- package/dist/src/react/sides/RugPanel.d.ts +28 -0
- package/dist/src/react/sides/RugPanel.js +21 -0
- package/dist/src/react/sides/TrackPanel.d.ts +37 -0
- package/dist/src/react/sides/TrackPanel.js +27 -0
- package/dist/src/react/theme.d.ts +48 -0
- package/dist/src/react/theme.js +148 -0
- package/dist/src/react/useFits.d.ts +26 -0
- package/dist/src/react/useFits.js +62 -0
- package/dist/src/react/useZoom.d.ts +50 -0
- package/dist/src/react/useZoom.js +141 -0
- package/package.json +164 -5
- package/theme/default.css +62 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
export function Violin({ data, x, y, band, ramp, thickness, opacity = 0.72, stroke, lineWidth = 0.9, transposed = false, side = "both", showMedian = true, onHover, onSelect, }) {
|
|
3
|
+
const half = thickness != null ? Math.min(band, thickness) / 2 : Math.min(band * 0.42, 34);
|
|
4
|
+
/* The band's scale is whichever one the density does not read. */
|
|
5
|
+
const along = transposed ? y : x;
|
|
6
|
+
const measure = transposed ? x : y;
|
|
7
|
+
/* A vertex named by role, handed to the screen the way round the frame drew. */
|
|
8
|
+
const at = (band_, on) => (transposed ? `${on},${band_}` : `${band_},${on}`);
|
|
9
|
+
return (_jsx("g", { children: data.map((d, index) => {
|
|
10
|
+
const cx = along(d.category);
|
|
11
|
+
const color = ramp(d.median);
|
|
12
|
+
const middle = measure(d.median);
|
|
13
|
+
const hit = { datum: d, index, at: transposed ? { x: middle, y: cx } : { x: cx, y: middle } };
|
|
14
|
+
/*
|
|
15
|
+
Both sides, or one of them.
|
|
16
|
+
|
|
17
|
+
Mirroring is the default and reads as a distribution: the shape is symmetric about the
|
|
18
|
+
band and a reader takes width off either arm. One side is what a raincloud wants, and
|
|
19
|
+
what it buys is the other half of the band, which the box and the readings go into. The
|
|
20
|
+
flat edge sits on the band center, so the three layers of a raincloud share one line.
|
|
21
|
+
|
|
22
|
+
The offset is band space and the grid is measure space, so `at` carries a transpose for
|
|
23
|
+
free: which screen axis the arm runs along is the frame's answer and not this one's.
|
|
24
|
+
*/
|
|
25
|
+
const outward = side === "low" ? -1 : 1;
|
|
26
|
+
const arm = d.grid.map((value, i) => `${i === 0 ? "M" : "L"}${at(cx + outward * d.weight[i] * half, measure(value))}`);
|
|
27
|
+
const back = side === "both"
|
|
28
|
+
? d.grid.map((value, i) => `L${at(cx - d.weight[i] * half, measure(value))}`).reverse()
|
|
29
|
+
: [`L${at(cx, measure(d.grid[d.grid.length - 1]))}`, `L${at(cx, measure(d.grid[0]))}`];
|
|
30
|
+
const outline = [...arm, ...back, "Z"].join("");
|
|
31
|
+
/* A mirrored median spans the band; a one-sided one starts at the flat edge. */
|
|
32
|
+
const medianFrom = side === "both" ? cx - half * 0.5 : cx;
|
|
33
|
+
const medianTo = side === "both" ? cx + half * 0.5 : cx + outward * half * 0.6;
|
|
34
|
+
/*
|
|
35
|
+
How wide the outline is at one reading, for the quantile lines the statistic asked for.
|
|
36
|
+
|
|
37
|
+
Read off the estimate instead of drawn at a fixed length, so a line stops where the density
|
|
38
|
+
it sits inside stops. A quartile line running past the arm would claim width the estimate
|
|
39
|
+
does not carry, which is the thing a violin exists to state.
|
|
40
|
+
*/
|
|
41
|
+
const widthAt = (value) => {
|
|
42
|
+
let nearest = 0;
|
|
43
|
+
let gap = Infinity;
|
|
44
|
+
for (let i = 0; i < d.grid.length; i += 1) {
|
|
45
|
+
const away = Math.abs(d.grid[i] - value);
|
|
46
|
+
if (away < gap) {
|
|
47
|
+
gap = away;
|
|
48
|
+
nearest = i;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return (d.weight[nearest] ?? 0) * half;
|
|
52
|
+
};
|
|
53
|
+
return (_jsxs("g", { "data-geom": "violin", onMouseEnter: () => onHover?.(hit), onMouseLeave: () => onHover?.(null), onClick: onSelect ? () => onSelect(hit) : undefined, style: onSelect ? { cursor: "pointer" } : undefined, children: [_jsx("path", { d: outline, fill: color, fillOpacity: opacity, stroke: stroke ?? color, strokeWidth: lineWidth }), (d.quantiles ?? []).map((value) => {
|
|
54
|
+
const span = widthAt(value);
|
|
55
|
+
const from = side === "both" ? cx - span : cx;
|
|
56
|
+
const to = cx + outward * span;
|
|
57
|
+
return (_jsx("line", { x1: transposed ? measure(value) : from, x2: transposed ? measure(value) : to, y1: transposed ? from : measure(value), y2: transposed ? to : measure(value), stroke: "var(--viz-paper)", strokeWidth: 0.8, strokeOpacity: 0.55 }, value));
|
|
58
|
+
}), showMedian && (_jsx("line", { x1: transposed ? measure(d.median) : medianFrom, x2: transposed ? measure(d.median) : medianTo, y1: transposed ? medianFrom : measure(d.median), y2: transposed ? medianTo : measure(d.median), stroke: "var(--viz-paper)", strokeWidth: 1.6, strokeOpacity: 0.85 }))] }, d.category));
|
|
59
|
+
}) }));
|
|
60
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A field read through its depth, as a shell or as a whole.
|
|
3
|
+
*
|
|
4
|
+
* `isosurface` draws where the field holds one value, which is the shape a threshold picks out of a
|
|
5
|
+
* cloud. `volume` integrates along the ray, which shows the field's own falloff instead of one
|
|
6
|
+
* level of it. Both are the honest 3D case the design language already allowed, and both need the
|
|
7
|
+
* camera the amendment added: a still projection of a translucent field is a picture nobody can
|
|
8
|
+
* read the depth of.
|
|
9
|
+
*
|
|
10
|
+
* The level a shell stands at is a reading, so it is stated in the figure instead of left to a
|
|
11
|
+
* default nobody sees. See the ADR "A third position scale is permitted where the reader can
|
|
12
|
+
* rotate".
|
|
13
|
+
*/
|
|
14
|
+
import { type Field3d, type LayerStyle, type ThemeSnapshot } from "../../core/internal.js";
|
|
15
|
+
import type { UnitRamp } from "../../core/internal.js";
|
|
16
|
+
export interface VolumeProps {
|
|
17
|
+
field: Field3d;
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
/** The magnitude map over nought to one, in the CSS the rest of the chart is drawn in. */
|
|
21
|
+
ramp: UnitRamp;
|
|
22
|
+
labels: {
|
|
23
|
+
x: string;
|
|
24
|
+
y: string;
|
|
25
|
+
z: string;
|
|
26
|
+
};
|
|
27
|
+
format?: (value: number) => string;
|
|
28
|
+
/** Which back faces of the box take a pane. */
|
|
29
|
+
panes?: LayerStyle["panes"];
|
|
30
|
+
/** The live token values where the chart sits, for the GL path's colors. */
|
|
31
|
+
theme?: ThemeSnapshot | null;
|
|
32
|
+
/** Set for the shell, clear for the integrated read. */
|
|
33
|
+
iso: boolean;
|
|
34
|
+
/** Where the shell stands, over nought to one. Absent puts it at the middle of the range. */
|
|
35
|
+
isoLevel?: number;
|
|
36
|
+
}
|
|
37
|
+
export declare function Volume({ field, width, height, ramp, labels, format, panes, theme, iso, isoLevel }: VolumeProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A field read through its depth, as a shell or as a whole.
|
|
4
|
+
*
|
|
5
|
+
* `isosurface` draws where the field holds one value, which is the shape a threshold picks out of a
|
|
6
|
+
* cloud. `volume` integrates along the ray, which shows the field's own falloff instead of one
|
|
7
|
+
* level of it. Both are the honest 3D case the design language already allowed, and both need the
|
|
8
|
+
* camera the amendment added: a still projection of a translucent field is a picture nobody can
|
|
9
|
+
* read the depth of.
|
|
10
|
+
*
|
|
11
|
+
* The level a shell stands at is a reading, so it is stated in the figure instead of left to a
|
|
12
|
+
* default nobody sees. See the ADR "A third position scale is permitted where the reader can
|
|
13
|
+
* rotate".
|
|
14
|
+
*/
|
|
15
|
+
import { useMemo } from "react";
|
|
16
|
+
import { rgbOf } from "../../core/internal.js";
|
|
17
|
+
import { GlVolume } from "../gl/GlVolume.js";
|
|
18
|
+
import { CubeStage } from "./cube-stage.js";
|
|
19
|
+
const MUTED = [0.55, 0.55, 0.58];
|
|
20
|
+
export function Volume({ field, width, height, ramp, labels, format, panes, theme, iso, isoLevel = 0.5 }) {
|
|
21
|
+
const domains = useMemo(() => ({ x: field.xDomain, y: field.yDomain, z: field.zDomain }), [field.xDomain, field.yDomain, field.zDomain]);
|
|
22
|
+
const center = useMemo(() => [
|
|
23
|
+
(field.xDomain[0] + field.xDomain[1]) / 2,
|
|
24
|
+
(field.yDomain[0] + field.yDomain[1]) / 2,
|
|
25
|
+
(field.zDomain[0] + field.zDomain[1]) / 2,
|
|
26
|
+
], [field.xDomain, field.yDomain, field.zDomain]);
|
|
27
|
+
const glRamp = useMemo(() => {
|
|
28
|
+
const cache = new Map();
|
|
29
|
+
return (t) => {
|
|
30
|
+
const step = Math.round(t * 64) / 64;
|
|
31
|
+
const held = cache.get(step);
|
|
32
|
+
if (held)
|
|
33
|
+
return held;
|
|
34
|
+
const rgb = rgbOf(ramp(step)) ?? MUTED;
|
|
35
|
+
cache.set(step, rgb);
|
|
36
|
+
return rgb;
|
|
37
|
+
};
|
|
38
|
+
}, [ramp]);
|
|
39
|
+
return (_jsx(CubeStage, { domains: domains, center: center, width: width, height: height, labels: labels, format: format, panes: panes, theme: theme, children: ({ orbit }) => (_jsx(GlVolume, { field: field, orbit: orbit, width: width, height: height, ramp: glRamp, iso: iso, isoLevel: isoLevel })) }));
|
|
40
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Waterfall: signed steps standing on the running total of the ones before them.
|
|
3
|
+
*
|
|
4
|
+
* The bars are the bar geom's. A step is a `BarDatum` carrying a floor, and `stepped` in `/core`
|
|
5
|
+
* resolved those floors against the band's own order, so nothing here does arithmetic over the
|
|
6
|
+
* sequence. What this adds is the two readings a plain bar has no room for.
|
|
7
|
+
*
|
|
8
|
+
* A rise and a fall take separate paints. The direction of the move is what the reader follows down
|
|
9
|
+
* the band, and it is the one thing a floating block cannot say for itself: a bar sitting at 800 and
|
|
10
|
+
* running to 500 looks like a bar sitting at 500 and running to 800. Chart-design rule 8 asks that
|
|
11
|
+
* color encode something, and here it encodes the sign. Both come off the categorical map, since the
|
|
12
|
+
* semantic tones are reserved for status and a fall is a fall and not a failure.
|
|
13
|
+
*
|
|
14
|
+
* A connector joins the end of one step to the start of the next, at the height they share. It draws
|
|
15
|
+
* under the bars, so the gap between two bands is the part a reader sees, and the eye carries the
|
|
16
|
+
* total across instead of re-finding it. Rule 9 craft: a hairline in the muted ink, costing little
|
|
17
|
+
* and reading as care.
|
|
18
|
+
*/
|
|
19
|
+
import type { BarDatum, GeomHit, Scale } from "../../core/internal.js";
|
|
20
|
+
export interface WaterfallProps {
|
|
21
|
+
/** One step per category. Each carries the floor that `stepped` resolved for it. */
|
|
22
|
+
data: BarDatum[];
|
|
23
|
+
x: Scale;
|
|
24
|
+
y: Scale;
|
|
25
|
+
band: number;
|
|
26
|
+
/** Paint for a step that moved the total up. */
|
|
27
|
+
rise: string;
|
|
28
|
+
/** Paint for a step that moved it down. */
|
|
29
|
+
fall: string;
|
|
30
|
+
/** Widest a step is drawn. The band bounds it where the band is narrower. */
|
|
31
|
+
maxWidth?: number;
|
|
32
|
+
transposed?: boolean;
|
|
33
|
+
opacity?: number;
|
|
34
|
+
/** Outline paint on each step, and its width. Absent draws none. */
|
|
35
|
+
stroke?: string;
|
|
36
|
+
lineWidth?: number;
|
|
37
|
+
/** Ink on the rule joining one step to the next. Absent takes the muted ink. */
|
|
38
|
+
connector?: string;
|
|
39
|
+
active?: string | null;
|
|
40
|
+
onHover?: (hit: GeomHit<BarDatum> | null) => void;
|
|
41
|
+
onSelect?: (hit: GeomHit<BarDatum>) => void;
|
|
42
|
+
}
|
|
43
|
+
export declare function Waterfall({ data, x, y, band, rise, fall, maxWidth, transposed, opacity, stroke, lineWidth, connector, active, onHover, onSelect, }: WaterfallProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Bars } from "./Bars.js";
|
|
3
|
+
export function Waterfall({ data, x, y, band, rise, fall, maxWidth, transposed = false, opacity, stroke, lineWidth, connector = "var(--viz-ink-muted)", active, onHover, onSelect, }) {
|
|
4
|
+
if (data.length === 0)
|
|
5
|
+
return null;
|
|
6
|
+
/* A per-datum color is what `Bars` reads ahead of its own, so the sign lands on the datum. */
|
|
7
|
+
const painted = data.map((step) => ({ ...step, color: step.color ?? (step.value < 0 ? fall : rise) }));
|
|
8
|
+
const along = transposed ? y : x;
|
|
9
|
+
const measure = transposed ? x : y;
|
|
10
|
+
return (_jsxs("g", { "data-geom": "waterfall", children: [_jsx("g", { "data-geom": "waterfall-connectors", stroke: connector, strokeWidth: 1, strokeOpacity: 0.55, children: data.slice(0, -1).map((step, index) => {
|
|
11
|
+
const next = data[index + 1];
|
|
12
|
+
/* The height the two share, which is where one step finished and the next starts. */
|
|
13
|
+
const at = measure((step.floor ?? 0) + step.value);
|
|
14
|
+
const from = along(step.at ?? step.category);
|
|
15
|
+
const to = along(next.at ?? next.category);
|
|
16
|
+
return transposed ? (_jsx("line", { x1: at, x2: at, y1: from, y2: to }, step.category)) : (_jsx("line", { x1: from, x2: to, y1: at, y2: at }, step.category));
|
|
17
|
+
}) }), _jsx(Bars, { data: painted, x: x, y: y, band: band, segmentGap: 0, transposed: transposed, maxWidth: maxWidth, opacity: opacity, stroke: stroke, lineWidth: lineWidth, active: active, onHover: onHover, onSelect: onSelect })] }));
|
|
18
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The box a cube kind draws inside, and the gesture that turns it.
|
|
3
|
+
*
|
|
4
|
+
* Shared by the geoms that position in three scales, because the box, the labels and the camera are
|
|
5
|
+
* the same for a cloud and for a surface: what differs is what gets drawn inside. The design
|
|
6
|
+
* language's two conditions live here, so a kind cannot ship the third scale without them.
|
|
7
|
+
*
|
|
8
|
+
* The children take the matrix, so anything the CPU draws over the GPU's work lands where the
|
|
9
|
+
* camera put it. See the ADR "A third position scale is permitted where the reader can rotate".
|
|
10
|
+
*/
|
|
11
|
+
import { type ReactNode } from "react";
|
|
12
|
+
import { type CubeDomains, type LayerStyle, type Orbit, type ThemeSnapshot } from "../../core/internal.js";
|
|
13
|
+
export interface CubeView {
|
|
14
|
+
matrix: Float32Array;
|
|
15
|
+
orbit: Orbit;
|
|
16
|
+
/** Whether the press that just ended turned the box, so a geom can hold back its click. */
|
|
17
|
+
turned: () => boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface CubeStageProps {
|
|
20
|
+
domains: CubeDomains;
|
|
21
|
+
/** The center the layers packed against, so the box and the geoms agree about where nought is. */
|
|
22
|
+
center: [number, number, number];
|
|
23
|
+
width: number;
|
|
24
|
+
height: number;
|
|
25
|
+
labels: {
|
|
26
|
+
x: string;
|
|
27
|
+
y: string;
|
|
28
|
+
z: string;
|
|
29
|
+
};
|
|
30
|
+
format?: (value: number) => string;
|
|
31
|
+
/** Which back faces take a pane. Absent draws none. */
|
|
32
|
+
panes?: LayerStyle["panes"];
|
|
33
|
+
/** The live token values where the chart sits, for the GL path's colors. */
|
|
34
|
+
theme?: ThemeSnapshot | null;
|
|
35
|
+
children: (view: CubeView) => ReactNode;
|
|
36
|
+
}
|
|
37
|
+
export declare function CubeStage({ domains, center, width, height, labels, format, panes, theme, children, }: CubeStageProps): import("react").JSX.Element;
|
|
38
|
+
/** The middle of a set of readings, which is the center the GL layers pack against. */
|
|
39
|
+
export declare const middleOf: (values: number[]) => number;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The box a cube kind draws inside, and the gesture that turns it.
|
|
4
|
+
*
|
|
5
|
+
* Shared by the geoms that position in three scales, because the box, the labels and the camera are
|
|
6
|
+
* the same for a cloud and for a surface: what differs is what gets drawn inside. The design
|
|
7
|
+
* language's two conditions live here, so a kind cannot ship the third scale without them.
|
|
8
|
+
*
|
|
9
|
+
* The children take the matrix, so anything the CPU draws over the GPU's work lands where the
|
|
10
|
+
* camera put it. See the ADR "A third position scale is permitted where the reader can rotate".
|
|
11
|
+
*/
|
|
12
|
+
import { useMemo } from "react";
|
|
13
|
+
import { cubeChrome, cubeMatrix, projectData, } from "../../core/internal.js";
|
|
14
|
+
import { useOrbit } from "../orbit.js";
|
|
15
|
+
import { GlWalls } from "../gl/GlWalls.js";
|
|
16
|
+
import { useSharedRenderer } from "../gl/context.js";
|
|
17
|
+
/** The grid's width in CSS pixels, its token and its opacity. */
|
|
18
|
+
const GRID_WIDTH = 1.5;
|
|
19
|
+
const GRID_INK = "--viz-ink-muted";
|
|
20
|
+
const GRID_OPACITY = 0.5;
|
|
21
|
+
/** The box edges' opacity. */
|
|
22
|
+
const EDGE_OPACITY = 0.35;
|
|
23
|
+
/** The panes' token, and an opacity for each. Two shades keep the corner between the walls in view. */
|
|
24
|
+
const PANE_INK = "--viz-rule";
|
|
25
|
+
const PANE_OPACITY = { x: 0.45, y: 0.75, z: 0.6 };
|
|
26
|
+
/** Pixels a tick and a title stand off the box, away from its middle, so both clear the geoms. */
|
|
27
|
+
const TICK_CLEARANCE = 14;
|
|
28
|
+
const TITLE_CLEARANCE = 34;
|
|
29
|
+
/**
|
|
30
|
+
* A point moved off its own edge, away from the middle of the box.
|
|
31
|
+
*
|
|
32
|
+
* Pushing radially from the middle is the obvious move and it fails on the vertical scale: that
|
|
33
|
+
* edge runs close to the middle in x, so the direction away from it is barely a direction and the
|
|
34
|
+
* title lands on the geoms. Stepping along the edge's own perpendicular puts a label beside the
|
|
35
|
+
* rule it belongs to whichever way the cube is turned.
|
|
36
|
+
*/
|
|
37
|
+
function beside(point, edge, middle, by) {
|
|
38
|
+
const dx = edge.to.x - edge.from.x;
|
|
39
|
+
const dy = edge.to.y - edge.from.y;
|
|
40
|
+
const length = Math.hypot(dx, dy) || 1;
|
|
41
|
+
const nx = -dy / length;
|
|
42
|
+
const ny = dx / length;
|
|
43
|
+
// Whichever side of the rule is further from the middle is the side with room on it.
|
|
44
|
+
const sign = (point.x - middle.x) * nx + (point.y - middle.y) * ny >= 0 ? 1 : -1;
|
|
45
|
+
return { x: point.x + nx * by * sign, y: point.y + ny * by * sign };
|
|
46
|
+
}
|
|
47
|
+
export function CubeStage({ domains, center, width, height, labels, format = (value) => value.toLocaleString(undefined, { maximumSignificantDigits: 3 }), panes, theme, children, }) {
|
|
48
|
+
const orbit = useOrbit();
|
|
49
|
+
const renderer = useSharedRenderer();
|
|
50
|
+
/* One matrix a frame, shared by the box, the ticks and whatever the caller draws over them. */
|
|
51
|
+
const matrix = useMemo(() => cubeMatrix(orbit.orbit, width / (height || 1), domains, center), [orbit.orbit, width, height, domains, center]);
|
|
52
|
+
const chrome = useMemo(() => cubeChrome(matrix, domains, center, width, height), [matrix, domains, center, width, height]);
|
|
53
|
+
const filled = panes === "all" ? ["x", "y", "z"] : panes === "walls" ? ["x", "y"] : [];
|
|
54
|
+
return (
|
|
55
|
+
/*
|
|
56
|
+
The export reads this: a file cannot be turned, so a copy of a cube admits as much.
|
|
57
|
+
|
|
58
|
+
The gesture is read here and not on a rectangle inside, so a drag that starts over a geom
|
|
59
|
+
turns the box while the geom keeps the hover and the click that belong to it. What a geom
|
|
60
|
+
does not stop bubbles up to this group.
|
|
61
|
+
*/
|
|
62
|
+
_jsxs("g", { ref: orbit.ref, "data-viz-cube": "true", style: { cursor: orbit.turning ? "grabbing" : "grab", userSelect: "none", WebkitUserSelect: "none" }, onPointerDown: orbit.onPointerDown, onPointerMove: orbit.onPointerMove, onPointerUp: orbit.onPointerUp, onPointerCancel: orbit.onPointerUp, children: [renderer ? (_jsxs(_Fragment, { children: [filled.map((axis) => (_jsx(GlWalls, { panes: [chrome.walls.panes[axis]], domains: domains, orbit: orbit.orbit, width: width, height: height, color: PANE_INK, opacity: PANE_OPACITY[axis], theme: theme }, `pane${axis}`))), _jsx(GlWalls, { rules: chrome.walls.grid, domains: domains, orbit: orbit.orbit, width: width, height: height, color: GRID_INK, opacity: GRID_OPACITY, linewidth: GRID_WIDTH, theme: theme }), _jsx(GlWalls, { rules: chrome.walls.edges, domains: domains, orbit: orbit.orbit, width: width, height: height, color: "--viz-rule", opacity: EDGE_OPACITY, theme: theme })] })) : (_jsxs(_Fragment, { children: [filled.map((axis) => (_jsx("polygon", { "data-pane": axis, points: chrome.walls.panes[axis]
|
|
63
|
+
.map((point) => projectData(matrix, point, center, width, height))
|
|
64
|
+
.map((at) => `${at.x},${at.y}`)
|
|
65
|
+
.join(" "), fill: `var(${PANE_INK})`, fillOpacity: PANE_OPACITY[axis] }, `pane${axis}`))), chrome.grid.map((line, index) => (_jsx("line", { "data-grid": "major", x1: line.from.x, y1: line.from.y, x2: line.to.x, y2: line.to.y, stroke: `var(${GRID_INK})`, strokeOpacity: GRID_OPACITY, strokeWidth: GRID_WIDTH }, `grid${index}`)))] })), chrome.edges.map((edge, index) => renderer && edge.back ? null : (_jsx("line", { x1: edge.from.x, y1: edge.from.y, x2: edge.to.x, y2: edge.to.y, stroke: "var(--viz-rule)", strokeWidth: 1, opacity: EDGE_OPACITY }, index))), chrome.axes.map((axis) => {
|
|
66
|
+
const mid = { x: (axis.from.x + axis.to.x) / 2, y: (axis.from.y + axis.to.y) / 2 };
|
|
67
|
+
const title = beside(mid, axis, chrome.middle, TITLE_CLEARANCE);
|
|
68
|
+
return (_jsxs("g", { children: [axis.ticks.map((tick, index) => {
|
|
69
|
+
const at = beside(tick.at, axis, chrome.middle, TICK_CLEARANCE);
|
|
70
|
+
return (_jsx("text", { x: at.x, y: at.y, fontSize: 10, textAnchor: "middle", dominantBaseline: "middle", fill: "var(--viz-ink-muted)", children: format(tick.value) }, index));
|
|
71
|
+
}), _jsx("text", { x: title.x, y: title.y, fontSize: 11, textAnchor: "middle", dominantBaseline: "middle", fill: "var(--viz-ink)", children: labels[axis.axis] })] }, axis.axis));
|
|
72
|
+
}), _jsx("rect", { width: width, height: height, fill: "transparent" }), children({ matrix, orbit: orbit.orbit, turned: orbit.turned })] }));
|
|
73
|
+
}
|
|
74
|
+
/** The middle of a set of readings, which is the center the GL layers pack against. */
|
|
75
|
+
export const middleOf = (values) => {
|
|
76
|
+
let lo = Infinity;
|
|
77
|
+
let hi = -Infinity;
|
|
78
|
+
for (const value of values) {
|
|
79
|
+
if (value < lo)
|
|
80
|
+
lo = value;
|
|
81
|
+
if (value > hi)
|
|
82
|
+
hi = value;
|
|
83
|
+
}
|
|
84
|
+
return Number.isFinite(lo) ? (lo + hi) / 2 : 0;
|
|
85
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A hue per group, a fit test for a cell's name, and the scaling both packed layouts run.
|
|
3
|
+
*
|
|
4
|
+
* One hierarchy reaches two components and a reader meeting both in a figure is owed the same
|
|
5
|
+
* grouping and the same treatment of a cell too small to label. Held here instead of in either
|
|
6
|
+
* component, since neither is the other's parent, and out of `/react`'s barrel because a paint
|
|
7
|
+
* decision between two geoms is no part of the published surface.
|
|
8
|
+
*/
|
|
9
|
+
import { type HierarchyCell } from "../../core/internal.js";
|
|
10
|
+
/** Paper-colored stroke between two cells, per chart-design rule 9. */
|
|
11
|
+
export declare const EDGE = 1.5;
|
|
12
|
+
/**
|
|
13
|
+
* Picks a hue per cell off the group it draws in.
|
|
14
|
+
*
|
|
15
|
+
* The area or the width carries magnitude. Color names the group off the categorical map, per
|
|
16
|
+
* chart-design rule 8. A stated `fill` paints one hue.
|
|
17
|
+
*/
|
|
18
|
+
export declare function hueFor(cells: readonly HierarchyCell[], identity: (index: number) => string, fill?: string, levels?: readonly {
|
|
19
|
+
value: string;
|
|
20
|
+
code: number;
|
|
21
|
+
}[]): (cell: HierarchyCell) => string;
|
|
22
|
+
/** Ink for a name written inside a cell. A cell in no group writes in the page's own ink. */
|
|
23
|
+
export declare const labelInk: (hue: string) => string;
|
|
24
|
+
/**
|
|
25
|
+
* Answers whether a name and its lines fit inside a cell.
|
|
26
|
+
*
|
|
27
|
+
* A clipped name reads as a different name, so a cell with no room carries none. The estimate is the
|
|
28
|
+
* same `textRun` the margin and the band size read, so a cell and an axis agree about how wide a
|
|
29
|
+
* string runs.
|
|
30
|
+
*/
|
|
31
|
+
export declare const fits: (label: string, width: number, height: number, fontSize: number, lines: number) => boolean;
|
|
32
|
+
/** One cell in pixels, with the hue it draws in. */
|
|
33
|
+
export interface PlacedCell {
|
|
34
|
+
cell: HierarchyCell;
|
|
35
|
+
x: number;
|
|
36
|
+
y: number;
|
|
37
|
+
w: number;
|
|
38
|
+
h: number;
|
|
39
|
+
hue: string;
|
|
40
|
+
}
|
|
41
|
+
/** Scales the layout's fractions onto a panel, so a resize needs no new layout. */
|
|
42
|
+
export declare const placeCells: (cells: HierarchyCell[], width: number, height: number, hue: (cell: HierarchyCell) => string) => PlacedCell[];
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A hue per group, a fit test for a cell's name, and the scaling both packed layouts run.
|
|
3
|
+
*
|
|
4
|
+
* One hierarchy reaches two components and a reader meeting both in a figure is owed the same
|
|
5
|
+
* grouping and the same treatment of a cell too small to label. Held here instead of in either
|
|
6
|
+
* component, since neither is the other's parent, and out of `/react`'s barrel because a paint
|
|
7
|
+
* decision between two geoms is no part of the published surface.
|
|
8
|
+
*/
|
|
9
|
+
import { groupsOf, inkOn, textRun } from "../../core/internal.js";
|
|
10
|
+
/** Paper-colored stroke between two cells, per chart-design rule 9. */
|
|
11
|
+
export const EDGE = 1.5;
|
|
12
|
+
/** Room a label needs above and below the baseline before it is written inside a cell. */
|
|
13
|
+
const LINE_HEIGHT = 1.6;
|
|
14
|
+
/**
|
|
15
|
+
* Picks a hue per cell off the group it draws in.
|
|
16
|
+
*
|
|
17
|
+
* The area or the width carries magnitude. Color names the group off the categorical map, per
|
|
18
|
+
* chart-design rule 8. A stated `fill` paints one hue.
|
|
19
|
+
*/
|
|
20
|
+
export function hueFor(cells, identity, fill, levels) {
|
|
21
|
+
const groups = groupsOf(cells);
|
|
22
|
+
const heads = new Set(groups.values());
|
|
23
|
+
/* Absent levels number the groups largest first, the name breaking a tie. Each layout emits its cells in its own order. */
|
|
24
|
+
const named = levels ??
|
|
25
|
+
[
|
|
26
|
+
...new Set(cells
|
|
27
|
+
.filter((cell) => heads.has(cell.label))
|
|
28
|
+
.sort((a, b) => b.value - a.value || a.label.localeCompare(b.label))
|
|
29
|
+
.map((cell) => cell.label)),
|
|
30
|
+
].map((value, code) => ({ value, code }));
|
|
31
|
+
const codes = new Map(named.map((level) => [level.value, level.code]));
|
|
32
|
+
return (cell) => {
|
|
33
|
+
if (fill)
|
|
34
|
+
return fill;
|
|
35
|
+
const code = codes.get(groups.get(cell.label) ?? "");
|
|
36
|
+
return code == null ? UNGROUPED : identity(code);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** Paint for a cell in no group. The root of a single tree is one. */
|
|
40
|
+
const UNGROUPED = "var(--viz-rule)";
|
|
41
|
+
/** Ink for a name written inside a cell. A cell in no group writes in the page's own ink. */
|
|
42
|
+
export const labelInk = (hue) => (hue === UNGROUPED ? "var(--viz-ink)" : inkOn(hue));
|
|
43
|
+
/**
|
|
44
|
+
* Answers whether a name and its lines fit inside a cell.
|
|
45
|
+
*
|
|
46
|
+
* A clipped name reads as a different name, so a cell with no room carries none. The estimate is the
|
|
47
|
+
* same `textRun` the margin and the band size read, so a cell and an axis agree about how wide a
|
|
48
|
+
* string runs.
|
|
49
|
+
*/
|
|
50
|
+
export const fits = (label, width, height, fontSize, lines) => width > textRun(label.length, fontSize) + EDGE * 2 && height > fontSize * LINE_HEIGHT * lines;
|
|
51
|
+
/** Scales the layout's fractions onto a panel, so a resize needs no new layout. */
|
|
52
|
+
export const placeCells = (cells, width, height, hue) => cells.map((cell) => ({
|
|
53
|
+
cell,
|
|
54
|
+
x: cell.x0 * width,
|
|
55
|
+
y: cell.y0 * height,
|
|
56
|
+
w: (cell.x1 - cell.x0) * width,
|
|
57
|
+
h: (cell.y1 - cell.y0) * height,
|
|
58
|
+
hue: hue(cell),
|
|
59
|
+
}));
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The readings written round a set of sectors.
|
|
3
|
+
*
|
|
4
|
+
* A chord and an ideogram share it. Both write their readings radially at one type size.
|
|
5
|
+
*/
|
|
6
|
+
import { type PlacedSector, type RingLayout } from "../../core/internal.js";
|
|
7
|
+
/** Length of one tick outside the ring, in pixels. */
|
|
8
|
+
export declare const TICK_LEN = 4;
|
|
9
|
+
/** What a sector draws with once the categorical map has run out of colors. */
|
|
10
|
+
export declare const SECTOR_INK = "var(--viz-ink-muted)";
|
|
11
|
+
/**
|
|
12
|
+
* Hue per sector: its own color, the author's fill, then the categorical map.
|
|
13
|
+
*
|
|
14
|
+
* Past the map's length the sectors share one ink, and the names tell them apart.
|
|
15
|
+
*/
|
|
16
|
+
export declare function sectorHues(sectors: readonly {
|
|
17
|
+
id: string;
|
|
18
|
+
color?: string;
|
|
19
|
+
}[], identity: (index: number) => string, categoricalSize?: number, fill?: string): Map<string, string>;
|
|
20
|
+
/**
|
|
21
|
+
* Where a reading round the ring is written, kept upright down the left side.
|
|
22
|
+
*
|
|
23
|
+
* The angle folds into one turn first. A rotated ring runs past 360 degrees.
|
|
24
|
+
*/
|
|
25
|
+
export declare function writtenAt(panel: RingLayout, angle: number, radius: number): {
|
|
26
|
+
x: number;
|
|
27
|
+
y: number;
|
|
28
|
+
anchor: "start" | "end";
|
|
29
|
+
rotate: string;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Room the readings and the names claim outside a ring, in pixels.
|
|
33
|
+
*
|
|
34
|
+
* Built the way `axisRoom` builds a margin: the tick, the gap, the reading, then the name past a
|
|
35
|
+
* title's own padding.
|
|
36
|
+
*/
|
|
37
|
+
export declare function sectorTextRoom(longestName: number, fontSize: number): number;
|
|
38
|
+
export interface SectorTick {
|
|
39
|
+
key: string;
|
|
40
|
+
angle: number;
|
|
41
|
+
text: string;
|
|
42
|
+
}
|
|
43
|
+
export interface SectorAxisArgs {
|
|
44
|
+
sectors: readonly PlacedSector[];
|
|
45
|
+
panel: RingLayout;
|
|
46
|
+
/** Radius the ring reaches. The readings and the names stack outward from it. */
|
|
47
|
+
from: number;
|
|
48
|
+
fontSize: number;
|
|
49
|
+
/** A reading in its own units. Absent writes no readings and leaves the names against the ring. */
|
|
50
|
+
format?: (value: number) => string;
|
|
51
|
+
/** Which readings are written. Absent writes each one with room. */
|
|
52
|
+
wanted?: (value: number) => boolean;
|
|
53
|
+
}
|
|
54
|
+
export interface SectorAxis {
|
|
55
|
+
ticks: SectorTick[];
|
|
56
|
+
/** Radius the readings are written at. */
|
|
57
|
+
radius: number;
|
|
58
|
+
/** Radius the names clear the readings at. */
|
|
59
|
+
nameRadius: number;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Readings placed round the ring, minus the ones landing on a neighbor.
|
|
63
|
+
*
|
|
64
|
+
* The thinning runs across the whole turn. One sector's last reading meets the next one's first.
|
|
65
|
+
*/
|
|
66
|
+
export declare function sectorAxis({ sectors, panel, from, fontSize, format, wanted }: SectorAxisArgs): SectorAxis;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The readings written round a set of sectors.
|
|
3
|
+
*
|
|
4
|
+
* A chord and an ideogram share it. Both write their readings radially at one type size.
|
|
5
|
+
*/
|
|
6
|
+
import { polarPoint, sectorAngle, sectorTicks, textRun, withoutCollisions, LABEL_GAP, TITLE_PAD, } from "../../core/internal.js";
|
|
7
|
+
/** Room one radial reading claims along the ring, as a multiple of its type size. */
|
|
8
|
+
const PITCH = 1.35;
|
|
9
|
+
/** Length of one tick outside the ring, in pixels. */
|
|
10
|
+
export const TICK_LEN = 4;
|
|
11
|
+
/** What a sector draws with once the categorical map has run out of colors. */
|
|
12
|
+
export const SECTOR_INK = "var(--viz-ink-muted)";
|
|
13
|
+
/**
|
|
14
|
+
* Hue per sector: its own color, the author's fill, then the categorical map.
|
|
15
|
+
*
|
|
16
|
+
* Past the map's length the sectors share one ink, and the names tell them apart.
|
|
17
|
+
*/
|
|
18
|
+
export function sectorHues(sectors, identity, categoricalSize, fill) {
|
|
19
|
+
const flat = categoricalSize != null && sectors.length > categoricalSize;
|
|
20
|
+
return new Map(sectors.map((sector, index) => [sector.id, sector.color ?? fill ?? (flat ? SECTOR_INK : identity(index))]));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Where a reading round the ring is written, kept upright down the left side.
|
|
24
|
+
*
|
|
25
|
+
* The angle folds into one turn first. A rotated ring runs past 360 degrees.
|
|
26
|
+
*/
|
|
27
|
+
export function writtenAt(panel, angle, radius) {
|
|
28
|
+
const degrees = ((((angle * 180) / Math.PI) % 360) + 360) % 360;
|
|
29
|
+
const turned = degrees > 180;
|
|
30
|
+
const on = polarPoint(panel, radius, angle);
|
|
31
|
+
return {
|
|
32
|
+
x: on.x,
|
|
33
|
+
y: on.y,
|
|
34
|
+
anchor: turned ? "end" : "start",
|
|
35
|
+
rotate: `rotate(${turned ? degrees + 90 : degrees - 90} ${on.x} ${on.y})`,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Characters a reading is reserved room for before one is drawn.
|
|
40
|
+
*
|
|
41
|
+
* The room comes first and the readings follow, so the count is a guess. `150M` is four.
|
|
42
|
+
*/
|
|
43
|
+
const TICK_CHARS = 5;
|
|
44
|
+
/**
|
|
45
|
+
* Room the readings and the names claim outside a ring, in pixels.
|
|
46
|
+
*
|
|
47
|
+
* Built the way `axisRoom` builds a margin: the tick, the gap, the reading, then the name past a
|
|
48
|
+
* title's own padding.
|
|
49
|
+
*/
|
|
50
|
+
export function sectorTextRoom(longestName, fontSize) {
|
|
51
|
+
return TICK_LEN + LABEL_GAP + textRun(TICK_CHARS, fontSize) + TITLE_PAD + textRun(longestName, fontSize);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Readings placed round the ring, minus the ones landing on a neighbor.
|
|
55
|
+
*
|
|
56
|
+
* The thinning runs across the whole turn. One sector's last reading meets the next one's first.
|
|
57
|
+
*/
|
|
58
|
+
export function sectorAxis({ sectors, panel, from, fontSize, format, wanted }) {
|
|
59
|
+
const radius = from + TICK_LEN + LABEL_GAP;
|
|
60
|
+
if (!format)
|
|
61
|
+
return { ticks: [], radius, nameRadius: from + LABEL_GAP };
|
|
62
|
+
const opening = [];
|
|
63
|
+
const rest = [];
|
|
64
|
+
for (const sector of sectors) {
|
|
65
|
+
/* Room off the arc's own length. A sector too short for one reading asks for none. */
|
|
66
|
+
const arc = (sector.to - sector.from) * radius;
|
|
67
|
+
const fits = Math.floor(arc / (fontSize * PITCH));
|
|
68
|
+
if (fits < 1)
|
|
69
|
+
continue;
|
|
70
|
+
/* A step wider than the sector leaves `ticks` empty, and the sector's own start stands in. */
|
|
71
|
+
const readings = sectorTicks(sector, fits);
|
|
72
|
+
const held = (readings.length > 0 ? readings : [sector.xlim[0]]).filter((reading) => wanted?.(reading) ?? true);
|
|
73
|
+
held.forEach((reading, index) => {
|
|
74
|
+
const tick = { key: `${sector.id}-${reading}`, angle: sectorAngle(sector, reading), text: format(reading) };
|
|
75
|
+
(index === 0 ? opening : rest).push(tick);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/*
|
|
79
|
+
Each sector's own first reading is offered before any interior one.
|
|
80
|
+
|
|
81
|
+
`withoutCollisions` keeps what it meets first, so a sector holding one reading keeps it against
|
|
82
|
+
a neighbor's second.
|
|
83
|
+
*/
|
|
84
|
+
opening.sort((a, b) => a.angle - b.angle);
|
|
85
|
+
rest.sort((a, b) => a.angle - b.angle);
|
|
86
|
+
const offered = [...opening, ...rest];
|
|
87
|
+
/* A radial reading runs outward. What one claims along the ring is its own height. */
|
|
88
|
+
const side = fontSize * PITCH;
|
|
89
|
+
const boxes = offered.map((tick) => {
|
|
90
|
+
const on = polarPoint(panel, radius, tick.angle);
|
|
91
|
+
return { x: on.x, y: on.y, width: side, height: side };
|
|
92
|
+
});
|
|
93
|
+
const ticks = withoutCollisions(boxes)
|
|
94
|
+
.map((index) => offered[index])
|
|
95
|
+
.sort((a, b) => a.angle - b.angle);
|
|
96
|
+
/* The names clear the longest reading that survived, past a title's own padding. */
|
|
97
|
+
const longest = ticks.reduce((held, tick) => Math.max(held, tick.text.length), 0);
|
|
98
|
+
return { ticks, radius, nameRadius: radius + textRun(longest, fontSize) + TITLE_PAD };
|
|
99
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A triangle mesh on the shared context, under the same camera the cube's geoms use.
|
|
3
|
+
*
|
|
4
|
+
* The vertices are packed the way a cube's points are, as offsets on the pair plus one on the third
|
|
5
|
+
* scale, so one matrix serves both programs and a relief can be drawn beside a cloud in one canvas.
|
|
6
|
+
* What this adds is the face list and a normal a vertex, which is what a light needs to make a
|
|
7
|
+
* projection read as an object.
|
|
8
|
+
*/
|
|
9
|
+
import type { MeshData, Orbit, Rgb, UnitRamp } from "../../core/internal.js";
|
|
10
|
+
export interface GlMeshProps {
|
|
11
|
+
mesh: MeshData;
|
|
12
|
+
xDomain: [number, number];
|
|
13
|
+
yDomain: [number, number];
|
|
14
|
+
orbit: Orbit;
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
/** Maps a vertex's height, over nought to one, to an RGB triple in the same range. */
|
|
18
|
+
ramp: UnitRamp<Rgb>;
|
|
19
|
+
/** Drawn when the page has no WebGL2, so a chart says something instead of nothing. */
|
|
20
|
+
fallback?: React.ReactNode;
|
|
21
|
+
}
|
|
22
|
+
export declare function GlMesh({ mesh, xDomain, yDomain, orbit, width, height, ramp, fallback }: GlMeshProps): import("react").JSX.Element;
|