@tetrascience-npm/ts-lib-viz 0.0.0-stage → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +2171 -2
- package/dist/src/builder/PlotPanel.d.ts +42 -0
- package/dist/src/builder/PlotPanel.js +433 -0
- package/dist/src/builder/Popover.d.ts +37 -0
- package/dist/src/builder/Popover.js +32 -0
- package/dist/src/builder/Stepper.d.ts +21 -0
- package/dist/src/builder/Stepper.js +41 -0
- package/dist/src/builder/index.d.ts +10 -0
- package/dist/src/builder/index.js +10 -0
- package/dist/src/core/adapters.d.ts +86 -0
- package/dist/src/core/adapters.js +219 -0
- package/dist/src/core/aggregate.d.ts +74 -0
- package/dist/src/core/aggregate.js +102 -0
- package/dist/src/core/annotations.d.ts +34 -0
- package/dist/src/core/annotations.js +71 -0
- package/dist/src/core/band-order.d.ts +86 -0
- package/dist/src/core/band-order.js +132 -0
- package/dist/src/core/binning.d.ts +123 -0
- package/dist/src/core/binning.js +193 -0
- package/dist/src/core/bounds.d.ts +40 -0
- package/dist/src/core/bounds.js +107 -0
- package/dist/src/core/brush.d.ts +73 -0
- package/dist/src/core/brush.js +102 -0
- package/dist/src/core/build.d.ts +322 -0
- package/dist/src/core/build.js +496 -0
- package/dist/src/core/camera.d.ts +152 -0
- package/dist/src/core/camera.js +303 -0
- package/dist/src/core/capabilities.d.ts +24 -0
- package/dist/src/core/capabilities.js +307 -0
- package/dist/src/core/chord.d.ts +49 -0
- package/dist/src/core/chord.js +57 -0
- package/dist/src/core/circular.d.ts +83 -0
- package/dist/src/core/circular.js +63 -0
- package/dist/src/core/cluster.d.ts +136 -0
- package/dist/src/core/cluster.js +607 -0
- package/dist/src/core/critique.d.ts +92 -0
- package/dist/src/core/critique.js +905 -0
- package/dist/src/core/density.d.ts +38 -0
- package/dist/src/core/density.js +82 -0
- package/dist/src/core/figure-set.d.ts +34 -0
- package/dist/src/core/figure-set.js +55 -0
- package/dist/src/core/finding-codes.d.ts +10 -0
- package/dist/src/core/finding-codes.js +1 -0
- package/dist/src/core/fit-types.d.ts +46 -0
- package/dist/src/core/fit-types.js +7 -0
- package/dist/src/core/fitter.d.ts +62 -0
- package/dist/src/core/fitter.js +102 -0
- package/dist/src/core/frame-geometry.d.ts +407 -0
- package/dist/src/core/frame-geometry.js +612 -0
- package/dist/src/core/frame.d.ts +329 -0
- package/dist/src/core/frame.js +1432 -0
- package/dist/src/core/geom-table.d.ts +503 -0
- package/dist/src/core/geom-table.js +484 -0
- package/dist/src/core/geom-types.d.ts +182 -0
- package/dist/src/core/geom-types.js +17 -0
- package/dist/src/core/grammar.d.ts +359 -0
- package/dist/src/core/grammar.js +397 -0
- package/dist/src/core/heat-reductions.d.ts +36 -0
- package/dist/src/core/heat-reductions.js +133 -0
- package/dist/src/core/hexbin.d.ts +84 -0
- package/dist/src/core/hexbin.js +168 -0
- package/dist/src/core/hierarchy.d.ts +59 -0
- package/dist/src/core/hierarchy.js +248 -0
- package/dist/src/core/hit.d.ts +75 -0
- package/dist/src/core/hit.js +37 -0
- package/dist/src/core/index.d.ts +33 -0
- package/dist/src/core/index.js +18 -0
- package/dist/src/core/internal.d.ts +58 -0
- package/dist/src/core/internal.js +58 -0
- package/dist/src/core/labels.d.ts +37 -0
- package/dist/src/core/labels.js +54 -0
- package/dist/src/core/layers.d.ts +594 -0
- package/dist/src/core/layers.js +2892 -0
- package/dist/src/core/load.d.ts +17 -0
- package/dist/src/core/load.js +356 -0
- package/dist/src/core/marginal.d.ts +65 -0
- package/dist/src/core/marginal.js +116 -0
- package/dist/src/core/mesh.d.ts +69 -0
- package/dist/src/core/mesh.js +237 -0
- package/dist/src/core/omission.d.ts +41 -0
- package/dist/src/core/omission.js +62 -0
- package/dist/src/core/palette-sets.d.ts +623 -0
- package/dist/src/core/palette-sets.js +1058 -0
- package/dist/src/core/palette.d.ts +871 -0
- package/dist/src/core/palette.js +511 -0
- package/dist/src/core/plot-data.d.ts +71 -0
- package/dist/src/core/plot-data.js +82 -0
- package/dist/src/core/predicate.d.ts +50 -0
- package/dist/src/core/predicate.js +20 -0
- package/dist/src/core/profile.d.ts +111 -0
- package/dist/src/core/profile.js +221 -0
- package/dist/src/core/readout.d.ts +108 -0
- package/dist/src/core/readout.js +215 -0
- package/dist/src/core/region.d.ts +56 -0
- package/dist/src/core/region.js +101 -0
- package/dist/src/core/rings.d.ts +96 -0
- package/dist/src/core/rings.js +171 -0
- package/dist/src/core/rules.d.ts +45 -0
- package/dist/src/core/rules.js +69 -0
- package/dist/src/core/sankey.d.ts +49 -0
- package/dist/src/core/sankey.js +96 -0
- package/dist/src/core/select.d.ts +52 -0
- package/dist/src/core/select.js +216 -0
- package/dist/src/core/side-track.d.ts +98 -0
- package/dist/src/core/side-track.js +197 -0
- package/dist/src/core/sizing.d.ts +54 -0
- package/dist/src/core/sizing.js +37 -0
- package/dist/src/core/spec-edit.d.ts +68 -0
- package/dist/src/core/spec-edit.js +105 -0
- package/dist/src/core/spec.d.ts +1111 -0
- package/dist/src/core/spec.js +39 -0
- package/dist/src/core/stats.d.ts +161 -0
- package/dist/src/core/stats.js +318 -0
- package/dist/src/core/tick-format.d.ts +21 -0
- package/dist/src/core/tick-format.js +87 -0
- package/dist/src/core/tokens.d.ts +47 -0
- package/dist/src/core/tokens.js +138 -0
- package/dist/src/core/transform.d.ts +21 -0
- package/dist/src/core/transform.js +19 -0
- package/dist/src/core/voxels.d.ts +53 -0
- package/dist/src/core/voxels.js +129 -0
- package/dist/src/core/zoom.d.ts +76 -0
- package/dist/src/core/zoom.js +103 -0
- package/dist/src/graph/GraphSurface.d.ts +127 -0
- package/dist/src/graph/GraphSurface.js +423 -0
- package/dist/src/graph/data.d.ts +103 -0
- package/dist/src/graph/data.js +140 -0
- package/dist/src/graph/index.d.ts +7 -0
- package/dist/src/graph/index.js +7 -0
- package/dist/src/mcp/data.d.ts +28 -0
- package/dist/src/mcp/data.js +131 -0
- package/dist/src/mcp/index.d.ts +7 -0
- package/dist/src/mcp/index.js +7 -0
- package/dist/src/mcp/paths.d.ts +12 -0
- package/dist/src/mcp/paths.js +30 -0
- package/dist/src/mcp/render.d.ts +67 -0
- package/dist/src/mcp/render.js +189 -0
- package/dist/src/mcp/server.d.ts +7 -0
- package/dist/src/mcp/server.js +25 -0
- package/dist/src/mcp/tools.d.ts +82 -0
- package/dist/src/mcp/tools.js +412 -0
- package/dist/src/react/BrushLayer.d.ts +20 -0
- package/dist/src/react/BrushLayer.js +98 -0
- package/dist/src/react/ColorLegend.d.ts +45 -0
- package/dist/src/react/ColorLegend.js +64 -0
- package/dist/src/react/Figure.d.ts +19 -0
- package/dist/src/react/Figure.js +6 -0
- package/dist/src/react/Frame.d.ts +87 -0
- package/dist/src/react/Frame.js +192 -0
- package/dist/src/react/MarkLegend.d.ts +32 -0
- package/dist/src/react/MarkLegend.js +24 -0
- package/dist/src/react/SeriesLegend.d.ts +38 -0
- package/dist/src/react/SeriesLegend.js +27 -0
- package/dist/src/react/SizeLegend.d.ts +24 -0
- package/dist/src/react/SizeLegend.js +25 -0
- package/dist/src/react/Toolbar.d.ts +109 -0
- package/dist/src/react/Toolbar.js +483 -0
- package/dist/src/react/Tooltip.d.ts +37 -0
- package/dist/src/react/Tooltip.js +59 -0
- package/dist/src/react/Viz.d.ts +112 -0
- package/dist/src/react/Viz.js +1311 -0
- package/dist/src/react/export.d.ts +32 -0
- package/dist/src/react/export.js +181 -0
- package/dist/src/react/geoms/Area.d.ts +38 -0
- package/dist/src/react/geoms/Area.js +48 -0
- package/dist/src/react/geoms/Bars.d.ts +130 -0
- package/dist/src/react/geoms/Bars.js +164 -0
- package/dist/src/react/geoms/Box.d.ts +50 -0
- package/dist/src/react/geoms/Box.js +32 -0
- package/dist/src/react/geoms/Chord.d.ts +60 -0
- package/dist/src/react/geoms/Chord.js +78 -0
- package/dist/src/react/geoms/Contour.d.ts +44 -0
- package/dist/src/react/geoms/Contour.js +78 -0
- package/dist/src/react/geoms/DensityCurve.d.ts +30 -0
- package/dist/src/react/geoms/DensityCurve.js +38 -0
- package/dist/src/react/geoms/FitCurve.d.ts +26 -0
- package/dist/src/react/geoms/FitCurve.js +52 -0
- package/dist/src/react/geoms/Freqpoly.d.ts +30 -0
- package/dist/src/react/geoms/Freqpoly.js +45 -0
- package/dist/src/react/geoms/Gauge.d.ts +42 -0
- package/dist/src/react/geoms/Gauge.js +90 -0
- package/dist/src/react/geoms/Heatmap.d.ts +79 -0
- package/dist/src/react/geoms/Heatmap.js +51 -0
- package/dist/src/react/geoms/Hexbin.d.ts +74 -0
- package/dist/src/react/geoms/Hexbin.js +89 -0
- package/dist/src/react/geoms/Icicle.d.ts +38 -0
- package/dist/src/react/geoms/Icicle.js +9 -0
- package/dist/src/react/geoms/Ideogram.d.ts +58 -0
- package/dist/src/react/geoms/Ideogram.js +77 -0
- package/dist/src/react/geoms/Interval.d.ts +28 -0
- package/dist/src/react/geoms/Interval.js +39 -0
- package/dist/src/react/geoms/Line.d.ts +39 -0
- package/dist/src/react/geoms/Line.js +52 -0
- package/dist/src/react/geoms/Parallel.d.ts +38 -0
- package/dist/src/react/geoms/Parallel.js +131 -0
- package/dist/src/react/geoms/Pie.d.ts +62 -0
- package/dist/src/react/geoms/Pie.js +59 -0
- package/dist/src/react/geoms/Points.d.ts +84 -0
- package/dist/src/react/geoms/Points.js +207 -0
- package/dist/src/react/geoms/Points3d.d.ts +49 -0
- package/dist/src/react/geoms/Points3d.js +58 -0
- package/dist/src/react/geoms/Radar.d.ts +39 -0
- package/dist/src/react/geoms/Radar.js +59 -0
- package/dist/src/react/geoms/Range.d.ts +31 -0
- package/dist/src/react/geoms/Range.js +20 -0
- package/dist/src/react/geoms/RingStack.d.ts +39 -0
- package/dist/src/react/geoms/RingStack.js +65 -0
- package/dist/src/react/geoms/Rule.d.ts +29 -0
- package/dist/src/react/geoms/Rule.js +51 -0
- package/dist/src/react/geoms/Sankey.d.ts +24 -0
- package/dist/src/react/geoms/Sankey.js +51 -0
- package/dist/src/react/geoms/Segment.d.ts +36 -0
- package/dist/src/react/geoms/Segment.js +39 -0
- package/dist/src/react/geoms/Sunburst.d.ts +46 -0
- package/dist/src/react/geoms/Sunburst.js +64 -0
- package/dist/src/react/geoms/Surface.d.ts +32 -0
- package/dist/src/react/geoms/Surface.js +49 -0
- package/dist/src/react/geoms/Text.d.ts +35 -0
- package/dist/src/react/geoms/Text.js +40 -0
- package/dist/src/react/geoms/Treemap.d.ts +39 -0
- package/dist/src/react/geoms/Treemap.js +16 -0
- package/dist/src/react/geoms/Violin.d.ts +56 -0
- package/dist/src/react/geoms/Violin.js +60 -0
- package/dist/src/react/geoms/Volume.d.ts +37 -0
- package/dist/src/react/geoms/Volume.js +40 -0
- package/dist/src/react/geoms/Waterfall.d.ts +43 -0
- package/dist/src/react/geoms/Waterfall.js +18 -0
- package/dist/src/react/geoms/cube-stage.d.ts +39 -0
- package/dist/src/react/geoms/cube-stage.js +85 -0
- package/dist/src/react/geoms/hierarchy-cells.d.ts +42 -0
- package/dist/src/react/geoms/hierarchy-cells.js +59 -0
- package/dist/src/react/geoms/sector-axis.d.ts +66 -0
- package/dist/src/react/geoms/sector-axis.js +99 -0
- package/dist/src/react/gl/GlMesh.d.ts +22 -0
- package/dist/src/react/gl/GlMesh.js +78 -0
- package/dist/src/react/gl/GlPoints.d.ts +45 -0
- package/dist/src/react/gl/GlPoints.js +117 -0
- package/dist/src/react/gl/GlVolume.d.ts +28 -0
- package/dist/src/react/gl/GlVolume.js +112 -0
- package/dist/src/react/gl/GlWalls.d.ts +24 -0
- package/dist/src/react/gl/GlWalls.js +55 -0
- package/dist/src/react/gl/context.d.ts +71 -0
- package/dist/src/react/gl/context.js +98 -0
- package/dist/src/react/gl/encode.d.ts +120 -0
- package/dist/src/react/gl/encode.js +215 -0
- package/dist/src/react/gl/index.d.ts +10 -0
- package/dist/src/react/gl/index.js +8 -0
- package/dist/src/react/gl/refresh.d.ts +7 -0
- package/dist/src/react/gl/refresh.js +19 -0
- package/dist/src/react/gl/renderer.d.ts +377 -0
- package/dist/src/react/gl/renderer.js +1081 -0
- package/dist/src/react/gl/shaders.d.ts +92 -0
- package/dist/src/react/gl/shaders.js +405 -0
- package/dist/src/react/gl/surface.d.ts +31 -0
- package/dist/src/react/gl/surface.js +73 -0
- package/dist/src/react/index.d.ts +12 -0
- package/dist/src/react/index.js +11 -0
- package/dist/src/react/orbit.d.ts +38 -0
- package/dist/src/react/orbit.js +81 -0
- package/dist/src/react/sides/DendrogramPanel.d.ts +32 -0
- package/dist/src/react/sides/DendrogramPanel.js +39 -0
- package/dist/src/react/sides/DensityPanel.d.ts +31 -0
- package/dist/src/react/sides/DensityPanel.js +37 -0
- package/dist/src/react/sides/HistogramPanel.d.ts +30 -0
- package/dist/src/react/sides/HistogramPanel.js +18 -0
- package/dist/src/react/sides/RugPanel.d.ts +28 -0
- package/dist/src/react/sides/RugPanel.js +21 -0
- package/dist/src/react/sides/TrackPanel.d.ts +37 -0
- package/dist/src/react/sides/TrackPanel.js +27 -0
- package/dist/src/react/theme.d.ts +48 -0
- package/dist/src/react/theme.js +148 -0
- package/dist/src/react/useFits.d.ts +26 -0
- package/dist/src/react/useFits.js +62 -0
- package/dist/src/react/useZoom.d.ts +50 -0
- package/dist/src/react/useZoom.js +141 -0
- package/package.json +164 -5
- package/theme/default.css +62 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The reference geoms: a line across the plot area per row, labeled where it ends.
|
|
4
|
+
*
|
|
5
|
+
* Rule 4 ink unless the layer maps or states a color.
|
|
6
|
+
*/
|
|
7
|
+
import { dashArray, ruleSegment, textRun, } from "../../core/internal.js";
|
|
8
|
+
/** Rule 4's pattern, where the layer names none. */
|
|
9
|
+
const RULE_DASH = "3 3";
|
|
10
|
+
export function Rule({ rules, x, y, xAxis, yAxis, xBand, yBand, width, height, transposed = false, color, dash, lineWidth = 1, opacity, fontSize = 11, }) {
|
|
11
|
+
/* A position in the data's roles, put on screen. A transpose swaps the pair. */
|
|
12
|
+
const at = (dataX, dataY) => transposed ? [x(dataY), y(dataX)] : [x(dataX), y(dataY)];
|
|
13
|
+
/* Upright labels, a row of horizontal spans per line of text. A label takes the first row it fits. */
|
|
14
|
+
const rows = [];
|
|
15
|
+
const rowFor = (from, to) => {
|
|
16
|
+
let row = rows.findIndex((spans) => spans.every(([start, end]) => to < start || from > end));
|
|
17
|
+
if (row < 0)
|
|
18
|
+
row = rows.push([]) - 1;
|
|
19
|
+
rows[row].push([from, to]);
|
|
20
|
+
return row;
|
|
21
|
+
};
|
|
22
|
+
return (_jsx("g", { pointerEvents: "none", "data-geom": "rule", children: rules.map((rule, index) => {
|
|
23
|
+
const segment = ruleSegment(rule, xAxis, yAxis);
|
|
24
|
+
if (!segment)
|
|
25
|
+
return null;
|
|
26
|
+
if ("x" in segment && xBand && !xBand.includes(String(segment.x)))
|
|
27
|
+
return null;
|
|
28
|
+
if ("y" in segment && yBand && !yBand.includes(String(segment.y)))
|
|
29
|
+
return null;
|
|
30
|
+
let ends;
|
|
31
|
+
if ("x0" in segment) {
|
|
32
|
+
ends = [...at(segment.x0, segment.y0), ...at(segment.x1, segment.y1)];
|
|
33
|
+
}
|
|
34
|
+
else if ("y" in segment) {
|
|
35
|
+
ends = transposed ? [x(segment.y), height, x(segment.y), 0] : [0, y(segment.y), width, y(segment.y)];
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
ends = transposed ? [0, y(segment.x), width, y(segment.x)] : [x(segment.x), height, x(segment.x), 0];
|
|
39
|
+
}
|
|
40
|
+
/* The label at the right-hand end, inside the plot area. */
|
|
41
|
+
const [ax, ay, bx, by] = ends;
|
|
42
|
+
const [ex, ey] = bx >= ax ? [bx, by] : [ax, ay];
|
|
43
|
+
const upright = ax === bx;
|
|
44
|
+
const low = ey < fontSize + 4;
|
|
45
|
+
/* An upright label that would cross the right edge turns to the left of its line. */
|
|
46
|
+
const run = textRun(rule.label?.length ?? 0, fontSize);
|
|
47
|
+
const leftward = upright && ex + 4 + run > width;
|
|
48
|
+
const row = upright && rule.label ? (leftward ? rowFor(ex - 4 - run, ex - 4) : rowFor(ex + 4, ex + 4 + run)) : 0;
|
|
49
|
+
return (_jsxs("g", { children: [_jsx("line", { x1: ax, y1: ay, x2: bx, y2: by, stroke: color ?? "var(--viz-ink)", strokeOpacity: opacity ?? (color ? 0.9 : 0.55), strokeWidth: lineWidth, strokeDasharray: dash ? dashArray(dash) : RULE_DASH }), rule.label && (_jsx("text", { x: upright && !leftward ? ex + 4 : ex - 4, y: upright ? fontSize + row * (fontSize + 2) : low ? ey + fontSize + 2 : ey - 4, textAnchor: upright && !leftward ? "start" : "end", fontSize: fontSize, fill: "var(--viz-annotation)", children: rule.label }))] }, `${rule.kind}${index}`));
|
|
50
|
+
}) }));
|
|
51
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A flow between named stages. Ribbon thickness stands for what passed along it.
|
|
3
|
+
*
|
|
4
|
+
* `GRAMMAR` answers `flow`. The frame draws no axes and the geom takes the panel whole.
|
|
5
|
+
*/
|
|
6
|
+
import { type SankeyLinkInput, type SankeyNodeInput } from "../../core/internal.js";
|
|
7
|
+
export interface SankeyProps {
|
|
8
|
+
nodes: SankeyNodeInput[];
|
|
9
|
+
links: SankeyLinkInput[];
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
/** Hue per node, taken off the categorical map. Read where a node states no `color`. */
|
|
13
|
+
identity: (index: number) => string;
|
|
14
|
+
/** One hue for the whole figure, where the author picked one. */
|
|
15
|
+
fill?: string;
|
|
16
|
+
opacity?: number;
|
|
17
|
+
/** Type size for the labels, in pixels. Absent writes none. */
|
|
18
|
+
fontSize?: number;
|
|
19
|
+
/** The node's value written under its name. Absent writes the name alone. */
|
|
20
|
+
format?: (value: number) => string;
|
|
21
|
+
/** How a value becomes a thickness. A funnel reads each column against its own population. */
|
|
22
|
+
normalize?: "global" | "column";
|
|
23
|
+
}
|
|
24
|
+
export declare function Sankey({ nodes, links, width, height, identity, fill, opacity, fontSize, format, normalize, }: SankeyProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A flow between named stages. Ribbon thickness stands for what passed along it.
|
|
4
|
+
*
|
|
5
|
+
* `GRAMMAR` answers `flow`. The frame draws no axes and the geom takes the panel whole.
|
|
6
|
+
*/
|
|
7
|
+
import { sankeyLayout } from "../../core/internal.js";
|
|
8
|
+
/** Gap between a node and the label beside it, in pixels. */
|
|
9
|
+
const NODE_LABEL_GAP = 5;
|
|
10
|
+
/** Weak enough that the nodes stay countable under the ribbons crossing them. */
|
|
11
|
+
const RIBBON_OPACITY = 0.34;
|
|
12
|
+
/** Vertical room a label needs before the one under it overwrites it, in multiples of its type size. */
|
|
13
|
+
const LABEL_PITCH = 2.4;
|
|
14
|
+
/**
|
|
15
|
+
* Which nodes write their name, walking each column from the top.
|
|
16
|
+
*
|
|
17
|
+
* A gate turning five million candidates into a few hundred draws its survivors a pixel apart.
|
|
18
|
+
* Three names centered inside eight pixels is one smear. The node draws and the name gives way.
|
|
19
|
+
*/
|
|
20
|
+
function labeled(nodes, pitch) {
|
|
21
|
+
const ids = new Set();
|
|
22
|
+
for (const column of new Set(nodes.map((node) => node.column))) {
|
|
23
|
+
let lastY = -Infinity;
|
|
24
|
+
const members = nodes.filter((node) => node.column === column && node.label !== "").sort((a, b) => a.y0 - b.y0);
|
|
25
|
+
for (const node of members) {
|
|
26
|
+
const at = (node.y0 + node.y1) / 2;
|
|
27
|
+
if (at - lastY < pitch)
|
|
28
|
+
continue;
|
|
29
|
+
ids.add(node.id);
|
|
30
|
+
lastY = at;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return ids;
|
|
34
|
+
}
|
|
35
|
+
export function Sankey({ nodes, links, width, height, identity, fill, opacity = 1, fontSize, format, normalize = "global", }) {
|
|
36
|
+
if (nodes.length === 0 || width <= 0 || height <= 0)
|
|
37
|
+
return null;
|
|
38
|
+
const layout = sankeyLayout(nodes, links, { width, height, normalize });
|
|
39
|
+
const hue = new Map(layout.nodes.map((node, index) => [node.id, node.color ?? fill ?? identity(index)]));
|
|
40
|
+
const lastColumn = layout.nodes.reduce((held, node) => Math.max(held, node.column), 0);
|
|
41
|
+
const written = labeled(layout.nodes, (fontSize ?? 0) * LABEL_PITCH);
|
|
42
|
+
return (_jsxs(_Fragment, { children: [_jsxs("g", { "data-geom": "sankey", children: [layout.links.map((link, index) => (_jsx("path", { d: link.path, fill: link.color ?? hue.get(link.source) ?? "var(--viz-ink-muted)", fillOpacity: RIBBON_OPACITY * opacity }, `${link.source}-${link.target}-${index}`))), layout.nodes.map((node) => (_jsx("rect", { x: node.x0, y: node.y0, width: node.x1 - node.x0, height: Math.max(1, node.y1 - node.y0), rx: 2, fill: hue.get(node.id), fillOpacity: opacity, children: _jsx("title", { children: `${node.label} ${node.value.toLocaleString()}` }) }, node.id)))] }), fontSize != null && (
|
|
43
|
+
/* A label stands outside its node and turns inward at the last column to stay on the frame. */
|
|
44
|
+
_jsx("g", { "data-geom": "sankey-labels", fontSize: fontSize, pointerEvents: "none", fill: "var(--viz-ink-muted)", children: layout.nodes.map((node) => {
|
|
45
|
+
if (!written.has(node.id))
|
|
46
|
+
return null;
|
|
47
|
+
const inward = node.column === lastColumn && lastColumn > 0;
|
|
48
|
+
const at = inward ? node.x0 - NODE_LABEL_GAP : node.x1 + NODE_LABEL_GAP;
|
|
49
|
+
return (_jsxs("text", { x: at, y: (node.y0 + node.y1) / 2, dominantBaseline: "middle", textAnchor: inward ? "end" : "start", children: [_jsx("tspan", { x: at, dy: format ? "-0.1em" : 0, children: node.label }), format && (_jsx("tspan", { x: at, dy: "1.2em", fillOpacity: 0.75, children: format(node.value) }))] }, node.id));
|
|
50
|
+
}) }))] }));
|
|
51
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The segment geom: one straight run per reading, from where it started to where it finished.
|
|
3
|
+
*
|
|
4
|
+
* The pair the author already holds. A before-and-after reading and a drift vector are the same
|
|
5
|
+
* geometry: two coordinates per row, with the travel between them drawn once. Nothing runs between
|
|
6
|
+
* one reading and the next, which is what tells this apart from the line beside it, and it is why
|
|
7
|
+
* the build hands the segments over unordered.
|
|
8
|
+
*
|
|
9
|
+
* A `line` element per segment instead of one path with a move before each run. Each segment is a
|
|
10
|
+
* geom a reader points at, so it gets an element of its own, and a hover or a click has something
|
|
11
|
+
* to land on when either arrives.
|
|
12
|
+
*
|
|
13
|
+
* `GRAMMAR` marks the kind unproportional, so the vertical scale is not grounded at zero. The
|
|
14
|
+
* length of a segment is a displacement between two readings and not a magnitude measured up from
|
|
15
|
+
* nothing. See rule 11 of `CHART-DESIGN.md` for the reading that makes bars and areas the other
|
|
16
|
+
* answer.
|
|
17
|
+
*/
|
|
18
|
+
import type { GeomHit, Scale, SegmentPoint } from "../../core/internal.js";
|
|
19
|
+
export interface SegmentProps {
|
|
20
|
+
/** In axis units. Unordered, since each segment draws on its own. */
|
|
21
|
+
points: SegmentPoint[];
|
|
22
|
+
x: Scale;
|
|
23
|
+
y: Scale;
|
|
24
|
+
color: string;
|
|
25
|
+
lineWidth?: number;
|
|
26
|
+
opacity?: number;
|
|
27
|
+
/** Whether each run carries a head at the end it finishes on. Drawn unless refused. */
|
|
28
|
+
arrow?: boolean;
|
|
29
|
+
/** Whether the pair of scales is drawn the other way round, the way the band geoms take it. */
|
|
30
|
+
transposed?: boolean;
|
|
31
|
+
/** The segment under the pointer, placed at the middle of its run. */
|
|
32
|
+
onHover?: (hit: GeomHit<SegmentPoint> | null) => void;
|
|
33
|
+
/** A segment clicked. Its record is what a linked view filters on. */
|
|
34
|
+
onSelect?: (hit: GeomHit<SegmentPoint>) => void;
|
|
35
|
+
}
|
|
36
|
+
export declare function Segment({ points, x, y, color, lineWidth, opacity, arrow, transposed, onHover, onSelect, }: SegmentProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/** Head length in pixels, off the stroke, with a floor so a hairline still points somewhere. */
|
|
3
|
+
const headLength = (lineWidth) => Math.max(5, lineWidth * 3.5);
|
|
4
|
+
/**
|
|
5
|
+
* The three corners of a head sitting on the end of a run.
|
|
6
|
+
*
|
|
7
|
+
* Along the run and not at a fixed angle, so the head says the direction the reading took. Null
|
|
8
|
+
* where the two ends resolve to the same pixel: a segment that finishes where it started states no
|
|
9
|
+
* direction, and a head drawn on it would point whichever way the arithmetic fell.
|
|
10
|
+
*/
|
|
11
|
+
function head(x1, y1, x2, y2, lineWidth) {
|
|
12
|
+
const dx = x2 - x1;
|
|
13
|
+
const dy = y2 - y1;
|
|
14
|
+
const run = Math.hypot(dx, dy);
|
|
15
|
+
if (run < 0.5)
|
|
16
|
+
return null;
|
|
17
|
+
const long = Math.min(headLength(lineWidth), run);
|
|
18
|
+
const alongX = (dx / run) * long;
|
|
19
|
+
const alongY = (dy / run) * long;
|
|
20
|
+
/* Half the head's width, across the run. */
|
|
21
|
+
const acrossX = (-dy / run) * long * 0.42;
|
|
22
|
+
const acrossY = (dx / run) * long * 0.42;
|
|
23
|
+
const baseX = x2 - alongX;
|
|
24
|
+
const baseY = y2 - alongY;
|
|
25
|
+
return `M${x2.toFixed(2)},${y2.toFixed(2)}L${(baseX + acrossX).toFixed(2)},${(baseY + acrossY).toFixed(2)}L${(baseX - acrossX).toFixed(2)},${(baseY - acrossY).toFixed(2)}Z`;
|
|
26
|
+
}
|
|
27
|
+
export function Segment({ points, x, y, color, lineWidth = 1.5, opacity = 1, arrow = true, transposed = false, onHover, onSelect, }) {
|
|
28
|
+
return (_jsx("g", { children: points.map((segment, index) => {
|
|
29
|
+
/* The names stay with the data and the swap happens here, which is where the band geoms
|
|
30
|
+
take it too: the reading bound to X goes up the side once the pair is turned. */
|
|
31
|
+
const x1 = transposed ? x(segment.y) : x(segment.x);
|
|
32
|
+
const y1 = transposed ? y(segment.x) : y(segment.y);
|
|
33
|
+
const x2 = transposed ? x(segment.yEnd) : x(segment.xEnd);
|
|
34
|
+
const y2 = transposed ? y(segment.xEnd) : y(segment.yEnd);
|
|
35
|
+
const tip = arrow ? head(x1, y1, x2, y2, lineWidth) : null;
|
|
36
|
+
const hit = { datum: segment, index, at: { x: (x1 + x2) / 2, y: (y1 + y2) / 2 } };
|
|
37
|
+
return (_jsxs("g", { "data-geom": "segment", onMouseEnter: () => onHover?.(hit), onMouseLeave: () => onHover?.(null), onClick: onSelect ? () => onSelect(hit) : undefined, style: onSelect ? { cursor: "pointer" } : undefined, children: [(onHover || onSelect) && (_jsx("line", { "data-hit": "", x1: x1.toFixed(2), y1: y1.toFixed(2), x2: x2.toFixed(2), y2: y2.toFixed(2), stroke: "transparent", strokeWidth: Math.max(lineWidth, 8), pointerEvents: "stroke" })), _jsx("line", { x1: x1.toFixed(2), y1: y1.toFixed(2), x2: x2.toFixed(2), y2: y2.toFixed(2), stroke: color, strokeWidth: lineWidth, strokeOpacity: opacity, strokeLinecap: "round" }), tip && _jsx("path", { d: tip, fill: color, fillOpacity: opacity })] }, index));
|
|
38
|
+
}) }));
|
|
39
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sunburst: the icicle's layout turned round a center, one ring per level.
|
|
3
|
+
*
|
|
4
|
+
* The layout is the icicle's exactly, and what changes is where a cell lands. A span that was a
|
|
5
|
+
* width becomes an angle and a level that was a row becomes a ring, so the nesting reads outward
|
|
6
|
+
* from the middle and a child sits inside the arc its parent took.
|
|
7
|
+
*
|
|
8
|
+
* `arcPath` draws each cell, the same builder the pie uses. A ring layout is made per
|
|
9
|
+
* cell out of that cell\'s own two radii, which is what lets one path builder serve a geometry whose
|
|
10
|
+
* inner and outer edges move with the depth.
|
|
11
|
+
*
|
|
12
|
+
* Polar, so the condition the coordinate is permitted under reaches it: a slice carries its value as
|
|
13
|
+
* text or the reader is left judging an angle. See the ADR "Polar is permitted where the figure
|
|
14
|
+
* writes its numbers".
|
|
15
|
+
*/
|
|
16
|
+
import { type GeomHit, type HierarchyCell } from "../../core/internal.js";
|
|
17
|
+
export interface SunburstProps {
|
|
18
|
+
cells: HierarchyCell[];
|
|
19
|
+
width: number;
|
|
20
|
+
height: number;
|
|
21
|
+
/** Hue per group, taken off the categorical map. Read where no `fill` is stated. */
|
|
22
|
+
identity: (index: number) => string;
|
|
23
|
+
/** One hue for the whole figure, where the author picked one. */
|
|
24
|
+
fill?: string;
|
|
25
|
+
/** Groups the legend names, with the categorical index of each. */
|
|
26
|
+
levels?: readonly {
|
|
27
|
+
value: string;
|
|
28
|
+
code: number;
|
|
29
|
+
}[];
|
|
30
|
+
opacity?: number;
|
|
31
|
+
/** Paint on each slice's edge. Absent is the paper, which reads as space between neighbors. */
|
|
32
|
+
stroke?: string;
|
|
33
|
+
/** The value written on each slice, which is what the coordinate is permitted on. `wanted` picks the slices. */
|
|
34
|
+
numbers?: {
|
|
35
|
+
format: (value: number) => string;
|
|
36
|
+
wanted?: (value: number) => boolean;
|
|
37
|
+
color?: string;
|
|
38
|
+
fontSize: number;
|
|
39
|
+
};
|
|
40
|
+
/** Writes the cell\'s name above the number. Chart-design rule 2, applied to a slice. */
|
|
41
|
+
names?: boolean;
|
|
42
|
+
/** The cell under the pointer, placed where its label sits. */
|
|
43
|
+
onHover?: (hit: GeomHit<HierarchyCell> | null) => void;
|
|
44
|
+
onSelect?: (hit: GeomHit<HierarchyCell>) => void;
|
|
45
|
+
}
|
|
46
|
+
export declare function Sunburst({ cells, width, height, identity, fill, levels, opacity, stroke, numbers, names, onHover, onSelect, }: SunburstProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Sunburst: the icicle's layout turned round a center, one ring per level.
|
|
4
|
+
*
|
|
5
|
+
* The layout is the icicle's exactly, and what changes is where a cell lands. A span that was a
|
|
6
|
+
* width becomes an angle and a level that was a row becomes a ring, so the nesting reads outward
|
|
7
|
+
* from the middle and a child sits inside the arc its parent took.
|
|
8
|
+
*
|
|
9
|
+
* `arcPath` draws each cell, the same builder the pie uses. A ring layout is made per
|
|
10
|
+
* cell out of that cell\'s own two radii, which is what lets one path builder serve a geometry whose
|
|
11
|
+
* inner and outer edges move with the depth.
|
|
12
|
+
*
|
|
13
|
+
* Polar, so the condition the coordinate is permitted under reaches it: a slice carries its value as
|
|
14
|
+
* text or the reader is left judging an angle. See the ADR "Polar is permitted where the figure
|
|
15
|
+
* writes its numbers".
|
|
16
|
+
*/
|
|
17
|
+
import { arcPath, METRICS, polarPoint, ringLayout, textRun, } from "../../core/internal.js";
|
|
18
|
+
import { EDGE, hueFor, labelInk } from "./hierarchy-cells.js";
|
|
19
|
+
/**
|
|
20
|
+
* Whether a slice has room along its own ring for the text it would carry.
|
|
21
|
+
*
|
|
22
|
+
* Measured as an arc length and not as an angle. A ring's inner cells sit at a small radius, so a
|
|
23
|
+
* wide angle there is a short arc and two roots' numbers run into each other in the middle, which is
|
|
24
|
+
* what a fixed angle floor let through. `textRun` is the same estimate the margin and the band use.
|
|
25
|
+
*/
|
|
26
|
+
const roomFor = (text, from, to, radius, fontSize) => (to - from) * radius >= textRun(text.length, fontSize);
|
|
27
|
+
/** Paper between one ring and the next, as a fraction of the panel\'s radius. */
|
|
28
|
+
const GAP = 0.004;
|
|
29
|
+
export function Sunburst({ cells, width, height, identity, fill, levels, opacity = 1, stroke = "var(--viz-paper)", numbers, names, onHover, onSelect, }) {
|
|
30
|
+
const panel = ringLayout(width, height, 0);
|
|
31
|
+
if (cells.length === 0 || panel.outer <= 0)
|
|
32
|
+
return null;
|
|
33
|
+
const hue = hueFor(cells, identity, fill, levels);
|
|
34
|
+
/* A name alone is written at the regular column's size. A number states its own. */
|
|
35
|
+
const type = numbers?.fontSize ?? METRICS.regular.axis;
|
|
36
|
+
/* One ring layout per cell, off that cell\'s own depth, so `arcPath` draws an annular sector. */
|
|
37
|
+
const placed = cells.map((cell) => {
|
|
38
|
+
const inner = cell.y0 * panel.outer;
|
|
39
|
+
const outer = Math.max(inner, cell.y1 * panel.outer - GAP * panel.outer);
|
|
40
|
+
const from = cell.x0 * Math.PI * 2;
|
|
41
|
+
const to = cell.x1 * Math.PI * 2;
|
|
42
|
+
const ring = { cx: panel.cx, cy: panel.cy, inner, outer, labelRadius: inner + (outer - inner) / 2 };
|
|
43
|
+
return { cell, ring, from, to, hue: hue(cell), at: polarPoint(ring, ring.labelRadius, (from + to) / 2) };
|
|
44
|
+
});
|
|
45
|
+
return (_jsxs(_Fragment, { children: [_jsx("g", { "data-geom": "sunburst", children: placed.map(({ cell, ring, from, to, hue: ink, at }, index) => (_jsx("path", { d: arcPath(ring, from, to), fill: ink, fillOpacity: opacity, stroke: stroke, strokeWidth: EDGE, onMouseEnter: () => onHover?.({ datum: cell, index, at }), onMouseLeave: () => onHover?.(null), onClick: onSelect ? () => onSelect({ datum: cell, index, at }) : undefined, style: onSelect ? { cursor: "pointer" } : undefined }, cell.label))) }), (numbers || names) && (
|
|
46
|
+
/*
|
|
47
|
+
Past the slices, so no later fill covers a number already written.
|
|
48
|
+
|
|
49
|
+
A slice narrower than `NARROW` gets no text, which is the same floor the pie holds. Text
|
|
50
|
+
drawn over a sliver runs across its neighbors and the reader loses both.
|
|
51
|
+
*/
|
|
52
|
+
_jsx("g", { "data-geom": "sunburst-labels", fontSize: type, pointerEvents: "none", textAnchor: "middle", children: placed.map(({ cell, ring, to, from, at, hue: ink }) => {
|
|
53
|
+
const lines = [
|
|
54
|
+
...(names ? [cell.label] : []),
|
|
55
|
+
...(numbers && (numbers.wanted?.(cell.value) ?? true) ? [numbers.format(cell.value)] : []),
|
|
56
|
+
];
|
|
57
|
+
if (lines.length === 0)
|
|
58
|
+
return null;
|
|
59
|
+
const widest = lines.reduce((held, line) => (line.length > held.length ? line : held), "");
|
|
60
|
+
if (!roomFor(widest, from, to, ring.labelRadius, type))
|
|
61
|
+
return null;
|
|
62
|
+
return (_jsx("text", { x: at.x, y: at.y, dominantBaseline: "central", fill: numbers?.color ?? labelInk(ink), children: lines.map((line, row) => (_jsx("tspan", { x: at.x, dy: row === 0 ? `${-((lines.length - 1) * 0.55)}em` : "1.1em", children: line }, line))) }, cell.label));
|
|
63
|
+
}) }))] }));
|
|
64
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A relief, and a structure: the two cube kinds that draw a lit surface.
|
|
3
|
+
*
|
|
4
|
+
* The design language always allowed this case. A topographic relief and a protein structure are 3D
|
|
5
|
+
* objects, and drawing them as one is the honest choice, which is the sentence the coordinates rule
|
|
6
|
+
* carried before it was amended. What the amendment adds is the camera: the reader turns the object
|
|
7
|
+
* and the light crosses it, which is what a still projection cannot give.
|
|
8
|
+
*
|
|
9
|
+
* Height carries the color as well as the position. A surface read by shading alone hides a plateau
|
|
10
|
+
* under a light that happens to face it, and the ramp is the reading that survives any camera.
|
|
11
|
+
*/
|
|
12
|
+
import type { LayerStyle, MeshData, ThemeSnapshot, UnitRamp } from "../../core/internal.js";
|
|
13
|
+
export interface SurfaceProps {
|
|
14
|
+
mesh: MeshData;
|
|
15
|
+
xDomain: [number, number];
|
|
16
|
+
yDomain: [number, number];
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
/** The magnitude map, over nought to one, in the CSS the rest of the chart is drawn in. */
|
|
20
|
+
ramp: UnitRamp;
|
|
21
|
+
labels: {
|
|
22
|
+
x: string;
|
|
23
|
+
y: string;
|
|
24
|
+
z: string;
|
|
25
|
+
};
|
|
26
|
+
format?: (value: number) => string;
|
|
27
|
+
/** Which back faces of the box take a pane. */
|
|
28
|
+
panes?: LayerStyle["panes"];
|
|
29
|
+
/** The live token values where the chart sits, for the GL path's colors. */
|
|
30
|
+
theme?: ThemeSnapshot | null;
|
|
31
|
+
}
|
|
32
|
+
export declare function Surface({ mesh, xDomain, yDomain, width, height, ramp, labels, format, panes, theme }: SurfaceProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A relief, and a structure: the two cube kinds that draw a lit surface.
|
|
4
|
+
*
|
|
5
|
+
* The design language always allowed this case. A topographic relief and a protein structure are 3D
|
|
6
|
+
* objects, and drawing them as one is the honest choice, which is the sentence the coordinates rule
|
|
7
|
+
* carried before it was amended. What the amendment adds is the camera: the reader turns the object
|
|
8
|
+
* and the light crosses it, which is what a still projection cannot give.
|
|
9
|
+
*
|
|
10
|
+
* Height carries the color as well as the position. A surface read by shading alone hides a plateau
|
|
11
|
+
* under a light that happens to face it, and the ramp is the reading that survives any camera.
|
|
12
|
+
*/
|
|
13
|
+
import { useMemo } from "react";
|
|
14
|
+
import { rgbOf } from "../../core/internal.js";
|
|
15
|
+
import { GlMesh } from "../gl/GlMesh.js";
|
|
16
|
+
import { CubeStage } from "./cube-stage.js";
|
|
17
|
+
const MUTED = [0.55, 0.55, 0.58];
|
|
18
|
+
/** The middle of the vertices, which is what the layer packs its offsets against. */
|
|
19
|
+
function centerOf(positions) {
|
|
20
|
+
const lo = [Infinity, Infinity, Infinity];
|
|
21
|
+
const hi = [-Infinity, -Infinity, -Infinity];
|
|
22
|
+
for (let at = 0; at < positions.length; at += 3) {
|
|
23
|
+
for (let axis = 0; axis < 3; axis += 1) {
|
|
24
|
+
const value = positions[at + axis];
|
|
25
|
+
if (value < lo[axis])
|
|
26
|
+
lo[axis] = value;
|
|
27
|
+
if (value > hi[axis])
|
|
28
|
+
hi[axis] = value;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return [0, 1, 2].map((axis) => (Number.isFinite(lo[axis]) ? (lo[axis] + hi[axis]) / 2 : 0));
|
|
32
|
+
}
|
|
33
|
+
export function Surface({ mesh, xDomain, yDomain, width, height, ramp, labels, format, panes, theme }) {
|
|
34
|
+
const domains = useMemo(() => ({ x: xDomain, y: yDomain, z: mesh.zDomain }), [xDomain, yDomain, mesh.zDomain]);
|
|
35
|
+
const center = useMemo(() => centerOf(mesh.positions), [mesh.positions]);
|
|
36
|
+
const glRamp = useMemo(() => {
|
|
37
|
+
const cache = new Map();
|
|
38
|
+
return (t) => {
|
|
39
|
+
const step = Math.round(t * 64) / 64;
|
|
40
|
+
const held = cache.get(step);
|
|
41
|
+
if (held)
|
|
42
|
+
return held;
|
|
43
|
+
const rgb = rgbOf(ramp(step)) ?? MUTED;
|
|
44
|
+
cache.set(step, rgb);
|
|
45
|
+
return rgb;
|
|
46
|
+
};
|
|
47
|
+
}, [ramp]);
|
|
48
|
+
return (_jsx(CubeStage, { domains: domains, center: center, width: width, height: height, labels: labels, format: format, panes: panes, theme: theme, children: ({ orbit }) => (_jsx(GlMesh, { mesh: mesh, xDomain: xDomain, yDomain: yDomain, orbit: orbit, width: width, height: height, ramp: glRamp })) }));
|
|
49
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The text geoms: a label per row at its reading. ggplot's `geom_text` and `geom_label`.
|
|
3
|
+
*
|
|
4
|
+
* Plain SVG text, which an export and a headless draw keep.
|
|
5
|
+
*/
|
|
6
|
+
import { type LayerPoint, type Scale } from "../../core/internal.js";
|
|
7
|
+
export interface TextProps {
|
|
8
|
+
points: readonly LayerPoint[];
|
|
9
|
+
x: Scale;
|
|
10
|
+
y: Scale;
|
|
11
|
+
/** Category width on the band axis, zero on a value scale. */
|
|
12
|
+
band: number;
|
|
13
|
+
/** Distance between two neighboring band centers, in pixels. A jitter's or a nudge's offset there reads in it. */
|
|
14
|
+
step?: number;
|
|
15
|
+
/** The dodged bar's slot, where the layer named one. `ofBand` overrides `of` per category. */
|
|
16
|
+
slot?: {
|
|
17
|
+
index: number;
|
|
18
|
+
of: number;
|
|
19
|
+
width?: number;
|
|
20
|
+
cap?: number;
|
|
21
|
+
ofBand?: Record<string, number>;
|
|
22
|
+
};
|
|
23
|
+
transposed?: boolean;
|
|
24
|
+
/** Ink per label off its weight, where a color channel is bound. */
|
|
25
|
+
ramp?: (weight: number) => string;
|
|
26
|
+
/** Ink for the whole layer. Absent writes in the foreground ink. */
|
|
27
|
+
color?: string;
|
|
28
|
+
fontSize?: number;
|
|
29
|
+
hjust?: number;
|
|
30
|
+
vjust?: number;
|
|
31
|
+
opacity?: number;
|
|
32
|
+
/** Draws the paper box behind each label, which is `geom_label`. */
|
|
33
|
+
boxed?: boolean;
|
|
34
|
+
}
|
|
35
|
+
export declare function Text({ points, x, y, band, step, slot, transposed, ramp, color, fontSize, hjust, vjust, opacity, boxed, }: TextProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The text geoms: a label per row at its reading. ggplot's `geom_text` and `geom_label`.
|
|
4
|
+
*
|
|
5
|
+
* Plain SVG text, which an export and a headless draw keep.
|
|
6
|
+
*/
|
|
7
|
+
import { textRun } from "../../core/internal.js";
|
|
8
|
+
import { BAR_CAP, MARK_GAP } from "./Bars.js";
|
|
9
|
+
/** Height of a capital, as a share of the type size. `vjust` measures against it. */
|
|
10
|
+
const CAP = 0.72;
|
|
11
|
+
const PAD = 3;
|
|
12
|
+
/** The SVG anchor nearest to ggplot's `hjust`. */
|
|
13
|
+
const anchorOf = (hjust) => hjust <= 0.25 ? "start" : hjust >= 0.75 ? "end" : "middle";
|
|
14
|
+
export function Text({ points, x, y, band, step = 0, slot, transposed = false, ramp, color, fontSize = 11, hjust = 0.5, vjust = 0.5, opacity = 1, boxed = false, }) {
|
|
15
|
+
/* The bar's own slot arithmetic. A label then stands over the middle of the bar it names. */
|
|
16
|
+
const whole = Math.max(1, Math.min(band - MARK_GAP, slot?.cap ?? BAR_CAP));
|
|
17
|
+
const spread = whole * (slot?.width ?? 1);
|
|
18
|
+
const offsetOf = (point) => {
|
|
19
|
+
if (!slot || band <= 0)
|
|
20
|
+
return 0;
|
|
21
|
+
const of = (point.category != null ? slot.ofBand?.[point.category] : undefined) ?? slot.of;
|
|
22
|
+
return (slot.index - (of - 1) / 2) * (spread / of);
|
|
23
|
+
};
|
|
24
|
+
const along = transposed ? y : x;
|
|
25
|
+
const measure = transposed ? x : y;
|
|
26
|
+
const anchor = anchorOf(hjust);
|
|
27
|
+
return (_jsx("g", { pointerEvents: "none", "data-geom": "text", children: points.map((point, index) => {
|
|
28
|
+
const reading = point.category ?? point.x + (point.dx ?? 0);
|
|
29
|
+
const moved = offsetOf(point) + (point.category == null ? 0 : (point.dx ?? 0) * step);
|
|
30
|
+
const value = point.y + (point.dy ?? 0);
|
|
31
|
+
const [px, py] = transposed
|
|
32
|
+
? [measure(value), along(reading) + moved]
|
|
33
|
+
: [along(reading) + moved, measure(value)];
|
|
34
|
+
const baseline = py + vjust * fontSize * CAP;
|
|
35
|
+
const ink = point.weight != null && ramp ? ramp(point.weight) : (color ?? "var(--viz-ink)");
|
|
36
|
+
const run = textRun(point.text?.length ?? 0, fontSize);
|
|
37
|
+
const left = anchor === "start" ? px : anchor === "end" ? px - run : px - run / 2;
|
|
38
|
+
return (_jsxs("g", { children: [boxed && (_jsx("rect", { x: left - PAD, y: baseline - fontSize * CAP - PAD, width: run + PAD * 2, height: fontSize * CAP + PAD * 2 + 2, rx: 3, fill: "var(--viz-paper)", stroke: "var(--viz-rule)" })), _jsx("text", { x: px, y: baseline, textAnchor: anchor, fontSize: fontSize, fill: ink, fillOpacity: opacity, children: point.text })] }, `${point.row}:${index}`));
|
|
39
|
+
}) }));
|
|
40
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A hierarchy tiled into the panel. A cell's area stands for its value.
|
|
3
|
+
*
|
|
4
|
+
* `GRAMMAR` answers `packed` for the coordinate system, so the frame draws no axes and the geom takes
|
|
5
|
+
* the plot area whole. The rectangles come off `treemapLayout` in `/core` as fractions of that area,
|
|
6
|
+
* so this scales them and draws.
|
|
7
|
+
*
|
|
8
|
+
* A parent stands before its children in the payload and the children cover it, so drawing in order
|
|
9
|
+
* leaves the leaves on top and a parent's own fill shows only where it has none. What separates two
|
|
10
|
+
* neighbors is the paper-colored stroke of chart-design rule 9, the same one a stacked bar's segments
|
|
11
|
+
* take.
|
|
12
|
+
*
|
|
13
|
+
* A cell gets its label and its value written inside it where both fit, per rule 9 and the guides
|
|
14
|
+
* section's preference for a direct label over a legend. A packed layout has no axis to carry the
|
|
15
|
+
* number, so the cell carries it.
|
|
16
|
+
*/
|
|
17
|
+
import type { HierarchyCell } from "../../core/internal.js";
|
|
18
|
+
export interface TreemapProps {
|
|
19
|
+
cells: HierarchyCell[];
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
/** Hue per group, taken off the categorical map. Read where no `fill` is stated. */
|
|
23
|
+
identity: (index: number) => string;
|
|
24
|
+
/** One hue for the whole figure, where the author picked one. */
|
|
25
|
+
fill?: string;
|
|
26
|
+
/** Groups the legend names, with the categorical index of each. */
|
|
27
|
+
levels?: readonly {
|
|
28
|
+
value: string;
|
|
29
|
+
code: number;
|
|
30
|
+
}[];
|
|
31
|
+
opacity?: number;
|
|
32
|
+
/** Paint on each cell's edge. Absent is the paper, which reads as space between neighbors. */
|
|
33
|
+
stroke?: string;
|
|
34
|
+
/** The cell's value written under its name. Absent writes the name alone. */
|
|
35
|
+
format?: (value: number) => string;
|
|
36
|
+
/** Type size for the labels, in pixels. Absent writes none. */
|
|
37
|
+
fontSize?: number;
|
|
38
|
+
}
|
|
39
|
+
export declare function Treemap({ cells, width, height, identity, fill, levels, opacity, stroke, format, fontSize, }: TreemapProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { MARK_RADIUS } from "./Bars.js";
|
|
3
|
+
import { EDGE, fits, hueFor, labelInk, placeCells } from "./hierarchy-cells.js";
|
|
4
|
+
export function Treemap({ cells, width, height, identity, fill, levels, opacity = 1, stroke = "var(--viz-paper)", format, fontSize, }) {
|
|
5
|
+
if (cells.length === 0 || width <= 0 || height <= 0)
|
|
6
|
+
return null;
|
|
7
|
+
const boxes = placeCells(cells, width, height, hueFor(cells, identity, fill, levels));
|
|
8
|
+
/* Written on the cells nothing covers, since a parent's own name sits under its children. */
|
|
9
|
+
const covered = new Set(cells.map((cell) => cell.parent).filter((label) => label != null));
|
|
10
|
+
const written = fontSize == null
|
|
11
|
+
? []
|
|
12
|
+
: boxes.filter(({ cell, w, h }) => !covered.has(cell.label) && fits(cell.label, w, h, fontSize, format ? 2 : 1));
|
|
13
|
+
return (_jsxs(_Fragment, { children: [_jsx("g", { "data-geom": "treemap", children: boxes.map(({ cell, x, y, w, h, hue }) => (_jsx("rect", { x: x + EDGE / 2, y: y + EDGE / 2, width: Math.max(0, w - EDGE), height: Math.max(0, h - EDGE), rx: Math.min(MARK_RADIUS / 2, w / 2, h / 2), fill: hue, fillOpacity: opacity, stroke: stroke, strokeWidth: EDGE }, cell.label))) }), written.length > 0 && fontSize != null && (
|
|
14
|
+
/* Past the cells, so no later fill covers a name already written. */
|
|
15
|
+
_jsx("g", { "data-geom": "treemap-labels", fontSize: fontSize, pointerEvents: "none", textAnchor: "middle", children: written.map(({ cell, x, y, w, h, hue }) => (_jsxs("text", { x: x + w / 2, y: y + h / 2, dominantBaseline: "central", fill: labelInk(hue), children: [_jsx("tspan", { x: x + w / 2, dy: format ? "-0.1em" : 0, children: cell.label }), format && (_jsx("tspan", { x: x + w / 2, dy: "1.2em", fillOpacity: 0.75, children: format(cell.value) }))] }, cell.label))) }))] }));
|
|
16
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kernel density per category, mirrored around the band center.
|
|
3
|
+
*
|
|
4
|
+
* A box says where the middle half sits and nothing about the shape it takes. Two distributions with
|
|
5
|
+
* the same quartiles draw the same box while one is bimodal and the other is not, and which of those
|
|
6
|
+
* a scientist is holding decides whether the median means anything. The violin is the geom that
|
|
7
|
+
* disagrees.
|
|
8
|
+
*
|
|
9
|
+
* It carries the box's median tick so the two can be read together, and it takes the same color
|
|
10
|
+
* ramp, since a set of geoms that shares a frame should share a system. The outline is written by
|
|
11
|
+
* hand instead of through a curve generator, per the ADR "A layer draws over a shared frame".
|
|
12
|
+
*
|
|
13
|
+
* The density itself is `kde` in `/core`. A distribution is a distribution whatever produced it, so
|
|
14
|
+
* the geom names no domain and takes its meaning from what the caller bound.
|
|
15
|
+
*/
|
|
16
|
+
import type { GeomHit, Scale, ValueRamp, ViolinDatum } from "../../core/internal.js";
|
|
17
|
+
export type { ViolinDatum };
|
|
18
|
+
export interface ViolinProps {
|
|
19
|
+
data: ViolinDatum[];
|
|
20
|
+
x: Scale;
|
|
21
|
+
y: Scale;
|
|
22
|
+
band: number;
|
|
23
|
+
/** Maps a group's median, in the units it carries, to a color. */
|
|
24
|
+
ramp: ValueRamp;
|
|
25
|
+
/**
|
|
26
|
+
* Widest the outline is drawn, in pixels.
|
|
27
|
+
*
|
|
28
|
+
* Unset, it takes most of its slot and stops at sixty-eight, the proportion that leaves air between
|
|
29
|
+
* neighbors. Set, it is the width asked for, bounded only by the slot.
|
|
30
|
+
*/
|
|
31
|
+
thickness?: number;
|
|
32
|
+
/** Opacity of the interior. Absent is 0.72. */
|
|
33
|
+
opacity?: number;
|
|
34
|
+
/** Paint on the outline, and its width. Absent takes the interior's color at 0.9 pixels. */
|
|
35
|
+
stroke?: string;
|
|
36
|
+
lineWidth?: number;
|
|
37
|
+
/**
|
|
38
|
+
* Draws the outline across the frame instead of up it, the band running down the side.
|
|
39
|
+
*
|
|
40
|
+
* Read off the frame, since it refuses a transpose where the geoms read no shared pair. The walk
|
|
41
|
+
* is the same one with the pair swapped: out along the density and back along its mirror.
|
|
42
|
+
*/
|
|
43
|
+
transposed?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Which side of the band the density occupies.
|
|
46
|
+
*
|
|
47
|
+
* Both is the distribution read on its own. One side is the raincloud's, which spends the other
|
|
48
|
+
* half of the band on the box and the readings. Stated in band space, so a transpose carries it.
|
|
49
|
+
*/
|
|
50
|
+
side?: "both" | "high" | "low";
|
|
51
|
+
showMedian?: boolean;
|
|
52
|
+
/** The violin under the pointer, placed at its median. */
|
|
53
|
+
onHover?: (hit: GeomHit<ViolinDatum> | null) => void;
|
|
54
|
+
onSelect?: (hit: GeomHit<ViolinDatum>) => void;
|
|
55
|
+
}
|
|
56
|
+
export declare function Violin({ data, x, y, band, ramp, thickness, opacity, stroke, lineWidth, transposed, side, showMedian, onHover, onSelect, }: ViolinProps): import("react").JSX.Element;
|