@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,32 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/** Matches --chart-radius-thin. */
|
|
3
|
+
const BOX_RADIUS = 3;
|
|
4
|
+
export function Box({ data, x, y, band, ramp, thickness, opacity, stroke, lineWidth = 1, transposed = false, showOutliers = true, showMedian = true, onHover, onSelect, }) {
|
|
5
|
+
const width = thickness != null ? Math.min(band, thickness) : Math.min(band * 0.62, 13);
|
|
6
|
+
/* The band's scale is whichever one the five numbers do not read. */
|
|
7
|
+
const along = transposed ? y : x;
|
|
8
|
+
const measure = transposed ? x : y;
|
|
9
|
+
/*
|
|
10
|
+
Two helpers name the roles, so the body below reads once for both ways round.
|
|
11
|
+
|
|
12
|
+
`block` is the interquartile rectangle and `rule` a line from one reading to another at the
|
|
13
|
+
band's own position. Everything else is a point on the two scales.
|
|
14
|
+
*/
|
|
15
|
+
const block = (at, from, to, thick, long) => transposed
|
|
16
|
+
? { x: Math.min(from, to), y: at - thick / 2, width: long, height: thick }
|
|
17
|
+
: { x: at - thick / 2, y: Math.min(from, to), width: thick, height: long };
|
|
18
|
+
const rule = (at, from, to) => transposed ? { x1: from, x2: to, y1: at, y2: at } : { x1: at, x2: at, y1: from, y2: to };
|
|
19
|
+
const cross = (at, half, on) => transposed ? { x1: on, x2: on, y1: at - half, y2: at + half } : { x1: at - half, x2: at + half, y1: on, y2: on };
|
|
20
|
+
return (_jsx("g", { children: data.map((d, index) => {
|
|
21
|
+
const cx = along(d.category);
|
|
22
|
+
const color = ramp(d.median);
|
|
23
|
+
const middle = measure(d.median);
|
|
24
|
+
const hit = { datum: d, index, at: transposed ? { x: middle, y: cx } : { x: cx, y: middle } };
|
|
25
|
+
const top = measure(d.q3);
|
|
26
|
+
const bottom = measure(d.q1);
|
|
27
|
+
const boxLength = Math.max(width * 0.7, Math.abs(bottom - top));
|
|
28
|
+
const radius = Math.min(BOX_RADIUS, width / 2, boxLength / 2);
|
|
29
|
+
return (_jsxs("g", { "data-geom": "box", onMouseEnter: () => onHover?.(hit), onMouseLeave: () => onHover?.(null), onClick: onSelect ? () => onSelect(hit) : undefined, style: onSelect ? { cursor: "pointer" } : undefined, children: [_jsx("line", { ...rule(cx, measure(d.hi), measure(d.lo)), stroke: "var(--viz-ink-muted)", strokeWidth: 0.9, strokeOpacity: 0.7 }), _jsx("rect", { ...block(cx, top, bottom, width, boxLength), rx: radius, fill: color, fillOpacity: opacity, ...(stroke ? { stroke, strokeWidth: lineWidth } : {}) }), showMedian && boxLength > width * 1.6 && (_jsx("line", { ...cross(cx, width / 2, measure(d.median)), stroke: "var(--viz-paper)", strokeWidth: 1.6, strokeOpacity: 0.85 })), showOutliers &&
|
|
30
|
+
d.outliers.map((value, i) => (_jsx("circle", { cx: transposed ? measure(value) : cx, cy: transposed ? cx : measure(value), r: 1.9, fill: "none", stroke: "var(--viz-ink-muted)", strokeWidth: 0.8 }, i)))] }, d.category));
|
|
31
|
+
}) }));
|
|
32
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A flow between names, closed into a circle.
|
|
3
|
+
*
|
|
4
|
+
* `GRAMMAR` answers `polar`. The geom takes the panel whole and places its own sectors.
|
|
5
|
+
*/
|
|
6
|
+
import { type ChordLink, type GeomHit, type RingPanel, type RingReading } from "../../core/internal.js";
|
|
7
|
+
export interface ChordProps {
|
|
8
|
+
links: ChordLink[];
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
/** Hue per sector, taken off the categorical map. Read where a link states no `color`. */
|
|
12
|
+
identity: (index: number) => string;
|
|
13
|
+
/** Distinct colors that map offers. More sectors than this draws them all in one ink. */
|
|
14
|
+
categoricalSize?: number;
|
|
15
|
+
/** The magnitude map, over 0..1. A ring's dots read their own values against it. */
|
|
16
|
+
ramp?: (t: number) => string;
|
|
17
|
+
/** The value the magnitude map treats as its middle, where the map has two arms. */
|
|
18
|
+
center?: number;
|
|
19
|
+
/** One hue for the whole figure, where the author picked one. */
|
|
20
|
+
fill?: string;
|
|
21
|
+
opacity?: number;
|
|
22
|
+
/** Gap between one sector and the next, in degrees. */
|
|
23
|
+
gap?: number;
|
|
24
|
+
/** Where the first sector starts, in degrees counterclockwise from twelve. */
|
|
25
|
+
rotate?: number;
|
|
26
|
+
/** Radial gap between the sector band and the ribbons, in pixels. */
|
|
27
|
+
inset?: number;
|
|
28
|
+
/** Type size for the names and the readings, in pixels. Absent writes neither. */
|
|
29
|
+
fontSize?: number;
|
|
30
|
+
/**
|
|
31
|
+
* The readings round each sector, in their own units. Absent draws no axis.
|
|
32
|
+
*
|
|
33
|
+
* `wanted` picks the readings written and `color` inks them.
|
|
34
|
+
*/
|
|
35
|
+
numbers?: {
|
|
36
|
+
format: (value: number) => string;
|
|
37
|
+
wanted?: (value: number) => boolean;
|
|
38
|
+
color?: string;
|
|
39
|
+
};
|
|
40
|
+
/** Writes each sector's name outside its band. */
|
|
41
|
+
names?: boolean;
|
|
42
|
+
/** Rings stacked outside the sector band, innermost first. */
|
|
43
|
+
panels?: readonly RingPanel[];
|
|
44
|
+
/** What each ring read, in the same order. A ring with no reading draws nothing. */
|
|
45
|
+
rings?: (RingReading | null)[];
|
|
46
|
+
/**
|
|
47
|
+
* The ribbon or sector under the pointer, and null when it leaves.
|
|
48
|
+
*
|
|
49
|
+
* Given, the geom drops the browser's title boxes and the caller draws the card at `at`.
|
|
50
|
+
*/
|
|
51
|
+
onHover?: (hit: (GeomHit<ChordLink> & {
|
|
52
|
+
kind: "flow";
|
|
53
|
+
}) | (GeomHit<{
|
|
54
|
+
id: string;
|
|
55
|
+
value: number;
|
|
56
|
+
}> & {
|
|
57
|
+
kind: "sector";
|
|
58
|
+
}) | null) => void;
|
|
59
|
+
}
|
|
60
|
+
export declare function Chord({ links, width, height, identity, categoricalSize, ramp, center, fill, opacity, gap, rotate, inset, fontSize, numbers, names, panels, rings, onHover, }: ChordProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A flow between names, closed into a circle.
|
|
4
|
+
*
|
|
5
|
+
* `GRAMMAR` answers `polar`. The geom takes the panel whole and places its own sectors.
|
|
6
|
+
*/
|
|
7
|
+
import { RingStack } from "./RingStack.js";
|
|
8
|
+
import { sectorAxis, sectorHues, sectorTextRoom, TICK_LEN, writtenAt } from "./sector-axis.js";
|
|
9
|
+
import { chordLayout, polarPoint, ringBands, ringLayout, RING_GAP, } from "../../core/internal.js";
|
|
10
|
+
/** Weight of the band a sector draws, in pixels. */
|
|
11
|
+
const SECTOR_WEIGHT = 10;
|
|
12
|
+
/** Weak enough that a ribbon crossing another stays readable. */
|
|
13
|
+
const RIBBON_OPACITY = 0.62;
|
|
14
|
+
export function Chord({ links, width, height, identity, categoricalSize, ramp, center, fill, opacity = 1, gap, rotate, inset = 0, fontSize, numbers, names = true, panels = [], rings = [], onHover, }) {
|
|
15
|
+
if (links.length === 0 || width <= 0 || height <= 0)
|
|
16
|
+
return null;
|
|
17
|
+
const panel = ringLayout(width, height);
|
|
18
|
+
const longestName = links.reduce((held, link) => Math.max(held, link.source.length, link.target.length), 0);
|
|
19
|
+
const room = fontSize == null ? 0 : sectorTextRoom(longestName, fontSize);
|
|
20
|
+
/* The stack takes its room off the figure, so the sectors give way to the rings outside them. */
|
|
21
|
+
const stack = panels.reduce((held, one) => held + Math.max(0, one.size) + (one.gap ?? RING_GAP), 0);
|
|
22
|
+
const sectorRadius = Math.max(0, panel.outer - room - stack) - SECTOR_WEIGHT / 2;
|
|
23
|
+
if (sectorRadius <= 0)
|
|
24
|
+
return null;
|
|
25
|
+
const layout = chordLayout(links, { gap, start: rotate });
|
|
26
|
+
const hue = sectorHues(layout.sectors, identity, categoricalSize, fill);
|
|
27
|
+
const ribbonRadius = Math.max(0, sectorRadius - SECTOR_WEIGHT / 2 - inset);
|
|
28
|
+
/* The readout a pointer gets. A chord has no axis to read a ribbon's own value off. */
|
|
29
|
+
const reads = numbers?.format ?? ((value) => String(value));
|
|
30
|
+
const at = (radius, angle) => polarPoint(panel, radius, angle);
|
|
31
|
+
const point = (radius, angle) => {
|
|
32
|
+
const on = at(radius, angle);
|
|
33
|
+
return `${on.x} ${on.y}`;
|
|
34
|
+
};
|
|
35
|
+
const sweep = (radius, from, to) => `A ${radius} ${radius} 0 ${to - from > Math.PI ? 1 : 0} 1 ${point(radius, to)}`;
|
|
36
|
+
/* Out along one end, through the middle, out along the other, and back through the middle. */
|
|
37
|
+
const ribbon = (from, to) => [
|
|
38
|
+
`M ${point(ribbonRadius, from[0])}`,
|
|
39
|
+
sweep(ribbonRadius, from[0], from[1]),
|
|
40
|
+
`Q ${panel.cx} ${panel.cy} ${point(ribbonRadius, to[0])}`,
|
|
41
|
+
sweep(ribbonRadius, to[0], to[1]),
|
|
42
|
+
`Q ${panel.cx} ${panel.cy} ${point(ribbonRadius, from[0])}`,
|
|
43
|
+
"Z",
|
|
44
|
+
].join(" ");
|
|
45
|
+
/** The middle of a ribbon's curve, where its card is placed. */
|
|
46
|
+
const spine = (from, to) => {
|
|
47
|
+
const head = at(ribbonRadius, (from[0] + from[1]) / 2);
|
|
48
|
+
const tail = at(ribbonRadius, (to[0] + to[1]) / 2);
|
|
49
|
+
return { x: (head.x + 2 * panel.cx + tail.x) / 4, y: (head.y + 2 * panel.cy + tail.y) / 4 };
|
|
50
|
+
};
|
|
51
|
+
const written = (angle, radius) => writtenAt(panel, angle, radius);
|
|
52
|
+
const bands = ringBands(sectorRadius + SECTOR_WEIGHT / 2, panels);
|
|
53
|
+
const outermost = bands.length > 0 ? bands[bands.length - 1].outer : sectorRadius + SECTOR_WEIGHT / 2;
|
|
54
|
+
/* Past the readings the axis writes, which run outward from their own ticks. */
|
|
55
|
+
const axis = sectorAxis({
|
|
56
|
+
sectors: layout.sectors,
|
|
57
|
+
panel,
|
|
58
|
+
from: outermost,
|
|
59
|
+
fontSize: fontSize ?? 11,
|
|
60
|
+
format: numbers?.format,
|
|
61
|
+
wanted: numbers?.wanted,
|
|
62
|
+
});
|
|
63
|
+
const axes = fontSize == null ? [] : axis.ticks;
|
|
64
|
+
return (_jsxs(_Fragment, { children: [_jsx("g", { "data-geom": "chord-ribbons", fillOpacity: RIBBON_OPACITY * opacity, children: layout.ribbons.map((one, index) => (_jsx("path", { d: ribbon(one.at, one.to), fill: one.color ?? hue.get(one.source) ?? "var(--viz-ink-muted)", onMouseEnter: () => onHover?.({ kind: "flow", datum: one, index, at: spine(one.at, one.to) }), onMouseLeave: () => onHover?.(null), children: !onHover && _jsx("title", { children: `${one.source} to ${one.target}, ${reads(one.value)}` }) }, `${one.source}-${one.target}-${index}`))) }), _jsx("g", { "data-geom": "chord", fill: "none", strokeWidth: SECTOR_WEIGHT, children: layout.sectors.map((sector, index) => (_jsx("path", { d: `M ${point(sectorRadius, sector.from)} ${sweep(sectorRadius, sector.from, sector.to)}`, stroke: hue.get(sector.id), strokeOpacity: opacity, onMouseEnter: () => onHover?.({
|
|
65
|
+
kind: "sector",
|
|
66
|
+
datum: { id: sector.id, value: sector.value },
|
|
67
|
+
index,
|
|
68
|
+
at: at(sectorRadius, sector.mid),
|
|
69
|
+
}), onMouseLeave: () => onHover?.(null), children: !onHover && _jsx("title", { children: `${sector.id}, ${reads(sector.value)}` }) }, sector.id))) }), _jsx(RingStack, { panel: panel, sectors: layout.sectors, bands: bands, readings: rings, hue: hue, identity: identity, ramp: fill == null ? ramp : undefined, center: center, opacity: opacity, format: reads, ribbons: layout.ribbons }), axes.length > 0 && fontSize != null && (_jsx("g", { "data-geom": "chord-axis", fontSize: fontSize, pointerEvents: "none", fill: numbers?.color ?? "var(--viz-ink-muted)", children: axes.map((tick) => {
|
|
70
|
+
const mark = written(tick.angle, axis.radius);
|
|
71
|
+
const head = at(outermost, tick.angle);
|
|
72
|
+
const tail = at(outermost + TICK_LEN, tick.angle);
|
|
73
|
+
return (_jsxs("g", { children: [_jsx("line", { x1: head.x, y1: head.y, x2: tail.x, y2: tail.y, stroke: "var(--viz-rule)" }), _jsx("text", { x: mark.x, y: mark.y, textAnchor: mark.anchor, dominantBaseline: "central", transform: mark.rotate, children: tick.text })] }, tick.key));
|
|
74
|
+
}) })), names && fontSize != null && (_jsx("g", { "data-geom": "chord-labels", fontSize: fontSize, pointerEvents: "none", fill: "var(--viz-ink)", children: layout.sectors.map((sector) => {
|
|
75
|
+
const mark = written(sector.mid, axis.nameRadius);
|
|
76
|
+
return (_jsx("text", { x: mark.x, y: mark.y, textAnchor: mark.anchor, dominantBaseline: "central", transform: mark.rotate, children: sector.id }, sector.id));
|
|
77
|
+
}) }))] }));
|
|
78
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Two measures as a smoothed density, drawn as nested bands.
|
|
3
|
+
*
|
|
4
|
+
* The hexbin beside this answers the same question by counting into cells, and the two are read
|
|
5
|
+
* differently. A bin is a number a reader can take off the chart; a contour is a shape, and the
|
|
6
|
+
* shape is what says whether a population is one cloud or two. A scatter of a quarter of a million
|
|
7
|
+
* records shows neither.
|
|
8
|
+
*
|
|
9
|
+
* `d3-contour` estimates the density and this draws it. The estimate runs in pixel space, so it is
|
|
10
|
+
* computed here instead of in the layer engine, which resolves traces before a width is known. See
|
|
11
|
+
* the ADR "Density is estimated where the pixels are".
|
|
12
|
+
*
|
|
13
|
+
* The rings carry magnitude, so they take the sequential map instead of the categorical one, per
|
|
14
|
+
* chart-design rule 8.
|
|
15
|
+
*/
|
|
16
|
+
import { type PlotPoint, type Relief } from "../../core/internal.js";
|
|
17
|
+
import type { Scale, UnitRamp, ValueRamp } from "../../core/internal.js";
|
|
18
|
+
export interface ContourProps {
|
|
19
|
+
points: PlotPoint[];
|
|
20
|
+
x: Scale;
|
|
21
|
+
y: Scale;
|
|
22
|
+
width: number;
|
|
23
|
+
height: number;
|
|
24
|
+
/** Sequential map, taken over zero to one. */
|
|
25
|
+
ramp: UnitRamp;
|
|
26
|
+
/**
|
|
27
|
+
* Multiplier on the smoothing radius. Absent takes 1.
|
|
28
|
+
*
|
|
29
|
+
* The author's reach into a radius the geom owns, which is what ggplot's `adjust` is on a
|
|
30
|
+
* two-dimensional density. Under one the second cloud sharpens and the rings pick up noise; over
|
|
31
|
+
* one the two clouds merge, which is the same claim a wide bandwidth makes on a curve.
|
|
32
|
+
*/
|
|
33
|
+
adjust?: number;
|
|
34
|
+
/** The rows' own lattice, where a measure is bound to `z`. Its values are cut in place of a density. */
|
|
35
|
+
grid?: Relief;
|
|
36
|
+
/** The measure's color in its own units, for the lattice's bands. */
|
|
37
|
+
levelRamp?: ValueRamp;
|
|
38
|
+
/** One paint for each band, where the author picked one over the ramp. */
|
|
39
|
+
fill?: string;
|
|
40
|
+
/** Paint on each band's edge. Absent draws the lattice's paper seam and the density's none. */
|
|
41
|
+
stroke?: string;
|
|
42
|
+
opacity?: number;
|
|
43
|
+
}
|
|
44
|
+
export declare function Contour(props: ContourProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Two measures as a smoothed density, drawn as nested bands.
|
|
4
|
+
*
|
|
5
|
+
* The hexbin beside this answers the same question by counting into cells, and the two are read
|
|
6
|
+
* differently. A bin is a number a reader can take off the chart; a contour is a shape, and the
|
|
7
|
+
* shape is what says whether a population is one cloud or two. A scatter of a quarter of a million
|
|
8
|
+
* records shows neither.
|
|
9
|
+
*
|
|
10
|
+
* `d3-contour` estimates the density and this draws it. The estimate runs in pixel space, so it is
|
|
11
|
+
* computed here instead of in the layer engine, which resolves traces before a width is known. See
|
|
12
|
+
* the ADR "Density is estimated where the pixels are".
|
|
13
|
+
*
|
|
14
|
+
* The rings carry magnitude, so they take the sequential map instead of the categorical one, per
|
|
15
|
+
* chart-design rule 8.
|
|
16
|
+
*/
|
|
17
|
+
import { contourDensity, contours } from "d3-contour";
|
|
18
|
+
import { scaleLinear } from "d3-scale";
|
|
19
|
+
import { useMemo } from "react";
|
|
20
|
+
import { placePoints } from "../../core/internal.js";
|
|
21
|
+
/**
|
|
22
|
+
* Bands drawn between the sparsest and the densest.
|
|
23
|
+
*
|
|
24
|
+
* Enough that a gradient reads as one, few enough that the rings stay countable. Past a dozen the
|
|
25
|
+
* bands are thinner than their own edges and the chart reads as a blur.
|
|
26
|
+
*/
|
|
27
|
+
const BANDS = 10;
|
|
28
|
+
/** Radius the estimate smooths over, in pixels. Wider loses the second cloud, narrower draws noise. */
|
|
29
|
+
const BANDWIDTH = 18;
|
|
30
|
+
/** A GeoJSON multipolygon as one path, holes and all. Drawn even-odd, which is what makes a ring a ring. */
|
|
31
|
+
const toPath = (rings, place = (x, y) => [x, y]) => rings
|
|
32
|
+
.map((polygon) => polygon
|
|
33
|
+
.map((ring) => `M${ring
|
|
34
|
+
.map(([x, y]) => {
|
|
35
|
+
const [px, py] = place(x, y);
|
|
36
|
+
return `${px.toFixed(1)},${py.toFixed(1)}`;
|
|
37
|
+
})
|
|
38
|
+
.join("L")}Z`)
|
|
39
|
+
.join(""))
|
|
40
|
+
.join("");
|
|
41
|
+
/** Levels a lattice is cut at, on round numbers across its range. */
|
|
42
|
+
const LEVELS = 20;
|
|
43
|
+
/** Bands of a lattice's own values, placed through the frame's scales. */
|
|
44
|
+
function Lattice({ grid, x, y, ramp, fill, stroke = "var(--viz-paper)", opacity, }) {
|
|
45
|
+
const bands = useMemo(() => {
|
|
46
|
+
const { values, columns, rows, xDomain, yDomain, zDomain } = grid;
|
|
47
|
+
const thresholds = scaleLinear().domain(zDomain).nice().ticks(LEVELS);
|
|
48
|
+
const cut = contours().size([columns, rows]).thresholds(thresholds)(Array.from(values, (value) => (Number.isNaN(value) ? -Infinity : value)));
|
|
49
|
+
const dx = (xDomain[1] - xDomain[0]) / columns;
|
|
50
|
+
const dy = (yDomain[1] - yDomain[0]) / rows;
|
|
51
|
+
const place = (gx, gy) => [x(xDomain[0] + gx * dx), y(yDomain[0] + gy * dy)];
|
|
52
|
+
return cut.map((band) => ({ value: band.value, d: toPath(band.coordinates, place) }));
|
|
53
|
+
}, [grid, x, y]);
|
|
54
|
+
return (_jsx("g", { pointerEvents: "none", "data-geom": "contour-lattice", children: bands.map((band) => (_jsx("path", { d: band.d, fill: fill ?? ramp(band.value), fillOpacity: opacity, stroke: stroke, strokeWidth: 0.5, fillRule: "evenodd" }, band.value))) }));
|
|
55
|
+
}
|
|
56
|
+
export function Contour(props) {
|
|
57
|
+
if (props.grid && props.levelRamp)
|
|
58
|
+
return (_jsx(Lattice, { grid: props.grid, x: props.x, y: props.y, ramp: props.levelRamp, fill: props.fill, stroke: props.stroke, opacity: props.opacity }));
|
|
59
|
+
return _jsx(Density, { ...props });
|
|
60
|
+
}
|
|
61
|
+
/** The density estimate over the points, cut into nested bands. */
|
|
62
|
+
function Density({ points, x, y, width, height, ramp, adjust = 1, fill, stroke, opacity = 0.72 }) {
|
|
63
|
+
const bands = useMemo(() => {
|
|
64
|
+
if (width <= 0 || height <= 0 || points.length < 2)
|
|
65
|
+
return [];
|
|
66
|
+
const radius = BANDWIDTH * (adjust > 0 ? adjust : 1);
|
|
67
|
+
const placed = placePoints(points, (v) => x(v), (v) => y(v));
|
|
68
|
+
return contourDensity()
|
|
69
|
+
.x((p) => p.x)
|
|
70
|
+
.y((p) => p.y)
|
|
71
|
+
.size([Math.round(width), Math.round(height)])
|
|
72
|
+
.bandwidth(radius)
|
|
73
|
+
.thresholds(BANDS)(placed);
|
|
74
|
+
}, [points, x, y, width, height, adjust]);
|
|
75
|
+
if (bands.length === 0)
|
|
76
|
+
return null;
|
|
77
|
+
return (_jsx("g", { pointerEvents: "none", children: bands.map((band, index) => (_jsx("path", { d: toPath(band.coordinates), fill: fill ?? ramp(bands.length === 1 ? 1 : index / (bands.length - 1)), fillOpacity: opacity, ...(stroke ? { stroke, strokeWidth: 0.5 } : {}), fillRule: "evenodd" }, band.value))) }));
|
|
78
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A kernel density over one measure, drawn as a curve in the main panel.
|
|
3
|
+
*
|
|
4
|
+
* The histogram's question with the count swapped for an estimate. A histogram states where the mass
|
|
5
|
+
* is at the resolution of its bins and a density states the shape, and the shape is what a reader
|
|
6
|
+
* compares between groups: three overlapping distributions read as three curves and as one muddle of
|
|
7
|
+
* bars.
|
|
8
|
+
*
|
|
9
|
+
* Filled under the curve and stroked along it, for `DensityPanel`'s reason and `Area`'s. The fill is
|
|
10
|
+
* what lets a reader see where two distributions overlap; the stroke is what keeps them separable
|
|
11
|
+
* inside it, since a wash with no boundary stops being two things.
|
|
12
|
+
*
|
|
13
|
+
* The estimate is `kde` in `/core`, and the bandwidth it was smoothed at travels with it. Nothing
|
|
14
|
+
* here can show that number and nothing here should: the curve is a shape and the footer is where
|
|
15
|
+
* the figure says what it hides.
|
|
16
|
+
*/
|
|
17
|
+
import type { Density, Scale } from "../../core/internal.js";
|
|
18
|
+
export interface DensityCurveProps {
|
|
19
|
+
/** The estimate, on the grid it was evaluated over. */
|
|
20
|
+
curve: Density;
|
|
21
|
+
x: Scale;
|
|
22
|
+
y: Scale;
|
|
23
|
+
color: string;
|
|
24
|
+
/** Paint of the wash under the curve. Absent takes `color`. */
|
|
25
|
+
fill?: string;
|
|
26
|
+
/** Opacity of the wash under the curve. The stroke stays solid so the outline survives an overlap. */
|
|
27
|
+
fillOpacity?: number;
|
|
28
|
+
lineWidth?: number;
|
|
29
|
+
}
|
|
30
|
+
export declare function DensityCurve({ curve, x, y, color, fill, fillOpacity, lineWidth, }: DensityCurveProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A kernel density over one measure, drawn as a curve in the main panel.
|
|
4
|
+
*
|
|
5
|
+
* The histogram's question with the count swapped for an estimate. A histogram states where the mass
|
|
6
|
+
* is at the resolution of its bins and a density states the shape, and the shape is what a reader
|
|
7
|
+
* compares between groups: three overlapping distributions read as three curves and as one muddle of
|
|
8
|
+
* bars.
|
|
9
|
+
*
|
|
10
|
+
* Filled under the curve and stroked along it, for `DensityPanel`'s reason and `Area`'s. The fill is
|
|
11
|
+
* what lets a reader see where two distributions overlap; the stroke is what keeps them separable
|
|
12
|
+
* inside it, since a wash with no boundary stops being two things.
|
|
13
|
+
*
|
|
14
|
+
* The estimate is `kde` in `/core`, and the bandwidth it was smoothed at travels with it. Nothing
|
|
15
|
+
* here can show that number and nothing here should: the curve is a shape and the footer is where
|
|
16
|
+
* the figure says what it hides.
|
|
17
|
+
*/
|
|
18
|
+
import { useMemo } from "react";
|
|
19
|
+
export function DensityCurve({ curve, x, y, color, fill = color, fillOpacity = 0.22, lineWidth = 1.6, }) {
|
|
20
|
+
const { outline, under } = useMemo(() => {
|
|
21
|
+
let path = "";
|
|
22
|
+
for (let at = 0; at < curve.grid.length; at += 1) {
|
|
23
|
+
const px = x(curve.grid[at]).toFixed(2);
|
|
24
|
+
const py = y(curve.weight[at]).toFixed(2);
|
|
25
|
+
path += `${path ? "L" : "M"}${px},${py}`;
|
|
26
|
+
}
|
|
27
|
+
if (!path)
|
|
28
|
+
return { outline: "", under: "" };
|
|
29
|
+
/* Closed along the baseline, so the fill is the area under the curve instead of a smear. */
|
|
30
|
+
const base = y(0).toFixed(2);
|
|
31
|
+
const first = x(curve.grid[0]).toFixed(2);
|
|
32
|
+
const last = x(curve.grid[curve.grid.length - 1]).toFixed(2);
|
|
33
|
+
return { outline: path, under: `${path}L${last},${base}L${first},${base}Z` };
|
|
34
|
+
}, [curve, x, y]);
|
|
35
|
+
if (!outline)
|
|
36
|
+
return null;
|
|
37
|
+
return (_jsxs("g", { "data-geom": "density", children: [_jsx("path", { d: under, fill: fill, fillOpacity: fillOpacity, stroke: "none" }), _jsx("path", { d: outline, fill: "none", stroke: color, strokeWidth: lineWidth, strokeLinejoin: "round", strokeLinecap: "round" })] }));
|
|
38
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A fitted curve, drawn from what the fitter returned.
|
|
3
|
+
*
|
|
4
|
+
* The overlay for `LayerSpec.fit`. It samples nothing and solves nothing: `curveX` and `curveY`
|
|
5
|
+
* are the positions the service chose, so the drawn line is the fitted line and no interpolation of
|
|
6
|
+
* this package's sits between a reader and the model. Rule 11 sends the arithmetic to the service
|
|
7
|
+
* and this is the half that stays.
|
|
8
|
+
*
|
|
9
|
+
* A curve the fit did not settle on draws dashed, per the design language's line on fits. Which is
|
|
10
|
+
* a narrower case than it sounds: a fit that failed outright comes back with no coordinates and
|
|
11
|
+
* draws nothing, and the footer is what reports it. Dashed is for the answer that arrived and stops
|
|
12
|
+
* short of convergence, where parameters exist and stopped on a bound or on a budget.
|
|
13
|
+
*/
|
|
14
|
+
import type { Fit, Scale } from "../../core/internal.js";
|
|
15
|
+
export interface FitCurveProps {
|
|
16
|
+
fit: Fit;
|
|
17
|
+
x: Scale;
|
|
18
|
+
y: Scale;
|
|
19
|
+
color: string;
|
|
20
|
+
lineWidth?: number;
|
|
21
|
+
/** Opacity of the curve, and a multiplier on the band's own. */
|
|
22
|
+
opacity?: number;
|
|
23
|
+
/** Off where the frame decided a band is unreadable, which is what `BAND_LIMIT` counts toward. */
|
|
24
|
+
showBand?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare function FitCurve({ fit, x, y, color, lineWidth, opacity, showBand }: FitCurveProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A fitted curve, drawn from what the fitter returned.
|
|
4
|
+
*
|
|
5
|
+
* The overlay for `LayerSpec.fit`. It samples nothing and solves nothing: `curveX` and `curveY`
|
|
6
|
+
* are the positions the service chose, so the drawn line is the fitted line and no interpolation of
|
|
7
|
+
* this package's sits between a reader and the model. Rule 11 sends the arithmetic to the service
|
|
8
|
+
* and this is the half that stays.
|
|
9
|
+
*
|
|
10
|
+
* A curve the fit did not settle on draws dashed, per the design language's line on fits. Which is
|
|
11
|
+
* a narrower case than it sounds: a fit that failed outright comes back with no coordinates and
|
|
12
|
+
* draws nothing, and the footer is what reports it. Dashed is for the answer that arrived and stops
|
|
13
|
+
* short of convergence, where parameters exist and stopped on a bound or on a budget.
|
|
14
|
+
*/
|
|
15
|
+
import { useMemo } from "react";
|
|
16
|
+
/** Enough of the interval to read as an interval. Below this the band is drawn as nothing. */
|
|
17
|
+
const BAND_MIN = 2;
|
|
18
|
+
/** Weak enough that the curve stays the geom and the interval stays context. */
|
|
19
|
+
const BAND_OPACITY = 0.13;
|
|
20
|
+
export function FitCurve({ fit, x, y, color, lineWidth = 1.6, opacity = 1, showBand = true }) {
|
|
21
|
+
const curve = useMemo(() => {
|
|
22
|
+
let path = "";
|
|
23
|
+
for (let i = 0; i < fit.curveX.length; i += 1) {
|
|
24
|
+
const at = fit.curveX[i];
|
|
25
|
+
const value = fit.curveY[i];
|
|
26
|
+
if (value == null || !Number.isFinite(value))
|
|
27
|
+
continue;
|
|
28
|
+
path += `${path ? "L" : "M"}${x(at).toFixed(2)},${y(value).toFixed(2)}`;
|
|
29
|
+
}
|
|
30
|
+
return path;
|
|
31
|
+
}, [fit, x, y]);
|
|
32
|
+
/* Out along the top and back along the bottom, which closes the interval into one fillable path. */
|
|
33
|
+
const band = useMemo(() => {
|
|
34
|
+
if (!showBand || !fit.band)
|
|
35
|
+
return "";
|
|
36
|
+
const { lo, hi } = fit.band;
|
|
37
|
+
const count = Math.min(fit.curveX.length, lo.length, hi.length);
|
|
38
|
+
if (count < BAND_MIN)
|
|
39
|
+
return "";
|
|
40
|
+
let top = "";
|
|
41
|
+
let bottom = "";
|
|
42
|
+
for (let i = 0; i < count; i += 1) {
|
|
43
|
+
const at = x(fit.curveX[i]).toFixed(2);
|
|
44
|
+
top += `${top ? "L" : "M"}${at},${y(hi[i]).toFixed(2)}`;
|
|
45
|
+
bottom = `L${at},${y(lo[i]).toFixed(2)}${bottom}`;
|
|
46
|
+
}
|
|
47
|
+
return `${top}${bottom}Z`;
|
|
48
|
+
}, [fit, x, y, showBand]);
|
|
49
|
+
if (!curve)
|
|
50
|
+
return null;
|
|
51
|
+
return (_jsxs("g", { children: [band && _jsx("path", { d: band, fill: color, fillOpacity: BAND_OPACITY * opacity }), _jsx("path", { d: curve, fill: "none", stroke: color, strokeWidth: lineWidth, strokeOpacity: opacity, strokeLinecap: "round", strokeDasharray: fit.success ? undefined : "4 3" })] }));
|
|
52
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A histogram's counts drawn as a run between the bin centers.
|
|
3
|
+
*
|
|
4
|
+
* Same statistic, same bins, different geometry. Columns tile the axis and stop being separable the
|
|
5
|
+
* moment two distributions share a panel, where three runs stay three runs. So this is the geom for
|
|
6
|
+
* comparing distributions and the histogram is the geom for reading one.
|
|
7
|
+
*
|
|
8
|
+
* The vertex sits at the bin's center and not at its edge, which is where the count belongs: a bin is
|
|
9
|
+
* an interval and its count is a property of the whole interval, so the center is the only position
|
|
10
|
+
* in it that does not favor one end.
|
|
11
|
+
*
|
|
12
|
+
* It reads the binned payload itself instead of taking points, so the reading of a bin center as a
|
|
13
|
+
* position lives in one place. A stepped run is the outline-histogram form, and it claims the count
|
|
14
|
+
* held flat across each bin where the straight run claims a gradual change nobody measured.
|
|
15
|
+
*/
|
|
16
|
+
import { type BarDatum, type Linetype, type Scale } from "../../core/internal.js";
|
|
17
|
+
export interface FreqpolyProps {
|
|
18
|
+
/** The bins, in axis order. `at` carries a bin center and its absence means a named category. */
|
|
19
|
+
data: BarDatum[];
|
|
20
|
+
x: Scale;
|
|
21
|
+
y: Scale;
|
|
22
|
+
color: string;
|
|
23
|
+
/** Holds each bin's count flat across the bin instead of sloping to the next. */
|
|
24
|
+
step?: "after" | "before";
|
|
25
|
+
lineWidth?: number;
|
|
26
|
+
/** Pattern the run draws. Absent draws it whole, which is what a solid linetype means. */
|
|
27
|
+
dash?: Linetype;
|
|
28
|
+
opacity?: number;
|
|
29
|
+
}
|
|
30
|
+
export declare function Freqpoly({ data, x, y, color, step, lineWidth, opacity, dash }: FreqpolyProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A histogram's counts drawn as a run between the bin centers.
|
|
4
|
+
*
|
|
5
|
+
* Same statistic, same bins, different geometry. Columns tile the axis and stop being separable the
|
|
6
|
+
* moment two distributions share a panel, where three runs stay three runs. So this is the geom for
|
|
7
|
+
* comparing distributions and the histogram is the geom for reading one.
|
|
8
|
+
*
|
|
9
|
+
* The vertex sits at the bin's center and not at its edge, which is where the count belongs: a bin is
|
|
10
|
+
* an interval and its count is a property of the whole interval, so the center is the only position
|
|
11
|
+
* in it that does not favor one end.
|
|
12
|
+
*
|
|
13
|
+
* It reads the binned payload itself instead of taking points, so the reading of a bin center as a
|
|
14
|
+
* position lives in one place. A stepped run is the outline-histogram form, and it claims the count
|
|
15
|
+
* held flat across each bin where the straight run claims a gradual change nobody measured.
|
|
16
|
+
*/
|
|
17
|
+
import { useMemo } from "react";
|
|
18
|
+
import { dashArray } from "../../core/internal.js";
|
|
19
|
+
export function Freqpoly({ data, x, y, color, step, lineWidth = 1.6, opacity = 1, dash }) {
|
|
20
|
+
const d = useMemo(() => {
|
|
21
|
+
const at = (bin) => [x(bin.at ?? bin.category).toFixed(2), y(bin.value).toFixed(2)];
|
|
22
|
+
let path = "";
|
|
23
|
+
let last;
|
|
24
|
+
for (const bin of data) {
|
|
25
|
+
const [px, py] = at(bin);
|
|
26
|
+
if (!last) {
|
|
27
|
+
path = `M${px},${py}`;
|
|
28
|
+
}
|
|
29
|
+
else if (step === "after") {
|
|
30
|
+
path += `L${px},${at(last)[1]}L${px},${py}`;
|
|
31
|
+
}
|
|
32
|
+
else if (step === "before") {
|
|
33
|
+
path += `L${at(last)[0]},${py}L${px},${py}`;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
path += `L${px},${py}`;
|
|
37
|
+
}
|
|
38
|
+
last = bin;
|
|
39
|
+
}
|
|
40
|
+
return path;
|
|
41
|
+
}, [data, x, y, step]);
|
|
42
|
+
if (data.length < 2)
|
|
43
|
+
return null;
|
|
44
|
+
return (_jsx("path", { "data-geom": "freqpoly", d: d, fill: "none", stroke: color, strokeWidth: lineWidth, strokeDasharray: dashArray(dash), strokeOpacity: opacity, strokeLinejoin: "round", strokeLinecap: "round" }));
|
|
45
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One reading against a stated range, as an arc with the number under it.
|
|
3
|
+
*
|
|
4
|
+
* The track states where the ends are. A scale ring outside it sections the range.
|
|
5
|
+
*/
|
|
6
|
+
export interface GaugeProps {
|
|
7
|
+
value: number;
|
|
8
|
+
/** Low and high end of the dial, in the measure's own units. */
|
|
9
|
+
range: [number, number];
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
/** Ink on the arc the reading sweeps. */
|
|
13
|
+
color: string;
|
|
14
|
+
/** Ink on the track behind it, which is the page's own muted tone. */
|
|
15
|
+
trackColor?: string;
|
|
16
|
+
/** Weight of both arcs, in pixels. */
|
|
17
|
+
thickness?: number;
|
|
18
|
+
opacity?: number;
|
|
19
|
+
/** How far the dial turns, in degrees. Default 180. */
|
|
20
|
+
sweep?: number;
|
|
21
|
+
/** How much of the room the dial takes, as a fraction. Under 1 leaves space for a scale ring. */
|
|
22
|
+
radius?: number;
|
|
23
|
+
/** Sections the scale ring is cut into. Absent draws no ring. */
|
|
24
|
+
bands?: number;
|
|
25
|
+
/** The magnitude map a section reads at its own midpoint. */
|
|
26
|
+
ramp?: (at: number) => string;
|
|
27
|
+
/**
|
|
28
|
+
* The number written under the arc.
|
|
29
|
+
*
|
|
30
|
+
* `format` takes the reading in its own units. `fontSize` is the axis size, and the number draws
|
|
31
|
+
* well above it. `wanted` decides whether the reading gets its number.
|
|
32
|
+
*/
|
|
33
|
+
numbers?: {
|
|
34
|
+
format: (value: number) => string;
|
|
35
|
+
wanted?: (value: number) => boolean;
|
|
36
|
+
color?: string;
|
|
37
|
+
fontSize: number;
|
|
38
|
+
};
|
|
39
|
+
/** The measure's name, written under the number. */
|
|
40
|
+
label?: string;
|
|
41
|
+
}
|
|
42
|
+
export declare function Gauge({ value, range, width, height, color, trackColor, thickness, opacity, sweep, radius, bands, ramp, numbers, label, }: GaugeProps): import("react").JSX.Element | null;
|