@tetrascience-npm/ts-lib-viz 0.0.0-stage → 0.1.4
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 +28 -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,303 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The camera a cube is read through.
|
|
3
|
+
*
|
|
4
|
+
* The floor is the x-y plane and z draws upward. The model normalizes each domain onto -1 to 1.
|
|
5
|
+
*/
|
|
6
|
+
import { scaleLinear } from "d3-scale";
|
|
7
|
+
/**
|
|
8
|
+
* Where a cube opens.
|
|
9
|
+
*
|
|
10
|
+
* Turned off the axes and tilted above the floor, which shows three scales at once. Straight
|
|
11
|
+
* down an axis draws two of the three edge-on.
|
|
12
|
+
*/
|
|
13
|
+
export const AT_REST_ORBIT = { azimuth: 0.7, elevation: 0.42, distance: 4.7 };
|
|
14
|
+
/**
|
|
15
|
+
* How close to the poles a tilt may come.
|
|
16
|
+
*
|
|
17
|
+
* At the pole the up vector and the view direction are parallel and the view frame collapses.
|
|
18
|
+
*/
|
|
19
|
+
const ELEVATION_LIMIT = Math.PI / 2 - 0.05;
|
|
20
|
+
const DISTANCE_RANGE = [2, 16];
|
|
21
|
+
const clamp = (value, lo, hi) => Math.min(hi, Math.max(lo, value));
|
|
22
|
+
/** Radians of turn a pixel of drag is worth. A half turn is that many pixels. */
|
|
23
|
+
const DRAG_RADIANS = 0.008;
|
|
24
|
+
/** The orbit after a drag, in pixels, with the tilt held clear of the poles. */
|
|
25
|
+
export const orbited = (orbit, dx, dy) => ({
|
|
26
|
+
azimuth: orbit.azimuth - dx * DRAG_RADIANS,
|
|
27
|
+
elevation: clamp(orbit.elevation + dy * DRAG_RADIANS, -ELEVATION_LIMIT, ELEVATION_LIMIT),
|
|
28
|
+
distance: orbit.distance,
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* The orbit after a wheel notch.
|
|
32
|
+
*
|
|
33
|
+
* Multiplicative, and a notch moves the same proportion of the way in at any distance.
|
|
34
|
+
*/
|
|
35
|
+
export const dollied = (orbit, notches) => ({
|
|
36
|
+
...orbit,
|
|
37
|
+
distance: clamp(orbit.distance * Math.exp(notches * 0.12), DISTANCE_RANGE[0], DISTANCE_RANGE[1]),
|
|
38
|
+
});
|
|
39
|
+
/** Whether the reader has moved. A cube at rest draws what it always drew. */
|
|
40
|
+
export const isOrbited = (orbit) => orbit.azimuth !== AT_REST_ORBIT.azimuth ||
|
|
41
|
+
orbit.elevation !== AT_REST_ORBIT.elevation ||
|
|
42
|
+
orbit.distance !== AT_REST_ORBIT.distance;
|
|
43
|
+
function multiply(a, b) {
|
|
44
|
+
const out = new Float32Array(16);
|
|
45
|
+
for (let col = 0; col < 4; col += 1) {
|
|
46
|
+
for (let row = 0; row < 4; row += 1) {
|
|
47
|
+
let sum = 0;
|
|
48
|
+
for (let k = 0; k < 4; k += 1)
|
|
49
|
+
sum += a[k * 4 + row] * b[col * 4 + k];
|
|
50
|
+
out[col * 4 + row] = sum;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A perspective projection.
|
|
57
|
+
*
|
|
58
|
+
* Geoms grow as they approach and the reader recovers the near-far ordering from a turn. An
|
|
59
|
+
* orthographic cube turns without saying which face is nearer.
|
|
60
|
+
*/
|
|
61
|
+
function perspective(fovy, aspect, near, far) {
|
|
62
|
+
const f = 1 / Math.tan(fovy / 2);
|
|
63
|
+
const out = new Float32Array(16);
|
|
64
|
+
out[0] = f / aspect;
|
|
65
|
+
out[5] = f;
|
|
66
|
+
out[10] = (far + near) / (near - far);
|
|
67
|
+
out[11] = -1;
|
|
68
|
+
out[14] = (2 * far * near) / (near - far);
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
/** The view from an eye onto the origin, with the world's up vector as the frame's third axis. */
|
|
72
|
+
function lookAt(eye) {
|
|
73
|
+
const [ex, ey, ez] = eye;
|
|
74
|
+
const length = Math.hypot(ex, ey, ez) || 1;
|
|
75
|
+
const zx = ex / length;
|
|
76
|
+
const zy = ey / length;
|
|
77
|
+
const zz = ez / length;
|
|
78
|
+
// Right is up crossed into the view direction, with up as +y in world space.
|
|
79
|
+
let xx = zz;
|
|
80
|
+
let xy = 0;
|
|
81
|
+
let xz = -zx;
|
|
82
|
+
const across = Math.hypot(xx, xy, xz) || 1;
|
|
83
|
+
xx /= across;
|
|
84
|
+
xy /= across;
|
|
85
|
+
xz /= across;
|
|
86
|
+
const yx = zy * xz - zz * xy;
|
|
87
|
+
const yy = zz * xx - zx * xz;
|
|
88
|
+
const yz = zx * xy - zy * xx;
|
|
89
|
+
const out = new Float32Array(16);
|
|
90
|
+
out[0] = xx;
|
|
91
|
+
out[4] = xy;
|
|
92
|
+
out[8] = xz;
|
|
93
|
+
out[1] = yx;
|
|
94
|
+
out[5] = yy;
|
|
95
|
+
out[9] = yz;
|
|
96
|
+
out[2] = zx;
|
|
97
|
+
out[6] = zy;
|
|
98
|
+
out[10] = zz;
|
|
99
|
+
out[12] = -(xx * ex + xy * ey + xz * ez);
|
|
100
|
+
out[13] = -(yx * ex + yy * ey + yz * ez);
|
|
101
|
+
out[14] = -(zx * ex + zy * ey + zz * ez);
|
|
102
|
+
out[15] = 1;
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
/** Where the eye falls for an orbit, in world space. */
|
|
106
|
+
export function eyeOf(orbit) {
|
|
107
|
+
const { azimuth, elevation, distance } = orbit;
|
|
108
|
+
const flat = Math.cos(elevation) * distance;
|
|
109
|
+
return [flat * Math.sin(azimuth), Math.sin(elevation) * distance, flat * Math.cos(azimuth)];
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The model matrix -- data offsets onto the unit cube, with z drawing upward.
|
|
113
|
+
*
|
|
114
|
+
* A float32 spends its digits on a timestamp. The center is the number the CPU keeps.
|
|
115
|
+
*/
|
|
116
|
+
export function cubeModel(domains, center) {
|
|
117
|
+
const span = (range) => range[1] - range[0] || 1;
|
|
118
|
+
const scale = (range) => 2 / span(range);
|
|
119
|
+
const bias = (range, mid) => (2 * (mid - range[0])) / span(range) - 1;
|
|
120
|
+
const out = new Float32Array(16);
|
|
121
|
+
// Column 0 sends data x to world x, column 1 sends data y to world z, column 2 sends data z up.
|
|
122
|
+
out[0] = scale(domains.x);
|
|
123
|
+
out[6] = scale(domains.y);
|
|
124
|
+
out[9] = scale(domains.z);
|
|
125
|
+
out[12] = bias(domains.x, center[0]);
|
|
126
|
+
out[13] = bias(domains.z, center[2]);
|
|
127
|
+
out[14] = bias(domains.y, center[1]);
|
|
128
|
+
out[15] = 1;
|
|
129
|
+
return out;
|
|
130
|
+
}
|
|
131
|
+
/** How much of the view the cube fills. This sets the projection's field of view. */
|
|
132
|
+
const FIELD_OF_VIEW = Math.PI / 4;
|
|
133
|
+
const NEAR = 0.1;
|
|
134
|
+
const FAR = 100;
|
|
135
|
+
/**
|
|
136
|
+
* The one matrix the cube program takes.
|
|
137
|
+
*
|
|
138
|
+
* Model, view and projection multiplied on the CPU. The product changes once a frame.
|
|
139
|
+
*/
|
|
140
|
+
export function cubeMatrix(orbit, aspect, domains, center) {
|
|
141
|
+
return multiply(multiply(perspective(FIELD_OF_VIEW, aspect || 1, NEAR, FAR), lookAt(eyeOf(orbit))), cubeModel(domains, center));
|
|
142
|
+
}
|
|
143
|
+
/** Where a data point lands, for the chrome the CPU draws around what the GPU drew. */
|
|
144
|
+
export function projectData(matrix, point, center, width, height) {
|
|
145
|
+
const dx = point[0] - center[0];
|
|
146
|
+
const dy = point[1] - center[1];
|
|
147
|
+
const dz = point[2] - center[2];
|
|
148
|
+
const out = [0, 0, 0, 0];
|
|
149
|
+
for (let row = 0; row < 4; row += 1) {
|
|
150
|
+
out[row] = matrix[row] * dx + matrix[4 + row] * dy + matrix[8 + row] * dz + matrix[12 + row];
|
|
151
|
+
}
|
|
152
|
+
const w = out[3] || 1e-6;
|
|
153
|
+
return {
|
|
154
|
+
x: (out[0] / w / 2 + 0.5) * width,
|
|
155
|
+
y: (0.5 - out[1] / w / 2) * height,
|
|
156
|
+
depth: w,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
const CORNERS = [
|
|
160
|
+
[0, 0, 0],
|
|
161
|
+
[1, 0, 0],
|
|
162
|
+
[0, 1, 0],
|
|
163
|
+
[1, 1, 0],
|
|
164
|
+
[0, 0, 1],
|
|
165
|
+
[1, 0, 1],
|
|
166
|
+
[0, 1, 1],
|
|
167
|
+
[1, 1, 1],
|
|
168
|
+
];
|
|
169
|
+
/** Pairs of corners one step apart. A wider pair would be a diagonal. */
|
|
170
|
+
const EDGES = [];
|
|
171
|
+
for (let a = 0; a < CORNERS.length; a += 1) {
|
|
172
|
+
for (let b = a + 1; b < CORNERS.length; b += 1) {
|
|
173
|
+
const steps = CORNERS[a].reduce((count, value, axis) => count + (value === CORNERS[b][axis] ? 0 : 1), 0);
|
|
174
|
+
if (steps === 1)
|
|
175
|
+
EDGES.push([a, b]);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/** Target break count per axis. d3 may return a few more or fewer to land on round values. */
|
|
179
|
+
const TICKS = 5;
|
|
180
|
+
/**
|
|
181
|
+
* The box the geoms draw in, projected.
|
|
182
|
+
*
|
|
183
|
+
* Two of the three scales are foreshortened and a rule draws in projection. The axis edge is the
|
|
184
|
+
* one furthest from the reader.
|
|
185
|
+
*/
|
|
186
|
+
export function cubeChrome(matrix, domains, center, width, height) {
|
|
187
|
+
const axisRange = { x: domains.x, y: domains.y, z: domains.z };
|
|
188
|
+
const cornerAt = (corner) => projectData(matrix, [axisRange.x[corner[0]], axisRange.y[corner[1]], axisRange.z[corner[2]]], center, width, height);
|
|
189
|
+
const middle = projectData(matrix, center, center, width, height);
|
|
190
|
+
const project = (point) => projectData(matrix, point, center, width, height);
|
|
191
|
+
const ranges = [axisRange.x, axisRange.y, axisRange.z];
|
|
192
|
+
const values = ranges.map((range) => scaleLinear().domain(range).ticks(TICKS));
|
|
193
|
+
/* The back wall's end of each axis, read off the view depth of the two opposite face centers. */
|
|
194
|
+
const backEnd = ranges.map((range, wall) => {
|
|
195
|
+
const ends = range.map((end) => {
|
|
196
|
+
const point = [...center];
|
|
197
|
+
point[wall] = end;
|
|
198
|
+
return project(point).depth;
|
|
199
|
+
});
|
|
200
|
+
return ends[0] > ends[1] ? 0 : 1;
|
|
201
|
+
});
|
|
202
|
+
const backCorner = CORNERS.findIndex((corner) => corner.every((end, axis) => end === backEnd[axis]));
|
|
203
|
+
const touchesBack = ([a, b]) => a === backCorner || b === backCorner;
|
|
204
|
+
const placed = CORNERS.map(cornerAt);
|
|
205
|
+
const edges = EDGES.map(([a, b]) => ({
|
|
206
|
+
from: placed[a],
|
|
207
|
+
to: placed[b],
|
|
208
|
+
depth: (placed[a].depth + placed[b].depth) / 2,
|
|
209
|
+
back: touchesBack([a, b]),
|
|
210
|
+
}));
|
|
211
|
+
const dataCorner = (index) => CORNERS[index].map((end, axis) => ranges[axis][end]);
|
|
212
|
+
const backEdges = EDGES.filter(touchesBack).map(([a, b]) => [dataCorner(a), dataCorner(b)]);
|
|
213
|
+
/* Draws grid lines on each axis's back wall, at the breaks of the other two axes. */
|
|
214
|
+
const grid = [];
|
|
215
|
+
const gridSegments = [];
|
|
216
|
+
for (let wall = 0; wall < 3; wall += 1) {
|
|
217
|
+
const at = ranges[wall][backEnd[wall]];
|
|
218
|
+
for (const across of [0, 1, 2].filter((axis) => axis !== wall)) {
|
|
219
|
+
const along = 3 - wall - across;
|
|
220
|
+
const [lo, hi] = ranges[across];
|
|
221
|
+
for (const value of values[across].filter((tick) => tick > lo && tick < hi)) {
|
|
222
|
+
const from = [0, 0, 0];
|
|
223
|
+
from[wall] = at;
|
|
224
|
+
from[across] = value;
|
|
225
|
+
from[along] = ranges[along][0];
|
|
226
|
+
const to = [...from];
|
|
227
|
+
to[along] = ranges[along][1];
|
|
228
|
+
const [start, end] = [project(from), project(to)];
|
|
229
|
+
grid.push({ from: start, to: end, depth: (start.depth + end.depth) / 2, back: true });
|
|
230
|
+
gridSegments.push([from, to]);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const axes = ["x", "y", "z"].map((axis, index) => {
|
|
235
|
+
const along = EDGES.filter(([a, b]) => CORNERS[a][index] !== CORNERS[b][index]);
|
|
236
|
+
/*
|
|
237
|
+
The edge to write along is furthest from the middle of the box on the page. A label on the
|
|
238
|
+
vertical scale's far edge would land in the cloud.
|
|
239
|
+
*/
|
|
240
|
+
const outermost = along
|
|
241
|
+
.map(([a, b]) => {
|
|
242
|
+
const mx = (placed[a].x + placed[b].x) / 2 - middle.x;
|
|
243
|
+
const my = (placed[a].y + placed[b].y) / 2 - middle.y;
|
|
244
|
+
return { a, b, reach: Math.hypot(mx, my) };
|
|
245
|
+
})
|
|
246
|
+
.sort((one, other) => other.reach - one.reach)[0];
|
|
247
|
+
const low = CORNERS[outermost.a][index] === 0 ? outermost.a : outermost.b;
|
|
248
|
+
const high = low === outermost.a ? outermost.b : outermost.a;
|
|
249
|
+
const corner = CORNERS[low];
|
|
250
|
+
const ticks = values[index].map((value) => {
|
|
251
|
+
const point = [
|
|
252
|
+
axisRange.x[corner[0]],
|
|
253
|
+
axisRange.y[corner[1]],
|
|
254
|
+
axisRange.z[corner[2]],
|
|
255
|
+
];
|
|
256
|
+
point[index] = value;
|
|
257
|
+
return { at: projectData(matrix, point, center, width, height), value };
|
|
258
|
+
});
|
|
259
|
+
return { axis, from: placed[low], to: placed[high], ticks };
|
|
260
|
+
});
|
|
261
|
+
/* Each back face, corner to corner across the two axes it spans. */
|
|
262
|
+
const pane = (wall) => {
|
|
263
|
+
const [a, b] = [0, 1, 2].filter((axis) => axis !== wall);
|
|
264
|
+
const corner = (atA, atB) => {
|
|
265
|
+
const point = [0, 0, 0];
|
|
266
|
+
point[wall] = ranges[wall][backEnd[wall]];
|
|
267
|
+
point[a] = ranges[a][atA];
|
|
268
|
+
point[b] = ranges[b][atB];
|
|
269
|
+
return point;
|
|
270
|
+
};
|
|
271
|
+
return [corner(0, 0), corner(1, 0), corner(1, 1), corner(0, 1)];
|
|
272
|
+
};
|
|
273
|
+
const panes = { x: pane(0), y: pane(1), z: pane(2) };
|
|
274
|
+
return { edges, axes, grid, walls: { grid: gridSegments, edges: backEdges, panes }, middle };
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* What turns a normal in the data's axes into one in the light's world.
|
|
278
|
+
*
|
|
279
|
+
* The inverse transpose of a diagonal map is the reciprocal of its diagonal.
|
|
280
|
+
*/
|
|
281
|
+
export function normalMatrix(domains) {
|
|
282
|
+
const span = (range) => (range[1] - range[0] || 1) / 2;
|
|
283
|
+
const out = new Float32Array(9);
|
|
284
|
+
// Column-major, with the same axis swap the model makes: data y draws into world z, data z up.
|
|
285
|
+
out[0] = span(domains.x);
|
|
286
|
+
out[5] = span(domains.y);
|
|
287
|
+
out[7] = span(domains.z);
|
|
288
|
+
return out;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Where the light stands, in world space.
|
|
292
|
+
*
|
|
293
|
+
* Fixed to the world. Turning the figure moves the light across it.
|
|
294
|
+
*/
|
|
295
|
+
export const CUBE_LIGHT = [0.4, 0.85, 0.35];
|
|
296
|
+
/** How much of a face's color survives with no light on it. A shadowed slope stays readable. */
|
|
297
|
+
export const AMBIENT = 0.45;
|
|
298
|
+
/**
|
|
299
|
+
* The view depth at which a geom draws the diameter its caller asked for.
|
|
300
|
+
*
|
|
301
|
+
* The shader divides this by the vertex view depth. A geom mid-cube draws its given size.
|
|
302
|
+
*/
|
|
303
|
+
export const restingDepth = (orbit) => orbit.distance;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a chart type needs, and whether a source can supply it.
|
|
3
|
+
*
|
|
4
|
+
* Each kind declares its channels as role requirements and the schema answers. Anything
|
|
5
|
+
* unsatisfied appears grayed.
|
|
6
|
+
*/
|
|
7
|
+
import { type Aesthetic } from "./geom-table.js";
|
|
8
|
+
import type { PlotFieldRole } from "./plot-data.js";
|
|
9
|
+
import type { PlotKind } from "./spec.js";
|
|
10
|
+
export interface AestheticReq {
|
|
11
|
+
aesthetic: Aesthetic;
|
|
12
|
+
label: string;
|
|
13
|
+
roles: PlotFieldRole[];
|
|
14
|
+
required: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface Capability<K> {
|
|
17
|
+
kind: K;
|
|
18
|
+
label: string;
|
|
19
|
+
describe: string;
|
|
20
|
+
/** The kind's required aesthetics, then the ones it accepts, in the geom table's order. */
|
|
21
|
+
aesthetics: AestheticReq[];
|
|
22
|
+
}
|
|
23
|
+
/** Each kind as the builder offers it, in menu order. */
|
|
24
|
+
export declare const PLOTS: readonly Capability<PlotKind>[];
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a chart type needs, and whether a source can supply it.
|
|
3
|
+
*
|
|
4
|
+
* Each kind declares its channels as role requirements and the schema answers. Anything
|
|
5
|
+
* unsatisfied appears grayed.
|
|
6
|
+
*/
|
|
7
|
+
import { GEOMS } from "./geom-table.js";
|
|
8
|
+
/** Each aesthetic's name and roles on a kind that states none of its own. */
|
|
9
|
+
const DEFAULT = {
|
|
10
|
+
x: { label: "X", roles: ["measure", "timestamp", "dimension"] },
|
|
11
|
+
y: { label: "Y", roles: ["measure"] },
|
|
12
|
+
z: { label: "Z", roles: ["measure"] },
|
|
13
|
+
ymin: { label: "Low", roles: ["measure"] },
|
|
14
|
+
ymax: { label: "High", roles: ["measure"] },
|
|
15
|
+
xend: { label: "X end", roles: ["measure", "timestamp"] },
|
|
16
|
+
yend: { label: "Y end", roles: ["measure"] },
|
|
17
|
+
color: { label: "Color", roles: ["dimension", "identity", "measure", "status"] },
|
|
18
|
+
fill: { label: "Fill", roles: ["dimension", "identity", "measure", "status"] },
|
|
19
|
+
size: { label: "Size", roles: ["measure"] },
|
|
20
|
+
shape: { label: "Shape", roles: ["dimension", "identity", "status"] },
|
|
21
|
+
alpha: { label: "Opacity", roles: ["measure", "dimension"] },
|
|
22
|
+
linetype: { label: "Dash", roles: ["dimension", "identity", "status"] },
|
|
23
|
+
source: { label: "From", roles: ["stage", "dimension", "status"] },
|
|
24
|
+
target: { label: "To", roles: ["stage", "dimension", "status"] },
|
|
25
|
+
value: { label: "Value", roles: ["measure"] },
|
|
26
|
+
sector: { label: "Sector", roles: ["dimension", "identity"] },
|
|
27
|
+
start: { label: "From", roles: ["measure"] },
|
|
28
|
+
end: { label: "To", roles: ["measure"] },
|
|
29
|
+
dimensions: { label: "Measures", roles: ["measure"] },
|
|
30
|
+
faces: { label: "Faces", roles: ["measure"] },
|
|
31
|
+
label: { label: "Label", roles: ["dimension", "identity"] },
|
|
32
|
+
parent: { label: "Nesting", roles: ["parent", "dimension"] },
|
|
33
|
+
group: { label: "Group", roles: ["dimension", "identity", "stage", "status"] },
|
|
34
|
+
xintercept: { label: "X", roles: ["measure", "timestamp"] },
|
|
35
|
+
yintercept: { label: "Y", roles: ["measure"] },
|
|
36
|
+
slope: { label: "Slope", roles: ["measure"] },
|
|
37
|
+
intercept: { label: "Intercept", roles: ["measure"] },
|
|
38
|
+
};
|
|
39
|
+
/** The channels the four interval kinds share. */
|
|
40
|
+
const RANGE = {
|
|
41
|
+
x: { roles: ["timestamp", "measure", "stage", "dimension"] },
|
|
42
|
+
y: { label: "Estimate" },
|
|
43
|
+
color: { label: "Series", roles: ["dimension", "identity"] },
|
|
44
|
+
};
|
|
45
|
+
const SERIES = { label: "Series", roles: ["dimension", "identity"] };
|
|
46
|
+
const OFFERS = {
|
|
47
|
+
point: {
|
|
48
|
+
label: "Scatter",
|
|
49
|
+
describe: "Two measures against each other, one geom per record.",
|
|
50
|
+
aesthetics: { x: { roles: ["measure", "timestamp"] } },
|
|
51
|
+
},
|
|
52
|
+
line: {
|
|
53
|
+
label: "Line",
|
|
54
|
+
describe: "A measure over time or over an ordered axis.",
|
|
55
|
+
aesthetics: { x: { roles: ["timestamp", "measure", "stage"] }, color: SERIES },
|
|
56
|
+
},
|
|
57
|
+
area: {
|
|
58
|
+
label: "Area",
|
|
59
|
+
describe: "A measure over an ordered axis, filled to zero.",
|
|
60
|
+
aesthetics: { x: { roles: ["timestamp", "measure", "stage"] }, fill: SERIES },
|
|
61
|
+
},
|
|
62
|
+
ribbon: {
|
|
63
|
+
label: "Interval",
|
|
64
|
+
describe: "A band between two bound measures, for a confidence or tolerance interval.",
|
|
65
|
+
aesthetics: { x: RANGE.x, y: RANGE.y, fill: SERIES },
|
|
66
|
+
},
|
|
67
|
+
/* The band's channels drawn a mark at a time, as ggplot's four interval geoms. */
|
|
68
|
+
errorbar: { label: "Error bar", describe: "An interval per reading, capped at both ends.", aesthetics: RANGE },
|
|
69
|
+
linerange: { label: "Line range", describe: "An interval per reading, as a bare run.", aesthetics: RANGE },
|
|
70
|
+
pointrange: {
|
|
71
|
+
label: "Point range",
|
|
72
|
+
describe: "An interval per reading, with its estimate marked on the run.",
|
|
73
|
+
aesthetics: RANGE,
|
|
74
|
+
},
|
|
75
|
+
crossbar: {
|
|
76
|
+
label: "Crossbar",
|
|
77
|
+
describe: "An interval per reading, as a box with its estimate across it.",
|
|
78
|
+
aesthetics: RANGE,
|
|
79
|
+
},
|
|
80
|
+
segment: {
|
|
81
|
+
label: "Segment",
|
|
82
|
+
describe: "A run per record from one position to another, for a before-and-after pair or a drift.",
|
|
83
|
+
aesthetics: {
|
|
84
|
+
x: { label: "X start", roles: ["timestamp", "measure", "stage"] },
|
|
85
|
+
y: { label: "Y start" },
|
|
86
|
+
xend: { roles: ["timestamp", "measure", "stage"] },
|
|
87
|
+
color: SERIES,
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
smooth: {
|
|
91
|
+
label: "Trend",
|
|
92
|
+
describe: "The conditional mean through two measures, drawn as a curve with its interval.",
|
|
93
|
+
aesthetics: { x: { roles: ["measure", "timestamp"] }, color: SERIES },
|
|
94
|
+
},
|
|
95
|
+
bar: {
|
|
96
|
+
label: "Bar",
|
|
97
|
+
describe: "An aggregate per category. Counts when no measure is bound.",
|
|
98
|
+
aesthetics: {
|
|
99
|
+
x: { label: "Category", roles: ["dimension", "stage", "status", "priority", "owner", "identity"] },
|
|
100
|
+
y: { label: "Value" },
|
|
101
|
+
fill: { label: "Stack", roles: ["dimension", "status"] },
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
/* Signed steps on a running total, offered beside the bar. No fill channel: the hue is each step's direction. */
|
|
105
|
+
waterfall: {
|
|
106
|
+
label: "Waterfall",
|
|
107
|
+
describe: "Signed steps on a running total. Where a population gained and lost.",
|
|
108
|
+
aesthetics: {
|
|
109
|
+
x: { label: "Steps", roles: ["stage", "dimension", "status", "priority", "owner", "identity"] },
|
|
110
|
+
y: { label: "Change" },
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
histogram: {
|
|
114
|
+
label: "Histogram",
|
|
115
|
+
describe: "The distribution of one measure.",
|
|
116
|
+
aesthetics: {
|
|
117
|
+
x: { label: "Measure", roles: ["measure"] },
|
|
118
|
+
y: { label: "Value" },
|
|
119
|
+
fill: { label: "Split", roles: ["dimension", "status"] },
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
freqpoly: {
|
|
123
|
+
label: "Frequency polygon",
|
|
124
|
+
describe: "The same count under the same bin as a histogram, drawn as a line.",
|
|
125
|
+
aesthetics: {
|
|
126
|
+
x: { label: "Measure", roles: ["measure"] },
|
|
127
|
+
y: { label: "Value" },
|
|
128
|
+
color: { label: "Split", roles: ["dimension", "status"] },
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
hex: {
|
|
132
|
+
label: "Density",
|
|
133
|
+
describe: "Two measures as binned density. What a scatter becomes at scale.",
|
|
134
|
+
aesthetics: { x: { roles: ["measure"] } },
|
|
135
|
+
},
|
|
136
|
+
boxplot: {
|
|
137
|
+
label: "Box",
|
|
138
|
+
describe: "Quartiles of a measure, optionally per category.",
|
|
139
|
+
aesthetics: { y: { label: "Measure" }, x: { label: "Group", roles: ["dimension", "stage", "owner", "status"] } },
|
|
140
|
+
},
|
|
141
|
+
violin: {
|
|
142
|
+
label: "Violin",
|
|
143
|
+
describe: "Full distribution shape per category, for multimodal data.",
|
|
144
|
+
aesthetics: { y: { label: "Measure" }, x: { label: "Group", roles: ["dimension", "stage", "owner"] } },
|
|
145
|
+
},
|
|
146
|
+
density: {
|
|
147
|
+
label: "Density curve",
|
|
148
|
+
describe: "The distribution of one measure as a kernel density, at a stated bandwidth.",
|
|
149
|
+
aesthetics: {
|
|
150
|
+
x: { label: "Measure", roles: ["measure"] },
|
|
151
|
+
color: { label: "Split", roles: ["dimension", "status"] },
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
heatmap: {
|
|
155
|
+
label: "Heatmap",
|
|
156
|
+
describe: "Category by category, cells colored by an aggregate.",
|
|
157
|
+
aesthetics: {
|
|
158
|
+
x: { roles: ["dimension", "stage", "position"] },
|
|
159
|
+
y: { roles: ["dimension", "identity", "position"] },
|
|
160
|
+
/* Unbound, the cells count the rows that landed in them. */
|
|
161
|
+
z: { label: "Color" },
|
|
162
|
+
dimensions: { label: "Cuts" },
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
contour: {
|
|
166
|
+
label: "Contour",
|
|
167
|
+
describe: "Smoothed density over two measures, or a third measure's levels over a lattice.",
|
|
168
|
+
aesthetics: { x: { roles: ["measure"] }, z: { label: "Level" } },
|
|
169
|
+
},
|
|
170
|
+
parcoords: {
|
|
171
|
+
label: "Parallel coordinates",
|
|
172
|
+
describe: "One line per record across several measures. The trade-off view.",
|
|
173
|
+
aesthetics: { color: { roles: ["measure", "identity", "status"] } },
|
|
174
|
+
},
|
|
175
|
+
sankey: {
|
|
176
|
+
label: "Sankey",
|
|
177
|
+
describe: "Flow between stages. Where the population went.",
|
|
178
|
+
aesthetics: { value: { label: "Width" } },
|
|
179
|
+
},
|
|
180
|
+
ideogram: {
|
|
181
|
+
label: "Ideogram",
|
|
182
|
+
describe: "A genome round a circle. Where a reading falls along a chromosome.",
|
|
183
|
+
aesthetics: { sector: { label: "Chromosome" }, fill: { label: "Stain", roles: ["dimension", "identity", "status"] } },
|
|
184
|
+
},
|
|
185
|
+
chord: {
|
|
186
|
+
label: "Chord",
|
|
187
|
+
describe: "Flow between names, closed into a circle. Which pairs carry the traffic.",
|
|
188
|
+
aesthetics: { value: { label: "Width" } },
|
|
189
|
+
},
|
|
190
|
+
/* A hierarchy reads no shared pair of scales and its channels take role names. */
|
|
191
|
+
treemap: {
|
|
192
|
+
label: "Treemap",
|
|
193
|
+
describe: "Nested share of a total.",
|
|
194
|
+
aesthetics: { label: { label: "Cells", roles: ["dimension", "identity", "stage"] }, value: { label: "Size" } },
|
|
195
|
+
},
|
|
196
|
+
icicle: {
|
|
197
|
+
label: "Icicle",
|
|
198
|
+
describe: "The same nesting with a row per level, read as a width.",
|
|
199
|
+
aesthetics: { label: { label: "Cells", roles: ["dimension", "identity", "stage"] }, value: { label: "Width" } },
|
|
200
|
+
},
|
|
201
|
+
sunburst: {
|
|
202
|
+
label: "Sunburst",
|
|
203
|
+
describe: "The same nesting round a center, one ring per level.",
|
|
204
|
+
aesthetics: { label: { label: "Cells", roles: ["dimension", "identity", "stage"] }, value: { label: "Share" } },
|
|
205
|
+
},
|
|
206
|
+
pie: {
|
|
207
|
+
label: "Pie",
|
|
208
|
+
describe: "Shares of one whole, as slices. Counts when no measure is bound.",
|
|
209
|
+
aesthetics: {
|
|
210
|
+
x: { label: "Slices", roles: ["dimension", "stage", "status", "priority", "owner", "identity"] },
|
|
211
|
+
y: { label: "Share" },
|
|
212
|
+
fill: { label: "Slices", roles: ["dimension", "status"] },
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
gauge: {
|
|
216
|
+
label: "Gauge",
|
|
217
|
+
describe: "One reduction against a stated range, written as a number under its arc.",
|
|
218
|
+
aesthetics: { value: { label: "Reading" } },
|
|
219
|
+
},
|
|
220
|
+
radar: {
|
|
221
|
+
label: "Radar",
|
|
222
|
+
describe: "One polygon per record across several measures, on rules round a center.",
|
|
223
|
+
aesthetics: { color: { roles: ["measure", "identity", "status"] } },
|
|
224
|
+
},
|
|
225
|
+
point3d: {
|
|
226
|
+
label: "Scatter 3D",
|
|
227
|
+
describe: "Three measures on three scales, one geom per record. Turn it to read depth.",
|
|
228
|
+
aesthetics: { x: { roles: ["measure", "timestamp"] } },
|
|
229
|
+
},
|
|
230
|
+
surface: {
|
|
231
|
+
label: "Surface",
|
|
232
|
+
describe: "A measure as height over two dimensions. A relief, meshed.",
|
|
233
|
+
aesthetics: { x: { roles: ["measure", "dimension"] }, y: { roles: ["measure", "dimension"] }, z: { label: "Height" } },
|
|
234
|
+
},
|
|
235
|
+
mesh3d: {
|
|
236
|
+
label: "Mesh",
|
|
237
|
+
describe: "Vertices and faces as the object they are. A structure, not a plot of one.",
|
|
238
|
+
aesthetics: { x: { roles: ["measure"] } },
|
|
239
|
+
},
|
|
240
|
+
isosurface: {
|
|
241
|
+
label: "Isosurface",
|
|
242
|
+
describe: "The shell where a scalar field holds one value.",
|
|
243
|
+
aesthetics: { x: { roles: ["measure"] }, value: { label: "Field" } },
|
|
244
|
+
},
|
|
245
|
+
volume: {
|
|
246
|
+
label: "Volume",
|
|
247
|
+
describe: "A scalar field read through its whole depth, with a transfer function.",
|
|
248
|
+
aesthetics: { x: { roles: ["measure"] }, value: { label: "Field" } },
|
|
249
|
+
},
|
|
250
|
+
/* ggplot's three reference geoms, a layer over another kind. Each reads its own position. */
|
|
251
|
+
hline: {
|
|
252
|
+
label: "Horizontal line",
|
|
253
|
+
describe: "A reference line at each value, across the plot area and labeled where it ends.",
|
|
254
|
+
aesthetics: { color: SERIES },
|
|
255
|
+
},
|
|
256
|
+
vline: {
|
|
257
|
+
label: "Vertical line",
|
|
258
|
+
describe: "A reference line at each value, up the plot area and labeled where it ends.",
|
|
259
|
+
aesthetics: { color: SERIES },
|
|
260
|
+
},
|
|
261
|
+
abline: {
|
|
262
|
+
label: "Sloped line",
|
|
263
|
+
describe: "A line from a slope and an intercept, read in the scales' transformed space.",
|
|
264
|
+
aesthetics: { color: SERIES },
|
|
265
|
+
},
|
|
266
|
+
/* ggplot's two text geoms, a layer over another kind. The second boxes each label. */
|
|
267
|
+
text: {
|
|
268
|
+
label: "Text",
|
|
269
|
+
describe: "A label per row at its reading, for naming bars, points or a region.",
|
|
270
|
+
aesthetics: {
|
|
271
|
+
x: { roles: ["measure", "timestamp", "dimension", "identity"] },
|
|
272
|
+
label: { label: "Text", roles: ["dimension", "identity", "measure"] },
|
|
273
|
+
color: SERIES,
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
label: {
|
|
277
|
+
label: "Label",
|
|
278
|
+
describe: "The same label with a box behind it, for text over a busy region.",
|
|
279
|
+
aesthetics: {
|
|
280
|
+
x: { roles: ["measure", "timestamp", "dimension", "identity"] },
|
|
281
|
+
label: { label: "Text", roles: ["dimension", "identity", "measure"] },
|
|
282
|
+
color: SERIES,
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
};
|
|
286
|
+
/** A kind's offer, with each aesthetic its geom table row binds. */
|
|
287
|
+
function capabilityOf(kind, { label, describe, aesthetics = {} }) {
|
|
288
|
+
const row = GEOMS[kind];
|
|
289
|
+
const stated = aesthetics;
|
|
290
|
+
const offered = (aesthetic, required) => ({
|
|
291
|
+
aesthetic,
|
|
292
|
+
...DEFAULT[aesthetic],
|
|
293
|
+
...stated[aesthetic],
|
|
294
|
+
required,
|
|
295
|
+
});
|
|
296
|
+
return {
|
|
297
|
+
kind,
|
|
298
|
+
label,
|
|
299
|
+
describe,
|
|
300
|
+
aesthetics: [
|
|
301
|
+
...row.requires.map((aesthetic) => offered(aesthetic, true)),
|
|
302
|
+
...row.accepts.map((aesthetic) => offered(aesthetic, false)),
|
|
303
|
+
],
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
/** Each kind as the builder offers it, in menu order. */
|
|
307
|
+
export const PLOTS = Object.freeze(Object.entries(OFFERS).map(([kind, offer]) => capabilityOf(kind, offer)));
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A flow closed into a circle.
|
|
3
|
+
*
|
|
4
|
+
* Angles come out in radians and no radius enters. The geom picks the radii it draws on.
|
|
5
|
+
*/
|
|
6
|
+
import { type PlacedSector } from "./circular.js";
|
|
7
|
+
/** One link of a chord, which is the row shape a flow already reads. */
|
|
8
|
+
export interface ChordLink {
|
|
9
|
+
source: string;
|
|
10
|
+
target: string;
|
|
11
|
+
value: number;
|
|
12
|
+
color?: string;
|
|
13
|
+
}
|
|
14
|
+
/** A name's own arc. `value` is the total passing through it, both ways counted. */
|
|
15
|
+
export interface ChordSector extends PlacedSector {
|
|
16
|
+
value: number;
|
|
17
|
+
color?: string;
|
|
18
|
+
}
|
|
19
|
+
/** One pair's ribbon, as the two angular ranges it occupies. */
|
|
20
|
+
export interface ChordRibbon extends ChordLink {
|
|
21
|
+
/** Range inside the source's sector. */
|
|
22
|
+
at: [number, number];
|
|
23
|
+
/** Range inside the target's sector. */
|
|
24
|
+
to: [number, number];
|
|
25
|
+
}
|
|
26
|
+
export interface ChordLayout {
|
|
27
|
+
sectors: ChordSector[];
|
|
28
|
+
ribbons: ChordRibbon[];
|
|
29
|
+
/** What one turn stands for, less the gaps. */
|
|
30
|
+
total: number;
|
|
31
|
+
/** Sectors the cap turned down. The footer owes a clause for it. */
|
|
32
|
+
dropped: number;
|
|
33
|
+
}
|
|
34
|
+
export interface ChordOptions {
|
|
35
|
+
/** Gap between one sector and the next, in degrees. Default 2. */
|
|
36
|
+
gap?: number;
|
|
37
|
+
/** Where the first sector starts, in degrees counterclockwise from twelve. Default 0. */
|
|
38
|
+
start?: number;
|
|
39
|
+
/** Sectors to keep, largest first. */
|
|
40
|
+
cap?: number;
|
|
41
|
+
}
|
|
42
|
+
/** Sectors past this are slivers with names that collide. The footer states the count. */
|
|
43
|
+
export declare const CHORD_CAP = 26;
|
|
44
|
+
/**
|
|
45
|
+
* Sectors placed and ribbons seated inside them.
|
|
46
|
+
*
|
|
47
|
+
* A name's sector is sized by everything touching it. The widest link of a sector seats first.
|
|
48
|
+
*/
|
|
49
|
+
export declare function chordLayout(links: readonly ChordLink[], { gap, start, cap }?: ChordOptions): ChordLayout;
|