@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,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The plot frame: scales, dash ticks, and the annotation layer.
|
|
3
|
+
*
|
|
4
|
+
* Encodes the chart-design rules so a geom author cannot get them wrong. Transparent background,
|
|
5
|
+
* no box, no gridlines unless a value has to be read off the chart, ticks as short dashes outside
|
|
6
|
+
* the axis, one axis title inline with the tick labels, axis ends captioned with what more and less
|
|
7
|
+
* mean.
|
|
8
|
+
*
|
|
9
|
+
* Geoms receive scales through a render prop, so a geom holds no layout opinion and any geom can
|
|
10
|
+
* appear inside a facet. An axis is continuous or banded, which is what lets bars, boxes, and
|
|
11
|
+
* spans share the frame with scatter and density.
|
|
12
|
+
*
|
|
13
|
+
* Those rules are the defaults and not the only answer. Rule width, tick length and side, the turn
|
|
14
|
+
* on the labels, the type size and where the title sits come off the axis spec, because a scatter of a
|
|
15
|
+
* quarter of a million geoms and a bar chart of nine categories want different chrome around the same
|
|
16
|
+
* frame. `axisRoom` hands the caller the arithmetic, so a turned label grows the margin that holds it.
|
|
17
|
+
*
|
|
18
|
+
* The arithmetic itself is in `/core`: axis specs, scale building, tick stepping, the room an axis
|
|
19
|
+
* takes and the plot area inside a margin. What is left here is the drawing.
|
|
20
|
+
*/
|
|
21
|
+
import { type ReactNode, type Ref } from "react";
|
|
22
|
+
import { type AxisEnd, type AxisSpec, type FrameChildProps, type Metrics, type FrameNote, type SideChildProps, type SidePanel, type MovedNote } from "../core/internal.js";
|
|
23
|
+
export interface FrameProps {
|
|
24
|
+
width: number;
|
|
25
|
+
height: number;
|
|
26
|
+
x: AxisSpec;
|
|
27
|
+
y: AxisSpec;
|
|
28
|
+
headline?: string;
|
|
29
|
+
subtitle?: string;
|
|
30
|
+
/** The footer line under the figure. */
|
|
31
|
+
caption?: string;
|
|
32
|
+
aside?: ReactNode;
|
|
33
|
+
axisEnds?: AxisEnd[];
|
|
34
|
+
notes?: FrameNote[];
|
|
35
|
+
/** Dotted verticals between categories, so a stacked column reads as its own group. */
|
|
36
|
+
columnRules?: boolean;
|
|
37
|
+
margin?: {
|
|
38
|
+
top: number;
|
|
39
|
+
right: number;
|
|
40
|
+
bottom: number;
|
|
41
|
+
left: number;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Holds the geoms and the notes inside the plot area.
|
|
45
|
+
*
|
|
46
|
+
* Off by default, since a label above a point and a geom on the baseline both reach past the area
|
|
47
|
+
* on purpose. A caller that narrowed the domain turns it on, because the geoms left outside it
|
|
48
|
+
* would otherwise be drawn across the ticks and the panel beside them.
|
|
49
|
+
*/
|
|
50
|
+
clip?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Type and spacing for this panel's size.
|
|
53
|
+
*
|
|
54
|
+
* Hand it `frame.metrics`, which is what the frame was built at. The axis type size and tick
|
|
55
|
+
* length are already resolved onto `x` and `y`, so a mismatch here cannot move a margin; what it
|
|
56
|
+
* would move is the annotation type and whatever the geoms take off `FrameChildProps`.
|
|
57
|
+
*/
|
|
58
|
+
metrics?: Metrics;
|
|
59
|
+
/**
|
|
60
|
+
* Panels drawn beside the plot area, each sharing one of its axes.
|
|
61
|
+
*
|
|
62
|
+
* Declared here and rendered by `side`, so the frame owns where they sit and the caller owns what
|
|
63
|
+
* goes in them. The extent comes off the geoms and not off the figure: a side is room the plot
|
|
64
|
+
* area gives up, which is what keeps a figure that grew for its content the size it grew to.
|
|
65
|
+
*/
|
|
66
|
+
sides?: readonly SidePanel[];
|
|
67
|
+
/** The box the geoms are drawn in, handed out so a caller binds gestures to the chart. */
|
|
68
|
+
surface?: Ref<HTMLDivElement>;
|
|
69
|
+
/** A note dragged to a new anchor, reported in data coordinates. Absent means the notes hold still. */
|
|
70
|
+
onNoteMove?: (moved: MovedNote) => void;
|
|
71
|
+
children: (props: FrameChildProps) => ReactNode;
|
|
72
|
+
/**
|
|
73
|
+
* HTML drawn over the plot area, for a readout that wants type and a shadow.
|
|
74
|
+
*
|
|
75
|
+
* Positioned to the same origin the geoms use, so a caller places a card at the pixel a geom
|
|
76
|
+
* reported without knowing what the margins are.
|
|
77
|
+
*/
|
|
78
|
+
overlay?: (props: FrameChildProps) => ReactNode;
|
|
79
|
+
/**
|
|
80
|
+
* What one side panel draws, against the shared scale the geoms use.
|
|
81
|
+
*
|
|
82
|
+
* Takes the same props the geoms take, plus the panel it is drawing for, since the box it is
|
|
83
|
+
* given is already translated to the plot area's own origin along the shared axis.
|
|
84
|
+
*/
|
|
85
|
+
side?: (props: SideChildProps) => ReactNode;
|
|
86
|
+
}
|
|
87
|
+
export declare function Frame({ width, height, x, y, headline, subtitle, caption, aside, axisEnds, notes, columnRules, margin, clip, metrics, sides, surface, onNoteMove, children, overlay, side, }: FrameProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The plot frame: scales, dash ticks, and the annotation layer.
|
|
4
|
+
*
|
|
5
|
+
* Encodes the chart-design rules so a geom author cannot get them wrong. Transparent background,
|
|
6
|
+
* no box, no gridlines unless a value has to be read off the chart, ticks as short dashes outside
|
|
7
|
+
* the axis, one axis title inline with the tick labels, axis ends captioned with what more and less
|
|
8
|
+
* mean.
|
|
9
|
+
*
|
|
10
|
+
* Geoms receive scales through a render prop, so a geom holds no layout opinion and any geom can
|
|
11
|
+
* appear inside a facet. An axis is continuous or banded, which is what lets bars, boxes, and
|
|
12
|
+
* spans share the frame with scatter and density.
|
|
13
|
+
*
|
|
14
|
+
* Those rules are the defaults and not the only answer. Rule width, tick length and side, the turn
|
|
15
|
+
* on the labels, the type size and where the title sits come off the axis spec, because a scatter of a
|
|
16
|
+
* quarter of a million geoms and a bar chart of nine categories want different chrome around the same
|
|
17
|
+
* frame. `axisRoom` hands the caller the arithmetic, so a turned label grows the margin that holds it.
|
|
18
|
+
*
|
|
19
|
+
* The arithmetic itself is in `/core`: axis specs, scale building, tick stepping, the room an axis
|
|
20
|
+
* takes and the plot area inside a margin. What is left here is the drawing.
|
|
21
|
+
*/
|
|
22
|
+
import { Annotation, Connector, EditableAnnotation, Label } from "@visx/annotation";
|
|
23
|
+
import { useId, useMemo } from "react";
|
|
24
|
+
import { buildAxis, REGULAR, isBand, LABEL_GAP, longestOf, scaleKey, sideLayout, tickRoom, ASCENT, TITLE_PAD, Y_TITLE_ABOVE, } from "../core/internal.js";
|
|
25
|
+
import { Figure } from "./Figure.js";
|
|
26
|
+
/** Tabular figures, so a column of numbers lines up on the digit. */
|
|
27
|
+
const TABULAR = { fontVariantNumeric: "tabular-nums" };
|
|
28
|
+
/** The annotation size from the type ramp, as a number the label component asks for. */
|
|
29
|
+
/** How wide a note runs before it wraps, so a sentence on the chart stays a couple of lines. */
|
|
30
|
+
const ANNOT_WIDTH = 160;
|
|
31
|
+
/** The grip on a note that can be moved: a ring in the leader's own ink instead of a library gray. */
|
|
32
|
+
const HANDLE = {
|
|
33
|
+
r: 7,
|
|
34
|
+
fill: "transparent",
|
|
35
|
+
stroke: "var(--viz-leader)",
|
|
36
|
+
strokeDasharray: "2 2",
|
|
37
|
+
strokeWidth: 1,
|
|
38
|
+
};
|
|
39
|
+
/** Tick and title ink. Strong lifts a band axis carrying identity up to the weight of the geoms. */
|
|
40
|
+
const inkOf = (chrome) => (chrome.ink === "strong" ? "var(--viz-ink)" : "var(--viz-ink-muted)");
|
|
41
|
+
/**
|
|
42
|
+
* Where a tick, its label and the turn on that label are drawn.
|
|
43
|
+
*
|
|
44
|
+
* Ticks follow the side the author asked for; the labels stay outside the plot area either way, since
|
|
45
|
+
* a number sitting among the geoms is read as one of them.
|
|
46
|
+
*/
|
|
47
|
+
function tickPlacement(chrome, axis) {
|
|
48
|
+
const inward = chrome.tickSide === "in";
|
|
49
|
+
const sign = (inward ? -1 : 1) * (axis === "x" ? 1 : -1);
|
|
50
|
+
const beyond = inward ? 0 : chrome.tickLength;
|
|
51
|
+
const angle = chrome.tickAngle;
|
|
52
|
+
return {
|
|
53
|
+
tick: sign * chrome.tickLength,
|
|
54
|
+
/** Half a major, so the eye reads which tick carries the number. */
|
|
55
|
+
minor: (sign * chrome.tickLength) / 2,
|
|
56
|
+
/** A flat x label sits on its baseline. A turned one centers on its pivot, like a y label. */
|
|
57
|
+
label: axis === "y" ? -(beyond + LABEL_GAP) : angle ? beyond + LABEL_GAP : beyond + chrome.fontSize + 1,
|
|
58
|
+
dy: axis === "y" || angle ? "0.32em" : undefined,
|
|
59
|
+
/** An x label turned clockwise hangs from its start. */
|
|
60
|
+
anchor: (axis === "x" && angle < 0 ? "start" : angle || axis === "y" ? "end" : "middle"),
|
|
61
|
+
turn: (at) => (angle ? `rotate(${-angle},${axis === "x" ? `0,${at}` : `${at},0`})` : undefined),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** Where a title sits along its own rule, which is what `titleAlign` names. */
|
|
65
|
+
const alongRule = (align, span) => align === "start"
|
|
66
|
+
? { at: 0, anchor: "start" }
|
|
67
|
+
: align === "center"
|
|
68
|
+
? { at: span / 2, anchor: "middle" }
|
|
69
|
+
: { at: span, anchor: "end" };
|
|
70
|
+
export function Frame({ width, height, x, y, headline, subtitle, caption, aside, axisEnds = [], notes = [], columnRules = false, margin = { top: 14, right: 14, bottom: 30, left: 44 }, clip = false, metrics = REGULAR, sides, surface, onNoteMove, children, overlay, side, }) {
|
|
71
|
+
const { room, inner, inside, regions } = sideLayout(sides, width, height, margin);
|
|
72
|
+
/*
|
|
73
|
+
X reads left to right and its title has always sat at the high end; Y's sits above its top.
|
|
74
|
+
|
|
75
|
+
A vertical value scale runs upward from the origin, and a vertical band runs down from the top.
|
|
76
|
+
The order a band carries is a reading order and not a magnitude: a ranked bar chart puts its
|
|
77
|
+
longest bar at the top, and a clustered grid puts the first leaf of its tree there, which is
|
|
78
|
+
where pheatmap draws it. Inheriting the value scale's inverted range drew both upside down.
|
|
79
|
+
*/
|
|
80
|
+
const yRange = isBand(y) ? [0, inner.height] : [inner.height, 0];
|
|
81
|
+
const xa = buildAxis(x, [0, inner.width], metrics.ticks, "end");
|
|
82
|
+
const ya = buildAxis(y, yRange, metrics.ticks, "end");
|
|
83
|
+
const xRoom = tickRoom(xa.chrome, xa.labelTicks, longestOf(xa), "x");
|
|
84
|
+
const yRoom = tickRoom(ya.chrome, ya.labelTicks, longestOf(ya), "y");
|
|
85
|
+
/*
|
|
86
|
+
Where the axis chrome sits, which is not always the edge of the plot area.
|
|
87
|
+
|
|
88
|
+
A panel drawn inside the axis labels stands between them and the geoms, so the ticks, their
|
|
89
|
+
numbers and the title all move out past it. Without this the labels drew over the panel: they are
|
|
90
|
+
placed against the plot area's own origin, and an inside panel is the one thing that can be
|
|
91
|
+
between the two.
|
|
92
|
+
*/
|
|
93
|
+
const chromeX = -inside.left;
|
|
94
|
+
const chromeY = inner.height + inside.bottom;
|
|
95
|
+
/* Titles sit past the labels, on the far edge of the room the ticks asked for. */
|
|
96
|
+
const xTitleY = chromeY + xRoom + TITLE_PAD / 2 + ASCENT * xa.chrome.fontSize;
|
|
97
|
+
const xTicks = tickPlacement(xa.chrome, "x");
|
|
98
|
+
const yTicks = tickPlacement(ya.chrome, "y");
|
|
99
|
+
/*
|
|
100
|
+
The scales the geoms are handed keep their identity for as long as they answer the same.
|
|
101
|
+
|
|
102
|
+
Held apart from `xa` and `ya`, which rebuild freely: a geom reads the scale and the axis reads the
|
|
103
|
+
ticks, so the two want different lifetimes. While the key holds, the function from the render that
|
|
104
|
+
minted it is handed back, and it maps as it did because the key covers what the mapping reads.
|
|
105
|
+
*/
|
|
106
|
+
const xKey = scaleKey(x, [0, inner.width]);
|
|
107
|
+
const yKey = scaleKey(y, yRange);
|
|
108
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- the key covers what the mapping reads, which is the point
|
|
109
|
+
const xScale = useMemo(() => xa.scale, [xKey]);
|
|
110
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- as above
|
|
111
|
+
const yScale = useMemo(() => ya.scale, [yKey]);
|
|
112
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- as above
|
|
113
|
+
const xInvert = useMemo(() => xa.invert, [xKey]);
|
|
114
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- as above
|
|
115
|
+
const yInvert = useMemo(() => ya.invert, [yKey]);
|
|
116
|
+
const childProps = {
|
|
117
|
+
x: xScale,
|
|
118
|
+
y: yScale,
|
|
119
|
+
xInvert,
|
|
120
|
+
yInvert,
|
|
121
|
+
xBand: xa.bandwidth,
|
|
122
|
+
yBand: ya.bandwidth,
|
|
123
|
+
xStep: xa.step,
|
|
124
|
+
yStep: ya.step,
|
|
125
|
+
width: inner.width,
|
|
126
|
+
height: inner.height,
|
|
127
|
+
metrics,
|
|
128
|
+
};
|
|
129
|
+
// Boundaries sit midway between adjacent category centers, plus the two outer edges.
|
|
130
|
+
const rules = columnRules && isBand(x)
|
|
131
|
+
? (() => {
|
|
132
|
+
const centers = x.values.map((v) => xa.scale(v));
|
|
133
|
+
const mids = centers.slice(0, -1).map((c, i) => (c + centers[i + 1]) / 2);
|
|
134
|
+
return [0, ...mids, inner.width];
|
|
135
|
+
})()
|
|
136
|
+
: [];
|
|
137
|
+
/*
|
|
138
|
+
A grid line stands where a tick stands, so the two read one interval.
|
|
139
|
+
|
|
140
|
+
Drawn from the axis and not from a frame-wide switch, since a reader takes a value off one scale
|
|
141
|
+
at a time and a chart wanting horizontals rarely wants verticals with them. Both sets read
|
|
142
|
+
`--viz-rule` and separate by weight, which keeps the labeled set legible against the
|
|
143
|
+
subdivisions and leaves a theme flip to the browser.
|
|
144
|
+
*/
|
|
145
|
+
const gridFor = (axis, along) => ["major", "minor"].flatMap((kind) => {
|
|
146
|
+
if (!(kind === "major" ? axis.chrome.grid : axis.chrome.minorGrid))
|
|
147
|
+
return [];
|
|
148
|
+
return (kind === "major" ? axis.ticks : axis.minor).map((at) => {
|
|
149
|
+
const p = axis.scale(at);
|
|
150
|
+
return (_jsx("line", { "data-grid": kind, x1: along === "x" ? p : 0, x2: along === "x" ? p : inner.width, y1: along === "x" ? 0 : p, y2: along === "x" ? inner.height : p, stroke: "var(--viz-rule)", strokeOpacity: kind === "major" ? undefined : 0.45, strokeDasharray: "1 3" }, `grid${along}${kind}${at}`));
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
const hold = useId();
|
|
154
|
+
const holdIn = clip ? `url(#${hold})` : undefined;
|
|
155
|
+
return (_jsx(Figure, { headline: headline, subtitle: subtitle, caption: caption, aside: aside, children: _jsxs("div", { ref: surface, className: "relative", style: { position: "relative", width, height }, children: [_jsxs("svg", { "data-viz-panel": "", width: width, height: height, style: { overflow: "visible" }, children: [clip && (_jsx("clipPath", { id: hold, children: _jsx("rect", { x: 0, y: 0, width: inner.width, height: inner.height }) })), side &&
|
|
156
|
+
regions.map((region, at) => (_jsxs("g", { "data-side": region.panel.content.kind, transform: `translate(${region.x},${region.y})`, clipPath: clip ? `url(#${hold}side${at})` : undefined, children: [clip && (_jsx("clipPath", { id: `${hold}side${at}`, children: _jsx("rect", { x: 0, y: 0, width: region.width, height: region.height }) })), side({ ...childProps, panel: region.panel, width: region.width, height: region.height })] }, `side${at}`))), _jsxs("g", { transform: `translate(${room.left + margin.left},${room.top + margin.top})`, children: [rules.map((rx, i) => (_jsx("line", { x1: rx, x2: rx, y1: 0, y2: inner.height, stroke: "var(--viz-rule)", strokeOpacity: 0.7, strokeDasharray: "2 4" }, `r${i}`))), gridFor(xa, "x"), gridFor(ya, "y"), _jsxs("g", { clipPath: holdIn, children: [children(childProps), notes.map((note, i) => {
|
|
157
|
+
const nx = xa.scale(note.at.x);
|
|
158
|
+
const ny = ya.scale(note.at.y);
|
|
159
|
+
const at = note.toward ? { x: xa.scale(note.toward.x), y: ya.scale(note.toward.y) } : { x: nx, y: ny };
|
|
160
|
+
const written = (_jsxs(_Fragment, { children: [note.toward && _jsx(Connector, { type: "line", stroke: "var(--viz-leader)", pathProps: { strokeWidth: 0.9 } }), _jsx(Label, { title: note.text, showBackground: false, showAnchorLine: false, fontColor: "var(--viz-annotation)", titleFontSize: metrics.annotation, titleFontWeight: 400, horizontalAnchor: note.align ?? "start", verticalAnchor: "end", maxWidth: ANNOT_WIDTH })] }));
|
|
161
|
+
return onNoteMove ? (_jsx(EditableAnnotation, { x: at.x, y: at.y, dx: nx - at.x, dy: ny - at.y, width: inner.width, height: inner.height, canEditLabel: note.toward != null, subjectDragHandleProps: HANDLE, labelDragHandleProps: HANDLE, onDragEnd: ({ x: sx, y: sy, dx, dy }) => onNoteMove({
|
|
162
|
+
source: note.source,
|
|
163
|
+
at: { x: xa.invert(sx + dx), y: ya.invert(sy + dy) },
|
|
164
|
+
toward: note.toward ? { x: xa.invert(sx), y: ya.invert(sy) } : undefined,
|
|
165
|
+
}), children: written }, `n${i}`)) : (_jsx(Annotation, { x: at.x, y: at.y, dx: nx - at.x, dy: ny - at.y, children: written }, `n${i}`));
|
|
166
|
+
})] }), xa.ticks.length > 0 && (_jsx("line", { x1: 0, x2: inner.width, y1: inner.height, y2: inner.height, stroke: "var(--viz-rule)", strokeWidth: xa.chrome.lineWidth })), ya.chrome.rule && ya.ticks.length > 0 && (_jsx("line", { x1: 0, x2: 0, y1: 0, y2: inner.height, stroke: "var(--viz-rule)", strokeWidth: ya.chrome.lineWidth })), xa.minor.map((t) => (_jsx("line", { x1: xa.scale(t), x2: xa.scale(t), y1: chromeY, y2: chromeY + xTicks.minor, stroke: "var(--viz-rule)", strokeWidth: xa.chrome.lineWidth, strokeOpacity: 0.6 }, `xm${t}`))), ya.minor.map((t) => (_jsx("line", { x1: chromeX + yTicks.minor, x2: chromeX, y1: ya.scale(t), y2: ya.scale(t), stroke: "var(--viz-rule)", strokeWidth: ya.chrome.lineWidth, strokeOpacity: 0.6 }, `ym${t}`))), xa.ticks.map((t) => (_jsxs("g", { transform: `translate(${xa.scale(t)},${chromeY})`, children: [_jsx("line", { y2: xTicks.tick, stroke: "var(--viz-rule)", strokeWidth: xa.chrome.lineWidth }), xa.labelTicks && (_jsx("text", { y: xTicks.label, dy: xTicks.dy, textAnchor: xTicks.anchor, transform: xTicks.turn(xTicks.label), fontSize: xa.chrome.fontSize, style: TABULAR, fill: inkOf(xa.chrome), children: xa.format(t) }))] }, `x${t}`))), ya.ticks.map((t) => (_jsxs("g", { transform: `translate(${chromeX},${ya.scale(t)})`, children: [_jsx("line", { x2: yTicks.tick, stroke: "var(--viz-rule)", strokeWidth: ya.chrome.lineWidth }), ya.labelTicks && (_jsx("text", { x: yTicks.label, dy: yTicks.dy, textAnchor: yTicks.anchor, transform: yTicks.turn(yTicks.label), fontSize: ya.chrome.fontSize, style: TABULAR, fill: inkOf(ya.chrome), children: ya.format(t) }))] }, `y${t}`))), xa.label &&
|
|
167
|
+
!axisEnds.some((e) => e.axis === "x" &&
|
|
168
|
+
e.end === (xa.chrome.titleAlign === "start" ? "low" : xa.chrome.titleAlign === "end" ? "high" : null)) &&
|
|
169
|
+
(() => {
|
|
170
|
+
const { at, anchor } = alongRule(xa.chrome.titleAlign, inner.width);
|
|
171
|
+
return (_jsx("text", { x: at, y: xTitleY, textAnchor: anchor, fontSize: xa.chrome.fontSize, fill: inkOf(xa.chrome), children: xa.label }));
|
|
172
|
+
})(), ya.label &&
|
|
173
|
+
!(ya.chrome.titleAlign === "start" && axisEnds.some((e) => e.axis === "y" && e.end === "high")) &&
|
|
174
|
+
(ya.chrome.titleAlign === "end" ? (_jsx("text", { x: chromeX - yRoom, y: -Y_TITLE_ABOVE, textAnchor: "start", fontSize: ya.chrome.fontSize, fill: inkOf(ya.chrome), children: ya.label })) : ((() => {
|
|
175
|
+
const { at, anchor } = alongRule(ya.chrome.titleAlign, inner.height);
|
|
176
|
+
const x = chromeX - (yRoom + TITLE_PAD / 2 + (1 - ASCENT) * ya.chrome.fontSize);
|
|
177
|
+
return (_jsx("text", { textAnchor: anchor === "start" ? "end" : anchor, fontSize: ya.chrome.fontSize, fill: inkOf(ya.chrome), transform: `translate(${x},${at}) rotate(-90)`, children: ya.label }));
|
|
178
|
+
})())), axisEnds.map((end) => {
|
|
179
|
+
const atLow = end.end === "low";
|
|
180
|
+
if (end.axis === "x") {
|
|
181
|
+
return (_jsx("text", { x: atLow ? 0 : inner.width, y: xTitleY, textAnchor: atLow ? "start" : "end", fontSize: xa.chrome.fontSize, className: "font-medium", fill: "var(--viz-annotation)", children: end.text }, `ae${end.axis}${end.end}`));
|
|
182
|
+
}
|
|
183
|
+
return (_jsx("text", { x: yTicks.label, y: atLow ? inner.height : 10, textAnchor: "end", fontSize: ya.chrome.fontSize, className: "font-medium", fill: "var(--viz-annotation)", children: end.text }, `ae${end.axis}${end.end}`));
|
|
184
|
+
})] })] }), overlay && (_jsx("div", { className: "pointer-events-none absolute", style: {
|
|
185
|
+
position: "absolute",
|
|
186
|
+
pointerEvents: "none",
|
|
187
|
+
left: room.left + margin.left,
|
|
188
|
+
top: room.top + margin.top,
|
|
189
|
+
width: inner.width,
|
|
190
|
+
height: inner.height,
|
|
191
|
+
}, children: overlay(childProps) }))] }) }));
|
|
192
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Draws one sample mark per level of a bound shape, dash or categorical opacity.
|
|
3
|
+
*
|
|
4
|
+
* One component serves the three. A guide for each asks the reader the same thing: here is a mark,
|
|
5
|
+
* here is what it stands for. `ColorLegend` draws a bar because a measure is continuous, and
|
|
6
|
+
* `SizeLegend` draws three circles because area is judged against a neighbor. A glyph and a pattern
|
|
7
|
+
* are neither, so the guide is the marks themselves.
|
|
8
|
+
*
|
|
9
|
+
* The sample takes the trace's own ink, so a reader matches it against the chart by eye instead of
|
|
10
|
+
* by name. A figure that bound the channel to separate its groups without hue carries one color
|
|
11
|
+
* across the set, which is the case chart-design rule 8 is about.
|
|
12
|
+
*/
|
|
13
|
+
import { type Linetype, type PointShape } from "../core/internal.js";
|
|
14
|
+
/** One level, with the mark that stands for it. */
|
|
15
|
+
export interface MarkLevel {
|
|
16
|
+
label: string;
|
|
17
|
+
/** Glyph the sample draws. Absent draws a run instead, which is what a dash guide wants. */
|
|
18
|
+
shape?: PointShape;
|
|
19
|
+
/** Pattern the run draws, where the sample is a run. */
|
|
20
|
+
dash?: Linetype;
|
|
21
|
+
/** Opacity the sample draws at. Absent draws it solid. */
|
|
22
|
+
opacity?: number;
|
|
23
|
+
}
|
|
24
|
+
export interface MarkLegendProps {
|
|
25
|
+
/** The channel's own field, or the name an author gave the guide. */
|
|
26
|
+
label?: string;
|
|
27
|
+
levels: readonly MarkLevel[];
|
|
28
|
+
/** Ink the samples take, which is the color the marks carry on the chart. */
|
|
29
|
+
color: string;
|
|
30
|
+
orientation?: "row" | "column";
|
|
31
|
+
}
|
|
32
|
+
export declare function MarkLegend({ label, levels, color, orientation }: MarkLegendProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Draws one sample mark per level of a bound shape, dash or categorical opacity.
|
|
4
|
+
*
|
|
5
|
+
* One component serves the three. A guide for each asks the reader the same thing: here is a mark,
|
|
6
|
+
* here is what it stands for. `ColorLegend` draws a bar because a measure is continuous, and
|
|
7
|
+
* `SizeLegend` draws three circles because area is judged against a neighbor. A glyph and a pattern
|
|
8
|
+
* are neither, so the guide is the marks themselves.
|
|
9
|
+
*
|
|
10
|
+
* The sample takes the trace's own ink, so a reader matches it against the chart by eye instead of
|
|
11
|
+
* by name. A figure that bound the channel to separate its groups without hue carries one color
|
|
12
|
+
* across the set, which is the case chart-design rule 8 is about.
|
|
13
|
+
*/
|
|
14
|
+
import { dashArray } from "../core/internal.js";
|
|
15
|
+
import { glyph } from "./geoms/Points.js";
|
|
16
|
+
/** How wide a sample sits, in pixels. Wide enough for two runs of the longest pattern to read. */
|
|
17
|
+
const SAMPLE = 26;
|
|
18
|
+
const HEIGHT = 12;
|
|
19
|
+
export function MarkLegend({ label, levels, color, orientation = "row" }) {
|
|
20
|
+
if (levels.length === 0)
|
|
21
|
+
return null;
|
|
22
|
+
const lay = orientation === "column" ? "flex-col items-start" : "flex-wrap items-center";
|
|
23
|
+
return (_jsxs("div", { className: "contents", children: [_jsx("span", { className: "text-xs text-muted-foreground", children: label }), _jsx("span", { className: `flex min-w-0 ${lay} gap-x-3 gap-y-1`, children: levels.map((level) => (_jsxs("span", { className: "flex items-center gap-1.5", children: [_jsx("svg", { width: SAMPLE, height: HEIGHT, "aria-hidden": true, children: level.shape ? (_jsx("path", { d: glyph(level.shape, SAMPLE / 2, HEIGHT / 2, 4), fill: color, fillOpacity: level.opacity ?? 0.85 })) : (_jsx("line", { x1: 1, x2: SAMPLE - 1, y1: HEIGHT / 2, y2: HEIGHT / 2, stroke: color, strokeWidth: 1.6, strokeOpacity: level.opacity ?? 0.85, strokeDasharray: dashArray(level.dash), strokeLinecap: "round" })) }), _jsx("span", { className: "text-xs text-muted-foreground", children: level.label })] }, level.label))) })] }));
|
|
24
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An inline dot-and-label row.
|
|
3
|
+
*
|
|
4
|
+
* Sits above or below the plot, out of the data region. Used where direct labels do not fit: a
|
|
5
|
+
* stacked bar has no room to write inside its segments, so the series names go here and the values
|
|
6
|
+
* go in the tooltip. Above six series this stops being readable and the chart wants faceting
|
|
7
|
+
* instead.
|
|
8
|
+
*
|
|
9
|
+
* Part of the chart layer, which is hand-drawn svg for the reason the widget geoms record.
|
|
10
|
+
*/
|
|
11
|
+
export interface SeriesItem {
|
|
12
|
+
id: string;
|
|
13
|
+
label: string;
|
|
14
|
+
color: string;
|
|
15
|
+
value?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface SeriesLegendProps {
|
|
18
|
+
items: SeriesItem[];
|
|
19
|
+
/**
|
|
20
|
+
* What the swatches stand for, written ahead of them.
|
|
21
|
+
*
|
|
22
|
+
* The series legend needs none: its rows are the series and the chart is about them. An annotation
|
|
23
|
+
* track does, since its swatches name values of some other column and two unlabeled strips beside
|
|
24
|
+
* one grid leave a reader guessing which is which.
|
|
25
|
+
*/
|
|
26
|
+
label?: string;
|
|
27
|
+
/** Series drawn at full strength. The rest read as context. */
|
|
28
|
+
active?: string | null;
|
|
29
|
+
/**
|
|
30
|
+
* Which way the names run.
|
|
31
|
+
*
|
|
32
|
+
* A row under the plot is the default and wraps. A column is what a legend beside the panel
|
|
33
|
+
* wants, since names stacked against the geoms they label are read down the way the geoms are.
|
|
34
|
+
*/
|
|
35
|
+
orientation?: "row" | "column";
|
|
36
|
+
onToggle?: (id: string) => void;
|
|
37
|
+
}
|
|
38
|
+
export declare function SeriesLegend({ items, label, active, orientation, onToggle }: SeriesLegendProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* An inline dot-and-label row.
|
|
4
|
+
*
|
|
5
|
+
* Sits above or below the plot, out of the data region. Used where direct labels do not fit: a
|
|
6
|
+
* stacked bar has no room to write inside its segments, so the series names go here and the values
|
|
7
|
+
* go in the tooltip. Above six series this stops being readable and the chart wants faceting
|
|
8
|
+
* instead.
|
|
9
|
+
*
|
|
10
|
+
* Part of the chart layer, which is hand-drawn svg for the reason the widget geoms record.
|
|
11
|
+
*/
|
|
12
|
+
/** The 6px rhythm the kit prebuilt sheet does not carry. */
|
|
13
|
+
const GAP_1_5 = { gap: 6 };
|
|
14
|
+
/** Tabular figures, so a column of numbers lines up on the digit. */
|
|
15
|
+
const TABULAR = { fontVariantNumeric: "tabular-nums" };
|
|
16
|
+
export function SeriesLegend({ items, label, active, orientation = "row", onToggle }) {
|
|
17
|
+
if (items.length === 0)
|
|
18
|
+
return null;
|
|
19
|
+
const interactive = Boolean(onToggle);
|
|
20
|
+
return (_jsxs("div", { className: "contents", children: [_jsx("span", { className: "text-xs text-muted-foreground", children: label }), _jsx("span", { className: orientation === "column"
|
|
21
|
+
? "flex min-w-0 shrink-0 flex-col items-start gap-y-1"
|
|
22
|
+
: "flex min-w-0 flex-wrap items-center gap-x-4 gap-y-1", children: items.map((item) => {
|
|
23
|
+
const dim = active != null && item.id !== active;
|
|
24
|
+
const content = (_jsxs(_Fragment, { children: [_jsx("span", { className: "size-2 shrink-0 rounded-full", style: { background: item.color, opacity: dim ? 0.35 : 1 } }), _jsx("span", { className: `text-xs ${dim ? "text-muted-foreground" : "text-foreground"}`, children: item.label }), item.value && (_jsx("span", { className: "text-xs font-medium text-muted-foreground", style: TABULAR, children: item.value }))] }));
|
|
25
|
+
return interactive ? (_jsx("button", { type: "button", onClick: () => onToggle?.(item.id), className: "flex items-center", style: GAP_1_5, children: content }, item.id)) : (_jsx("span", { className: "flex items-center", style: GAP_1_5, children: content }, item.id));
|
|
26
|
+
}) })] }));
|
|
27
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a diameter stands for.
|
|
3
|
+
*
|
|
4
|
+
* A bound size channel draws geoms a reader can rank and cannot read back, so the ramp states the
|
|
5
|
+
* two ends of the range and its middle. Three circles instead of a continuous bar, because area is
|
|
6
|
+
* judged against a neighbor and not against a gradient.
|
|
7
|
+
*
|
|
8
|
+
* The middle sits at the value whose area is halfway, which is where the square-root scale puts it:
|
|
9
|
+
* a ramp labeled at the arithmetic midpoint would say the middle geom stands for a number it does
|
|
10
|
+
* not. See the ADR "Size is a channel and the critic has an opinion about it".
|
|
11
|
+
*/
|
|
12
|
+
export interface SizeLegendProps {
|
|
13
|
+
/** The field's name, with its unit where it carries one. */
|
|
14
|
+
label: string;
|
|
15
|
+
/** That field's range over the whole table. */
|
|
16
|
+
domain: [number, number];
|
|
17
|
+
/** Smallest and largest radius the channel resolved to, in pixels. */
|
|
18
|
+
radii: readonly [number, number];
|
|
19
|
+
/** Color the sample geoms draw in, so the ramp reads as the same chart. */
|
|
20
|
+
color: string;
|
|
21
|
+
/** Formats a value the way the axis and the readout do. */
|
|
22
|
+
format?: (value: number) => string;
|
|
23
|
+
}
|
|
24
|
+
export declare function SizeLegend({ label, domain, radii, color, format }: SizeLegendProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* What a diameter stands for.
|
|
4
|
+
*
|
|
5
|
+
* A bound size channel draws geoms a reader can rank and cannot read back, so the ramp states the
|
|
6
|
+
* two ends of the range and its middle. Three circles instead of a continuous bar, because area is
|
|
7
|
+
* judged against a neighbor and not against a gradient.
|
|
8
|
+
*
|
|
9
|
+
* The middle sits at the value whose area is halfway, which is where the square-root scale puts it:
|
|
10
|
+
* a ramp labeled at the arithmetic midpoint would say the middle geom stands for a number it does
|
|
11
|
+
* not. See the ADR "Size is a channel and the critic has an opinion about it".
|
|
12
|
+
*/
|
|
13
|
+
import { sizeRadius } from "../core/internal.js";
|
|
14
|
+
/** Tabular figures, so a column of numbers lines up on the digit. */
|
|
15
|
+
const TABULAR = { fontVariantNumeric: "tabular-nums" };
|
|
16
|
+
export function SizeLegend({ label, domain, radii, color, format }) {
|
|
17
|
+
const [lo, hi] = domain;
|
|
18
|
+
const say = format ?? ((value) => value.toLocaleString(undefined, { maximumSignificantDigits: 3 }));
|
|
19
|
+
const stops = [lo, lo + (hi - lo) / 2, hi];
|
|
20
|
+
const widest = radii[1] * 2;
|
|
21
|
+
return (_jsxs("div", { className: "contents", children: [_jsx("span", { className: "text-xs text-muted-foreground", children: label }), _jsx("span", { className: "flex min-w-0 flex-wrap items-end gap-x-3 gap-y-1", children: stops.map((value) => {
|
|
22
|
+
const r = sizeRadius(value, lo, hi, radii);
|
|
23
|
+
return (_jsxs("span", { className: "flex flex-col items-center gap-1", style: { width: widest }, children: [_jsx("svg", { width: widest, height: widest, "aria-hidden": true, children: _jsx("circle", { cx: widest / 2, cy: widest - r, r: r, fill: color, fillOpacity: 0.85 }) }), _jsx("span", { className: "text-xs text-muted-foreground", style: TABULAR, children: say(value) })] }, value));
|
|
24
|
+
}) })] }));
|
|
25
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ghost toolbar: a figure's controls for its reader.
|
|
3
|
+
*
|
|
4
|
+
* Listed items draw in listed order. A choice stays with the reader and the spec stays as authored.
|
|
5
|
+
*/
|
|
6
|
+
import { type ChartSpec, type PaletteKind, type PaletteName, type Palettes, type PlotData } from "../core/internal.js";
|
|
7
|
+
export type ToolbarItem = "zoom" | "reset" | "pan" | "zoomBox" | "box" | "lasso" | "tooltip" | "palette" | "colorblind" | "facet" | "export";
|
|
8
|
+
type DragMode = Extract<ToolbarItem, "pan" | "zoomBox" | "box" | "lasso">;
|
|
9
|
+
/** What the reader chose. An absent field leaves the authored figure. */
|
|
10
|
+
export interface ToolbarView {
|
|
11
|
+
drag?: DragMode;
|
|
12
|
+
tooltip?: boolean;
|
|
13
|
+
palette?: PaletteName;
|
|
14
|
+
colorblind?: boolean;
|
|
15
|
+
/** A null `by` draws one panel. */
|
|
16
|
+
facet?: {
|
|
17
|
+
by: string | null;
|
|
18
|
+
columns?: number;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export interface ToolbarOptions {
|
|
22
|
+
items: readonly ToolbarItem[];
|
|
23
|
+
/** The maps the palette menu offers. Absent offers the registry's maps of the figure's color kind. */
|
|
24
|
+
palette?: {
|
|
25
|
+
options: readonly PaletteName[];
|
|
26
|
+
};
|
|
27
|
+
/** The colorblind-safe map per kind, over okabe-ito, cividis and puor. */
|
|
28
|
+
colorblind?: Partial<Record<PaletteKind, PaletteName>>;
|
|
29
|
+
/** Fields a facet may split by and the column counts offered. Absent offers text fields up to the panel cap, and one to four. */
|
|
30
|
+
facet?: {
|
|
31
|
+
by?: readonly string[];
|
|
32
|
+
columns?: readonly number[];
|
|
33
|
+
};
|
|
34
|
+
export?: {
|
|
35
|
+
formats?: readonly ("png" | "svg")[];
|
|
36
|
+
ground?: boolean;
|
|
37
|
+
};
|
|
38
|
+
onChange?: (view: ToolbarView) => void;
|
|
39
|
+
}
|
|
40
|
+
export declare const COLORBLIND: Readonly<Record<PaletteKind, PaletteName>>;
|
|
41
|
+
/** The drag modes a list names, in its order. */
|
|
42
|
+
export declare const dragsOf: (items: readonly ToolbarItem[]) => DragMode[];
|
|
43
|
+
/** A download name off the headline, or `figure` where it has none. */
|
|
44
|
+
export declare const fileName: (headline: string | undefined, format: string) => string;
|
|
45
|
+
/**
|
|
46
|
+
* The reader's choices the toolbar still offers.
|
|
47
|
+
*
|
|
48
|
+
* A choice needs its item listed. A picked map needs the host's list, and a facet field the menu.
|
|
49
|
+
*/
|
|
50
|
+
export declare function viewOf(view: ToolbarView, options: ToolbarOptions | undefined, facetBy: readonly {
|
|
51
|
+
id: string;
|
|
52
|
+
}[]): ToolbarView;
|
|
53
|
+
/**
|
|
54
|
+
* The spec the figure draws, with the reader's facet laid over.
|
|
55
|
+
*
|
|
56
|
+
* Colorblind moves each layer's named map to its kind's target. A pick drops the names of its own kind.
|
|
57
|
+
*/
|
|
58
|
+
export declare function viewSpec(spec: ChartSpec, view: ToolbarView, targets: Readonly<Record<PaletteKind, PaletteName>>): ChartSpec;
|
|
59
|
+
/** The figure's maps with the reader's swap laid over. Returns the base where nothing swaps. */
|
|
60
|
+
export declare function viewPalettes(base: Palettes, view: ToolbarView, targets: Readonly<Record<PaletteKind, PaletteName>>, dark: boolean): Palettes;
|
|
61
|
+
/**
|
|
62
|
+
* The fields the facet menu offers, with their labels.
|
|
63
|
+
*
|
|
64
|
+
* The host's list, or each text field with at most `FACET_CAP` values. The authored facet field stays listed.
|
|
65
|
+
*/
|
|
66
|
+
export declare function facetFields(data: PlotData, listed: readonly string[] | undefined, authored: string | undefined): {
|
|
67
|
+
id: string;
|
|
68
|
+
label: string;
|
|
69
|
+
}[];
|
|
70
|
+
/**
|
|
71
|
+
* The maps the palette menu offers: the host's list, or the registry's, narrowed to the kinds the figure draws.
|
|
72
|
+
*
|
|
73
|
+
* A diverging map needs a center.
|
|
74
|
+
*/
|
|
75
|
+
export declare function paletteOptions(listed: readonly PaletteName[] | undefined, figure: {
|
|
76
|
+
magnitude: boolean;
|
|
77
|
+
centered: boolean;
|
|
78
|
+
}): PaletteName[];
|
|
79
|
+
/** Saves a blob under a file name through a transient link. */
|
|
80
|
+
export declare function download(blob: Blob, name: string): void;
|
|
81
|
+
export interface ToolbarProps {
|
|
82
|
+
/** Where the strip's corner falls inside the panel holder. */
|
|
83
|
+
at: React.CSSProperties;
|
|
84
|
+
options: ToolbarOptions;
|
|
85
|
+
view: ToolbarView;
|
|
86
|
+
onView: (next: ToolbarView) => void;
|
|
87
|
+
/** The drag mode in force. */
|
|
88
|
+
drag?: DragMode;
|
|
89
|
+
palettes: readonly PaletteName[];
|
|
90
|
+
/** Fields the facet menu offers, with their labels. */
|
|
91
|
+
facetBy: readonly {
|
|
92
|
+
id: string;
|
|
93
|
+
label: string;
|
|
94
|
+
}[];
|
|
95
|
+
/** The facet the figure draws now. */
|
|
96
|
+
facet: {
|
|
97
|
+
by: string | null;
|
|
98
|
+
columns?: number;
|
|
99
|
+
};
|
|
100
|
+
/** Why the view tools are off, where they are. */
|
|
101
|
+
viewLocked?: string;
|
|
102
|
+
/** Why the facet menu is off, where it is. */
|
|
103
|
+
facetLocked?: string;
|
|
104
|
+
onZoom: (factor: number) => void;
|
|
105
|
+
onReset: () => void;
|
|
106
|
+
onExport: (format: "png" | "svg") => void;
|
|
107
|
+
}
|
|
108
|
+
export declare function Toolbar({ at, options, view, onView, drag, palettes, facetBy, facet, viewLocked, facetLocked, onZoom, onReset, onExport, }: ToolbarProps): import("react").JSX.Element;
|
|
109
|
+
export {};
|