@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,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Triangles for the two cube kinds drawing a surface.
|
|
3
|
+
*
|
|
4
|
+
* `surface` reduces a measure over a grid of two and triangulates it. `mesh3d` arrives as
|
|
5
|
+
* vertices and faces.
|
|
6
|
+
*/
|
|
7
|
+
import { NEEDS_VALUES, reduceBucket } from "./aggregate.js";
|
|
8
|
+
/**
|
|
9
|
+
* The most cells a relief takes across each dimension.
|
|
10
|
+
*
|
|
11
|
+
* Forty squares a side is 1,600 cells and 3,200 triangles, which draws in one call.
|
|
12
|
+
*/
|
|
13
|
+
export const SURFACE_CELLS = 40;
|
|
14
|
+
/**
|
|
15
|
+
* Cells a table of this many rows supports.
|
|
16
|
+
*
|
|
17
|
+
* A cell with no reading is a hole and the quads either side go too. Two rows a cell.
|
|
18
|
+
*/
|
|
19
|
+
export const cellsFor = (rowCount) => Math.max(4, Math.min(SURFACE_CELLS, Math.round(Math.sqrt(rowCount / 2))));
|
|
20
|
+
/** The most cells a lattice takes across each dimension. */
|
|
21
|
+
export const LATTICE_CAP = 256;
|
|
22
|
+
/** Cells across a set of values at its smallest step. Each value takes a cell of its own. */
|
|
23
|
+
function stepsOf(values) {
|
|
24
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
25
|
+
let step = Infinity;
|
|
26
|
+
for (let at = 1; at < sorted.length; at += 1)
|
|
27
|
+
step = Math.min(step, sorted[at] - sorted[at - 1]);
|
|
28
|
+
return Math.round((sorted[sorted.length - 1] - sorted[0]) / step) + 1;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The lattice under two columns, as cells across and down. Null for a scatter.
|
|
32
|
+
*
|
|
33
|
+
* One row per crossing. Cells run at the smallest step between two values.
|
|
34
|
+
*/
|
|
35
|
+
export function latticeOf(data, xId, yId) {
|
|
36
|
+
const xs = new Set();
|
|
37
|
+
const ys = new Set();
|
|
38
|
+
for (let row = 0; row < data.rowCount; row += 1) {
|
|
39
|
+
const x = data.number(row, xId);
|
|
40
|
+
const y = data.number(row, yId);
|
|
41
|
+
if (x == null || y == null)
|
|
42
|
+
continue;
|
|
43
|
+
xs.add(x);
|
|
44
|
+
ys.add(y);
|
|
45
|
+
if (xs.size > LATTICE_CAP || ys.size > LATTICE_CAP)
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
if (xs.size < 2 || ys.size < 2 || xs.size * ys.size > data.rowCount * 1.05)
|
|
49
|
+
return null;
|
|
50
|
+
const across = stepsOf(xs);
|
|
51
|
+
const down = stepsOf(ys);
|
|
52
|
+
return across > LATTICE_CAP || down > LATTICE_CAP ? null : [across, down];
|
|
53
|
+
}
|
|
54
|
+
const extentOf = (data, field) => {
|
|
55
|
+
let lo = Infinity;
|
|
56
|
+
let hi = -Infinity;
|
|
57
|
+
for (let row = 0; row < data.rowCount; row += 1) {
|
|
58
|
+
const value = data.number(row, field);
|
|
59
|
+
if (value == null)
|
|
60
|
+
continue;
|
|
61
|
+
if (value < lo)
|
|
62
|
+
lo = value;
|
|
63
|
+
if (value > hi)
|
|
64
|
+
hi = value;
|
|
65
|
+
}
|
|
66
|
+
return Number.isFinite(lo) ? [lo, hi] : null;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* A measure reduced over a grid of two others.
|
|
70
|
+
*
|
|
71
|
+
* The grid is regular in both dimensions. Rows on a lattice take its own cells. Cells nothing
|
|
72
|
+
* landed in stay holes -- interpolating them would draw terrain nobody measured.
|
|
73
|
+
*/
|
|
74
|
+
export function relief(data, xId, yId, zId, aggregate = "mean", cells = latticeOf(data, xId, yId) ?? cellsFor(data.rowCount)) {
|
|
75
|
+
const xDomain = extentOf(data, xId);
|
|
76
|
+
const yDomain = extentOf(data, yId);
|
|
77
|
+
if (!xDomain || !yDomain)
|
|
78
|
+
return null;
|
|
79
|
+
const [columns, rows] = typeof cells === "number" ? [cells, cells] : cells;
|
|
80
|
+
const xSpan = xDomain[1] - xDomain[0] || 1;
|
|
81
|
+
const ySpan = yDomain[1] - yDomain[0] || 1;
|
|
82
|
+
const buckets = Array.from({ length: columns * rows }, () => ({
|
|
83
|
+
sum: 0,
|
|
84
|
+
sumSq: 0,
|
|
85
|
+
n: 0,
|
|
86
|
+
min: Infinity,
|
|
87
|
+
max: -Infinity,
|
|
88
|
+
}));
|
|
89
|
+
/* The readings themselves, kept only under the aggregates that read them. */
|
|
90
|
+
const keeps = NEEDS_VALUES.includes(aggregate);
|
|
91
|
+
const collected = keeps ? Array.from({ length: columns * rows }, () => []) : null;
|
|
92
|
+
for (let row = 0; row < data.rowCount; row += 1) {
|
|
93
|
+
const x = data.number(row, xId);
|
|
94
|
+
const y = data.number(row, yId);
|
|
95
|
+
const z = data.number(row, zId);
|
|
96
|
+
if (x == null || y == null || z == null)
|
|
97
|
+
continue;
|
|
98
|
+
const column = Math.min(columns - 1, Math.floor(((x - xDomain[0]) / xSpan) * columns));
|
|
99
|
+
const line = Math.min(rows - 1, Math.floor(((y - yDomain[0]) / ySpan) * rows));
|
|
100
|
+
const cell = line * columns + column;
|
|
101
|
+
const bucket = buckets[cell];
|
|
102
|
+
bucket.sum += z;
|
|
103
|
+
bucket.sumSq += z * z;
|
|
104
|
+
bucket.n += 1;
|
|
105
|
+
if (z < bucket.min)
|
|
106
|
+
bucket.min = z;
|
|
107
|
+
if (z > bucket.max)
|
|
108
|
+
bucket.max = z;
|
|
109
|
+
collected?.[cell].push(z);
|
|
110
|
+
}
|
|
111
|
+
const values = new Float64Array(columns * rows);
|
|
112
|
+
let lo = Infinity;
|
|
113
|
+
let hi = -Infinity;
|
|
114
|
+
for (let cell = 0; cell < values.length; cell += 1) {
|
|
115
|
+
const bucket = buckets[cell];
|
|
116
|
+
if (bucket.n === 0) {
|
|
117
|
+
values[cell] = NaN;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const value = reduceBucket(bucket, aggregate, collected?.[cell]);
|
|
121
|
+
values[cell] = value;
|
|
122
|
+
if (value < lo)
|
|
123
|
+
lo = value;
|
|
124
|
+
if (value > hi)
|
|
125
|
+
hi = value;
|
|
126
|
+
}
|
|
127
|
+
if (!Number.isFinite(lo))
|
|
128
|
+
return null;
|
|
129
|
+
return { values, columns, rows, xDomain, yDomain, zDomain: [lo, hi] };
|
|
130
|
+
}
|
|
131
|
+
/** Unit normals averaged over the faces each vertex belongs to. */
|
|
132
|
+
function normalsOf(positions, indices) {
|
|
133
|
+
const normals = new Float32Array(positions.length);
|
|
134
|
+
for (let face = 0; face < indices.length; face += 3) {
|
|
135
|
+
const a = indices[face] * 3;
|
|
136
|
+
const b = indices[face + 1] * 3;
|
|
137
|
+
const c = indices[face + 2] * 3;
|
|
138
|
+
const ux = positions[b] - positions[a];
|
|
139
|
+
const uy = positions[b + 1] - positions[a + 1];
|
|
140
|
+
const uz = positions[b + 2] - positions[a + 2];
|
|
141
|
+
const vx = positions[c] - positions[a];
|
|
142
|
+
const vy = positions[c + 1] - positions[a + 1];
|
|
143
|
+
const vz = positions[c + 2] - positions[a + 2];
|
|
144
|
+
const nx = uy * vz - uz * vy;
|
|
145
|
+
const ny = uz * vx - ux * vz;
|
|
146
|
+
const nz = ux * vy - uy * vx;
|
|
147
|
+
for (const at of [a, b, c]) {
|
|
148
|
+
normals[at] += nx;
|
|
149
|
+
normals[at + 1] += ny;
|
|
150
|
+
normals[at + 2] += nz;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
for (let at = 0; at < normals.length; at += 3) {
|
|
154
|
+
const length = Math.hypot(normals[at], normals[at + 1], normals[at + 2]) || 1;
|
|
155
|
+
normals[at] /= length;
|
|
156
|
+
normals[at + 1] /= length;
|
|
157
|
+
normals[at + 2] /= length;
|
|
158
|
+
}
|
|
159
|
+
return normals;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* A relief as triangles.
|
|
163
|
+
*
|
|
164
|
+
* Two a cell, and a cell missing any of its four corners is left out. The positions take the
|
|
165
|
+
* third scale in its own units.
|
|
166
|
+
*/
|
|
167
|
+
export function meshOfRelief(grid) {
|
|
168
|
+
const { values, columns, rows, xDomain, yDomain } = grid;
|
|
169
|
+
/* A vertex sits at the center of the cell it summarizes. `relief` bins the domain into
|
|
170
|
+
`columns` cells, and spacing over `columns - 1` intervals would stretch the surface. */
|
|
171
|
+
const xStep = (xDomain[1] - xDomain[0]) / columns;
|
|
172
|
+
const yStep = (yDomain[1] - yDomain[0]) / rows;
|
|
173
|
+
const positions = new Float32Array(columns * rows * 3);
|
|
174
|
+
for (let line = 0; line < rows; line += 1) {
|
|
175
|
+
for (let column = 0; column < columns; column += 1) {
|
|
176
|
+
const at = (line * columns + column) * 3;
|
|
177
|
+
positions[at] = xDomain[0] + (column + 0.5) * xStep;
|
|
178
|
+
positions[at + 1] = yDomain[0] + (line + 0.5) * yStep;
|
|
179
|
+
positions[at + 2] = values[line * columns + column];
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const faces = [];
|
|
183
|
+
for (let line = 0; line < rows - 1; line += 1) {
|
|
184
|
+
for (let column = 0; column < columns - 1; column += 1) {
|
|
185
|
+
const a = line * columns + column;
|
|
186
|
+
const b = a + 1;
|
|
187
|
+
const c = a + columns;
|
|
188
|
+
const d = c + 1;
|
|
189
|
+
if ([a, b, c, d].some((corner) => Number.isNaN(values[corner])))
|
|
190
|
+
continue;
|
|
191
|
+
/* Counterclockwise seen from above, which puts the face normal on +z. */
|
|
192
|
+
faces.push(a, b, c, c, b, d);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (faces.length === 0)
|
|
196
|
+
return null;
|
|
197
|
+
// A hole leaves its corner unreferenced, and a vertex with no reading would draw at NaN.
|
|
198
|
+
for (let at = 2; at < positions.length; at += 3) {
|
|
199
|
+
if (Number.isNaN(positions[at]))
|
|
200
|
+
positions[at] = grid.zDomain[0];
|
|
201
|
+
}
|
|
202
|
+
const indices = new Uint32Array(faces);
|
|
203
|
+
return { positions, normals: normalsOf(positions, indices), indices, zDomain: grid.zDomain };
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Vertices and faces as they arrive.
|
|
207
|
+
*
|
|
208
|
+
* The faces are triples of row numbers. A triple naming a row the table does not have is dropped.
|
|
209
|
+
*/
|
|
210
|
+
export function meshOfRows(data, xId, yId, zId, faces) {
|
|
211
|
+
const positions = new Float32Array(data.rowCount * 3);
|
|
212
|
+
let lo = Infinity;
|
|
213
|
+
let hi = -Infinity;
|
|
214
|
+
const usable = new Uint8Array(data.rowCount);
|
|
215
|
+
for (let row = 0; row < data.rowCount; row += 1) {
|
|
216
|
+
const x = data.number(row, xId);
|
|
217
|
+
const y = data.number(row, yId);
|
|
218
|
+
const z = data.number(row, zId);
|
|
219
|
+
if (x == null || y == null || z == null)
|
|
220
|
+
continue;
|
|
221
|
+
positions[row * 3] = x;
|
|
222
|
+
positions[row * 3 + 1] = y;
|
|
223
|
+
positions[row * 3 + 2] = z;
|
|
224
|
+
usable[row] = 1;
|
|
225
|
+
if (z < lo)
|
|
226
|
+
lo = z;
|
|
227
|
+
if (z > hi)
|
|
228
|
+
hi = z;
|
|
229
|
+
}
|
|
230
|
+
if (!Number.isFinite(lo))
|
|
231
|
+
return null;
|
|
232
|
+
const kept = faces.filter((face) => face.every((row) => row >= 0 && row < data.rowCount && usable[row] === 1));
|
|
233
|
+
if (kept.length === 0)
|
|
234
|
+
return null;
|
|
235
|
+
const indices = new Uint32Array(kept.flat());
|
|
236
|
+
return { positions, normals: normalsOf(positions, indices), indices, zDomain: [lo, hi] };
|
|
237
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Omissions a build records, and the footer sentence they produce.
|
|
3
|
+
*
|
|
4
|
+
* The build applies ten caps. A new cap is a member of `OmittedKind` and a row in `SAYS`.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* What a figure can leave out.
|
|
8
|
+
*
|
|
9
|
+
* Named after what the reader lost. `rows-sampled` and `rows-incomplete` are both rows gone
|
|
10
|
+
* missing, and the reader is owed which.
|
|
11
|
+
*/
|
|
12
|
+
export type OmittedKind = "panels" | "categories" | "splits" | "dashes" | "rows-sampled" | "stack" | "replicates" | "rows-incomplete" | "segments" | "off-log" | "off-root" | "off-range" | "floored" | "references" | "rules" | "measures" | "flows" | "links" | "colors" | "fills" | "labels";
|
|
13
|
+
/** A count of one kind, from one of the places that turned them down. */
|
|
14
|
+
export interface Omission {
|
|
15
|
+
of: OmittedKind;
|
|
16
|
+
count: number;
|
|
17
|
+
/** The categories behind a `fills` count, where a keyed map missed them. Facet panels union them. */
|
|
18
|
+
levels?: readonly string[];
|
|
19
|
+
}
|
|
20
|
+
/** The kinds in the order the footer states them. A caller walks these to render a ledger. */
|
|
21
|
+
export declare const OMITTED_KINDS: OmittedKind[];
|
|
22
|
+
/**
|
|
23
|
+
* A count added to a ledger, where there is anything to add.
|
|
24
|
+
*
|
|
25
|
+
* Zero pushes nothing. A ledger records what a reader has to be told.
|
|
26
|
+
*/
|
|
27
|
+
export declare function omit(into: Omission[], of: OmittedKind, count: number): void;
|
|
28
|
+
/**
|
|
29
|
+
* A cap that either applied or did not, entered as one.
|
|
30
|
+
*
|
|
31
|
+
* A refusal has nothing to count. It takes the smallest count standing for "this happened".
|
|
32
|
+
*/
|
|
33
|
+
export declare function flag(into: Omission[], of: OmittedKind, on: boolean): void;
|
|
34
|
+
/**
|
|
35
|
+
* How many of one kind a ledger records, over the places that reported it.
|
|
36
|
+
*
|
|
37
|
+
* Summed. A grid caps its columns and its rows apart and both reach the ledger.
|
|
38
|
+
*/
|
|
39
|
+
export declare const omittedCount: (ledger: Omission[], of: OmittedKind) => number;
|
|
40
|
+
/** One clause, in the footer's own voice. */
|
|
41
|
+
export declare const omissionLine: (of: OmittedKind, count: number) => string;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Omissions a build records, and the footer sentence they produce.
|
|
3
|
+
*
|
|
4
|
+
* The build applies ten caps. A new cap is a member of `OmittedKind` and a row in `SAYS`.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* What the footer writes for each kind, in the order it writes them.
|
|
8
|
+
*
|
|
9
|
+
* Declaration order is reading order. `stack` ignores its count and its wording states the
|
|
10
|
+
* refusal.
|
|
11
|
+
*/
|
|
12
|
+
const SAYS = {
|
|
13
|
+
panels: (many) => `${many} smaller panels past the facet cap`,
|
|
14
|
+
categories: (many) => `${many} smaller categories hidden`,
|
|
15
|
+
splits: (many) => `${many} smaller groups past the split cap`,
|
|
16
|
+
dashes: (many, count) => `${many} group${count === 1 ? "" : "s"} over several linetype values, each dashed as its first row`,
|
|
17
|
+
"rows-sampled": (many) => `${many} rows past the line cap`,
|
|
18
|
+
stack: () => "stack dropped over a negative reading",
|
|
19
|
+
replicates: (many, count) => `${many} group${count === 1 ? "" : "s"} past the replicate cap`,
|
|
20
|
+
"rows-incomplete": (many) => `${many} rows missing a measure`,
|
|
21
|
+
segments: (many, count) => `${many} segment${count === 1 ? "" : "s"} dropped over a categorical end`,
|
|
22
|
+
"off-log": (many, count) => `${many} reading${count === 1 ? "" : "s"} at or below zero left off the log axis`,
|
|
23
|
+
"off-root": (many, count) => `${many} reading${count === 1 ? "" : "s"} below zero left off the square-root axis`,
|
|
24
|
+
"off-range": (many, count) => `${many} reading${count === 1 ? "" : "s"} outside the stated range`,
|
|
25
|
+
floored: (many, count) => `${many} interval${count === 1 ? "" : "s"} cut at the axis floor`,
|
|
26
|
+
references: (many, count) => `${many} reference line${count === 1 ? "" : "s"} outside the axis range`,
|
|
27
|
+
rules: (many, count) => `${many} reference line${count === 1 ? "" : "s"} past the rule cap`,
|
|
28
|
+
measures: (many) => `${many} measures past the axis cap`,
|
|
29
|
+
flows: (many) => `${many} smaller flows hidden`,
|
|
30
|
+
links: (many, count) => `${many} link${count === 1 ? "" : "s"} outside the drawn sectors`,
|
|
31
|
+
colors: (many) => `${many} sectors drawn in one ink, past the color map`,
|
|
32
|
+
fills: (many, count) => `${many} categor${count === 1 ? "y" : "ies"} drawn in one ink, outside the color map`,
|
|
33
|
+
labels: (many) => `${many} more match the label rule`,
|
|
34
|
+
};
|
|
35
|
+
/** The kinds in the order the footer states them. A caller walks these to render a ledger. */
|
|
36
|
+
export const OMITTED_KINDS = Object.keys(SAYS);
|
|
37
|
+
/**
|
|
38
|
+
* A count added to a ledger, where there is anything to add.
|
|
39
|
+
*
|
|
40
|
+
* Zero pushes nothing. A ledger records what a reader has to be told.
|
|
41
|
+
*/
|
|
42
|
+
export function omit(into, of, count) {
|
|
43
|
+
if (count > 0)
|
|
44
|
+
into.push({ of, count });
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A cap that either applied or did not, entered as one.
|
|
48
|
+
*
|
|
49
|
+
* A refusal has nothing to count. It takes the smallest count standing for "this happened".
|
|
50
|
+
*/
|
|
51
|
+
export function flag(into, of, on) {
|
|
52
|
+
if (on)
|
|
53
|
+
into.push({ of, count: 1 });
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* How many of one kind a ledger records, over the places that reported it.
|
|
57
|
+
*
|
|
58
|
+
* Summed. A grid caps its columns and its rows apart and both reach the ledger.
|
|
59
|
+
*/
|
|
60
|
+
export const omittedCount = (ledger, of) => ledger.reduce((total, one) => (one.of === of ? total + one.count : total), 0);
|
|
61
|
+
/** One clause, in the footer's own voice. */
|
|
62
|
+
export const omissionLine = (of, count) => SAYS[of](count.toLocaleString(), count);
|