@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,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Density -- geoms binned into a grid. The drawn count follows the pixels.
|
|
3
|
+
*
|
|
4
|
+
* One cell per device pixel. A cell cannot be hovered for its record. The grid accumulates.
|
|
5
|
+
*/
|
|
6
|
+
export interface DensityGrid {
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
/** One count per cell, row-major from the low corner of the domain. */
|
|
10
|
+
counts: Uint32Array;
|
|
11
|
+
/** Rows binned to date, in-domain only. */
|
|
12
|
+
binned: number;
|
|
13
|
+
}
|
|
14
|
+
export declare function densityGrid(width: number, height: number): DensityGrid;
|
|
15
|
+
/**
|
|
16
|
+
* Bins a batch of points into the grid and returns how many landed inside the domain.
|
|
17
|
+
*
|
|
18
|
+
* A point on the domain's top edge belongs to the last cell.
|
|
19
|
+
*/
|
|
20
|
+
export declare function binPoints(grid: DensityGrid, xs: ArrayLike<number>, ys: ArrayLike<number>, xDomain: [number, number], yDomain: [number, number], count?: number): number;
|
|
21
|
+
/** Sums a shard's counts into the whole, for grids binned in parallel over one domain. */
|
|
22
|
+
export declare function mergeGrids(into: DensityGrid, from: DensityGrid): void;
|
|
23
|
+
export interface DensityCells {
|
|
24
|
+
/** Cell centers in data space. The cells draw through an ordinary geom. */
|
|
25
|
+
xs: Float64Array;
|
|
26
|
+
ys: Float64Array;
|
|
27
|
+
/**
|
|
28
|
+
* Log-scaled density from 0 to 1, 1 at the fullest cell.
|
|
29
|
+
*
|
|
30
|
+
* Counts skew by orders of magnitude wherever real data clusters. A linear ramp over that
|
|
31
|
+
* renders as two shades.
|
|
32
|
+
*/
|
|
33
|
+
weight: Float64Array;
|
|
34
|
+
cells: number;
|
|
35
|
+
peak: number;
|
|
36
|
+
}
|
|
37
|
+
/** The non-empty cells for a geom. Positions at cell centers and weights for a ramp. */
|
|
38
|
+
export declare function densityCells(grid: DensityGrid, xDomain: [number, number], yDomain: [number, number]): DensityCells;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Density -- geoms binned into a grid. The drawn count follows the pixels.
|
|
3
|
+
*
|
|
4
|
+
* One cell per device pixel. A cell cannot be hovered for its record. The grid accumulates.
|
|
5
|
+
*/
|
|
6
|
+
export function densityGrid(width, height) {
|
|
7
|
+
return { width, height, counts: new Uint32Array(width * height), binned: 0 };
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Bins a batch of points into the grid and returns how many landed inside the domain.
|
|
11
|
+
*
|
|
12
|
+
* A point on the domain's top edge belongs to the last cell.
|
|
13
|
+
*/
|
|
14
|
+
export function binPoints(grid, xs, ys, xDomain, yDomain, count = Math.min(xs.length, ys.length)) {
|
|
15
|
+
const { width, height, counts } = grid;
|
|
16
|
+
const xSpan = xDomain[1] - xDomain[0] || 1;
|
|
17
|
+
const ySpan = yDomain[1] - yDomain[0] || 1;
|
|
18
|
+
const xScale = width / xSpan;
|
|
19
|
+
const yScale = height / ySpan;
|
|
20
|
+
let landed = 0;
|
|
21
|
+
for (let i = 0; i < count; i += 1) {
|
|
22
|
+
const x = xs[i];
|
|
23
|
+
const y = ys[i];
|
|
24
|
+
/* The domain test runs before the cell index. `|0` truncates toward zero and a reading
|
|
25
|
+
below the domain would land in cell zero. NaN slips the comparisons. */
|
|
26
|
+
if (!Number.isFinite(x) || !Number.isFinite(y))
|
|
27
|
+
continue;
|
|
28
|
+
if (x < xDomain[0] || x > xDomain[1] || y < yDomain[0] || y > yDomain[1])
|
|
29
|
+
continue;
|
|
30
|
+
let gx = ((x - xDomain[0]) * xScale) | 0;
|
|
31
|
+
let gy = ((y - yDomain[0]) * yScale) | 0;
|
|
32
|
+
if (gx === width)
|
|
33
|
+
gx = width - 1;
|
|
34
|
+
if (gy === height)
|
|
35
|
+
gy = height - 1;
|
|
36
|
+
counts[gy * width + gx] += 1;
|
|
37
|
+
landed += 1;
|
|
38
|
+
}
|
|
39
|
+
grid.binned += landed;
|
|
40
|
+
return landed;
|
|
41
|
+
}
|
|
42
|
+
/** Sums a shard's counts into the whole, for grids binned in parallel over one domain. */
|
|
43
|
+
export function mergeGrids(into, from) {
|
|
44
|
+
if (into.width !== from.width || into.height !== from.height) {
|
|
45
|
+
throw new Error("ts-lib-viz: grids of different shapes cannot merge");
|
|
46
|
+
}
|
|
47
|
+
for (let cell = 0; cell < into.counts.length; cell += 1) {
|
|
48
|
+
into.counts[cell] += from.counts[cell];
|
|
49
|
+
}
|
|
50
|
+
into.binned += from.binned;
|
|
51
|
+
}
|
|
52
|
+
/** The non-empty cells for a geom. Positions at cell centers and weights for a ramp. */
|
|
53
|
+
export function densityCells(grid, xDomain, yDomain) {
|
|
54
|
+
const { width, height, counts } = grid;
|
|
55
|
+
let cells = 0;
|
|
56
|
+
let peak = 0;
|
|
57
|
+
for (let cell = 0; cell < counts.length; cell += 1) {
|
|
58
|
+
const held = counts[cell];
|
|
59
|
+
if (held === 0)
|
|
60
|
+
continue;
|
|
61
|
+
cells += 1;
|
|
62
|
+
if (held > peak)
|
|
63
|
+
peak = held;
|
|
64
|
+
}
|
|
65
|
+
const xs = new Float64Array(cells);
|
|
66
|
+
const ys = new Float64Array(cells);
|
|
67
|
+
const weight = new Float64Array(cells);
|
|
68
|
+
const cellWidth = (xDomain[1] - xDomain[0]) / width;
|
|
69
|
+
const cellHeight = (yDomain[1] - yDomain[0]) / height;
|
|
70
|
+
const logPeak = Math.log(peak + 1);
|
|
71
|
+
let at = 0;
|
|
72
|
+
for (let cell = 0; cell < counts.length; cell += 1) {
|
|
73
|
+
const held = counts[cell];
|
|
74
|
+
if (held === 0)
|
|
75
|
+
continue;
|
|
76
|
+
xs[at] = xDomain[0] + ((cell % width) + 0.5) * cellWidth;
|
|
77
|
+
ys[at] = yDomain[0] + (Math.floor(cell / width) + 0.5) * cellHeight;
|
|
78
|
+
weight[at] = Math.log(held + 1) / logPeak;
|
|
79
|
+
at += 1;
|
|
80
|
+
}
|
|
81
|
+
return { xs, ys, weight, cells, peak };
|
|
82
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A set of figures and the colors they agree on.
|
|
3
|
+
*
|
|
4
|
+
* `assignments` maps a field id to a value to a categorical index. `assign` grows it at the save
|
|
5
|
+
* path.
|
|
6
|
+
*/
|
|
7
|
+
export interface SetMember {
|
|
8
|
+
plotId: string;
|
|
9
|
+
}
|
|
10
|
+
/** Field id, to value, to position in the categorical palette. */
|
|
11
|
+
export type Assignments = Record<string, Record<string, number>>;
|
|
12
|
+
/**
|
|
13
|
+
* What the figures of a set agree on. A host keeps its own name and id for the set on its own type.
|
|
14
|
+
*
|
|
15
|
+
* `Viz` reads `assignments`, and `critiqueSet` reads `members`.
|
|
16
|
+
*/
|
|
17
|
+
export interface FigureSet {
|
|
18
|
+
assignments: Assignments;
|
|
19
|
+
/** The members in reading order. The arc checks read this order. Absent is a set with none. */
|
|
20
|
+
members?: readonly SetMember[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A field's codes under the set's assignments.
|
|
24
|
+
*
|
|
25
|
+
* A pinned value draws at its pinned index. An unpinned value takes the next index above the
|
|
26
|
+
* pinned ones and gaps stay unfilled.
|
|
27
|
+
*/
|
|
28
|
+
export declare function pinnedOver(seen: Map<string, number>, pinned?: Record<string, number>): Map<string, number>;
|
|
29
|
+
/**
|
|
30
|
+
* The set with any unassigned value of a field given an index.
|
|
31
|
+
*
|
|
32
|
+
* Called at the save path. Returns the set it was handed when there is nothing to add.
|
|
33
|
+
*/
|
|
34
|
+
export declare function assign(set: FigureSet, fieldId: string, values: Iterable<string>): FigureSet;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A set of figures and the colors they agree on.
|
|
3
|
+
*
|
|
4
|
+
* `assignments` maps a field id to a value to a categorical index. `assign` grows it at the save
|
|
5
|
+
* path.
|
|
6
|
+
*/
|
|
7
|
+
import { boundsOf } from "./aggregate.js";
|
|
8
|
+
/** The first index above everything a field has assigned. */
|
|
9
|
+
const nextFree = (pinned) => {
|
|
10
|
+
const held = Object.values(pinned);
|
|
11
|
+
return held.length === 0 ? 0 : boundsOf(held)[1] + 1;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A field's codes under the set's assignments.
|
|
15
|
+
*
|
|
16
|
+
* A pinned value draws at its pinned index. An unpinned value takes the next index above the
|
|
17
|
+
* pinned ones and gaps stay unfilled.
|
|
18
|
+
*/
|
|
19
|
+
export function pinnedOver(seen, pinned) {
|
|
20
|
+
if (!pinned || Object.keys(pinned).length === 0)
|
|
21
|
+
return seen;
|
|
22
|
+
const codes = new Map();
|
|
23
|
+
let free = nextFree(pinned);
|
|
24
|
+
for (const value of seen.keys()) {
|
|
25
|
+
const held = pinned[value];
|
|
26
|
+
codes.set(value, held ?? free);
|
|
27
|
+
if (held == null)
|
|
28
|
+
free += 1;
|
|
29
|
+
}
|
|
30
|
+
for (const [value, index] of Object.entries(pinned)) {
|
|
31
|
+
if (!codes.has(value))
|
|
32
|
+
codes.set(value, index);
|
|
33
|
+
}
|
|
34
|
+
return codes;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The set with any unassigned value of a field given an index.
|
|
38
|
+
*
|
|
39
|
+
* Called at the save path. Returns the set it was handed when there is nothing to add.
|
|
40
|
+
*/
|
|
41
|
+
export function assign(set, fieldId, values) {
|
|
42
|
+
const pinned = set.assignments[fieldId] ?? {};
|
|
43
|
+
const fresh = [...values].filter((value) => pinned[value] == null);
|
|
44
|
+
if (fresh.length === 0)
|
|
45
|
+
return set;
|
|
46
|
+
let free = nextFree(pinned);
|
|
47
|
+
const grown = { ...pinned };
|
|
48
|
+
for (const value of fresh) {
|
|
49
|
+
if (grown[value] != null)
|
|
50
|
+
continue;
|
|
51
|
+
grown[value] = free;
|
|
52
|
+
free += 1;
|
|
53
|
+
}
|
|
54
|
+
return { ...set, assignments: { ...set.assignments, [fieldId]: grown } };
|
|
55
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stable identifier for a check.
|
|
3
|
+
*
|
|
4
|
+
* An override names one of these. Overriding by severity would waive checks nobody looked at.
|
|
5
|
+
*/
|
|
6
|
+
export type FindingCode = "grounded-nonlinear-axis" | "grounded-truncated-axis" | "cumulative-of-a-statistic" | "cumulative-unsupported" | "empty-as-zero-of-a-statistic" | "fixed-statistic" | "color-alone" | "colors-past-legible" | "band-below-legible" | "numbers-below-legible" | "cluster-past-cap" | "dendrogram-without-order" | "sides-under-facet" | "track-group-disagrees" | "track-without-categories" | "marginal-without-readings" | "ring-without-readings" | "magnitudes-past-legible" | "figure-past-container" | "unlabeled-reference" | "bare-numeric-axis" | "headline-restates-axes" | "overplotted-past-switch" | "legend-order" | "legend-missing" | "title-over-numbers" | "headline-missing" | "set-repeats-form" | "set-opens-derived" | "size-carries-the-measure" | "size-past-fill-budget" | "cube-copied-static" | "graph-links-dropped" | "angle-encodes-comparison" | "slices-past-legible" | "single-value-as-arc" | "pie-not-parts" | "area-with-no-nesting" | "bandwidths-disagree" | "width-hides-the-count" | "shapes-past-glyphs";
|
|
7
|
+
/** A code no override waives. A figure with no headline makes no claim to disagree with. */
|
|
8
|
+
export type UnwaivableCode = "headline-missing";
|
|
9
|
+
/** A code `ChartSpec.overrides` can name. */
|
|
10
|
+
export type WaivableCode = Exclude<FindingCode, UnwaivableCode>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fitted curve shapes.
|
|
3
|
+
*
|
|
4
|
+
* Fitting runs in the service and the package reads results. The fetch and the hook that fills
|
|
5
|
+
* these stay with the consumer.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* One curve's outcome.
|
|
9
|
+
*
|
|
10
|
+
* `reason` carries the solver's taxonomy. `max_nfev` means the solver spent its whole budget.
|
|
11
|
+
* `unidentifiable` means the data does not determine the solution it returned.
|
|
12
|
+
*/
|
|
13
|
+
export interface Fit {
|
|
14
|
+
id: string;
|
|
15
|
+
/**
|
|
16
|
+
* Facet value for this curve, echoed from the request.
|
|
17
|
+
*
|
|
18
|
+
* Absent on an unfaceted plot. Separate from `id` -- a category can hold characters that
|
|
19
|
+
* collide on a delimiter join.
|
|
20
|
+
*/
|
|
21
|
+
panel?: string;
|
|
22
|
+
success: boolean;
|
|
23
|
+
reason: string | null;
|
|
24
|
+
params: Record<string, number>;
|
|
25
|
+
r2: number | null;
|
|
26
|
+
rmse: number | null;
|
|
27
|
+
n: number;
|
|
28
|
+
curveX: readonly number[];
|
|
29
|
+
curveY: readonly number[];
|
|
30
|
+
band: {
|
|
31
|
+
lo: readonly number[];
|
|
32
|
+
hi: readonly number[];
|
|
33
|
+
} | null;
|
|
34
|
+
}
|
|
35
|
+
export interface LayerFits {
|
|
36
|
+
fits: Fit[];
|
|
37
|
+
/** Groups a cap refused. A partial answer should not read as a whole one. */
|
|
38
|
+
dropped: number;
|
|
39
|
+
}
|
|
40
|
+
export interface FitState {
|
|
41
|
+
/** Keyed by series id. Absent where a series asked for no fit. */
|
|
42
|
+
byLayer: Map<string, LayerFits>;
|
|
43
|
+
pending: boolean;
|
|
44
|
+
/** Set where the service could not be reached or refused the request. */
|
|
45
|
+
problem: string | null;
|
|
46
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The seam a fitted curve arrives through.
|
|
3
|
+
*
|
|
4
|
+
* `FitSpec` says what to fit and `Fit` says what came back. The consumer supplies the function
|
|
5
|
+
* between them.
|
|
6
|
+
*/
|
|
7
|
+
import type { LayerFits } from "./fit-types.js";
|
|
8
|
+
import type { Trace } from "./layers.js";
|
|
9
|
+
import type { FitSpec, LayerSpec, SmoothSpec } from "./spec.js";
|
|
10
|
+
/** Points one curve is fitted through. */
|
|
11
|
+
export interface FitGroup {
|
|
12
|
+
/**
|
|
13
|
+
* Value of the split field these points share. Empty where the series draws as one trace.
|
|
14
|
+
*
|
|
15
|
+
* The id the returned `Fit` takes. `fitsFor` reads it.
|
|
16
|
+
*/
|
|
17
|
+
id: string;
|
|
18
|
+
/** Facet value the points came from. Absent where the plot draws one panel. */
|
|
19
|
+
panel?: string;
|
|
20
|
+
points: {
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
}[];
|
|
24
|
+
}
|
|
25
|
+
/** One series' fit as the author asked for it, with the points underneath. */
|
|
26
|
+
export interface FitRequest {
|
|
27
|
+
layerId: string;
|
|
28
|
+
/** What to compute. A `SmoothSpec` names a method, a `FitSpec` names a parametric model. */
|
|
29
|
+
spec: FitSpec | SmoothSpec;
|
|
30
|
+
groups: FitGroup[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* What fills a `FitState`.
|
|
34
|
+
*
|
|
35
|
+
* Async, and the answer comes over a wire while the chart is already drawn. Keyed by series id
|
|
36
|
+
* coming back.
|
|
37
|
+
*/
|
|
38
|
+
export type Fitter = (requests: FitRequest[]) => Promise<Map<string, LayerFits>>;
|
|
39
|
+
/**
|
|
40
|
+
* What to fit, off the traces the frame built.
|
|
41
|
+
*
|
|
42
|
+
* The split cap decides how many curves reach the frame. A series with no `fit` or no records
|
|
43
|
+
* asks for nothing.
|
|
44
|
+
*/
|
|
45
|
+
export declare function fitRequests(traces: Trace[], series: readonly LayerSpec[], panel?: string): FitRequest[];
|
|
46
|
+
/**
|
|
47
|
+
* What to fit across a faceted figure.
|
|
48
|
+
*
|
|
49
|
+
* A facet builds a frame per panel and the same series appears in each. The panel is part of the
|
|
50
|
+
* key.
|
|
51
|
+
*/
|
|
52
|
+
export declare function fitRequestsOver(panels: {
|
|
53
|
+
value: string;
|
|
54
|
+
traces: Trace[];
|
|
55
|
+
}[], series: readonly LayerSpec[]): FitRequest[];
|
|
56
|
+
/**
|
|
57
|
+
* What would change the curves, in one string.
|
|
58
|
+
*
|
|
59
|
+
* Covers the model, the interval, the grouping and the coordinates. The coordinates go through a
|
|
60
|
+
* rolling hash.
|
|
61
|
+
*/
|
|
62
|
+
export declare function fitSignature(requests: FitRequest[]): string;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The seam a fitted curve arrives through.
|
|
3
|
+
*
|
|
4
|
+
* `FitSpec` says what to fit and `Fit` says what came back. The consumer supplies the function
|
|
5
|
+
* between them.
|
|
6
|
+
*/
|
|
7
|
+
import { pointsOf } from "./frame.js";
|
|
8
|
+
/**
|
|
9
|
+
* What to fit, off the traces the frame built.
|
|
10
|
+
*
|
|
11
|
+
* The split cap decides how many curves reach the frame. A series with no `fit` or no records
|
|
12
|
+
* asks for nothing.
|
|
13
|
+
*/
|
|
14
|
+
export function fitRequests(traces, series, panel) {
|
|
15
|
+
const asked = new Map();
|
|
16
|
+
/*
|
|
17
|
+
A smooth kind reads `smooth` and anything else reads `fit`. A field set on a kind that ignores
|
|
18
|
+
it asks for nothing.
|
|
19
|
+
*/
|
|
20
|
+
for (const entry of series) {
|
|
21
|
+
const spec = entry.kind === "smooth" ? entry.smooth : entry.fit;
|
|
22
|
+
if (spec)
|
|
23
|
+
asked.set(entry.id, spec);
|
|
24
|
+
}
|
|
25
|
+
const groups = new Map();
|
|
26
|
+
for (const trace of traces) {
|
|
27
|
+
if (!asked.has(trace.layerId))
|
|
28
|
+
continue;
|
|
29
|
+
/* A non-finite coordinate is a row missing a measure. One rule covers each fitter. */
|
|
30
|
+
const points = pointsOf(trace)
|
|
31
|
+
.filter((point) => Number.isFinite(point.x) && Number.isFinite(point.y))
|
|
32
|
+
.map((point) => ({ x: point.x, y: point.y }));
|
|
33
|
+
if (points.length === 0)
|
|
34
|
+
continue;
|
|
35
|
+
const found = groups.get(trace.layerId) ?? [];
|
|
36
|
+
found.push({ id: trace.splitValue ?? "", ...(panel === undefined ? {} : { panel }), points });
|
|
37
|
+
groups.set(trace.layerId, found);
|
|
38
|
+
}
|
|
39
|
+
return [...groups].map(([layerId, found]) => ({ layerId, spec: asked.get(layerId), groups: found }));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* What to fit across a faceted figure.
|
|
43
|
+
*
|
|
44
|
+
* A facet builds a frame per panel and the same series appears in each. The panel is part of the
|
|
45
|
+
* key.
|
|
46
|
+
*/
|
|
47
|
+
export function fitRequestsOver(panels, series) {
|
|
48
|
+
const merged = new Map();
|
|
49
|
+
for (const panel of panels) {
|
|
50
|
+
for (const request of fitRequests(panel.traces, series, panel.value)) {
|
|
51
|
+
const found = merged.get(request.layerId);
|
|
52
|
+
if (found)
|
|
53
|
+
found.groups.push(...request.groups);
|
|
54
|
+
else
|
|
55
|
+
merged.set(request.layerId, request);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return [...merged.values()];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Order-sensitive hash of a group's coordinates, as an unsigned 32-bit integer.
|
|
62
|
+
*
|
|
63
|
+
* FNV-1a over the bit patterns of the doubles, order included.
|
|
64
|
+
*/
|
|
65
|
+
function hash(points) {
|
|
66
|
+
const view = new DataView(new ArrayBuffer(8));
|
|
67
|
+
let out = 0x811c9dc5;
|
|
68
|
+
for (const point of points) {
|
|
69
|
+
for (const value of [point.x, point.y]) {
|
|
70
|
+
view.setFloat64(0, value);
|
|
71
|
+
for (let byte = 0; byte < 8; byte += 1) {
|
|
72
|
+
out ^= view.getUint8(byte);
|
|
73
|
+
out = Math.imul(out, 0x01000193);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return out >>> 0;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* What would change the curves, in one string.
|
|
81
|
+
*
|
|
82
|
+
* Covers the model, the interval, the grouping and the coordinates. The coordinates go through a
|
|
83
|
+
* rolling hash.
|
|
84
|
+
*/
|
|
85
|
+
export function fitSignature(requests) {
|
|
86
|
+
return requests
|
|
87
|
+
.map((request) => {
|
|
88
|
+
/*
|
|
89
|
+
The spec's own fields, sorted by name. Taken whole -- a smoother's arguments move the curve
|
|
90
|
+
the way its method does.
|
|
91
|
+
*/
|
|
92
|
+
const spec = Object.entries(request.spec)
|
|
93
|
+
.filter(([, value]) => value !== undefined)
|
|
94
|
+
.sort(([left], [right]) => (left < right ? -1 : 1))
|
|
95
|
+
.map(([key, value]) => `${key}=${JSON.stringify(value)}`)
|
|
96
|
+
.join(",");
|
|
97
|
+
const head = [request.layerId, spec].join("|");
|
|
98
|
+
const groups = request.groups.map((group) => `${group.panel ?? ""}/${group.id}:${group.points.length}:${hash(group.points)}`);
|
|
99
|
+
return [head, ...groups].join("|");
|
|
100
|
+
})
|
|
101
|
+
.join(";");
|
|
102
|
+
}
|