@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,496 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authoring, apart from the format it produces.
|
|
3
|
+
*
|
|
4
|
+
* `plot()` takes rows and an aes and `spec()` emits a `ChartSpec`. `StoredSpec` adds where a host
|
|
5
|
+
* keeps it, and the host writes those fields.
|
|
6
|
+
*/
|
|
7
|
+
import { isAesthetic, kindFacts, statKeysOf, STYLE_KEYS, } from "./geom-table.js";
|
|
8
|
+
import { SPEC_VERSION, } from "./spec.js";
|
|
9
|
+
/** Confidence level a curve takes where the author states none. */
|
|
10
|
+
const DEFAULT_LEVEL = 0.95;
|
|
11
|
+
/** Fields any layer states, whatever its kind. */
|
|
12
|
+
const COMMON_FIELDS = [
|
|
13
|
+
"name",
|
|
14
|
+
"axis",
|
|
15
|
+
"visible",
|
|
16
|
+
"palette",
|
|
17
|
+
"scales",
|
|
18
|
+
"data",
|
|
19
|
+
"showLegend",
|
|
20
|
+
];
|
|
21
|
+
const everyFieldRouted = true;
|
|
22
|
+
void everyFieldRouted;
|
|
23
|
+
/** A spec's own copy of a layer. The rows stay shared, as `props()` shares the plot's. */
|
|
24
|
+
const fresh = ({ data, ...layer }) => ({ ...structuredClone(layer), ...(data ? { data } : {}) });
|
|
25
|
+
/**
|
|
26
|
+
* A chart under construction, ggplot's plot object.
|
|
27
|
+
*
|
|
28
|
+
* Persistent. Each method returns a new builder and leaves this one as it was, and a base plot
|
|
29
|
+
* branches into as many charts as the author builds from it. `plot()` makes the first.
|
|
30
|
+
*/
|
|
31
|
+
class PlotBuilder {
|
|
32
|
+
data;
|
|
33
|
+
aes;
|
|
34
|
+
id;
|
|
35
|
+
layers;
|
|
36
|
+
draft;
|
|
37
|
+
constructor(data, aes, id, layers = [], draft = {}) {
|
|
38
|
+
this.data = data;
|
|
39
|
+
this.aes = aes;
|
|
40
|
+
this.id = id;
|
|
41
|
+
this.layers = layers;
|
|
42
|
+
this.draft = draft;
|
|
43
|
+
}
|
|
44
|
+
/** This chart with some chart-level fields stated. */
|
|
45
|
+
stating(change) {
|
|
46
|
+
return new PlotBuilder(this.data, this.aes, this.id, this.layers, { ...this.draft, ...change });
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* This chart and one more layer, under the plot's aes or under `own` alone.
|
|
50
|
+
*
|
|
51
|
+
* The id is the kind and the layer's position, and two builds agree. A key the kind reads nowhere
|
|
52
|
+
* throws, naming the key.
|
|
53
|
+
*/
|
|
54
|
+
push(kind, options = {}, own) {
|
|
55
|
+
const { aes, parts, ...stated } = options;
|
|
56
|
+
const stray = Object.keys({ ...(own ?? this.aes), ...aes }).find((key) => !isAesthetic(key));
|
|
57
|
+
if (stray)
|
|
58
|
+
throw new Error(`ts-lib-viz: ${stray} is not an aesthetic`);
|
|
59
|
+
const facts = kindFacts(kind);
|
|
60
|
+
/*
|
|
61
|
+
The plot's aesthetics the kind reads reach the layer, and the rest stay behind. An aesthetic
|
|
62
|
+
the layer states that its kind reads nowhere throws.
|
|
63
|
+
*/
|
|
64
|
+
const reads = new Set([...facts.requires, ...facts.accepts]);
|
|
65
|
+
const refused = Object.entries(own ?? aes ?? {}).find(([key, column]) => column !== undefined && !reads.has(key));
|
|
66
|
+
if (refused)
|
|
67
|
+
throw new Error(`ts-lib-viz: ${refused[0]} is no aesthetic of a ${kind} layer`);
|
|
68
|
+
const merged = own ?? {
|
|
69
|
+
...Object.fromEntries(Object.entries(this.aes).filter(([key]) => reads.has(key))),
|
|
70
|
+
...aes,
|
|
71
|
+
};
|
|
72
|
+
const part = Object.keys(parts ?? {}).find((name) => !facts.parts.includes(name));
|
|
73
|
+
if (part)
|
|
74
|
+
throw new Error(`ts-lib-viz: a ${kind} layer has no ${part} part`);
|
|
75
|
+
const styles = new Set([...facts.paints, ...facts.style]);
|
|
76
|
+
const statKeys = statKeysOf(kind);
|
|
77
|
+
/* `bin` on a row marks the bin statistic's parameters and names no layer field. */
|
|
78
|
+
const fields = new Set([
|
|
79
|
+
...COMMON_FIELDS,
|
|
80
|
+
...facts.layer.filter((field) => field !== "bin"),
|
|
81
|
+
...(kind === "smooth" ? ["smooth"] : []),
|
|
82
|
+
]);
|
|
83
|
+
/*
|
|
84
|
+
The flat options sorted into three halves -- a style, statistic parameters and the layer.
|
|
85
|
+
Each is a constant. A column binds through the aes.
|
|
86
|
+
*/
|
|
87
|
+
const style = {};
|
|
88
|
+
const layer = {};
|
|
89
|
+
const statParams = {};
|
|
90
|
+
for (const [key, value] of Object.entries(stated)) {
|
|
91
|
+
if (value === undefined)
|
|
92
|
+
continue;
|
|
93
|
+
if (styles.has(key))
|
|
94
|
+
style[key] = value;
|
|
95
|
+
else if (statKeys.has(key))
|
|
96
|
+
statParams[key] = value;
|
|
97
|
+
else if (fields.has(key))
|
|
98
|
+
layer[key] = value;
|
|
99
|
+
else if (isAesthetic(key) && !STYLE_KEYS.has(key))
|
|
100
|
+
throw new Error(`ts-lib-viz: ${kind} maps ${key} to a column through aes`);
|
|
101
|
+
else
|
|
102
|
+
throw new Error(`ts-lib-viz: ${key} is no option of a ${kind} layer`);
|
|
103
|
+
}
|
|
104
|
+
const next = {
|
|
105
|
+
...layer,
|
|
106
|
+
id: `${kind}${this.layers.length}`,
|
|
107
|
+
kind,
|
|
108
|
+
aes: merged,
|
|
109
|
+
/*
|
|
110
|
+
Written where the author stated one. A spec gets no empty style or statistic object, and
|
|
111
|
+
each geom takes its own default at draw time.
|
|
112
|
+
*/
|
|
113
|
+
...(Object.keys(style).length > 0 || parts ? { style: { ...style, ...(parts ? { parts } : {}) } } : {}),
|
|
114
|
+
...(Object.keys(statParams).length > 0 ? { statParams: statParams } : {}),
|
|
115
|
+
};
|
|
116
|
+
return new PlotBuilder(this.data, this.aes, this.id, [...this.layers, next], this.draft);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* One layer of a named kind, under the plot's aes. `layer("point", options)` is `point(options)`.
|
|
120
|
+
*
|
|
121
|
+
* The kind decides the options, as it does on the kind's own method. A kind typed `PlotKind` takes
|
|
122
|
+
* each kind's fields at once.
|
|
123
|
+
*/
|
|
124
|
+
layer(kind, ...args) {
|
|
125
|
+
const options = (args[0] ?? {});
|
|
126
|
+
switch (kind) {
|
|
127
|
+
case "smooth":
|
|
128
|
+
return this.smooth(options);
|
|
129
|
+
case "hline":
|
|
130
|
+
return this.hline(options);
|
|
131
|
+
case "vline":
|
|
132
|
+
return this.vline(options);
|
|
133
|
+
case "abline":
|
|
134
|
+
return this.abline(options);
|
|
135
|
+
default:
|
|
136
|
+
return this.push(kind, options);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/*
|
|
140
|
+
One method per kind, taking what that kind's own geometry reads.
|
|
141
|
+
|
|
142
|
+
The argument list comes off `GEOMS` through `LayerArgs`. `LayerCall` decides whether the
|
|
143
|
+
argument is optional.
|
|
144
|
+
*/
|
|
145
|
+
point(...args) {
|
|
146
|
+
return this.push("point", args[0]);
|
|
147
|
+
}
|
|
148
|
+
line(...args) {
|
|
149
|
+
return this.push("line", args[0]);
|
|
150
|
+
}
|
|
151
|
+
area(...args) {
|
|
152
|
+
return this.push("area", args[0]);
|
|
153
|
+
}
|
|
154
|
+
bar(...args) {
|
|
155
|
+
return this.push("bar", args[0]);
|
|
156
|
+
}
|
|
157
|
+
/*
|
|
158
|
+
Signed steps on a running total, taking a bar's aes and reading no fill.
|
|
159
|
+
|
|
160
|
+
The hue is the step's direction. `parts.rise` and `parts.fall` paint it.
|
|
161
|
+
*/
|
|
162
|
+
waterfall(...args) {
|
|
163
|
+
return this.push("waterfall", args[0]);
|
|
164
|
+
}
|
|
165
|
+
histogram(...args) {
|
|
166
|
+
return this.push("histogram", args[0]);
|
|
167
|
+
}
|
|
168
|
+
/* The same count under the same bin, drawn as a run between the centers. */
|
|
169
|
+
freqpoly(...args) {
|
|
170
|
+
return this.push("freqpoly", args[0]);
|
|
171
|
+
}
|
|
172
|
+
hex(...args) {
|
|
173
|
+
return this.push("hex", args[0]);
|
|
174
|
+
}
|
|
175
|
+
boxplot(...args) {
|
|
176
|
+
return this.push("boxplot", args[0]);
|
|
177
|
+
}
|
|
178
|
+
violin(...args) {
|
|
179
|
+
return this.push("violin", args[0]);
|
|
180
|
+
}
|
|
181
|
+
/* A kernel density over one measure. `bw` states the smoothing the curve's shape rests on. */
|
|
182
|
+
density(...args) {
|
|
183
|
+
return this.push("density", args[0]);
|
|
184
|
+
}
|
|
185
|
+
contour(...args) {
|
|
186
|
+
return this.push("contour", args[0]);
|
|
187
|
+
}
|
|
188
|
+
heatmap(...args) {
|
|
189
|
+
return this.push("heatmap", args[0]);
|
|
190
|
+
}
|
|
191
|
+
ribbon(...args) {
|
|
192
|
+
return this.push("ribbon", args[0]);
|
|
193
|
+
}
|
|
194
|
+
/* The same two bounds a mark at a time, as ggplot's four interval geoms. */
|
|
195
|
+
errorbar(...args) {
|
|
196
|
+
return this.push("errorbar", args[0]);
|
|
197
|
+
}
|
|
198
|
+
linerange(...args) {
|
|
199
|
+
return this.push("linerange", args[0]);
|
|
200
|
+
}
|
|
201
|
+
pointrange(...args) {
|
|
202
|
+
return this.push("pointrange", args[0]);
|
|
203
|
+
}
|
|
204
|
+
crossbar(...args) {
|
|
205
|
+
return this.push("crossbar", args[0]);
|
|
206
|
+
}
|
|
207
|
+
segment(...args) {
|
|
208
|
+
return this.push("segment", args[0]);
|
|
209
|
+
}
|
|
210
|
+
/*
|
|
211
|
+
The three with a vocabulary of their own.
|
|
212
|
+
|
|
213
|
+
A flow names a source and a target. `plot()` takes whatever channels a kind reads.
|
|
214
|
+
*/
|
|
215
|
+
sankey(...args) {
|
|
216
|
+
return this.push("sankey", args[0]);
|
|
217
|
+
}
|
|
218
|
+
/** The same pairs round a center, with an axis per sector. */
|
|
219
|
+
chord(...args) {
|
|
220
|
+
return this.push("chord", args[0]);
|
|
221
|
+
}
|
|
222
|
+
/** A genome round a circle, one sector per chromosome. */
|
|
223
|
+
ideogram(...args) {
|
|
224
|
+
return this.push("ideogram", args[0]);
|
|
225
|
+
}
|
|
226
|
+
treemap(...args) {
|
|
227
|
+
return this.push("treemap", args[0]);
|
|
228
|
+
}
|
|
229
|
+
icicle(...args) {
|
|
230
|
+
return this.push("icicle", args[0]);
|
|
231
|
+
}
|
|
232
|
+
/* The same nesting round a center. It owes a number on each slice. */
|
|
233
|
+
sunburst(...args) {
|
|
234
|
+
return this.push("sunburst", args[0]);
|
|
235
|
+
}
|
|
236
|
+
parcoords(...args) {
|
|
237
|
+
return this.push("parcoords", args[0]);
|
|
238
|
+
}
|
|
239
|
+
/*
|
|
240
|
+
The polar three, with the coordinate on the kind.
|
|
241
|
+
|
|
242
|
+
A pie takes a bar's aes. `innerRadius` above zero draws a donut.
|
|
243
|
+
*/
|
|
244
|
+
pie(...args) {
|
|
245
|
+
return this.push("pie", args[0]);
|
|
246
|
+
}
|
|
247
|
+
gauge(...args) {
|
|
248
|
+
return this.push("gauge", args[0]);
|
|
249
|
+
}
|
|
250
|
+
/*
|
|
251
|
+
The parallel plot round a center, taking the same ordered list of measures.
|
|
252
|
+
|
|
253
|
+
The order the list keeps is the order the spokes take.
|
|
254
|
+
*/
|
|
255
|
+
radar(...args) {
|
|
256
|
+
return this.push("radar", args[0]);
|
|
257
|
+
}
|
|
258
|
+
/** ggplot's `geom_text`: a label per row at its reading. `vjust` and `hjust` read ggplot's way. */
|
|
259
|
+
text(...args) {
|
|
260
|
+
return this.push("text", args[0]);
|
|
261
|
+
}
|
|
262
|
+
/** ggplot's `geom_label`: the same label with a box behind it. */
|
|
263
|
+
label(...args) {
|
|
264
|
+
return this.push("label", args[0]);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* ggplot's `geom_hline`. A number or a list draws a line at each, and a column the aes binds reads
|
|
268
|
+
* them off rows.
|
|
269
|
+
*
|
|
270
|
+
* It inherits no aes and trains no scale.
|
|
271
|
+
*/
|
|
272
|
+
hline({ yintercept, ...options }) {
|
|
273
|
+
return this.rule("hline", { yintercept }, options);
|
|
274
|
+
}
|
|
275
|
+
/** ggplot's `geom_vline`, taking its positions the way `hline` does. */
|
|
276
|
+
vline({ xintercept, ...options }) {
|
|
277
|
+
return this.rule("vline", { xintercept }, options);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* ggplot's `geom_abline`, read in the scales' transformed space.
|
|
281
|
+
*
|
|
282
|
+
* Neither argument, flat or in the aes, draws the identity line. On log axes a 2-fold line is an
|
|
283
|
+
* intercept of `log10(2)`.
|
|
284
|
+
*/
|
|
285
|
+
abline({ slope, intercept, ...options } = {}) {
|
|
286
|
+
const bound = options.aes?.slope !== undefined || options.aes?.intercept !== undefined;
|
|
287
|
+
return this.rule("abline", bound ? { slope, intercept } : { slope: slope ?? 1, intercept: intercept ?? 0 }, options);
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* A reference layer off its positions.
|
|
291
|
+
*
|
|
292
|
+
* Constants alone become the layer's own rows, one per line. A column the aes binds reads the
|
|
293
|
+
* layer's rows, and a constant beside it lands on each row, a list of labels one per row. The aes
|
|
294
|
+
* wins a position or a label stated both ways.
|
|
295
|
+
*/
|
|
296
|
+
rule(kind, positions, { label, aes = {}, data, ...options }) {
|
|
297
|
+
const flat = Object.entries(positions).find(([, value]) => typeof value === "string");
|
|
298
|
+
if (flat)
|
|
299
|
+
throw new Error(`ts-lib-viz: ${kind} maps ${flat[0]} to a column through aes`);
|
|
300
|
+
const bound = Object.keys(positions).some((key) => aes[key] !== undefined);
|
|
301
|
+
const lists = Object.entries(positions).flatMap(([key, value]) => value === undefined || aes[key] !== undefined
|
|
302
|
+
? []
|
|
303
|
+
: [[key, typeof value === "number" ? [value] : value]]);
|
|
304
|
+
if (!bound && lists.length === 0)
|
|
305
|
+
throw new Error(`ts-lib-viz: ${kind} takes a position for each line it draws`);
|
|
306
|
+
const labels = label == null || aes.label !== undefined ? null : typeof label === "string" ? [label] : label;
|
|
307
|
+
const pick = (values, at) => values[Math.min(at, values.length - 1)];
|
|
308
|
+
const constants = (at) => ({
|
|
309
|
+
...Object.fromEntries(lists.map(([key, values]) => [key, pick(values, at)])),
|
|
310
|
+
...(labels ? { label: pick(labels, at) } : {}),
|
|
311
|
+
});
|
|
312
|
+
let rows = data;
|
|
313
|
+
if (!bound) {
|
|
314
|
+
const count = lists.reduce((most, [, values]) => Math.max(most, values.length), Math.max(1, labels?.length ?? 0));
|
|
315
|
+
rows = Array.from({ length: count }, (_, at) => constants(at));
|
|
316
|
+
}
|
|
317
|
+
else if (lists.length > 0 || labels) {
|
|
318
|
+
if (!data || lists.some(([, values]) => values.length !== 1))
|
|
319
|
+
throw new Error(`ts-lib-viz: ${kind} takes a constant beside a column as one value over rows of its own`);
|
|
320
|
+
rows = data.map((row, at) => ({ ...row, ...constants(at) }));
|
|
321
|
+
}
|
|
322
|
+
const own = { ...Object.fromEntries(lists.map(([key]) => [key, key])), ...(labels ? { label: "label" } : {}), ...aes };
|
|
323
|
+
/* ggplot's `inherit.aes = FALSE`: the layer reads its own channels and none of the plot's. */
|
|
324
|
+
return this.push(kind, { ...options, ...(rows ? { data: rows } : {}) }, own);
|
|
325
|
+
}
|
|
326
|
+
point3d(...args) {
|
|
327
|
+
return this.push("point3d", args[0]);
|
|
328
|
+
}
|
|
329
|
+
surface(...args) {
|
|
330
|
+
return this.push("surface", args[0]);
|
|
331
|
+
}
|
|
332
|
+
mesh3d(...args) {
|
|
333
|
+
return this.push("mesh3d", args[0]);
|
|
334
|
+
}
|
|
335
|
+
isosurface(...args) {
|
|
336
|
+
return this.push("isosurface", args[0]);
|
|
337
|
+
}
|
|
338
|
+
volume(...args) {
|
|
339
|
+
return this.push("volume", args[0]);
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* A curve through the points, drawn without them.
|
|
343
|
+
*
|
|
344
|
+
* The `Fitter` the chart was given answers it. A chart with none draws the other layers and no
|
|
345
|
+
* curve.
|
|
346
|
+
*/
|
|
347
|
+
smooth(options) {
|
|
348
|
+
const { method, span, degree, family, level = DEFAULT_LEVEL, band = true, ...layer } = options;
|
|
349
|
+
/*
|
|
350
|
+
Reassembled. The method and its arguments arrive in one flat object, and the union says
|
|
351
|
+
which of them belong together.
|
|
352
|
+
*/
|
|
353
|
+
const smooth = {
|
|
354
|
+
method,
|
|
355
|
+
...(span !== undefined ? { span } : {}),
|
|
356
|
+
...(degree !== undefined ? { degree } : {}),
|
|
357
|
+
...(family !== undefined ? { family } : {}),
|
|
358
|
+
level,
|
|
359
|
+
band,
|
|
360
|
+
};
|
|
361
|
+
return this.push("smooth", { ...layer, smooth });
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* A parametric model, over a geom that draws the readings it was fitted through.
|
|
365
|
+
*
|
|
366
|
+
* A property of the layer, and the curve takes those readings' color and split.
|
|
367
|
+
*/
|
|
368
|
+
fit(options) {
|
|
369
|
+
const { model, level = DEFAULT_LEVEL, band = true, ...layer } = options;
|
|
370
|
+
return this.push("point", { ...layer, fit: { model, level, band } });
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* The figure's words, ggplot's `labs()`: the claim, the line under it, the caption, and each
|
|
374
|
+
* aesthetic's title.
|
|
375
|
+
*
|
|
376
|
+
* The headline is a sentence the critic holds to the axis titles. A title writes
|
|
377
|
+
* `scales.<aesthetic>.title`, the field `scale()` writes.
|
|
378
|
+
*/
|
|
379
|
+
labs({ headline, subtitle, caption, ...titles }) {
|
|
380
|
+
let next = this.stating({
|
|
381
|
+
...(headline !== undefined ? { headline } : {}),
|
|
382
|
+
...(subtitle !== undefined ? { subtitle } : {}),
|
|
383
|
+
...(caption !== undefined ? { caption } : {}),
|
|
384
|
+
});
|
|
385
|
+
for (const [aesthetic, title] of Object.entries(titles)) {
|
|
386
|
+
if (title !== undefined)
|
|
387
|
+
next = next.scale(aesthetic, { title });
|
|
388
|
+
}
|
|
389
|
+
return next;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* One panel per value of `by`, `columns` of them to a row.
|
|
393
|
+
*
|
|
394
|
+
* ggplot's `facet_wrap(~by, ncol =)`. Absent, the width divides by the narrowest panel worth
|
|
395
|
+
* cutting a column for.
|
|
396
|
+
*/
|
|
397
|
+
facet(by, { columns } = {}) {
|
|
398
|
+
return this.stating({ facet: columns === undefined ? { by } : { by, columns } });
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Draws the shared pair of scales the other way round, which is ggplot's `coord_flip()`.
|
|
402
|
+
*
|
|
403
|
+
* The names stay with the data. `x` is still whatever the aes bound to it.
|
|
404
|
+
*/
|
|
405
|
+
flip() {
|
|
406
|
+
return this.stating({ coord: "flip" });
|
|
407
|
+
}
|
|
408
|
+
/** Units of y per unit of x on screen, in transformed space. ggplot's `coord_fixed()`. */
|
|
409
|
+
fixed(ratio = 1) {
|
|
410
|
+
return this.stating({ ratio });
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* What the author states on one aesthetic's scale, ggplot's `scale_*()`.
|
|
414
|
+
*
|
|
415
|
+
* Merged over what an earlier call stated, and this composes with `scales` and `labs` in any order.
|
|
416
|
+
*/
|
|
417
|
+
scale(aesthetic, options) {
|
|
418
|
+
return this.stating({ scales: { ...this.draft.scales, [aesthetic]: { ...this.draft.scales?.[aesthetic], ...options } } });
|
|
419
|
+
}
|
|
420
|
+
/** Each scale at once, for a caller that already has the object. Merged per aesthetic. */
|
|
421
|
+
scales(options) {
|
|
422
|
+
return Object.entries(options).reduce((next, [aesthetic, settings]) => (settings ? next.scale(aesthetic, settings) : next), this);
|
|
423
|
+
}
|
|
424
|
+
/** A `log10` transform on one scale, the override asked for most. The vertical by default. */
|
|
425
|
+
log(aesthetic = "y") {
|
|
426
|
+
return this.scale(aesthetic, { transform: "log10" });
|
|
427
|
+
}
|
|
428
|
+
legend(options) {
|
|
429
|
+
return this.stating({ legend: { ...this.draft.legend, ...options } });
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Columns the tooltip adds after the bound aesthetics, in order.
|
|
433
|
+
*
|
|
434
|
+
* Copied, and a caller that goes on mutating its own array cannot edit a spec it handed over.
|
|
435
|
+
*/
|
|
436
|
+
tooltip(fields) {
|
|
437
|
+
return this.stating({ tooltip: [...fields] });
|
|
438
|
+
}
|
|
439
|
+
side(...panels) {
|
|
440
|
+
return this.stating({ sides: [...(this.draft.sides ?? []), ...panels] });
|
|
441
|
+
}
|
|
442
|
+
annotate(...args) {
|
|
443
|
+
const [first, values] = args;
|
|
444
|
+
if (typeof first !== "string") {
|
|
445
|
+
return this.stating({ annotations: [...(this.draft.annotations ?? []), ...args] });
|
|
446
|
+
}
|
|
447
|
+
const stated = values;
|
|
448
|
+
if (first === "hline" || first === "vline" || first === "abline") {
|
|
449
|
+
const { yintercept, xintercept, slope, intercept, ...rest } = stated;
|
|
450
|
+
const positions = { yintercept, xintercept, slope, intercept };
|
|
451
|
+
return this.rule(first, positions, { ...rest, showLegend: false });
|
|
452
|
+
}
|
|
453
|
+
/* One row per entry off the required aesthetics. A scalar repeats on each row, as in ggplot's `annotate`. */
|
|
454
|
+
const required = new Set(kindFacts(first).requires);
|
|
455
|
+
const bound = Object.entries(stated).filter(([key]) => required.has(key));
|
|
456
|
+
const constants = Object.fromEntries(Object.entries(stated).filter(([key]) => !required.has(key)));
|
|
457
|
+
const count = bound.reduce((most, [, value]) => Math.max(most, Array.isArray(value) ? value.length : 1), 1);
|
|
458
|
+
const rows = Array.from({ length: count }, (_, at) => Object.fromEntries(bound.map(([key, value]) => [key, Array.isArray(value) ? value[Math.min(at, value.length - 1)] : value])));
|
|
459
|
+
/* ggplot's `annotate` inherits no aes. The layer reads its own columns. */
|
|
460
|
+
const own = Object.fromEntries(bound.map(([key]) => [key, key]));
|
|
461
|
+
return this.push(first, { ...constants, data: rows, showLegend: false }, own);
|
|
462
|
+
}
|
|
463
|
+
/** The figure's size and how it takes its room. `width` and `height` are the whole figure's. */
|
|
464
|
+
canvas(options) {
|
|
465
|
+
return this.stating(options);
|
|
466
|
+
}
|
|
467
|
+
/** A critic finding this figure is allowed to keep. */
|
|
468
|
+
override(...codes) {
|
|
469
|
+
return this.stating({ overrides: [...(this.draft.overrides ?? []), ...codes] });
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* The document a store saves, in objects of its own. Editing one spec leaves the builder and each
|
|
473
|
+
* other spec as they were.
|
|
474
|
+
*
|
|
475
|
+
* A figure with no claim builds and draws, and `blocking` refuses it. A headline of whitespace
|
|
476
|
+
* is dropped.
|
|
477
|
+
*/
|
|
478
|
+
spec() {
|
|
479
|
+
const { headline: written, ...draft } = structuredClone(this.draft);
|
|
480
|
+
const headline = written?.trim();
|
|
481
|
+
return {
|
|
482
|
+
version: SPEC_VERSION,
|
|
483
|
+
...draft,
|
|
484
|
+
id: this.id,
|
|
485
|
+
...(headline ? { headline } : {}),
|
|
486
|
+
layers: this.layers.map(fresh),
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
/** The document and its rows, for spreading onto `Viz`. */
|
|
490
|
+
props() {
|
|
491
|
+
return { spec: this.spec(), data: this.data };
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
export function plot(data, aes = {}, id = "chart") {
|
|
495
|
+
return new PlotBuilder(data, aes, id);
|
|
496
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
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
|
+
/** Where the reader is standing, in spherical coordinates about the cube's center. */
|
|
7
|
+
export interface Orbit {
|
|
8
|
+
/** Turn about the vertical axis, in radians. */
|
|
9
|
+
azimuth: number;
|
|
10
|
+
/** Height above the floor plane, in radians. */
|
|
11
|
+
elevation: number;
|
|
12
|
+
/** Distance from the center, in cube half-widths. */
|
|
13
|
+
distance: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Where a cube opens.
|
|
17
|
+
*
|
|
18
|
+
* Turned off the axes and tilted above the floor, which shows three scales at once. Straight
|
|
19
|
+
* down an axis draws two of the three edge-on.
|
|
20
|
+
*/
|
|
21
|
+
export declare const AT_REST_ORBIT: Orbit;
|
|
22
|
+
/** The orbit after a drag, in pixels, with the tilt held clear of the poles. */
|
|
23
|
+
export declare const orbited: (orbit: Orbit, dx: number, dy: number) => Orbit;
|
|
24
|
+
/**
|
|
25
|
+
* The orbit after a wheel notch.
|
|
26
|
+
*
|
|
27
|
+
* Multiplicative, and a notch moves the same proportion of the way in at any distance.
|
|
28
|
+
*/
|
|
29
|
+
export declare const dollied: (orbit: Orbit, notches: number) => Orbit;
|
|
30
|
+
/** Whether the reader has moved. A cube at rest draws what it always drew. */
|
|
31
|
+
export declare const isOrbited: (orbit: Orbit) => boolean;
|
|
32
|
+
/** Column-major. `uniformMatrix4fv` reads this order without transposing. */
|
|
33
|
+
type Mat4 = Float32Array;
|
|
34
|
+
/** Where the eye falls for an orbit, in world space. */
|
|
35
|
+
export declare function eyeOf(orbit: Orbit): [number, number, number];
|
|
36
|
+
/** The three domains a cube spans, in the data's own units. */
|
|
37
|
+
export interface CubeDomains {
|
|
38
|
+
x: [number, number];
|
|
39
|
+
y: [number, number];
|
|
40
|
+
z: [number, number];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The model matrix -- data offsets onto the unit cube, with z drawing upward.
|
|
44
|
+
*
|
|
45
|
+
* A float32 spends its digits on a timestamp. The center is the number the CPU keeps.
|
|
46
|
+
*/
|
|
47
|
+
export declare function cubeModel(domains: CubeDomains, center: [number, number, number]): Mat4;
|
|
48
|
+
/**
|
|
49
|
+
* The one matrix the cube program takes.
|
|
50
|
+
*
|
|
51
|
+
* Model, view and projection multiplied on the CPU. The product changes once a frame.
|
|
52
|
+
*/
|
|
53
|
+
export declare function cubeMatrix(orbit: Orbit, aspect: number, domains: CubeDomains, center: [number, number, number]): Float32Array;
|
|
54
|
+
/** A data point after the matrix, in the pixels of a plot area of a stated size. */
|
|
55
|
+
export interface Projected {
|
|
56
|
+
x: number;
|
|
57
|
+
y: number;
|
|
58
|
+
/** View depth. A caller tells a near edge from a far one. */
|
|
59
|
+
depth: number;
|
|
60
|
+
}
|
|
61
|
+
/** Where a data point lands, for the chrome the CPU draws around what the GPU drew. */
|
|
62
|
+
export declare function projectData(matrix: Float32Array, point: [number, number, number], center: [number, number, number], width: number, height: number): Projected;
|
|
63
|
+
/** One of the box's twelve edges, in pixels, with how far away it runs. */
|
|
64
|
+
export interface CubeEdge {
|
|
65
|
+
from: Projected;
|
|
66
|
+
to: Projected;
|
|
67
|
+
/** Mean view depth. The edges behind the geoms draw apart from the ones in front. */
|
|
68
|
+
depth: number;
|
|
69
|
+
/** Whether the edge joins two back walls. The GPU draws a back edge, under the geoms. */
|
|
70
|
+
back: boolean;
|
|
71
|
+
}
|
|
72
|
+
/** A segment between two data points, drawn under the camera. */
|
|
73
|
+
export type CubeSegment = [[number, number, number], [number, number, number]];
|
|
74
|
+
/** Four data points around a face of the box, in order. */
|
|
75
|
+
export type CubeQuad = [
|
|
76
|
+
[
|
|
77
|
+
number,
|
|
78
|
+
number,
|
|
79
|
+
number
|
|
80
|
+
],
|
|
81
|
+
[
|
|
82
|
+
number,
|
|
83
|
+
number,
|
|
84
|
+
number
|
|
85
|
+
],
|
|
86
|
+
[
|
|
87
|
+
number,
|
|
88
|
+
number,
|
|
89
|
+
number
|
|
90
|
+
],
|
|
91
|
+
[
|
|
92
|
+
number,
|
|
93
|
+
number,
|
|
94
|
+
number
|
|
95
|
+
]
|
|
96
|
+
];
|
|
97
|
+
/** An axis of the box: the edge it is written along, and the values it names. */
|
|
98
|
+
export interface CubeAxis {
|
|
99
|
+
axis: "x" | "y" | "z";
|
|
100
|
+
from: Projected;
|
|
101
|
+
to: Projected;
|
|
102
|
+
ticks: {
|
|
103
|
+
at: Projected;
|
|
104
|
+
value: number;
|
|
105
|
+
}[];
|
|
106
|
+
}
|
|
107
|
+
export interface CubeChrome {
|
|
108
|
+
edges: CubeEdge[];
|
|
109
|
+
axes: CubeAxis[];
|
|
110
|
+
/** Grid lines on the three back walls -- the walls furthest from the camera. */
|
|
111
|
+
grid: CubeEdge[];
|
|
112
|
+
/**
|
|
113
|
+
* The grid, back edges and back faces in data units, for the GPU.
|
|
114
|
+
*
|
|
115
|
+
* A pane is keyed by the axis it crosses. The `z` pane is the floor.
|
|
116
|
+
*/
|
|
117
|
+
walls: {
|
|
118
|
+
grid: CubeSegment[];
|
|
119
|
+
edges: CubeSegment[];
|
|
120
|
+
panes: Record<"x" | "y" | "z", CubeQuad>;
|
|
121
|
+
};
|
|
122
|
+
/** Where the middle of the box lands. A label pushes away from it to clear the geoms. */
|
|
123
|
+
middle: Projected;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The box the geoms draw in, projected.
|
|
127
|
+
*
|
|
128
|
+
* Two of the three scales are foreshortened and a rule draws in projection. The axis edge is the
|
|
129
|
+
* one furthest from the reader.
|
|
130
|
+
*/
|
|
131
|
+
export declare function cubeChrome(matrix: Float32Array, domains: CubeDomains, center: [number, number, number], width: number, height: number): CubeChrome;
|
|
132
|
+
/**
|
|
133
|
+
* What turns a normal in the data's axes into one in the light's world.
|
|
134
|
+
*
|
|
135
|
+
* The inverse transpose of a diagonal map is the reciprocal of its diagonal.
|
|
136
|
+
*/
|
|
137
|
+
export declare function normalMatrix(domains: CubeDomains): Float32Array;
|
|
138
|
+
/**
|
|
139
|
+
* Where the light stands, in world space.
|
|
140
|
+
*
|
|
141
|
+
* Fixed to the world. Turning the figure moves the light across it.
|
|
142
|
+
*/
|
|
143
|
+
export declare const CUBE_LIGHT: readonly [number, number, number];
|
|
144
|
+
/** How much of a face's color survives with no light on it. A shadowed slope stays readable. */
|
|
145
|
+
export declare const AMBIENT = 0.45;
|
|
146
|
+
/**
|
|
147
|
+
* The view depth at which a geom draws the diameter its caller asked for.
|
|
148
|
+
*
|
|
149
|
+
* The shader divides this by the vertex view depth. A geom mid-cube draws its given size.
|
|
150
|
+
*/
|
|
151
|
+
export declare const restingDepth: (orbit: Orbit) => number;
|
|
152
|
+
export {};
|