@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,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The property column: what a plot is made of, in collapsible sections.
|
|
3
|
+
*
|
|
4
|
+
* One option per row. The accent marks what is in force. X binds once, across every series.
|
|
5
|
+
*/
|
|
6
|
+
import { type ReactNode } from "react";
|
|
7
|
+
import { type CapabilityProfile, type ChartSpec, type Finding, type Palettes, type PlotField, type PlotSourceOption } from "../core/internal.js";
|
|
8
|
+
/** What `PlotPanel` takes. `S` is the host's own spec type, carried through each edit. */
|
|
9
|
+
export interface PlotPanelProps<S extends ChartSpec> {
|
|
10
|
+
spec: S;
|
|
11
|
+
/** Columns of the table the plot currently reads. */
|
|
12
|
+
fields: readonly PlotField[];
|
|
13
|
+
/**
|
|
14
|
+
* Tables the plot can be pointed at. Absent hides the table picker.
|
|
15
|
+
*
|
|
16
|
+
* The picker reads and writes `StoredSpec.source`.
|
|
17
|
+
*/
|
|
18
|
+
sources?: readonly PlotSourceOption[];
|
|
19
|
+
/** Each edit, as a new spec of the host's type. The host stamps the time it saves. */
|
|
20
|
+
onChange: (next: S) => void;
|
|
21
|
+
/**
|
|
22
|
+
* Series colors, taken from the host.
|
|
23
|
+
*
|
|
24
|
+
* The strip offers what the host's theme holds. A swatch here is a color the chart beside it draws.
|
|
25
|
+
*/
|
|
26
|
+
palettes: Pick<Palettes, "categorical">;
|
|
27
|
+
/** What this role may author. Unrestricted where the host names none. */
|
|
28
|
+
profile?: CapabilityProfile;
|
|
29
|
+
/**
|
|
30
|
+
* A summary of the table under the source picker.
|
|
31
|
+
*
|
|
32
|
+
* The host draws it, in its own vocabulary of roles, glyphs and colors.
|
|
33
|
+
*/
|
|
34
|
+
shape?: ReactNode;
|
|
35
|
+
/**
|
|
36
|
+
* What the critic said, where the host has an answer the panel cannot reach.
|
|
37
|
+
*
|
|
38
|
+
* The spec-only checks run here. The frame checks require a built frame the host passes in.
|
|
39
|
+
*/
|
|
40
|
+
findings?: readonly Finding[];
|
|
41
|
+
}
|
|
42
|
+
export declare function PlotPanel<S extends ChartSpec>({ spec, fields, sources, onChange, palettes, profile, shape, findings, }: PlotPanelProps<S>): import("react").JSX.Element;
|
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The property column: what a plot is made of, in collapsible sections.
|
|
4
|
+
*
|
|
5
|
+
* One option per row. The accent marks what is in force. X binds once, across every series.
|
|
6
|
+
*/
|
|
7
|
+
import { useEffect, useRef, useState } from "react";
|
|
8
|
+
import { AlignCenter, ArrowDownToLine, ArrowLeftRight, ArrowUpToLine, Blend, ChartScatter, ChevronRight, Circle, Columns3, Eye, EyeOff, Gauge, GripVertical, Hash, Heading, LayoutGrid, Maximize2, MessageSquare, Minus, MousePointerClick, MoveHorizontal, MoveVertical, Ratio, Palette as PaletteIcon, Pipette, Plus, RotateCw, Ruler, Settings2, Shapes, Sigma, Spline, Split, Table2, Tag, Text, Type, X, } from "lucide-react";
|
|
9
|
+
import { LABEL_CAP, OPEN_PROFILE, TICK_FORMATS, addLayer, allowedAesthetics, allowsKind, allowsSetting, bindAes, critique, describeAnnotation, isLog, drawsOneColor, plotKinds, removeLayer, setSource, suggest, updateLayer, usesY2, geomColor, paintAesthetic, paintColumn, paintedWith, } from "../core/internal.js";
|
|
10
|
+
import { Popover } from "./Popover.js";
|
|
11
|
+
import { Stepper } from "./Stepper.js";
|
|
12
|
+
/**
|
|
13
|
+
* The tone a severity carries, from the package's own fixed status colors.
|
|
14
|
+
*
|
|
15
|
+
* A `wrong` finding blocks the save and must read as that under any host palette.
|
|
16
|
+
*/
|
|
17
|
+
const SEVERITY_TONE = {
|
|
18
|
+
wrong: "var(--viz-status-fail)",
|
|
19
|
+
bad: "var(--viz-status-warn)",
|
|
20
|
+
ugly: "var(--viz-ink-muted)",
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Which section a finding belongs to, read off the path it names.
|
|
24
|
+
*
|
|
25
|
+
* The section is the path's first segment. A root no section edits falls to the title, where the
|
|
26
|
+
* save gate is explained.
|
|
27
|
+
*/
|
|
28
|
+
const SECTION_OF = {
|
|
29
|
+
headline: "Title",
|
|
30
|
+
subtitle: "Title",
|
|
31
|
+
caption: "Title",
|
|
32
|
+
scales: "Axes",
|
|
33
|
+
facet: "Axes",
|
|
34
|
+
coord: "Axes",
|
|
35
|
+
sides: "Axes",
|
|
36
|
+
layers: "Layers",
|
|
37
|
+
legend: "Layers",
|
|
38
|
+
width: "Size",
|
|
39
|
+
height: "Size",
|
|
40
|
+
aspect: "Size",
|
|
41
|
+
ratio: "Size",
|
|
42
|
+
sizing: "Size",
|
|
43
|
+
tooltip: "Hover",
|
|
44
|
+
annotations: "Annotations",
|
|
45
|
+
};
|
|
46
|
+
function bySection(findings) {
|
|
47
|
+
const grouped = new Map();
|
|
48
|
+
for (const finding of findings) {
|
|
49
|
+
const root = finding.path.split(/[.[]/, 1)[0] ?? "";
|
|
50
|
+
const section = SECTION_OF[root] ?? "Title";
|
|
51
|
+
grouped.set(section, [...(grouped.get(section) ?? []), finding]);
|
|
52
|
+
}
|
|
53
|
+
return grouped;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* What the critic said about this section, beside the controls that answer it.
|
|
57
|
+
*
|
|
58
|
+
* The dot on a closed header says a shut section has something to answer.
|
|
59
|
+
*/
|
|
60
|
+
function Findings({ findings }) {
|
|
61
|
+
return (_jsx(_Fragment, { children: findings.map((finding) => (_jsxs("div", { className: "text-2xs flex items-start gap-1.5 px-0.5 text-muted-foreground", children: [_jsx("span", { className: "mt-1 size-1.5 shrink-0 rounded-full", style: { background: SEVERITY_TONE[finding.severity] }, "aria-hidden": true }), _jsx("span", { className: "min-w-0 flex-1", children: finding.message })] }, `${finding.code} ${finding.path}`))) }));
|
|
62
|
+
}
|
|
63
|
+
function Section({ title, children, open: initial = true, findings = [], }) {
|
|
64
|
+
const [open, setOpen] = useState(initial);
|
|
65
|
+
const worst = findings[0];
|
|
66
|
+
return (_jsxs("section", { className: "border-b border-border last:border-b-0", children: [_jsxs("button", { type: "button", onClick: () => setOpen((v) => !v), "aria-expanded": open, className: "text-xs flex w-full items-center gap-1 py-2 font-medium uppercase tracking-wide text-muted-foreground hover:text-foreground", children: [_jsx(ChevronRight, { size: 11, className: `transition-transform ${open ? "rotate-90" : ""}` }), title, worst && (_jsx("span", { className: "size-1.5 rounded-full", style: { background: SEVERITY_TONE[worst.severity] }, "aria-hidden": true }))] }), open && (_jsxs("div", { className: "flex flex-col gap-2.5 pb-4", children: [findings.length > 0 && _jsx(Findings, { findings: findings }), children] }))] }));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* What a panel's own size may be set to, in pixels.
|
|
70
|
+
*
|
|
71
|
+
* A chart under a hundred pixels has no room for its axis. Between the bounds the author is trusted.
|
|
72
|
+
*/
|
|
73
|
+
const FIGURE_MIN = 120;
|
|
74
|
+
const FIGURE_MAX = 2000;
|
|
75
|
+
/**
|
|
76
|
+
* The shapes worth offering, named width to height and stored as `aspect`, height over width.
|
|
77
|
+
*
|
|
78
|
+
* A free number here is a control nobody can aim. A widescreen strip, a square for a cube, a tall panel for a ranked bar.
|
|
79
|
+
*/
|
|
80
|
+
const RATIOS = [
|
|
81
|
+
{ id: "16-9", label: "16 : 9", value: 9 / 16 },
|
|
82
|
+
{ id: "4-3", label: "4 : 3", value: 3 / 4 },
|
|
83
|
+
{ id: "1-1", label: "1 : 1", value: 1 },
|
|
84
|
+
{ id: "3-4", label: "3 : 4", value: 4 / 3 },
|
|
85
|
+
];
|
|
86
|
+
/** Which offered ratio a spec's number matches, or none. */
|
|
87
|
+
const ratioOf = (aspect) => aspect == null ? "" : (RATIOS.find((option) => Math.abs(option.value - aspect) < 0.001)?.id ?? "");
|
|
88
|
+
/**
|
|
89
|
+
* One option per row. The fixed columns make the panel scan.
|
|
90
|
+
*
|
|
91
|
+
* The floor is the control height. A row of 8px swatches stands as tall as a row of selects.
|
|
92
|
+
*/
|
|
93
|
+
function Opt({ icon: Icon, label, children }) {
|
|
94
|
+
return (_jsxs("div", { className: "grid min-h-5.5 grid-cols-[14px_58px_1fr] items-center gap-2", children: [_jsx(Icon, { size: 11, className: "text-muted-foreground", "aria-hidden": true }), _jsx("span", { className: "text-xs truncate text-muted-foreground", children: label }), _jsx("div", { className: "flex min-w-0 items-center gap-1", children: children })] }));
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* A row a profile withholds: shown, dimmed and unreachable.
|
|
98
|
+
*
|
|
99
|
+
* Grayed, and the reason shows. A disabled fieldset takes each control inside out of the tab
|
|
100
|
+
* order. The rows keep their places and their gap across roles.
|
|
101
|
+
*/
|
|
102
|
+
function Gated({ on, children }) {
|
|
103
|
+
if (on)
|
|
104
|
+
return _jsx(_Fragment, { children: children });
|
|
105
|
+
return (_jsx("fieldset", { disabled: true, "aria-disabled": true, title: "Outside your profile", className: "pointer-events-none flex min-w-0 select-none flex-col gap-[inherit] opacity-40", children: children }));
|
|
106
|
+
}
|
|
107
|
+
function Select({ value, onChange, options, ariaLabel, placeholder, }) {
|
|
108
|
+
return (_jsxs("select", { value: value, "aria-label": ariaLabel, onChange: (event) => onChange(event.target.value), className: "viz-control-field min-w-0 flex-1", children: [placeholder && _jsx("option", { value: "", children: placeholder }), options.map((option) => (_jsx("option", { value: option.id, children: option.label }, option.id)))] }));
|
|
109
|
+
}
|
|
110
|
+
const fieldOptions = (fields) => fields.map((field) => ({ id: field.id, label: field.label }));
|
|
111
|
+
function Line({ value, placeholder, ariaLabel, onChange, }) {
|
|
112
|
+
return (_jsx("input", { value: value, placeholder: placeholder, "aria-label": ariaLabel, onChange: (event) => onChange(event.target.value), className: "viz-control-field min-w-0 flex-1" }));
|
|
113
|
+
}
|
|
114
|
+
/** A glyph holding a state. The title names it. */
|
|
115
|
+
function Glyph({ icon: Icon, on, title, onClick }) {
|
|
116
|
+
return (_jsx("button", { type: "button", title: title, "aria-label": title, "aria-pressed": on, onClick: onClick, className: `viz-size-control flex shrink-0 items-center justify-center rounded-xs border ${on ? "border-primary/60 bg-primary/10 text-foreground" : "border-border text-muted-foreground hover:bg-accent"}`, children: _jsx(Icon, { size: 11 }) }));
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Exclusive choices: side by side at two, a dropdown past that.
|
|
120
|
+
*
|
|
121
|
+
* Two buttons show both answers at one click. A third truncates its labels against the row width.
|
|
122
|
+
*/
|
|
123
|
+
const SIDE_BY_SIDE = 2;
|
|
124
|
+
function Pick({ value, options, onChange, ariaLabel, tight = false, }) {
|
|
125
|
+
if (options.length > SIDE_BY_SIDE && !tight) {
|
|
126
|
+
return _jsx(Select, { ariaLabel: ariaLabel, value: value, options: options, onChange: (next) => onChange(next) });
|
|
127
|
+
}
|
|
128
|
+
/* A segment inside a recessed track reads as one setting with two positions. */
|
|
129
|
+
return (_jsx("div", { role: "group", "aria-label": ariaLabel, className: "flex min-w-0 flex-1 gap-0.5 rounded-xs bg-muted", children: options.map((option) => (_jsx("button", { type: "button", "aria-pressed": value === option.id, onClick: () => onChange(option.id), className: `text-xs viz-h-control min-w-0 flex-1 rounded-xs px-1 ${value === option.id
|
|
130
|
+
? "border border-border bg-background text-foreground"
|
|
131
|
+
: "text-muted-foreground hover:text-foreground"}`, children: option.label }, option.id))) }));
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* The series color, offered as the palette.
|
|
135
|
+
*
|
|
136
|
+
* Shown only where nothing else decides the color.
|
|
137
|
+
*
|
|
138
|
+
* The picker answers once, when the panel closes. A live drag measured 818ms of blocking.
|
|
139
|
+
*/
|
|
140
|
+
const SWATCHES = 8;
|
|
141
|
+
function ColorStrip({ value, palettes, onChange, }) {
|
|
142
|
+
const field = useRef(null);
|
|
143
|
+
/* `change` is the panel closing; React's `onChange` is the `input` event, which is the drag. */
|
|
144
|
+
useEffect(() => {
|
|
145
|
+
const input = field.current;
|
|
146
|
+
if (!input)
|
|
147
|
+
return;
|
|
148
|
+
const take = () => onChange(input.value);
|
|
149
|
+
input.addEventListener("change", take);
|
|
150
|
+
return () => input.removeEventListener("change", take);
|
|
151
|
+
}, [onChange]);
|
|
152
|
+
return (_jsxs("div", { className: "grid min-h-5.5 grid-cols-[14px_58px_1fr] items-center gap-2", children: [_jsx("span", { "aria-hidden": true }), _jsx("span", { "aria-hidden": true }), _jsxs("div", { role: "group", "aria-label": "Series color", className: "flex min-w-0 items-center gap-1", children: [Array.from({ length: SWATCHES }, (_, index) => {
|
|
153
|
+
const color = palettes.categorical(index);
|
|
154
|
+
return (_jsx("button", { type: "button", title: color, "aria-label": `Color ${index + 1}`, "aria-pressed": value === color, onClick: () => onChange(color), className: `size-3.5 shrink-0 rounded-xs ${value === color ? "ring-1 ring-foreground ring-offset-1 ring-offset-background" : ""}`, style: { background: color } }, color));
|
|
155
|
+
}), _jsx("button", { type: "button", title: "Any color", "aria-label": "Pick any color", onClick: () => field.current?.click(), className: "shrink-0 px-0.5 text-muted-foreground hover:text-foreground", children: _jsx(Pipette, { size: 12 }) }), _jsx("input", { ref: field, type: "color", defaultValue: value, tabIndex: -1, "aria-hidden": true, className: "pointer-events-none absolute size-0 opacity-0" })] })] }));
|
|
156
|
+
}
|
|
157
|
+
/** Turns the tick labels take. Enough to clear a collision, few enough to stay a choice. */
|
|
158
|
+
/** Weight of the tick and title ink. Muted is what the ten rules ask for. */
|
|
159
|
+
const INKS = [
|
|
160
|
+
{ id: "muted", label: "Muted" },
|
|
161
|
+
{ id: "strong", label: "Strong" },
|
|
162
|
+
];
|
|
163
|
+
const TURNS = [
|
|
164
|
+
{ id: "0", label: "flat" },
|
|
165
|
+
{ id: "45", label: "45°" },
|
|
166
|
+
{ id: "90", label: "90°" },
|
|
167
|
+
];
|
|
168
|
+
/**
|
|
169
|
+
* Where a title sits, in the direction of its own axis.
|
|
170
|
+
*
|
|
171
|
+
* `start` is the low end: left on a horizontal axis, the foot of a vertical one.
|
|
172
|
+
*/
|
|
173
|
+
const TITLE_AT = (along) => [
|
|
174
|
+
{ id: "start", label: along === "x" ? "left" : "bottom" },
|
|
175
|
+
{ id: "center", label: "center" },
|
|
176
|
+
{ id: "end", label: along === "x" ? "right" : "top" },
|
|
177
|
+
];
|
|
178
|
+
/**
|
|
179
|
+
* Axis parameters, behind a glyph.
|
|
180
|
+
*
|
|
181
|
+
* A fixed range makes two charts comparable. The tick interval is a step.
|
|
182
|
+
*
|
|
183
|
+
* The chrome rows below suit a dense chart.
|
|
184
|
+
*/
|
|
185
|
+
function AxisMenu({ title, along, axis, onChange, allow, }) {
|
|
186
|
+
const range = axis?.limits;
|
|
187
|
+
/* A bound typed ahead of its partner. The spec takes a range with both ends. */
|
|
188
|
+
const [pending, setPending] = useState(null);
|
|
189
|
+
const bounds = pending ?? range ?? [undefined, undefined];
|
|
190
|
+
const setRange = (at, value) => {
|
|
191
|
+
const next = [bounds[0], bounds[1]];
|
|
192
|
+
next[at] = value;
|
|
193
|
+
const [low, high] = next;
|
|
194
|
+
if (low != null && high != null) {
|
|
195
|
+
setPending(null);
|
|
196
|
+
return onChange({ ...axis, limits: [low, high] });
|
|
197
|
+
}
|
|
198
|
+
setPending(low == null && high == null ? null : next);
|
|
199
|
+
if (range)
|
|
200
|
+
onChange({ ...axis, limits: undefined });
|
|
201
|
+
};
|
|
202
|
+
// A count of what is no longer automatic. The glyph says whether anything was set.
|
|
203
|
+
const set = (axis?.transform && axis.transform !== "identity" ? 1 : 0) +
|
|
204
|
+
(range ? 1 : 0) +
|
|
205
|
+
(axis?.breakWidth != null ? 1 : 0) +
|
|
206
|
+
(axis?.format && axis.format !== "auto" ? 1 : 0) +
|
|
207
|
+
(axis?.title ? 1 : 0) +
|
|
208
|
+
(axis?.minorTicks === false ? 1 : 0) +
|
|
209
|
+
(axis?.linewidth != null ? 1 : 0) +
|
|
210
|
+
(axis?.tickLength != null ? 1 : 0) +
|
|
211
|
+
(axis?.tickSide === "in" ? 1 : 0) +
|
|
212
|
+
(axis?.tickAngle ? 1 : 0) +
|
|
213
|
+
(axis?.titleAlign ? 1 : 0) +
|
|
214
|
+
(axis?.fontSize != null ? 1 : 0);
|
|
215
|
+
return (_jsx(Popover, { label: "", icon: Settings2, title: `${title} settings`, count: set, width: 280, align: "right", children: () => (_jsxs("div", { className: "flex flex-col gap-2.5", children: [_jsx("span", { className: "text-xs px-0.5 font-medium", children: title }), _jsx(Opt, { icon: Text, label: "Title", children: _jsx(Line, { value: axis?.title ?? "", ariaLabel: `${title} title`, onChange: (text) => onChange({ ...axis, title: text || undefined }) }) }), _jsxs(Gated, { on: allow("axis-range"), children: [_jsxs(Opt, { icon: Maximize2, label: "Range", children: [_jsx(Stepper, { value: bounds[0], onChange: (v) => setRange(0, v) }), _jsx(Stepper, { value: bounds[1], onChange: (v) => setRange(1, v) })] }), _jsx(Opt, { icon: Ruler, label: "Every", children: _jsx(Stepper, { value: axis?.breakWidth, onChange: (breakWidth) => onChange({ ...axis, breakWidth }) }) }), _jsx(Opt, { icon: Hash, label: "Format", children: _jsx(Select, { ariaLabel: `${title} number format`, value: axis?.format ?? "auto", options: TICK_FORMATS, onChange: (format) => onChange({ ...axis, format: format }) }) }), axis?.format && axis.format !== "auto" && (_jsx(Opt, { icon: Hash, label: "Decimals", children: _jsx(Stepper, { value: axis.decimals ?? 2, onChange: (decimals) => onChange({ ...axis, decimals }) }) }))] }), _jsxs(Opt, { icon: Ruler, label: "Scale", children: [_jsx(Gated, { on: allow("log-scale"), children: _jsx(Pick, { ariaLabel: `${title} scale`, value: isLog(axis?.transform) ? "log" : "linear", options: [
|
|
216
|
+
{ id: "linear", label: "linear" },
|
|
217
|
+
{ id: "log", label: "log" },
|
|
218
|
+
], onChange: (kind) => onChange({ ...axis, transform: kind === "log" ? "log10" : "identity" }) }) }), _jsx(Gated, { on: allow("axis-chrome"), children: _jsx(Glyph, { icon: Ruler, on: axis?.minorTicks !== false, title: "Minor ticks between the labels", onClick: () => onChange({ ...axis, minorTicks: axis?.minorTicks === false }) }) })] }), _jsxs(Gated, { on: allow("axis-chrome"), children: [_jsx(Opt, { icon: Minus, label: "Rule", children: _jsx(Stepper, { value: axis?.linewidth, min: 0.5, max: 4, step: 0.5, suffix: "px", ariaLabel: `${title} rule width`, onChange: (linewidth) => onChange({ ...axis, linewidth }) }) }), _jsxs(Opt, { icon: ArrowDownToLine, label: "Ticks", children: [_jsx(Stepper, { value: axis?.tickLength, min: 0, max: 14, suffix: "px", ariaLabel: `${title} tick length`, onChange: (tickLength) => onChange({ ...axis, tickLength }) }), _jsx(Glyph, { icon: ArrowUpToLine, on: axis?.tickSide === "in", title: "Ticks inside the plot area", onClick: () => onChange({ ...axis, tickSide: axis?.tickSide === "in" ? undefined : "in" }) })] }), _jsx(Opt, { icon: RotateCw, label: "Turn", children: _jsx(Pick, { tight: true, ariaLabel: `${title} label turn`, value: String(axis?.tickAngle ?? 0), options: TURNS, onChange: (angle) => onChange({ ...axis, tickAngle: Number(angle) || undefined }) }) }), _jsx(Opt, { icon: AlignCenter, label: "Title at", children: _jsx(Pick, { tight: true, ariaLabel: `${title} title position`, value: axis?.titleAlign ?? "end", options: TITLE_AT(along), onChange: (titleAlign) => onChange({ ...axis, titleAlign: titleAlign }) }) }), _jsx(Opt, { icon: Type, label: "Size", children: _jsx(Stepper, { value: axis?.fontSize, min: 7, max: 20, suffix: "px", ariaLabel: `${title} type size`, onChange: (fontSize) => onChange({ ...axis, fontSize }) }) }), _jsx(Opt, { icon: Type, label: "Names", children: _jsx(Pick, { tight: true, ariaLabel: `${title} label ink`, value: axis?.ink ?? "muted", options: INKS, onChange: (ink) => onChange({ ...axis, ink: ink }) }) })] })] })) }));
|
|
219
|
+
}
|
|
220
|
+
const WHEN_OPTIONS = [
|
|
221
|
+
{ id: "top", label: "the top" },
|
|
222
|
+
{ id: "threshold", label: "those" },
|
|
223
|
+
{ id: "all", label: "all of them" },
|
|
224
|
+
];
|
|
225
|
+
const inlineSelect = "viz-control-field px-1";
|
|
226
|
+
/**
|
|
227
|
+
* The label rule as one sentence.
|
|
228
|
+
*
|
|
229
|
+
* "Name the top 8 by Y, highest" is something a reader checks at a glance.
|
|
230
|
+
*/
|
|
231
|
+
function LabelRule({ rule, onChange }) {
|
|
232
|
+
const axisOptions = [
|
|
233
|
+
{ id: "x", label: "X" },
|
|
234
|
+
{ id: "y", label: "Y" },
|
|
235
|
+
];
|
|
236
|
+
return (_jsxs("div", { className: "flex flex-wrap items-center gap-1 rounded-md border border-border bg-background p-1.5", children: [_jsx("span", { className: "flex shrink-0 items-center text-muted-foreground", children: _jsx(GripVertical, { size: 11 }) }), _jsx("span", { className: "text-xs shrink-0 text-muted-foreground", children: "Name" }), _jsx("select", { value: rule.kind, "aria-label": "Which points", onChange: (event) => {
|
|
237
|
+
const kind = event.target.value;
|
|
238
|
+
onChange(kind === "top"
|
|
239
|
+
? { kind: "top", count: 8, on: "y", end: "high" }
|
|
240
|
+
: kind === "threshold"
|
|
241
|
+
? { kind: "threshold", on: "y", op: "above", value: 0 }
|
|
242
|
+
: { kind: "all" });
|
|
243
|
+
}, className: inlineSelect, children: WHEN_OPTIONS.map((option) => (_jsx("option", { value: option.id, children: option.label }, option.id))) }), rule.kind === "top" && (_jsxs(_Fragment, { children: [_jsx(Stepper, { value: rule.count, width: 44, onChange: (count) => onChange({ ...rule, count: count ?? 8 }) }), _jsx("span", { className: "text-xs shrink-0 text-muted-foreground", children: "by" }), _jsx("select", { value: rule.on, "aria-label": "Ranked on", onChange: (event) => onChange({ ...rule, on: event.target.value }), className: inlineSelect, children: axisOptions.map((option) => (_jsx("option", { value: option.id, children: option.label }, option.id))) }), _jsxs("select", { value: rule.end, "aria-label": "Which end", onChange: (event) => onChange({ ...rule, end: event.target.value }), className: inlineSelect, children: [_jsx("option", { value: "high", children: "highest" }), _jsx("option", { value: "low", children: "lowest" })] })] })), rule.kind === "threshold" && (_jsxs(_Fragment, { children: [_jsx("span", { className: "text-xs shrink-0 text-muted-foreground", children: "whose" }), _jsx("select", { value: rule.on, "aria-label": "Measured on", onChange: (event) => onChange({ ...rule, on: event.target.value }), className: inlineSelect, children: axisOptions.map((option) => (_jsx("option", { value: option.id, children: option.label }, option.id))) }), _jsxs("select", { value: rule.op, "aria-label": "Comparison", onChange: (event) => onChange({ ...rule, op: event.target.value }), className: inlineSelect, children: [_jsx("option", { value: "above", children: "is above" }), _jsx("option", { value: "below", children: "is below" })] }), _jsx(Stepper, { value: rule.value, width: 64, onChange: (value) => onChange({ ...rule, value: value ?? 0 }) })] })), rule.kind === "all" && _jsxs("span", { className: "text-2xs text-muted-foreground", children: ["capped at ", LABEL_CAP] })] }));
|
|
244
|
+
}
|
|
245
|
+
const SHAPES = [
|
|
246
|
+
{ id: "circle", label: "circle" },
|
|
247
|
+
{ id: "square", label: "square" },
|
|
248
|
+
{ id: "triangle", label: "triangle" },
|
|
249
|
+
{ id: "diamond", label: "diamond" },
|
|
250
|
+
];
|
|
251
|
+
/**
|
|
252
|
+
* Whether a glyph carries ink or an outline.
|
|
253
|
+
*
|
|
254
|
+
* Held apart from the shape. Four glyphs cover eight geoms, and a series keeps its shape when opened up.
|
|
255
|
+
*/
|
|
256
|
+
const FILLS = [
|
|
257
|
+
{ id: "filled", label: "filled" },
|
|
258
|
+
{ id: "hollow", label: "hollow" },
|
|
259
|
+
];
|
|
260
|
+
/**
|
|
261
|
+
* Geoms an author sets a width on, and what each draws at unset.
|
|
262
|
+
*
|
|
263
|
+
* A bar fills its slot to forty pixels. A box is thick and short.
|
|
264
|
+
*/
|
|
265
|
+
const DEFAULT_THICKNESS = {
|
|
266
|
+
bar: 40,
|
|
267
|
+
histogram: 40,
|
|
268
|
+
boxplot: 13,
|
|
269
|
+
violin: 68,
|
|
270
|
+
};
|
|
271
|
+
const FIT_MODELS = [
|
|
272
|
+
{ id: "4pl", label: "Four-parameter logistic" },
|
|
273
|
+
{ id: "5pl", label: "Five-parameter logistic" },
|
|
274
|
+
];
|
|
275
|
+
/** Where a new fit starts. A 95% band is the convention a reader expects unless told otherwise. */
|
|
276
|
+
const DEFAULT_FIT = { model: "4pl", level: 0.95, band: true };
|
|
277
|
+
/**
|
|
278
|
+
* How sure a fit claims to be.
|
|
279
|
+
*
|
|
280
|
+
* The layer's group and color decide one solve or ten thousand.
|
|
281
|
+
*/
|
|
282
|
+
function FitOptions({ fit, onChange }) {
|
|
283
|
+
return (_jsxs("div", { className: "flex flex-col gap-2.5 rounded-md border border-border bg-background p-2", children: [_jsx(Opt, { icon: Sigma, label: "Band", children: _jsx(Pick, { ariaLabel: "Confidence band", value: fit.band ? "on" : "off", options: [
|
|
284
|
+
{ id: "on", label: "show" },
|
|
285
|
+
{ id: "off", label: "hide" },
|
|
286
|
+
], onChange: (state) => onChange({ ...fit, band: state === "on" }) }) }), fit.band && (_jsx(Opt, { icon: Sigma, label: "Level", children: _jsx(Select, { ariaLabel: "Confidence level", value: String(fit.level), options: [
|
|
287
|
+
{ id: "0.8", label: "80%" },
|
|
288
|
+
{ id: "0.9", label: "90%" },
|
|
289
|
+
{ id: "0.95", label: "95%" },
|
|
290
|
+
{ id: "0.99", label: "99%" },
|
|
291
|
+
], onChange: (level) => onChange({ ...fit, level: Number(level) }) }) }))] }));
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* What is written on the chart.
|
|
295
|
+
*
|
|
296
|
+
* Seeded annotations arrive as suggestions. A measure with a direction offers its axis-end captions.
|
|
297
|
+
*
|
|
298
|
+
* Only the kinds `Frame` draws are offered.
|
|
299
|
+
*/
|
|
300
|
+
function Annotations({ spec, bound, limit, onChange, }) {
|
|
301
|
+
const held = spec.annotations ?? [];
|
|
302
|
+
const full = limit != null && held.length >= limit;
|
|
303
|
+
const offered = full ? [] : suggest(bound, held);
|
|
304
|
+
const set = (annotations) => onChange({ ...spec, annotations });
|
|
305
|
+
return (_jsxs(_Fragment, { children: [held.map((annotation, index) => (_jsxs("div", { className: "flex flex-col gap-2 rounded-md border border-border p-2", children: [_jsxs("div", { className: "flex items-center gap-1", children: [_jsx(MessageSquare, { size: 11, className: "shrink-0 text-muted-foreground" }), _jsx("span", { className: "text-2xs flex-1 uppercase tracking-wide text-muted-foreground", children: annotation.kind === "axis-end" ? `${annotation.axis} ${annotation.end}` : annotation.kind }), _jsx("button", { type: "button", "aria-label": `Remove ${describeAnnotation(annotation)}`, onClick: () => set(held.filter((_, at) => at !== index)), className: "shrink-0 text-muted-foreground hover:text-foreground", children: _jsx(X, { size: 11 }) })] }), _jsx(Line, { value: annotation.text, ariaLabel: `${annotation.kind} text`, onChange: (text) => set(held.map((current, at) => (at === index ? { ...current, text } : current))) })] }, index))), offered.map((annotation, index) => (_jsxs("button", { type: "button", onClick: () => set([...held, annotation]), className: "text-xs flex items-center gap-1.5 rounded-md border border-dashed border-border px-1.5 py-1 text-left text-muted-foreground hover:bg-accent hover:text-foreground", children: [_jsx(Plus, { size: 11, className: "shrink-0" }), _jsx("span", { className: "min-w-0 flex-1 truncate", children: describeAnnotation(annotation) }), _jsx("span", { className: "text-2xs shrink-0", children: "suggested" })] }, `offer${index}`))), _jsxs("button", { type: "button", disabled: full, title: full ? `${limit} annotations allowed` : undefined, onClick: () =>
|
|
306
|
+
// Anchored at the middle of the data. A new note lands where the author can see and drag it.
|
|
307
|
+
set([...held, { kind: "note", text: "New note", at: { x: 0, y: 0 } }]), className: "text-sm viz-h-control flex items-center justify-center gap-1 rounded-md border border-dashed border-border text-muted-foreground hover:bg-accent hover:text-foreground", children: [_jsx(Plus, { size: 11 }), "Add note"] })] }));
|
|
308
|
+
}
|
|
309
|
+
export function PlotPanel({ spec, fields, sources, onChange, palettes, profile = OPEN_PROFILE, shape, findings, }) {
|
|
310
|
+
const allow = (group) => allowsSetting(profile, group);
|
|
311
|
+
const reported = bySection(findings ?? critique(spec));
|
|
312
|
+
const found = (section) => reported.get(section) ?? [];
|
|
313
|
+
const measures = fields.filter((field) => field.numeric);
|
|
314
|
+
const categories = fields.filter((field) => !field.numeric);
|
|
315
|
+
/* A kind the profile withholds stays visible and grayed, with the reason on it. */
|
|
316
|
+
const kinds = plotKinds(fields).map((option) => option.available && !allowsKind(profile, option.kind)
|
|
317
|
+
? { ...option, available: false, reason: "Not in your profile" }
|
|
318
|
+
: option);
|
|
319
|
+
const sourceKey = (option) => `${option.source.kind}:${option.source.id}`;
|
|
320
|
+
const stored = spec;
|
|
321
|
+
const activeSource = stored.source ? sourceKey({ source: stored.source, label: "" }) : "";
|
|
322
|
+
/* Whether a kind's row binds an aesthetic at all, whatever the profile says. */
|
|
323
|
+
const takes = (kind, aesthetic) => allowedAesthetics(OPEN_PROFILE, kind).includes(aesthetic);
|
|
324
|
+
/* A layer's aes carried to another kind. The paint moves between color and fill, and an aesthetic the kind reads nowhere drops. */
|
|
325
|
+
const carried = (kind, aes) => {
|
|
326
|
+
const moved = { ...aes };
|
|
327
|
+
if (moved.color !== undefined && !takes(kind, "color") && takes(kind, "fill"))
|
|
328
|
+
moved.fill ??= moved.color;
|
|
329
|
+
if (moved.fill !== undefined && !takes(kind, "fill") && takes(kind, "color"))
|
|
330
|
+
moved.color ??= moved.fill;
|
|
331
|
+
return Object.fromEntries(Object.entries(moved).filter(([aesthetic]) => takes(kind, aesthetic)));
|
|
332
|
+
};
|
|
333
|
+
/* The layers reading the chart's own x. A rule places itself, and a layer with its own rows reads its own columns. */
|
|
334
|
+
const onShelf = spec.layers.filter((layer) => !layer.data && takes(layer.kind, "x"));
|
|
335
|
+
const sharedX = onShelf.map((layer) => layer.aes.x).find((id) => id != null);
|
|
336
|
+
/* X is one shelf. Binding it writes through each layer on it. */
|
|
337
|
+
const bindX = (id) => {
|
|
338
|
+
let next = spec;
|
|
339
|
+
for (const layer of onShelf)
|
|
340
|
+
next = bindAes(next, { layerId: layer.id, aesthetic: "x", field: id });
|
|
341
|
+
onChange(next);
|
|
342
|
+
};
|
|
343
|
+
/* A new layer takes the first kind the profile allows, and none past the profile's cap. */
|
|
344
|
+
const addable = kinds.find((option) => allowsKind(profile, option.kind))?.kind;
|
|
345
|
+
const maxLayers = profile.limits?.layers;
|
|
346
|
+
const layersFull = maxLayers != null && spec.layers.length >= maxLayers;
|
|
347
|
+
const tooltip = spec.tooltip ?? [];
|
|
348
|
+
const unused = fields.filter((field) => !tooltip.includes(field.id));
|
|
349
|
+
return (_jsxs("div", { className: "flex flex-col px-3", children: [_jsxs(Section, { title: "Title", findings: found("Title"), children: [_jsx(Opt, { icon: Heading, label: "Title", children: _jsx(Line, { value: spec.headline ?? "", ariaLabel: "Title", onChange: (headline) => onChange({ ...spec, headline }) }) }), _jsx(Opt, { icon: Text, label: "Subtitle", children: _jsx(Line, { value: spec.subtitle ?? "", ariaLabel: "Subtitle", onChange: (subtitle) => onChange({ ...spec, subtitle }) }) })] }), _jsxs(Section, { title: "Data", findings: found("Data"), children: [sources && (_jsx(Opt, { icon: Table2, label: "Table", children: _jsx(Select, { ariaLabel: "Table", value: sources.some((option) => sourceKey(option) === activeSource) ? activeSource : "", placeholder: sources.length === 0 ? "No tables" : "Pick a table", options: sources.map((option) => ({ id: sourceKey(option), label: option.label })), onChange: (key) => {
|
|
350
|
+
const picked = sources.find((option) => sourceKey(option) === key);
|
|
351
|
+
if (picked)
|
|
352
|
+
onChange(setSource(spec, picked.source));
|
|
353
|
+
} }) })), shape] }), _jsxs(Section, { title: "Axes", findings: found("Axes"), children: [_jsxs(Opt, { icon: MoveHorizontal, label: "X", children: [_jsx(Select, { ariaLabel: "X field", placeholder: "Pick a field", value: sharedX ?? "", options: fieldOptions(fields), onChange: (id) => bindX(id || undefined) }), _jsx(AxisMenu, { title: "X axis", along: "x", allow: allow, axis: spec.scales?.x, onChange: (x) => onChange({ ...spec, scales: { ...spec.scales, x } }) })] }), _jsx(Gated, { on: allow("facets"), children: _jsx(Opt, { icon: LayoutGrid, label: "Facet", children: _jsx(Select, { ariaLabel: "Facet by", placeholder: "Single panel", value: spec.facet?.by ?? "", options: fieldOptions(categories), onChange: (id) => onChange({ ...spec, facet: id ? { ...spec.facet, by: id } : undefined }) }) }) }), _jsxs(Opt, { icon: Gauge, label: "Y axis", children: [_jsx("span", { className: "text-2xs min-w-0 flex-1 truncate text-muted-foreground", children: "In series panel" }), _jsx(AxisMenu, { title: "Y axis", along: "y", allow: allow, axis: spec.scales?.y, onChange: (y) => onChange({ ...spec, scales: { ...spec.scales, y } }) })] }), usesY2(spec) && allow("second-axis") && (_jsxs(Opt, { icon: Gauge, label: "Right", children: [_jsx("span", { className: "text-2xs min-w-0 flex-1 truncate text-muted-foreground", children: "Series set to the right" }), _jsx(AxisMenu, { title: "Right axis", along: "y", allow: allow, axis: spec.scales?.y2, onChange: (y2) => onChange({ ...spec, scales: { ...spec.scales, y2 } }) })] }))] }), _jsxs(Section, { title: "Layers", findings: found("Layers"), children: [spec.layers.map((series, index) => {
|
|
354
|
+
const style = series.style ?? {};
|
|
355
|
+
const color = geomColor(style, series.kind) ?? palettes.categorical(index);
|
|
356
|
+
const hidden = series.visible === false;
|
|
357
|
+
const isLine = series.kind === "line";
|
|
358
|
+
const isFlow = series.kind === "sankey" || series.kind === "chord";
|
|
359
|
+
const isParallel = series.kind === "parcoords";
|
|
360
|
+
const isGrid = series.kind === "heatmap";
|
|
361
|
+
const isPoints = series.kind === "point";
|
|
362
|
+
const isBanded = series.kind in DEFAULT_THICKNESS;
|
|
363
|
+
const bound = series.aes.dimensions;
|
|
364
|
+
const spans = Array.isArray(bound) ? bound : bound ? [bound] : [];
|
|
365
|
+
/* Required channels stay open whatever the profile says. `allowedAesthetics` holds that rule. */
|
|
366
|
+
const open = allowedAesthetics(profile, series.kind);
|
|
367
|
+
const channelOpen = (channel) => open.includes(channel);
|
|
368
|
+
/* What the kind declares. A channel outside it draws no row, and the gate is for what a profile withholds. */
|
|
369
|
+
const painting = paintAesthetic(series);
|
|
370
|
+
const takesColor = takes(series.kind, painting);
|
|
371
|
+
return (_jsxs("div", { className: `flex flex-col gap-2.5 rounded-md border border-border p-2 ${hidden ? "opacity-50" : ""}`, children: [_jsxs("div", { className: "flex items-center gap-1", children: [_jsx("span", { className: "size-2.5 shrink-0 rounded-full", style: { background: color }, "aria-hidden": true }), _jsx("span", { className: "text-xs flex-1 truncate font-medium", children: series.name ?? `Series ${index + 1}` }), _jsx(Glyph, { icon: hidden ? EyeOff : Eye, on: !hidden, title: hidden ? "Show this series" : "Hide this series", onClick: () => onChange(updateLayer(spec, series.id, { visible: hidden })) }), _jsx("button", { type: "button", "aria-label": "Remove series", title: spec.layers.length <= 1 ? "A plot keeps one series" : "Remove series", disabled: spec.layers.length <= 1, onClick: () => onChange(removeLayer(spec, series.id)), className: "shrink-0 px-0.5 text-muted-foreground hover:text-foreground", children: _jsx(X, { size: 11 }) })] }), _jsx(Opt, { icon: ChartScatter, label: "Type", children: _jsx("select", { "aria-label": "Chart type", value: series.kind, onChange: (event) => {
|
|
372
|
+
const kind = event.target.value;
|
|
373
|
+
onChange(updateLayer(spec, series.id, { kind, aes: carried(kind, series.aes) }));
|
|
374
|
+
}, className: "viz-control-field min-w-0 flex-1", children: kinds.map((option) => (_jsxs("option", { value: option.kind, disabled: !option.available, title: option.reason, children: [option.label, option.reason ? ` — ${option.reason}` : ""] }, option.kind))) }) }), isFlow ? (_jsxs(_Fragment, { children: [_jsx(Opt, { icon: MoveHorizontal, label: "From", children: _jsx(Select, { ariaLabel: "Source field", placeholder: "Pick a field", value: typeof series.aes.source === "string" ? series.aes.source : "", options: fieldOptions(categories), onChange: (id) => onChange(bindAes(spec, { layerId: series.id, aesthetic: "source", field: id || undefined })) }) }), _jsx(Opt, { icon: MoveHorizontal, label: "To", children: _jsx(Select, { ariaLabel: "Target field", placeholder: "Pick a field", value: typeof series.aes.target === "string" ? series.aes.target : "", options: fieldOptions(categories), onChange: (id) => onChange(bindAes(spec, { layerId: series.id, aesthetic: "target", field: id || undefined })) }) }), _jsx(Gated, { on: channelOpen("value"), children: _jsx(Opt, { icon: Gauge, label: "Width", children: _jsx(Select, { ariaLabel: "Value field", placeholder: "Count rows", value: typeof series.aes.value === "string" ? series.aes.value : "", options: fieldOptions(measures), onChange: (id) => onChange(bindAes(spec, { layerId: series.id, aesthetic: "value", field: id || undefined })) }) }) })] })) : isParallel ? (
|
|
375
|
+
/* Several measures at once. The trade-off between them is the whole chart. */
|
|
376
|
+
_jsxs(_Fragment, { children: [spans.map((id) => (_jsxs(Opt, { icon: Gauge, label: "Measure", children: [_jsx("span", { className: "text-sm min-w-0 flex-1 truncate", children: fields.find((field) => field.id === id)?.label ?? id }), _jsx("button", { type: "button", "aria-label": `Remove ${id} from the axes`, onClick: () => onChange(bindAes(spec, {
|
|
377
|
+
layerId: series.id,
|
|
378
|
+
aesthetic: "dimensions",
|
|
379
|
+
field: spans.filter((held) => held !== id),
|
|
380
|
+
})), className: "shrink-0 px-0.5 text-muted-foreground hover:text-foreground", children: _jsx(X, { size: 11 }) })] }, id))), _jsx(Opt, { icon: Plus, label: "Add", children: _jsx(Select, { ariaLabel: "Add a measure", value: "", placeholder: spans.length < 2 ? "Pick two or more" : "Pick a measure", options: fieldOptions(measures.filter((field) => !spans.includes(field.id))), onChange: (id) => id &&
|
|
381
|
+
onChange(bindAes(spec, { layerId: series.id, aesthetic: "dimensions", field: [...spans, id] })) }) })] })) : isGrid ? (
|
|
382
|
+
/* Three grids on one type. What the reader binds says which. */
|
|
383
|
+
_jsxs(_Fragment, { children: [spans.map((id) => (_jsxs(Opt, { icon: Gauge, label: "Cut", children: [_jsx("span", { className: "text-sm min-w-0 flex-1 truncate", children: fields.find((field) => field.id === id)?.label ?? id }), _jsx("button", { type: "button", "aria-label": `Remove ${id} from the cuts`, onClick: () => onChange(bindAes(spec, {
|
|
384
|
+
layerId: series.id,
|
|
385
|
+
aesthetic: "dimensions",
|
|
386
|
+
field: spans.filter((held) => held !== id),
|
|
387
|
+
})), className: "shrink-0 px-0.5 text-muted-foreground hover:text-foreground", children: _jsx(X, { size: 11 }) })] }, id))), _jsx(Gated, { on: channelOpen("dimensions"), children: _jsx(Opt, { icon: Plus, label: "Add cut", children: _jsx(Select, { ariaLabel: "Add a measure to compare against its cut", placeholder: "Pick a measure with a cut", value: "", options: fieldOptions(measures.filter((field) => field.target != null && !spans.includes(field.id))), onChange: (id) => id &&
|
|
388
|
+
onChange(bindAes(spec, { layerId: series.id, aesthetic: "dimensions", field: [...spans, id] })) }) }) }), spans.length === 0 && (_jsxs(_Fragment, { children: [_jsx(Opt, { icon: Gauge, label: "Y", children: _jsx(Select, { ariaLabel: "Y field", placeholder: "Pick a field", value: typeof series.aes.y === "string" ? series.aes.y : "", options: fieldOptions(categories), onChange: (id) => onChange(bindAes(spec, { layerId: series.id, aesthetic: "y", field: id || undefined })) }) }), _jsx(Gated, { on: channelOpen("z") || channelOpen("fill"), children: _jsx(Opt, { icon: PaletteIcon, label: "Cell", children: _jsx(Select, { ariaLabel: "Cell value", placeholder: "Count rows", value: paintColumn(series) ?? (typeof series.aes.z === "string" ? series.aes.z : ""), options: fieldOptions([
|
|
389
|
+
...(channelOpen("z") ? measures : []),
|
|
390
|
+
...(channelOpen("fill") ? categories : []),
|
|
391
|
+
]), onChange: (id) => {
|
|
392
|
+
/* A measure colors a cell by value and a text column by category. A cell takes one. */
|
|
393
|
+
const text = categories.some((field) => field.id === id);
|
|
394
|
+
const cleared = bindAes(spec, { layerId: series.id, aesthetic: text ? "z" : "fill" });
|
|
395
|
+
onChange(bindAes(cleared, {
|
|
396
|
+
layerId: series.id,
|
|
397
|
+
aesthetic: text ? "fill" : "z",
|
|
398
|
+
field: id || undefined,
|
|
399
|
+
}));
|
|
400
|
+
} }) }) })] }))] })) : (takes(series.kind, "y") && (_jsx(Gated, { on: channelOpen("y"), children: _jsx(Opt, { icon: Gauge, label: "Y", children: _jsx(Select, { ariaLabel: "Y field", placeholder: "Pick a field", value: typeof series.aes.y === "string" ? series.aes.y : "", options: fieldOptions(measures), onChange: (id) => onChange(bindAes(spec, { layerId: series.id, aesthetic: "y", field: id || undefined })) }) }) }))), takesColor && !isGrid && (_jsx(Gated, { on: channelOpen(painting), children: _jsx(Opt, { icon: PaletteIcon, label: "Color", children: _jsx(Select, { ariaLabel: "Color by", placeholder: "Single color", value: paintColumn(series) ?? "", options: fieldOptions(fields), onChange: (id) => onChange(bindAes(spec, { layerId: series.id, aesthetic: painting, field: id || undefined })) }) }) })), drawsOneColor(series) && (_jsx(Gated, { on: allow("geom-style"), children: _jsx(ColorStrip, { value: color, palettes: palettes, onChange: (next) => onChange(updateLayer(spec, series.id, { style: paintedWith(style, series.kind, next) })) }) })), takes(series.kind, "group") && (_jsx(Gated, { on: channelOpen("group"), children: _jsx(Opt, { icon: Split, label: "Group", children: _jsx(Select, { ariaLabel: "Group by", placeholder: "Single trace", value: typeof series.aes.group === "string" ? series.aes.group : "", options: fieldOptions(categories), onChange: (id) => onChange(bindAes(spec, { layerId: series.id, aesthetic: "group", field: id || undefined })) }) }) })), _jsx(Gated, { on: allow("second-axis"), children: _jsx(Opt, { icon: ArrowLeftRight, label: "Scale", children: _jsx(Pick, { ariaLabel: "Vertical scale", value: series.axis ?? "y", options: [
|
|
401
|
+
{ id: "y", label: "left" },
|
|
402
|
+
{ id: "y2", label: "right" },
|
|
403
|
+
], onChange: (axis) => onChange(updateLayer(spec, series.id, { axis })) }) }) }), _jsxs(Gated, { on: allow("geom-style"), children: [_jsxs(Opt, { icon: Circle, label: isLine ? "Width" : "Size", children: [_jsx("input", { type: "range", "aria-label": isLine ? "Line width" : "Point size", value: isLine ? (style.linewidth ?? 1.5) : (style.size ?? 4), step: 0.5, min: isLine ? 0.5 : 1, max: isLine ? 6 : 12, onChange: (event) => onChange(updateLayer(spec, series.id, {
|
|
404
|
+
style: isLine
|
|
405
|
+
? { ...style, linewidth: Number(event.target.value) }
|
|
406
|
+
: { ...style, size: Number(event.target.value) },
|
|
407
|
+
})), className: "min-w-0 flex-1 accent-primary" }), _jsx("span", { className: "text-2xs viz-num w-7 shrink-0 text-right text-muted-foreground", children: isLine ? (style.linewidth ?? 1.5) : (style.size ?? 4) })] }), _jsxs(Opt, { icon: Blend, label: "Opacity", children: [_jsx("input", { type: "range", "aria-label": "Opacity", value: Math.round((style.alpha ?? 0.85) * 100), min: 5, max: 100, onChange: (event) => onChange(updateLayer(spec, series.id, { style: { ...style, alpha: Number(event.target.value) / 100 } })), className: "min-w-0 flex-1 accent-primary" }), _jsx("span", { className: "text-2xs viz-num w-7 shrink-0 text-right text-muted-foreground", children: Math.round((style.alpha ?? 0.85) * 100) })] }), isGrid && (_jsxs(_Fragment, { children: [_jsx(Opt, { icon: Blend, label: "Radius", children: _jsx(Stepper, { value: style.cornerRadius, min: 0, max: 12, suffix: "px", ariaLabel: "Cell corner radius", onChange: (cornerRadius) => onChange(updateLayer(spec, series.id, { style: { ...style, cornerRadius } })) }) }), _jsx(Opt, { icon: Blend, label: "Gap", children: _jsx(Stepper, { value: style.cellGap, min: 0, max: 12, suffix: "px", ariaLabel: "Gap between cells", onChange: (cellGap) => onChange(updateLayer(spec, series.id, { style: { ...style, cellGap } })) }) })] })), isPoints && (_jsx(Opt, { icon: Shapes, label: "Shape", children: _jsx(Select, { ariaLabel: "Point shape", value: style.shape ?? "circle", options: SHAPES, onChange: (shape) => onChange(updateLayer(spec, series.id, { style: { ...style, shape: shape } })) }) })), isPoints && (_jsx(Opt, { icon: Circle, label: "Fill", children: _jsx(Select, { ariaLabel: "Point fill", value: style.hollow ? "hollow" : "filled", options: FILLS, onChange: (fill) => onChange(updateLayer(spec, series.id, { style: { ...style, hollow: fill === "hollow" } })) }) })), isBanded && (_jsxs(Opt, { icon: Columns3, label: "Thickness", children: [_jsx("input", { type: "range", "aria-label": "Thickness", value: style.thickness ?? DEFAULT_THICKNESS[series.kind] ?? 40, min: 2, max: 80, onChange: (event) => onChange(updateLayer(spec, series.id, { style: { ...style, thickness: Number(event.target.value) } })), className: "min-w-0 flex-1 accent-primary" }), _jsx("span", { className: "text-2xs viz-num w-7 shrink-0 text-right text-muted-foreground", children: style.thickness ?? DEFAULT_THICKNESS[series.kind] ?? 40 })] }))] }), _jsxs(Gated, { on: allow("labels"), children: [_jsx(Opt, { icon: Tag, label: "Label", children: _jsx(Select, { ariaLabel: "Label field", placeholder: "None", value: series.directLabels?.field ?? "", options: fieldOptions(fields), onChange: (field) => onChange(updateLayer(spec, series.id, {
|
|
408
|
+
directLabels: field
|
|
409
|
+
? {
|
|
410
|
+
field,
|
|
411
|
+
// Selective by default: naming all of them is a gray rectangle.
|
|
412
|
+
when: series.directLabels?.when ?? {
|
|
413
|
+
kind: "top",
|
|
414
|
+
count: 8,
|
|
415
|
+
on: "y",
|
|
416
|
+
end: "high",
|
|
417
|
+
},
|
|
418
|
+
}
|
|
419
|
+
: undefined,
|
|
420
|
+
})) }) }), series.directLabels && (_jsx(LabelRule, { rule: series.directLabels.when, onChange: (when) => onChange(updateLayer(spec, series.id, { directLabels: { ...series.directLabels, when } })) }))] }), _jsxs(Gated, { on: allow("fits"), children: [_jsx(Opt, { icon: Spline, label: "Fit", children: _jsx(Select, { ariaLabel: "Fit model", placeholder: "None", value: series.fit?.model ?? "", options: FIT_MODELS, onChange: (model) => onChange(updateLayer(spec, series.id, {
|
|
421
|
+
fit: model ? { ...(series.fit ?? DEFAULT_FIT), model: model } : undefined,
|
|
422
|
+
})) }) }), series.fit && (_jsx(FitOptions, { fit: series.fit, onChange: (fit) => onChange(updateLayer(spec, series.id, { fit })) }))] })] }, series.id));
|
|
423
|
+
}), _jsxs("button", { type: "button", disabled: !addable || layersFull, title: layersFull ? `${maxLayers} layers allowed` : addable ? undefined : "No kind in your profile", onClick: () => addable && onChange(addLayer(spec, addable)), className: "text-sm viz-h-control flex items-center justify-center gap-1 rounded-md border border-dashed border-border text-muted-foreground hover:bg-accent hover:text-foreground", children: [_jsx(Plus, { size: 11 }), "Add layer"] })] }), _jsx(Section, { title: "Size", open: false, findings: found("Size"), children: _jsxs(Gated, { on: allow("figure-size"), children: [_jsx(Opt, { icon: MoveHorizontal, label: "Width", children: _jsx(Stepper, { value: spec.width, min: FIGURE_MIN, max: FIGURE_MAX, step: 20, suffix: "px", ariaLabel: "Panel width", onChange: (width) => onChange({ ...spec, width }) }) }), _jsx(Opt, { icon: MoveVertical, label: "Height", children: _jsx(Stepper, { value: spec.height, min: FIGURE_MIN, max: FIGURE_MAX, step: 20, suffix: "px", ariaLabel: "Panel height", onChange: (height) => onChange({ ...spec, height }) }) }), _jsx(Opt, { icon: Ratio, label: "Aspect", children: _jsx(Select, { ariaLabel: "Panel aspect", placeholder: "None", value: ratioOf(spec.aspect), options: RATIOS.map((option) => ({ id: option.id, label: option.label })), onChange: (id) => onChange({ ...spec, aspect: RATIOS.find((option) => option.id === id)?.value }) }) })] }) }), _jsxs(Section, { title: "Hover", open: false, findings: found("Hover"), children: [tooltip.map((id) => (_jsxs(Opt, { icon: Tag, label: "Field", children: [_jsx("span", { className: "text-sm min-w-0 flex-1 truncate", children: fields.find((field) => field.id === id)?.label ?? id }), _jsx("button", { type: "button", "aria-label": `Remove ${id} from the readout`, onClick: () => onChange({
|
|
424
|
+
...spec,
|
|
425
|
+
tooltip: tooltip.filter((held) => held !== id),
|
|
426
|
+
}), className: "shrink-0 px-0.5 text-muted-foreground hover:text-foreground", children: _jsx(X, { size: 11 }) })] }, id))), _jsx(Opt, { icon: MousePointerClick, label: "Add", children: _jsx(Select, { ariaLabel: "Add a field to the readout", value: "", placeholder: unused.length === 0 ? "Every field is shown" : "Pick a field", options: fieldOptions(unused), onChange: (id) => id && onChange({ ...spec, tooltip: [...tooltip, id] }) }) })] }), _jsx(Section, { title: "Annotations", open: false, findings: found("Annotations"), children: _jsx(Gated, { on: allow("annotations"), children: _jsx(Annotations, { spec: spec, limit: profile.limits?.annotations, bound: [
|
|
427
|
+
{ axis: "x", field: fields.find((field) => field.id === sharedX) },
|
|
428
|
+
{
|
|
429
|
+
axis: "y",
|
|
430
|
+
field: fields.find((field) => field.id === spec.layers.find((series) => series.aes.y)?.aes.y),
|
|
431
|
+
},
|
|
432
|
+
], onChange: onChange }) }) })] }));
|
|
433
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The panel's button and the popover under it.
|
|
3
|
+
*
|
|
4
|
+
* The kit owns the portal and returns focus on close.
|
|
5
|
+
*
|
|
6
|
+
* Imported from the kit's `ui/popover` subpath. Its index re-exports monaco and shiki.
|
|
7
|
+
*/
|
|
8
|
+
import { type ReactNode } from "react";
|
|
9
|
+
export declare function Popover({ label, icon: Icon, children, align, width,
|
|
10
|
+
/** Shown as a badge when the control has something in force. */
|
|
11
|
+
count, disabled, title,
|
|
12
|
+
/**
|
|
13
|
+
* The glyph alone, drawn as a ghost. The border appears on hover.
|
|
14
|
+
*
|
|
15
|
+
* The glyph takes the primary ink and the count sits beside it.
|
|
16
|
+
*/
|
|
17
|
+
compact,
|
|
18
|
+
/**
|
|
19
|
+
* Glyph size, for a host denser than a toolbar.
|
|
20
|
+
*
|
|
21
|
+
* The rail draws its destinations at 19. A lid at 11 reads as a smaller control.
|
|
22
|
+
*/
|
|
23
|
+
glyph, }: {
|
|
24
|
+
label: string;
|
|
25
|
+
icon?: React.ComponentType<{
|
|
26
|
+
size?: number | string;
|
|
27
|
+
className?: string;
|
|
28
|
+
}>;
|
|
29
|
+
children: (close: () => void) => ReactNode;
|
|
30
|
+
align?: "left" | "right";
|
|
31
|
+
width?: number;
|
|
32
|
+
count?: number;
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
title?: string;
|
|
35
|
+
compact?: boolean;
|
|
36
|
+
glyph?: number;
|
|
37
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The panel's button and the popover under it.
|
|
4
|
+
*
|
|
5
|
+
* The kit owns the portal and returns focus on close.
|
|
6
|
+
*
|
|
7
|
+
* Imported from the kit's `ui/popover` subpath. Its index re-exports monaco and shiki.
|
|
8
|
+
*/
|
|
9
|
+
import { Popover as KitPopover, PopoverContent, PopoverTrigger, } from "@tetrascience-npm/tetrascience-react-ui/ui/popover";
|
|
10
|
+
import { ChevronDown } from "lucide-react";
|
|
11
|
+
import { useState } from "react";
|
|
12
|
+
const GAP = 4;
|
|
13
|
+
export function Popover({ label, icon: Icon, children, align = "left", width = 264,
|
|
14
|
+
/** Shown as a badge when the control has something in force. */
|
|
15
|
+
count, disabled, title,
|
|
16
|
+
/**
|
|
17
|
+
* The glyph alone, drawn as a ghost. The border appears on hover.
|
|
18
|
+
*
|
|
19
|
+
* The glyph takes the primary ink and the count sits beside it.
|
|
20
|
+
*/
|
|
21
|
+
compact,
|
|
22
|
+
/**
|
|
23
|
+
* Glyph size, for a host denser than a toolbar.
|
|
24
|
+
*
|
|
25
|
+
* The rail draws its destinations at 19. A lid at 11 reads as a smaller control.
|
|
26
|
+
*/
|
|
27
|
+
glyph = 11, }) {
|
|
28
|
+
const [open, setOpen] = useState(false);
|
|
29
|
+
return (_jsxs(KitPopover, { open: open, onOpenChange: setOpen, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs("button", { type: "button", disabled: disabled, title: title, "aria-label": compact ? label : undefined, className: compact
|
|
30
|
+
? `viz-press text-sm viz-h-control flex items-center justify-center gap-1 rounded-xs border border-transparent px-1.5 hover:bg-accent ${count ? "text-primary" : "text-muted-foreground hover:text-foreground"}`
|
|
31
|
+
: `viz-press text-sm viz-h-control flex items-center gap-1 rounded-xs border px-2 ${count ? "border-primary/60 bg-primary/10" : "border-border hover:bg-accent"}`, children: [Icon && _jsx(Icon, { size: glyph }), !compact && label, count ? _jsx("span", { className: "text-2xs viz-num rounded-xs bg-primary/25 px-1 font-mono", children: count }) : null, !compact && _jsx(ChevronDown, { size: 10, className: "text-muted-foreground" })] }) }), _jsx(PopoverContent, { align: align === "right" ? "end" : "start", sideOffset: GAP, style: { width }, className: "viz-popover max-h-[var(--radix-popover-content-available-height)] overflow-y-auto p-2", children: children(() => setOpen(false)) })] }));
|
|
32
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A number somebody picks, nudged or typed.
|
|
3
|
+
*
|
|
4
|
+
* For a count: rows to add, decimals to show, an axis bound, a threshold.
|
|
5
|
+
*
|
|
6
|
+
* The field stays typeable. Clearing it means unset.
|
|
7
|
+
*/
|
|
8
|
+
export declare function Stepper({ value, onChange, min, max, step, suffix, placeholder, width, ariaLabel, }: {
|
|
9
|
+
/** Absent is unset. Nought is a bound. */
|
|
10
|
+
value?: number;
|
|
11
|
+
onChange: (next: number | undefined) => void;
|
|
12
|
+
min?: number;
|
|
13
|
+
max?: number;
|
|
14
|
+
step?: number;
|
|
15
|
+
/** Shown after the number, for a unit the control would otherwise label. */
|
|
16
|
+
suffix?: string;
|
|
17
|
+
/** Stands in for the value while it is unset. An empty field still says what it is for. */
|
|
18
|
+
placeholder?: string;
|
|
19
|
+
width?: number;
|
|
20
|
+
ariaLabel?: string;
|
|
21
|
+
}): import("react").JSX.Element;
|