@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,207 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The point geom, and the record behind each geom.
|
|
4
|
+
*
|
|
5
|
+
* Split out of `Hexbin`, which drew circles keyed by array position when the count sat below the
|
|
6
|
+
* density switch. Those circles could not say what they stood for, so a scatter was a picture instead
|
|
7
|
+
* of a way into the data. A point here carries its record key, and hover resolves through one
|
|
8
|
+
* quadtree lookup against a single capture surface instead of a listener per point.
|
|
9
|
+
*
|
|
10
|
+
* Drawing and hit testing read the same projection, so the geom under the readout is the geom the
|
|
11
|
+
* pointer found.
|
|
12
|
+
*
|
|
13
|
+
* Above the fade threshold the points are drawn as a path per color step instead of an element
|
|
14
|
+
* each. A facet of fourteen thousand records is fourteen thousand nodes for the browser to lay out
|
|
15
|
+
* and paint, and six of them on one page is where the specimen section spent half a second. The
|
|
16
|
+
* treatment is the same either way: same radius, same opacity, same color off the ramp. Identity
|
|
17
|
+
* survives because hover resolves through the quadtree and the capture surface, neither of which
|
|
18
|
+
* ever read the drawn elements.
|
|
19
|
+
*/
|
|
20
|
+
import { useMemo, useRef, useState } from "react";
|
|
21
|
+
import { buildIndex, nearest, placePoints, POINT_OUTLINE, REGULAR, } from "../../core/internal.js";
|
|
22
|
+
/**
|
|
23
|
+
* Color steps across the ramp for the faded treatment.
|
|
24
|
+
*
|
|
25
|
+
* Enough that a bound color channel still reads as a gradient at 0.16 opacity, few enough that a
|
|
26
|
+
* facet draws a handful of paths.
|
|
27
|
+
*/
|
|
28
|
+
const FADED_STEPS = 24;
|
|
29
|
+
/**
|
|
30
|
+
* The faded treatment, per chart-design rule 7.
|
|
31
|
+
*
|
|
32
|
+
* Exported because the GPU renderer only ever draws counts that are already past the fade
|
|
33
|
+
* threshold, and a geom that changed size when the renderer changed would read as the data moving.
|
|
34
|
+
*/
|
|
35
|
+
export const FADED_R = REGULAR.fadedRadius;
|
|
36
|
+
export const FADED_OPACITY = 0.16;
|
|
37
|
+
/**
|
|
38
|
+
* Radius a point draws at when the caller names none.
|
|
39
|
+
*
|
|
40
|
+
* The regular column of `METRICS`. A caller with a panel of another size passes
|
|
41
|
+
* `metrics.pointRadius` off the frame's render prop, which is how a facet gets three pixels and a
|
|
42
|
+
* chart with a page to itself gets five.
|
|
43
|
+
*/
|
|
44
|
+
const POINT_R = REGULAR.pointRadius;
|
|
45
|
+
/** Outline width of a hollow glyph, capped so a small geom keeps a visible center. */
|
|
46
|
+
const outlineWidth = (r) => Math.min(POINT_OUTLINE, r * 0.5);
|
|
47
|
+
/** A dot written as a path: two half arcs, which is how a circle survives being merged with others. */
|
|
48
|
+
const dot = (x, y, r) => `M${(x - r).toFixed(2)},${y.toFixed(2)}a${r},${r} 0 1,0 ${2 * r},0a${r},${r} 0 1,0 ${-2 * r},0`;
|
|
49
|
+
/**
|
|
50
|
+
* Any glyph as a path, so one merged element can hold thousands of them.
|
|
51
|
+
*
|
|
52
|
+
* Exported so a guide draws its sample through the same arithmetic the chart drew the marks
|
|
53
|
+
* with. A legend that redrew the four shapes by hand is a second writer of one glyph set.
|
|
54
|
+
*/
|
|
55
|
+
export function glyph(shape, x, y, r) {
|
|
56
|
+
const at = (value) => value.toFixed(2);
|
|
57
|
+
if (shape === "circle")
|
|
58
|
+
return dot(x, y, r);
|
|
59
|
+
if (shape === "square") {
|
|
60
|
+
// Matched to the circle by area instead of by width, so a mixed plot reads as one weight.
|
|
61
|
+
const half = r * 0.886;
|
|
62
|
+
return `M${at(x - half)},${at(y - half)}h${at(half * 2)}v${at(half * 2)}h${at(-half * 2)}Z`;
|
|
63
|
+
}
|
|
64
|
+
if (shape === "triangle") {
|
|
65
|
+
const reach = r * 1.2;
|
|
66
|
+
return `M${at(x)},${at(y - reach)}L${at(x + reach)},${at(y + reach * 0.75)}L${at(x - reach)},${at(y + reach * 0.75)}Z`;
|
|
67
|
+
}
|
|
68
|
+
const reach = r * 1.25;
|
|
69
|
+
return `M${at(x)},${at(y - reach)}L${at(x + reach)},${at(y)}L${at(x)},${at(y + reach)}L${at(x - reach)},${at(y)}Z`;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Whether a point of radius `r` draws the paper-colored hairline around itself.
|
|
73
|
+
*
|
|
74
|
+
* Chart-design rule 9 asks for the hairline on points above 4px and says why: a crowd of large
|
|
75
|
+
* geoms stops being countable without space between them. A point at the default radius has that
|
|
76
|
+
* space already, and a ring on it reads as an outline the figure did not ask for.
|
|
77
|
+
*
|
|
78
|
+
* A stated width answers for itself either way, so an author can put the hairline on a small point
|
|
79
|
+
* or take it off a large one.
|
|
80
|
+
*/
|
|
81
|
+
const HALO_ABOVE = 4;
|
|
82
|
+
const haloOn = (r, halo) => (halo == null ? r > HALO_ABOVE : halo > 0);
|
|
83
|
+
export function Points({ points, x, y, faded = false, ramp, radius, opacity, shape = "circle", hollow = false, halo, width, height, onHover, onSelect, transposed = false, step, }) {
|
|
84
|
+
const [hovered, setHovered] = useState(null);
|
|
85
|
+
const placed = useMemo(() => placePoints(points, (v) => x(v), (v) => y(v), { transposed, step }), [points, x, y, transposed, step]);
|
|
86
|
+
const hoverable = onHover != null && width != null && height != null;
|
|
87
|
+
const index = useMemo(() => (hoverable ? buildIndex(placed) : null), [hoverable, placed]);
|
|
88
|
+
/*
|
|
89
|
+
One path per color step, built only for the treatment that draws enough points to need it.
|
|
90
|
+
|
|
91
|
+
Steps are cut across the weights in hand instead of across zero to one, so the ramp is asked
|
|
92
|
+
for a color a couple of dozen times whatever units the weights carry and whatever domain the
|
|
93
|
+
ramp was built over.
|
|
94
|
+
*/
|
|
95
|
+
const bands = useMemo(() => {
|
|
96
|
+
if (!faded)
|
|
97
|
+
return [];
|
|
98
|
+
const r = radius ?? FADED_R;
|
|
99
|
+
let lo = Infinity;
|
|
100
|
+
let hi = -Infinity;
|
|
101
|
+
for (const p of placed) {
|
|
102
|
+
const weight = p.point.weight;
|
|
103
|
+
if (weight == null)
|
|
104
|
+
continue;
|
|
105
|
+
if (weight < lo)
|
|
106
|
+
lo = weight;
|
|
107
|
+
if (weight > hi)
|
|
108
|
+
hi = weight;
|
|
109
|
+
}
|
|
110
|
+
const span = hi - lo;
|
|
111
|
+
const steps = span > 0 ? FADED_STEPS : 1;
|
|
112
|
+
const parts = new Array(steps).fill("");
|
|
113
|
+
for (const p of placed) {
|
|
114
|
+
const weight = p.point.weight;
|
|
115
|
+
const step = weight == null || span <= 0 ? 0 : Math.round(((weight - lo) / span) * (steps - 1));
|
|
116
|
+
// A step merges glyphs of one color, so a bound size channel still varies inside it.
|
|
117
|
+
parts[step] += glyph(shape, p.x, p.y, p.point.size ?? r);
|
|
118
|
+
}
|
|
119
|
+
return parts
|
|
120
|
+
.map((d, step) => ({
|
|
121
|
+
d,
|
|
122
|
+
// The weight this step stands for, which is what the ramp was given for a single geom.
|
|
123
|
+
weight: span > 0 ? lo + (step / (steps - 1)) * span : Number.isFinite(lo) ? lo : null,
|
|
124
|
+
}))
|
|
125
|
+
.filter((band) => band.d.length > 0);
|
|
126
|
+
}, [faded, placed, radius, shape]);
|
|
127
|
+
/*
|
|
128
|
+
Whether a bound channel reached these points, which is what takes them off the merged path.
|
|
129
|
+
|
|
130
|
+
The faded treatment merges glyphs into one path per color step, and a path carries one glyph and
|
|
131
|
+
one opacity between them. So a figure binding either channel draws its geoms one element each and
|
|
132
|
+
pays the node count. The treatment's own radius still applies, which is what keeps a dense panel
|
|
133
|
+
from filling in while the channel does its work.
|
|
134
|
+
*/
|
|
135
|
+
const perMark = useMemo(() => placed.some((p) => p.point.shape != null || p.point.opacity != null), [placed]);
|
|
136
|
+
/*
|
|
137
|
+
The geom the pointer last landed on, held so a move that lands on it again reports nothing.
|
|
138
|
+
|
|
139
|
+
A hand resting inside one geom's snap radius sends a move per frame, and each one used to
|
|
140
|
+
rebuild the readout rows and re-render the chart above them. The answer changes when the geom
|
|
141
|
+
changes, so that is what the guard watches. The quadtree hands back the datum it stored, so
|
|
142
|
+
identity is the comparison, and a rebuilt index carries fresh data that opens the guard again.
|
|
143
|
+
*/
|
|
144
|
+
const reported = useRef(null);
|
|
145
|
+
const report = (event) => {
|
|
146
|
+
if (!index)
|
|
147
|
+
return;
|
|
148
|
+
const bounds = event.currentTarget.getBoundingClientRect();
|
|
149
|
+
const found = nearest(index, event.clientX - bounds.left, event.clientY - bounds.top);
|
|
150
|
+
if (found === reported.current)
|
|
151
|
+
return;
|
|
152
|
+
reported.current = found;
|
|
153
|
+
setHovered(found);
|
|
154
|
+
onHover?.(found ? { datum: found.point, index: found.index, at: { x: found.x, y: found.y } } : null);
|
|
155
|
+
};
|
|
156
|
+
const clear = () => {
|
|
157
|
+
if (reported.current === null)
|
|
158
|
+
return;
|
|
159
|
+
reported.current = null;
|
|
160
|
+
setHovered(null);
|
|
161
|
+
onHover?.(null);
|
|
162
|
+
};
|
|
163
|
+
// The pointer already resolved a geom, so a click reuses that answer instead of looking again.
|
|
164
|
+
const take = () => {
|
|
165
|
+
if (hovered) {
|
|
166
|
+
onSelect?.({ datum: hovered.point, index: hovered.index, at: { x: hovered.x, y: hovered.y } });
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
return (_jsxs("g", { "data-geom": "points", children: [faded && !perMark
|
|
170
|
+
? bands.map((band, step) => {
|
|
171
|
+
const ink = ramp(band.weight ?? 0.72);
|
|
172
|
+
return hollow ? (_jsx("path", { d: band.d, fill: "none", stroke: ink, strokeOpacity: opacity ?? FADED_OPACITY, strokeWidth: outlineWidth(radius ?? FADED_R) }, step)) : (_jsx("path", { d: band.d, fill: ink, fillOpacity: opacity ?? FADED_OPACITY }, step));
|
|
173
|
+
})
|
|
174
|
+
: placed.map((p) => {
|
|
175
|
+
// A point carrying a weight colors by it, which is what a bound color channel sets.
|
|
176
|
+
const fill = ramp(p.point.weight ?? 0.62);
|
|
177
|
+
// A bound size channel resolved this point's radius in `buildLayers`.
|
|
178
|
+
const r = p.point.size ?? radius ?? (faded ? FADED_R : POINT_R);
|
|
179
|
+
/* A bound glyph and a bound opacity resolved the same way, and each falls back to the layer's. */
|
|
180
|
+
const mark = p.point.shape ?? shape;
|
|
181
|
+
const ink = p.point.opacity ?? opacity ?? (faded ? FADED_OPACITY : undefined);
|
|
182
|
+
/*
|
|
183
|
+
A hollow geom spends its stroke on the outline, and the paper halo it would otherwise
|
|
184
|
+
draw has nothing left to do: the open center is already what a reader counts through.
|
|
185
|
+
|
|
186
|
+
Filled geoms take the page color, so overlapping points stay countable and the halo
|
|
187
|
+
reads as space instead of as an outline. Zero width draws none.
|
|
188
|
+
*/
|
|
189
|
+
const paint = hollow
|
|
190
|
+
? { fill: "none", stroke: fill, strokeOpacity: ink ?? 0.85, strokeWidth: outlineWidth(r) }
|
|
191
|
+
: {
|
|
192
|
+
fill,
|
|
193
|
+
fillOpacity: ink ?? 0.85,
|
|
194
|
+
...(haloOn(r, halo) ? { stroke: "var(--viz-paper)", strokeWidth: halo ?? 1 } : {}),
|
|
195
|
+
};
|
|
196
|
+
/*
|
|
197
|
+
Keyed by position in the trace, which is the only thing here that is distinct.
|
|
198
|
+
|
|
199
|
+
`point.key` is the record's name, and `keyField` takes the table's first text column
|
|
200
|
+
where the caller states none. That column names a record on the readout and carries
|
|
201
|
+
no promise of being unique: a table of four thousand rows whose first text column is
|
|
202
|
+
the category gave nine hundred geoms the same key, and React keeps one child per key
|
|
203
|
+
and drops the rest. The index is unique inside the trace and stable in draw order.
|
|
204
|
+
*/
|
|
205
|
+
return mark === "circle" ? (_jsx("circle", { cx: p.x, cy: p.y, r: r, ...paint }, p.index)) : (_jsx("path", { d: glyph(mark, p.x, p.y, r), ...paint }, p.index));
|
|
206
|
+
}), hovered && (_jsx("circle", { cx: hovered.x, cy: hovered.y, r: 7, fill: "none", stroke: "var(--viz-ink)", strokeWidth: 1.2, pointerEvents: "none" })), hoverable && (_jsx("rect", { width: width, height: height, fill: "transparent", cursor: onSelect && hovered ? "pointer" : undefined, onPointerMove: report, onPointerLeave: clear, onClick: onSelect ? take : undefined }))] }));
|
|
207
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A cloud in three position scales.
|
|
3
|
+
*
|
|
4
|
+
* The design language's two conditions are met between this and `CubeStage`. The reader can rotate,
|
|
5
|
+
* which is what makes the projection invertible. And the chart carries two depth cues: geoms scale
|
|
6
|
+
* with distance in the vertex program, and each geom casts a copy of itself onto the floor of the
|
|
7
|
+
* box, so the height a reader is asked to judge has a second reading at a known position. Under a
|
|
8
|
+
* few hundred geoms the copy is joined to its geom by a drop line, which is the clearer cue and the
|
|
9
|
+
* one that stops being drawable at scale.
|
|
10
|
+
*
|
|
11
|
+
* See the ADR "A third position scale is permitted where the reader can rotate".
|
|
12
|
+
*/
|
|
13
|
+
import { type LayerStyle, type PlotPoint, type PointHit, type ThemeSnapshot } from "../../core/internal.js";
|
|
14
|
+
import type { ValueRamp } from "../../core/internal.js";
|
|
15
|
+
/** Geoms up to which each one keeps a line down to its shadow. Past it the lines are the picture. */
|
|
16
|
+
export declare const DROP_LINE_CAP = 300;
|
|
17
|
+
export interface Points3dProps {
|
|
18
|
+
points: PlotPoint[];
|
|
19
|
+
xDomain: [number, number];
|
|
20
|
+
yDomain: [number, number];
|
|
21
|
+
zDomain: [number, number];
|
|
22
|
+
width: number;
|
|
23
|
+
height: number;
|
|
24
|
+
/** Maps a point's weight to a color, in the CSS the rest of the chart is drawn in. */
|
|
25
|
+
ramp: ValueRamp;
|
|
26
|
+
/** Axis names, written along the box's outermost edges. */
|
|
27
|
+
labels: {
|
|
28
|
+
x: string;
|
|
29
|
+
y: string;
|
|
30
|
+
z: string;
|
|
31
|
+
};
|
|
32
|
+
/** Tick text, so a cube reads in the same precision the flat charts do. */
|
|
33
|
+
format?: (value: number) => string;
|
|
34
|
+
/** Which back faces of the box take a pane. */
|
|
35
|
+
panes?: LayerStyle["panes"];
|
|
36
|
+
/** The live token values where the chart sits, for the GL path's colors. */
|
|
37
|
+
theme?: ThemeSnapshot | null;
|
|
38
|
+
radius?: number;
|
|
39
|
+
/**
|
|
40
|
+
* The geom under the pointer, with the pixel the projection put it at.
|
|
41
|
+
*
|
|
42
|
+
* A flat geom knows where it drew itself and a cube geom does not: the GPU placed it under the
|
|
43
|
+
* camera and the CPU has the matrix. So the position is computed here, where the matrix is, and
|
|
44
|
+
* the readout lands beside the geom instead of at the panel origin.
|
|
45
|
+
*/
|
|
46
|
+
onHover?: (hit: PointHit | null) => void;
|
|
47
|
+
onSelect?: (hit: PointHit) => void;
|
|
48
|
+
}
|
|
49
|
+
export declare function Points3d({ points, xDomain, yDomain, zDomain, width, height, ramp, labels, format, panes, theme, radius, onHover, onSelect, }: Points3dProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A cloud in three position scales.
|
|
4
|
+
*
|
|
5
|
+
* The design language's two conditions are met between this and `CubeStage`. The reader can rotate,
|
|
6
|
+
* which is what makes the projection invertible. And the chart carries two depth cues: geoms scale
|
|
7
|
+
* with distance in the vertex program, and each geom casts a copy of itself onto the floor of the
|
|
8
|
+
* box, so the height a reader is asked to judge has a second reading at a known position. Under a
|
|
9
|
+
* few hundred geoms the copy is joined to its geom by a drop line, which is the clearer cue and the
|
|
10
|
+
* one that stops being drawable at scale.
|
|
11
|
+
*
|
|
12
|
+
* See the ADR "A third position scale is permitted where the reader can rotate".
|
|
13
|
+
*/
|
|
14
|
+
import { useMemo } from "react";
|
|
15
|
+
import { projectData, rgbOf, } from "../../core/internal.js";
|
|
16
|
+
import { GlPoints } from "../gl/GlPoints.js";
|
|
17
|
+
import { CubeStage, middleOf } from "./cube-stage.js";
|
|
18
|
+
/** Geoms up to which each one keeps a line down to its shadow. Past it the lines are the picture. */
|
|
19
|
+
export const DROP_LINE_CAP = 300;
|
|
20
|
+
const MUTED = [0.55, 0.55, 0.58];
|
|
21
|
+
/** Paints the shadow its one color. One function for the module's life, and the colors upload once. */
|
|
22
|
+
const SHADOW_RAMP = () => MUTED;
|
|
23
|
+
export function Points3d({ points, xDomain, yDomain, zDomain, width, height, ramp, labels, format, panes, theme, radius = 3, onHover, onSelect, }) {
|
|
24
|
+
const domains = useMemo(() => ({ x: xDomain, y: yDomain, z: zDomain }), [xDomain, yDomain, zDomain]);
|
|
25
|
+
const center = useMemo(() => [
|
|
26
|
+
middleOf(points.map((point) => point.x)),
|
|
27
|
+
middleOf(points.map((point) => point.y)),
|
|
28
|
+
middleOf(points.map((point) => point.z ?? zDomain[0])),
|
|
29
|
+
], [points, zDomain]);
|
|
30
|
+
/* The second depth cue: the same cloud flattened onto the floor of the box. */
|
|
31
|
+
const shadow = useMemo(() => points.map((point) => ({ ...point, z: zDomain[0] })), [points, zDomain]);
|
|
32
|
+
const glRamp = useMemo(() => {
|
|
33
|
+
const cache = new Map();
|
|
34
|
+
return (weight) => {
|
|
35
|
+
const held = cache.get(weight);
|
|
36
|
+
if (held)
|
|
37
|
+
return held;
|
|
38
|
+
const rgb = rgbOf(ramp(weight)) ?? MUTED;
|
|
39
|
+
cache.set(weight, rgb);
|
|
40
|
+
return rgb;
|
|
41
|
+
};
|
|
42
|
+
}, [ramp]);
|
|
43
|
+
return (_jsx(CubeStage, { domains: domains, center: center, width: width, height: height, labels: labels, format: format, panes: panes, theme: theme, children: ({ matrix, orbit, turned }) => {
|
|
44
|
+
const cube = { domain: zDomain, orbit };
|
|
45
|
+
/* The geom's own projection, where the card sits. The GPU pick reports the pointer. */
|
|
46
|
+
const placed = (hit) => {
|
|
47
|
+
const at = projectData(matrix, [hit.datum.x, hit.datum.y, hit.datum.z ?? zDomain[0]], center, width, height);
|
|
48
|
+
return { ...hit, at: { x: at.x, y: at.y } };
|
|
49
|
+
};
|
|
50
|
+
const lines = points.length > DROP_LINE_CAP
|
|
51
|
+
? []
|
|
52
|
+
: points.map((point) => ({
|
|
53
|
+
geom: projectData(matrix, [point.x, point.y, point.z ?? zDomain[0]], center, width, height),
|
|
54
|
+
floor: projectData(matrix, [point.x, point.y, zDomain[0]], center, width, height),
|
|
55
|
+
}));
|
|
56
|
+
return (_jsxs(_Fragment, { children: [_jsx(GlPoints, { points: shadow, x: (value) => Number(value), y: (value) => Number(value), xDomain: xDomain, yDomain: yDomain, width: width, height: height, ramp: SHADOW_RAMP, radius: radius * 0.6, opacity: 0.28, cube: cube }), _jsx(GlPoints, { points: points, x: (value) => Number(value), y: (value) => Number(value), xDomain: xDomain, yDomain: yDomain, width: width, height: height, ramp: glRamp, radius: radius, opacity: 1, cube: cube, onHover: onHover ? (hit) => onHover(hit && placed(hit)) : undefined, onSelect: onSelect ? (hit) => (turned() ? undefined : onSelect(placed(hit))) : undefined }), lines.map((line, index) => (_jsx("line", { x1: line.geom.x, y1: line.geom.y, x2: line.floor.x, y2: line.floor.y, stroke: "var(--viz-ink-muted)", strokeWidth: 0.75, opacity: 0.3 }, index)))] }));
|
|
57
|
+
} }));
|
|
58
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Radar: the parallel plot's rules turned out from a center, with each record closed into a polygon.
|
|
3
|
+
*
|
|
4
|
+
* The payload is the parallel geom's, since the two differ in where the rules go and in nothing else.
|
|
5
|
+
* Each rule holds one measure in that measure's own range, so the reader compares along a spoke and
|
|
6
|
+
* not across the figure. `GRAMMAR` answers false for the kind's axial coordinate, which is what stops
|
|
7
|
+
* the frame drawing a pair of flat rules around it.
|
|
8
|
+
*
|
|
9
|
+
* The order of the spokes is the author's, taken off the order the measures were bound. It has to be:
|
|
10
|
+
* the polygon closes over the spokes, so swapping two of them redraws the shape without changing a
|
|
11
|
+
* reading. The area that shape encloses stands for nothing, and that is why the fill stays low. A
|
|
12
|
+
* heavy wash asserts a quantity nobody measured, and two records overlaid would then hide each other.
|
|
13
|
+
* See the ADR "Polar is permitted where the figure writes its numbers".
|
|
14
|
+
*
|
|
15
|
+
* The rings are the grid, and they run perpendicular to what is being read the way rule 5 asks. A
|
|
16
|
+
* reader taking a value off a spoke crosses them, so four of them at even fractions give the counting
|
|
17
|
+
* marks a flat axis gets from its ticks.
|
|
18
|
+
*/
|
|
19
|
+
import { type GeomHit, type ParallelAxis, type ParallelLine, type ValueRamp } from "../../core/internal.js";
|
|
20
|
+
export interface RadarProps {
|
|
21
|
+
/** One rule per measure, in the order the author bound them. */
|
|
22
|
+
axes: ParallelAxis[];
|
|
23
|
+
/** One polygon per record. Each holds a reading per rule. */
|
|
24
|
+
lines: ParallelLine[];
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
/** Maps a line's weight to a color. Lines with no weight take `color`. */
|
|
28
|
+
ramp: ValueRamp;
|
|
29
|
+
color: string;
|
|
30
|
+
/** Interior paint of each polygon, where the author picked one. Absent takes the line's own. */
|
|
31
|
+
fill?: string;
|
|
32
|
+
opacity?: number;
|
|
33
|
+
/** Type size for the measure names at the spoke ends. Absent writes none. */
|
|
34
|
+
fontSize?: number;
|
|
35
|
+
/** The record under the pointer, placed at its first corner. */
|
|
36
|
+
onHover?: (hit: GeomHit<ParallelLine> | null) => void;
|
|
37
|
+
onSelect?: (hit: GeomHit<ParallelLine>) => void;
|
|
38
|
+
}
|
|
39
|
+
export declare function Radar({ axes, lines, width, height, ramp, color, fill, opacity, fontSize, onHover, onSelect, }: RadarProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Radar: the parallel plot's rules turned out from a center, with each record closed into a polygon.
|
|
4
|
+
*
|
|
5
|
+
* The payload is the parallel geom's, since the two differ in where the rules go and in nothing else.
|
|
6
|
+
* Each rule holds one measure in that measure's own range, so the reader compares along a spoke and
|
|
7
|
+
* not across the figure. `GRAMMAR` answers false for the kind's axial coordinate, which is what stops
|
|
8
|
+
* the frame drawing a pair of flat rules around it.
|
|
9
|
+
*
|
|
10
|
+
* The order of the spokes is the author's, taken off the order the measures were bound. It has to be:
|
|
11
|
+
* the polygon closes over the spokes, so swapping two of them redraws the shape without changing a
|
|
12
|
+
* reading. The area that shape encloses stands for nothing, and that is why the fill stays low. A
|
|
13
|
+
* heavy wash asserts a quantity nobody measured, and two records overlaid would then hide each other.
|
|
14
|
+
* See the ADR "Polar is permitted where the figure writes its numbers".
|
|
15
|
+
*
|
|
16
|
+
* The rings are the grid, and they run perpendicular to what is being read the way rule 5 asks. A
|
|
17
|
+
* reader taking a value off a spoke crosses them, so four of them at even fractions give the counting
|
|
18
|
+
* marks a flat axis gets from its ticks.
|
|
19
|
+
*/
|
|
20
|
+
import { spokeLayout, spokePoint, } from "../../core/internal.js";
|
|
21
|
+
/** Rings the grid draws between the center and the outermost one, so a reader can count in quarters. */
|
|
22
|
+
const RINGS = [0.25, 0.5, 0.75, 1];
|
|
23
|
+
/** How much of the polygon's own ink washes its interior. Low, the enclosed area standing for nothing. */
|
|
24
|
+
const FILL_OPACITY = 0.1;
|
|
25
|
+
/** How far off vertical a spoke has to lean before its name stops sitting over the tip. */
|
|
26
|
+
const LEAN = 0.2;
|
|
27
|
+
/** Where a reading falls along its own rule, as a fraction of that rule's range. */
|
|
28
|
+
const along = (value, axis) => {
|
|
29
|
+
const span = axis.hi - axis.lo;
|
|
30
|
+
return span === 0 ? 0.5 : Math.min(1, Math.max(0, (value - axis.lo) / span));
|
|
31
|
+
};
|
|
32
|
+
/** A closed path through one point per spoke. */
|
|
33
|
+
const closed = (corners) => `${corners.map(({ x, y }, at) => `${at === 0 ? "M" : "L"}${x.toFixed(2)},${y.toFixed(2)}`).join(" ")} Z`;
|
|
34
|
+
export function Radar({ axes, lines, width, height, ramp, color, fill, opacity, fontSize, onHover, onSelect, }) {
|
|
35
|
+
const layout = spokeLayout(axes.length, width, height);
|
|
36
|
+
if (axes.length < 3 || layout.radius <= 0)
|
|
37
|
+
return null;
|
|
38
|
+
return (_jsxs("g", { "data-geom": "radar", children: [_jsxs("g", { "data-geom": "radar-grid", fill: "none", stroke: "var(--viz-rule)", strokeWidth: 1, children: [RINGS.map((at) => (_jsx("path", { d: closed(axes.map((_, index) => spokePoint(layout, index, at))) }, at))), axes.map((axis, index) => {
|
|
39
|
+
const tip = spokePoint(layout, index, 1);
|
|
40
|
+
return _jsx("line", { x1: layout.cx, y1: layout.cy, x2: tip.x, y2: tip.y }, axis.id);
|
|
41
|
+
})] }), _jsx("g", { "data-geom": "radar-shapes", children: lines.map((line, index) => {
|
|
42
|
+
const corners = axes.map((axis, at) => spokePoint(layout, at, along(line.values[at] ?? axis.lo, axis)));
|
|
43
|
+
const ink = line.weight == null ? color : ramp(line.weight);
|
|
44
|
+
return (_jsx("path", { d: closed(corners), fill: fill ?? ink, fillOpacity: (opacity ?? 1) * FILL_OPACITY, stroke: ink, strokeWidth: 1.5, strokeOpacity: opacity ?? 0.85, onMouseEnter: () => onHover?.({ datum: line, index, at: corners[0] }), onMouseLeave: () => onHover?.(null), onClick: onSelect ? () => onSelect({ datum: line, index, at: corners[0] }) : undefined, style: onSelect ? { cursor: "pointer" } : undefined }, line.key ?? index));
|
|
45
|
+
}) }), fontSize != null && (
|
|
46
|
+
/*
|
|
47
|
+
The measure's name sits past the outermost ring, on the side the spoke leans.
|
|
48
|
+
|
|
49
|
+
A name centered over a spoke pointing sideways runs back over the polygon, so the anchor
|
|
50
|
+
follows the lean and `spokeLayout` gave the room up before it picked the radius.
|
|
51
|
+
*/
|
|
52
|
+
_jsx("g", { "data-geom": "radar-labels", fontSize: fontSize, pointerEvents: "none", fill: "var(--viz-ink)", children: axes.map((axis, index) => {
|
|
53
|
+
const at = spokePoint(layout, index, 1);
|
|
54
|
+
const lean = (at.x - layout.cx) / (layout.radius || 1);
|
|
55
|
+
const anchor = lean > LEAN ? "start" : lean < -LEAN ? "end" : "middle";
|
|
56
|
+
const dx = lean > LEAN ? 6 : lean < -LEAN ? -6 : 0;
|
|
57
|
+
return (_jsx("text", { x: at.x + dx, y: at.y + (at.y < layout.cy ? -6 : 12), textAnchor: anchor, dominantBaseline: Math.abs(lean) > LEAN ? "central" : undefined, children: axis.label }, axis.id));
|
|
58
|
+
}) }))] }));
|
|
59
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Range: an interval per reading, drawn as one of ggplot's four glyphs.
|
|
3
|
+
*
|
|
4
|
+
* `Interval` closes one region over its readings, which is right for a fit and wrong for a handful
|
|
5
|
+
* of doses somebody measured apart. This draws a mark per reading, so a single dose with an interval
|
|
6
|
+
* is a figure and two readings are not joined into an envelope nobody measured.
|
|
7
|
+
*
|
|
8
|
+
* The four glyphs differ in what sits between the bounds and in nothing else. Each is a kind, as in
|
|
9
|
+
* ggplot. `errorbar` caps both ends, `linerange` runs bare, `pointrange` marks the estimate on the
|
|
10
|
+
* run, and `crossbar` draws a box with the estimate across it.
|
|
11
|
+
*
|
|
12
|
+
* The estimate is the reading the interval is around, so the two glyphs that mark it draw it last
|
|
13
|
+
* and over the run. A reading with no estimate bound draws the run alone whichever glyph was asked
|
|
14
|
+
* for, since there is nothing to mark.
|
|
15
|
+
*/
|
|
16
|
+
import type { IntervalPoint, Scale } from "../../core/internal.js";
|
|
17
|
+
export interface RangeProps {
|
|
18
|
+
points: IntervalPoint[];
|
|
19
|
+
x: Scale;
|
|
20
|
+
y: Scale;
|
|
21
|
+
color: string;
|
|
22
|
+
/** Interior of a crossbar's box. Absent takes `color` at a low opacity. */
|
|
23
|
+
fill?: string;
|
|
24
|
+
/** Which glyph draws between the bounds. The estimate is marked by two of the four. */
|
|
25
|
+
glyph?: "errorbar" | "linerange" | "pointrange" | "crossbar";
|
|
26
|
+
/** Width of a cap or a box, in pixels. */
|
|
27
|
+
thickness?: number;
|
|
28
|
+
opacity?: number;
|
|
29
|
+
lineWidth?: number;
|
|
30
|
+
}
|
|
31
|
+
export declare function Range({ points, x, y, color, fill, glyph, thickness, opacity, lineWidth, }: RangeProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/** How wide a cap or a box runs, in pixels. */
|
|
3
|
+
const REACH = 10;
|
|
4
|
+
/** Radius of the dot a pointrange marks its estimate with. */
|
|
5
|
+
const DOT = 3;
|
|
6
|
+
export function Range({ points, x, y, color, fill, glyph = "pointrange", thickness = REACH, opacity = 1, lineWidth = 1.4, }) {
|
|
7
|
+
if (points.length === 0)
|
|
8
|
+
return null;
|
|
9
|
+
const half = Math.max(1, thickness / 2);
|
|
10
|
+
const capped = glyph === "errorbar";
|
|
11
|
+
const boxed = glyph === "crossbar";
|
|
12
|
+
const marked = glyph === "pointrange";
|
|
13
|
+
return (_jsx("g", { "data-geom": "range", stroke: color, strokeOpacity: opacity, strokeWidth: lineWidth, fill: "none", children: points.map((reading) => {
|
|
14
|
+
const at = x(reading.x);
|
|
15
|
+
const lo = y(reading.lo);
|
|
16
|
+
const hi = y(reading.hi);
|
|
17
|
+
const mid = reading.mid == null ? null : y(reading.mid);
|
|
18
|
+
return (_jsxs("g", { "data-geom": "range-mark", children: [boxed ? (_jsx("rect", { x: at - half, y: Math.min(lo, hi), width: half * 2, height: Math.abs(lo - hi), fill: fill ?? color, fillOpacity: fill ? opacity : opacity * 0.18 })) : (_jsx("line", { x1: at, x2: at, y1: lo, y2: hi, strokeLinecap: "round" })), capped && (_jsxs(_Fragment, { children: [_jsx("line", { x1: at - half, x2: at + half, y1: lo, y2: lo, strokeLinecap: "round" }), _jsx("line", { x1: at - half, x2: at + half, y1: hi, y2: hi, strokeLinecap: "round" })] })), mid != null && marked && (_jsx("circle", { cx: at, cy: mid, r: DOT, fill: color, fillOpacity: opacity, stroke: "none" })), mid != null && boxed && (_jsx("line", { x1: at - half, x2: at + half, y1: mid, y2: mid, strokeWidth: lineWidth * 1.6 }))] }, `${reading.x}`));
|
|
19
|
+
}) }));
|
|
20
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rings a circular figure stacks outside itself.
|
|
3
|
+
*
|
|
4
|
+
* A chord and an ideogram share it. The bands arrive placed and the readings arrive resolved.
|
|
5
|
+
*/
|
|
6
|
+
import { type PlacedSector, type RingBand, type RingReading, type RingLayout } from "../../core/internal.js";
|
|
7
|
+
export interface RingStackProps {
|
|
8
|
+
panel: RingLayout;
|
|
9
|
+
sectors: readonly PlacedSector[];
|
|
10
|
+
bands: readonly RingBand[];
|
|
11
|
+
readings: readonly (RingReading | null)[];
|
|
12
|
+
/** Hue per sector id. A bar and a dot take the hue of the sector they stand in. */
|
|
13
|
+
hue: Map<string, string | undefined>;
|
|
14
|
+
/** The categorical map, for a stack's own levels. */
|
|
15
|
+
identity: (index: number) => string;
|
|
16
|
+
/**
|
|
17
|
+
* The magnitude map, over 0..1. A dot reads its own value against the ring's scale.
|
|
18
|
+
*
|
|
19
|
+
* Absent leaves a dot on the hue of the sector it stands in.
|
|
20
|
+
*/
|
|
21
|
+
ramp?: (t: number) => string;
|
|
22
|
+
/** The value the magnitude map treats as its middle, where the map has two arms. */
|
|
23
|
+
center?: number;
|
|
24
|
+
opacity?: number;
|
|
25
|
+
/** A reading in its own units, for the readout a pointer gets. */
|
|
26
|
+
format: (value: number) => string;
|
|
27
|
+
/**
|
|
28
|
+
* Where each pair sits, for a ring drawing one point per pair.
|
|
29
|
+
*
|
|
30
|
+
* A chord hands its ribbons over. An ideogram has none and draws by position instead.
|
|
31
|
+
*/
|
|
32
|
+
ribbons?: readonly {
|
|
33
|
+
source: string;
|
|
34
|
+
target: string;
|
|
35
|
+
at: [number, number];
|
|
36
|
+
to: [number, number];
|
|
37
|
+
}[];
|
|
38
|
+
}
|
|
39
|
+
export declare function RingStack({ panel, sectors, bands, readings, hue, identity, ramp, center, opacity, format, ribbons, }: RingStackProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The rings a circular figure stacks outside itself.
|
|
4
|
+
*
|
|
5
|
+
* A chord and an ideogram share it. The bands arrive placed and the readings arrive resolved.
|
|
6
|
+
*/
|
|
7
|
+
import { arcPath, polarPoint, rampPosition, sectorAngle, trackRadius, } from "../../core/internal.js";
|
|
8
|
+
/** Gap either side of a bar inside its own sector, in radians. */
|
|
9
|
+
const BAR_GAP = 0.012;
|
|
10
|
+
/** Radius of a point a ring draws, in pixels. */
|
|
11
|
+
const POINT_R = 2.2;
|
|
12
|
+
/** Weak enough that a crowded track stays countable. */
|
|
13
|
+
const DOT_OPACITY = 0.7;
|
|
14
|
+
export function RingStack({ panel, sectors, bands, readings, hue, identity, ramp, center, opacity = 1, format, ribbons, }) {
|
|
15
|
+
if (bands.length === 0)
|
|
16
|
+
return null;
|
|
17
|
+
/* A dot stands for one reading. Its own value is what the color has to answer. */
|
|
18
|
+
const dotInk = (sector, value, domain) => ramp ? ramp(rampPosition(value, domain[0], domain[1], center)) : hue.get(sector);
|
|
19
|
+
const at = (radius, angle) => polarPoint(panel, radius, angle);
|
|
20
|
+
const held = new Map(sectors.map((sector) => [sector.id, sector]));
|
|
21
|
+
return (_jsx("g", { "data-geom": "rings", children: bands.map((band, index) => {
|
|
22
|
+
const reading = readings[index];
|
|
23
|
+
if (!reading)
|
|
24
|
+
return null;
|
|
25
|
+
/* A point per pair, standing where that pair's own ribbon met the sector. */
|
|
26
|
+
if (reading.kind === "point" && reading.points.length > 0) {
|
|
27
|
+
return (_jsx("g", { "data-geom": "ring-point", children: (ribbons ?? [])
|
|
28
|
+
.flatMap((one) => {
|
|
29
|
+
const point = reading.points.find((entry) => entry.source === one.source && entry.target === one.target);
|
|
30
|
+
if (!point)
|
|
31
|
+
return [];
|
|
32
|
+
const radius = trackRadius(band, reading.domain, point.value);
|
|
33
|
+
return [
|
|
34
|
+
{ id: `${one.source}-${one.target}-a`, angle: (one.at[0] + one.at[1]) / 2, radius, point },
|
|
35
|
+
{ id: `${one.source}-${one.target}-b`, angle: (one.to[0] + one.to[1]) / 2, radius, point },
|
|
36
|
+
];
|
|
37
|
+
})
|
|
38
|
+
.map((dot) => {
|
|
39
|
+
const on = at(dot.radius, dot.angle);
|
|
40
|
+
return (_jsx("circle", { cx: on.x, cy: on.y, r: POINT_R, fill: dotInk(dot.point.source, dot.point.value, reading.domain), fillOpacity: opacity, children: _jsx("title", { children: `${dot.point.source} to ${dot.point.target}, ${format(dot.point.value)}` }) }, dot.id));
|
|
41
|
+
}) }, index));
|
|
42
|
+
}
|
|
43
|
+
/* A point per row, standing at its own position along the sector. */
|
|
44
|
+
if (reading.kind === "point") {
|
|
45
|
+
return (_jsx("g", { "data-geom": "ring-point", children: reading.dots.map((dot, place) => {
|
|
46
|
+
const sector = held.get(dot.sector);
|
|
47
|
+
if (!sector)
|
|
48
|
+
return null;
|
|
49
|
+
const on = at(trackRadius(band, reading.domain, dot.value), sectorAngle(sector, dot.at));
|
|
50
|
+
return (_jsx("circle", { cx: on.x, cy: on.y, r: POINT_R, fill: dotInk(dot.sector, dot.value, reading.domain), fillOpacity: DOT_OPACITY * opacity }, place));
|
|
51
|
+
}) }, index));
|
|
52
|
+
}
|
|
53
|
+
const reach = band.outer - band.inner;
|
|
54
|
+
const top = reading.domain[1] || 1;
|
|
55
|
+
return (_jsx("g", { "data-geom": `ring-${reading.kind}`, children: reading.bars.map((bar) => {
|
|
56
|
+
const sector = held.get(bar.sector);
|
|
57
|
+
if (!sector)
|
|
58
|
+
return null;
|
|
59
|
+
const inner = band.inner + (bar.floor / top) * reach;
|
|
60
|
+
const outer = band.inner + ((bar.floor + bar.value) / top) * reach;
|
|
61
|
+
const level = bar.level == null ? -1 : reading.levels.indexOf(bar.level);
|
|
62
|
+
return (_jsx("path", { d: arcPath({ ...panel, inner, outer }, sector.from + BAR_GAP, Math.max(sector.from + BAR_GAP, sector.to - BAR_GAP)), fill: level < 0 ? hue.get(bar.sector) : identity(sectors.length + level), fillOpacity: opacity, children: _jsx("title", { children: `${bar.sector}${bar.level ? ` ${bar.level}` : ""}, ${format(bar.value)}` }) }, `${bar.sector}-${bar.level ?? ""}`));
|
|
63
|
+
}) }, index));
|
|
64
|
+
}) }));
|
|
65
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The reference geoms: a line across the plot area per row, labeled where it ends.
|
|
3
|
+
*
|
|
4
|
+
* Rule 4 ink unless the layer maps or states a color.
|
|
5
|
+
*/
|
|
6
|
+
import { type Linetype, type RuleAxis, type RuleLine, type Scale } from "../../core/internal.js";
|
|
7
|
+
export interface RuleProps {
|
|
8
|
+
rules: readonly RuleLine[];
|
|
9
|
+
x: Scale;
|
|
10
|
+
y: Scale;
|
|
11
|
+
/** The data's two axes, zoom included, in the data's own roles. A band axis is null. */
|
|
12
|
+
xAxis: RuleAxis | null;
|
|
13
|
+
yAxis: RuleAxis | null;
|
|
14
|
+
/** A band axis's categories in the data's roles. A value naming none of them draws nothing. */
|
|
15
|
+
xBand?: readonly string[] | undefined;
|
|
16
|
+
yBand?: readonly string[] | undefined;
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
/** Whether the frame drew its pair with the roles swapped. A horizontal line then stands upright. */
|
|
20
|
+
transposed?: boolean;
|
|
21
|
+
/** Ink the layer maps or states. Absent draws rule 4's foreground at low opacity. */
|
|
22
|
+
color?: string;
|
|
23
|
+
dash?: Linetype;
|
|
24
|
+
lineWidth?: number;
|
|
25
|
+
/** Opacity of the line. Absent is 0.9 on a stated color and rule 4's 0.55 on the foreground. */
|
|
26
|
+
opacity?: number;
|
|
27
|
+
fontSize?: number;
|
|
28
|
+
}
|
|
29
|
+
export declare function Rule({ rules, x, y, xAxis, yAxis, xBand, yBand, width, height, transposed, color, dash, lineWidth, opacity, fontSize, }: RuleProps): import("react").JSX.Element;
|