@tetrascience-npm/ts-lib-viz 0.0.0-stage → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +2171 -2
- package/dist/src/builder/PlotPanel.d.ts +42 -0
- package/dist/src/builder/PlotPanel.js +433 -0
- package/dist/src/builder/Popover.d.ts +37 -0
- package/dist/src/builder/Popover.js +32 -0
- package/dist/src/builder/Stepper.d.ts +21 -0
- package/dist/src/builder/Stepper.js +41 -0
- package/dist/src/builder/index.d.ts +10 -0
- package/dist/src/builder/index.js +10 -0
- package/dist/src/core/adapters.d.ts +86 -0
- package/dist/src/core/adapters.js +219 -0
- package/dist/src/core/aggregate.d.ts +74 -0
- package/dist/src/core/aggregate.js +102 -0
- package/dist/src/core/annotations.d.ts +34 -0
- package/dist/src/core/annotations.js +71 -0
- package/dist/src/core/band-order.d.ts +86 -0
- package/dist/src/core/band-order.js +132 -0
- package/dist/src/core/binning.d.ts +123 -0
- package/dist/src/core/binning.js +193 -0
- package/dist/src/core/bounds.d.ts +40 -0
- package/dist/src/core/bounds.js +107 -0
- package/dist/src/core/brush.d.ts +73 -0
- package/dist/src/core/brush.js +102 -0
- package/dist/src/core/build.d.ts +322 -0
- package/dist/src/core/build.js +496 -0
- package/dist/src/core/camera.d.ts +152 -0
- package/dist/src/core/camera.js +303 -0
- package/dist/src/core/capabilities.d.ts +24 -0
- package/dist/src/core/capabilities.js +307 -0
- package/dist/src/core/chord.d.ts +49 -0
- package/dist/src/core/chord.js +57 -0
- package/dist/src/core/circular.d.ts +83 -0
- package/dist/src/core/circular.js +63 -0
- package/dist/src/core/cluster.d.ts +136 -0
- package/dist/src/core/cluster.js +607 -0
- package/dist/src/core/critique.d.ts +92 -0
- package/dist/src/core/critique.js +905 -0
- package/dist/src/core/density.d.ts +38 -0
- package/dist/src/core/density.js +82 -0
- package/dist/src/core/figure-set.d.ts +34 -0
- package/dist/src/core/figure-set.js +55 -0
- package/dist/src/core/finding-codes.d.ts +10 -0
- package/dist/src/core/finding-codes.js +1 -0
- package/dist/src/core/fit-types.d.ts +46 -0
- package/dist/src/core/fit-types.js +7 -0
- package/dist/src/core/fitter.d.ts +62 -0
- package/dist/src/core/fitter.js +102 -0
- package/dist/src/core/frame-geometry.d.ts +407 -0
- package/dist/src/core/frame-geometry.js +612 -0
- package/dist/src/core/frame.d.ts +329 -0
- package/dist/src/core/frame.js +1432 -0
- package/dist/src/core/geom-table.d.ts +503 -0
- package/dist/src/core/geom-table.js +484 -0
- package/dist/src/core/geom-types.d.ts +182 -0
- package/dist/src/core/geom-types.js +17 -0
- package/dist/src/core/grammar.d.ts +359 -0
- package/dist/src/core/grammar.js +397 -0
- package/dist/src/core/heat-reductions.d.ts +36 -0
- package/dist/src/core/heat-reductions.js +133 -0
- package/dist/src/core/hexbin.d.ts +84 -0
- package/dist/src/core/hexbin.js +168 -0
- package/dist/src/core/hierarchy.d.ts +59 -0
- package/dist/src/core/hierarchy.js +248 -0
- package/dist/src/core/hit.d.ts +75 -0
- package/dist/src/core/hit.js +37 -0
- package/dist/src/core/index.d.ts +33 -0
- package/dist/src/core/index.js +18 -0
- package/dist/src/core/internal.d.ts +58 -0
- package/dist/src/core/internal.js +58 -0
- package/dist/src/core/labels.d.ts +37 -0
- package/dist/src/core/labels.js +54 -0
- package/dist/src/core/layers.d.ts +594 -0
- package/dist/src/core/layers.js +2892 -0
- package/dist/src/core/load.d.ts +17 -0
- package/dist/src/core/load.js +356 -0
- package/dist/src/core/marginal.d.ts +65 -0
- package/dist/src/core/marginal.js +116 -0
- package/dist/src/core/mesh.d.ts +69 -0
- package/dist/src/core/mesh.js +237 -0
- package/dist/src/core/omission.d.ts +41 -0
- package/dist/src/core/omission.js +62 -0
- package/dist/src/core/palette-sets.d.ts +623 -0
- package/dist/src/core/palette-sets.js +1058 -0
- package/dist/src/core/palette.d.ts +871 -0
- package/dist/src/core/palette.js +511 -0
- package/dist/src/core/plot-data.d.ts +71 -0
- package/dist/src/core/plot-data.js +82 -0
- package/dist/src/core/predicate.d.ts +50 -0
- package/dist/src/core/predicate.js +20 -0
- package/dist/src/core/profile.d.ts +111 -0
- package/dist/src/core/profile.js +221 -0
- package/dist/src/core/readout.d.ts +108 -0
- package/dist/src/core/readout.js +215 -0
- package/dist/src/core/region.d.ts +56 -0
- package/dist/src/core/region.js +101 -0
- package/dist/src/core/rings.d.ts +96 -0
- package/dist/src/core/rings.js +171 -0
- package/dist/src/core/rules.d.ts +45 -0
- package/dist/src/core/rules.js +69 -0
- package/dist/src/core/sankey.d.ts +49 -0
- package/dist/src/core/sankey.js +96 -0
- package/dist/src/core/select.d.ts +52 -0
- package/dist/src/core/select.js +216 -0
- package/dist/src/core/side-track.d.ts +98 -0
- package/dist/src/core/side-track.js +197 -0
- package/dist/src/core/sizing.d.ts +54 -0
- package/dist/src/core/sizing.js +37 -0
- package/dist/src/core/spec-edit.d.ts +68 -0
- package/dist/src/core/spec-edit.js +105 -0
- package/dist/src/core/spec.d.ts +1111 -0
- package/dist/src/core/spec.js +39 -0
- package/dist/src/core/stats.d.ts +161 -0
- package/dist/src/core/stats.js +318 -0
- package/dist/src/core/tick-format.d.ts +21 -0
- package/dist/src/core/tick-format.js +87 -0
- package/dist/src/core/tokens.d.ts +47 -0
- package/dist/src/core/tokens.js +138 -0
- package/dist/src/core/transform.d.ts +21 -0
- package/dist/src/core/transform.js +19 -0
- package/dist/src/core/voxels.d.ts +53 -0
- package/dist/src/core/voxels.js +129 -0
- package/dist/src/core/zoom.d.ts +76 -0
- package/dist/src/core/zoom.js +103 -0
- package/dist/src/graph/GraphSurface.d.ts +127 -0
- package/dist/src/graph/GraphSurface.js +423 -0
- package/dist/src/graph/data.d.ts +103 -0
- package/dist/src/graph/data.js +140 -0
- package/dist/src/graph/index.d.ts +7 -0
- package/dist/src/graph/index.js +7 -0
- package/dist/src/mcp/data.d.ts +28 -0
- package/dist/src/mcp/data.js +131 -0
- package/dist/src/mcp/index.d.ts +7 -0
- package/dist/src/mcp/index.js +7 -0
- package/dist/src/mcp/paths.d.ts +12 -0
- package/dist/src/mcp/paths.js +30 -0
- package/dist/src/mcp/render.d.ts +67 -0
- package/dist/src/mcp/render.js +189 -0
- package/dist/src/mcp/server.d.ts +7 -0
- package/dist/src/mcp/server.js +25 -0
- package/dist/src/mcp/tools.d.ts +82 -0
- package/dist/src/mcp/tools.js +412 -0
- package/dist/src/react/BrushLayer.d.ts +20 -0
- package/dist/src/react/BrushLayer.js +98 -0
- package/dist/src/react/ColorLegend.d.ts +45 -0
- package/dist/src/react/ColorLegend.js +64 -0
- package/dist/src/react/Figure.d.ts +19 -0
- package/dist/src/react/Figure.js +6 -0
- package/dist/src/react/Frame.d.ts +87 -0
- package/dist/src/react/Frame.js +192 -0
- package/dist/src/react/MarkLegend.d.ts +32 -0
- package/dist/src/react/MarkLegend.js +24 -0
- package/dist/src/react/SeriesLegend.d.ts +38 -0
- package/dist/src/react/SeriesLegend.js +27 -0
- package/dist/src/react/SizeLegend.d.ts +24 -0
- package/dist/src/react/SizeLegend.js +25 -0
- package/dist/src/react/Toolbar.d.ts +109 -0
- package/dist/src/react/Toolbar.js +483 -0
- package/dist/src/react/Tooltip.d.ts +37 -0
- package/dist/src/react/Tooltip.js +59 -0
- package/dist/src/react/Viz.d.ts +112 -0
- package/dist/src/react/Viz.js +1311 -0
- package/dist/src/react/export.d.ts +32 -0
- package/dist/src/react/export.js +181 -0
- package/dist/src/react/geoms/Area.d.ts +38 -0
- package/dist/src/react/geoms/Area.js +48 -0
- package/dist/src/react/geoms/Bars.d.ts +130 -0
- package/dist/src/react/geoms/Bars.js +164 -0
- package/dist/src/react/geoms/Box.d.ts +50 -0
- package/dist/src/react/geoms/Box.js +32 -0
- package/dist/src/react/geoms/Chord.d.ts +60 -0
- package/dist/src/react/geoms/Chord.js +78 -0
- package/dist/src/react/geoms/Contour.d.ts +44 -0
- package/dist/src/react/geoms/Contour.js +78 -0
- package/dist/src/react/geoms/DensityCurve.d.ts +30 -0
- package/dist/src/react/geoms/DensityCurve.js +38 -0
- package/dist/src/react/geoms/FitCurve.d.ts +26 -0
- package/dist/src/react/geoms/FitCurve.js +52 -0
- package/dist/src/react/geoms/Freqpoly.d.ts +30 -0
- package/dist/src/react/geoms/Freqpoly.js +45 -0
- package/dist/src/react/geoms/Gauge.d.ts +42 -0
- package/dist/src/react/geoms/Gauge.js +90 -0
- package/dist/src/react/geoms/Heatmap.d.ts +79 -0
- package/dist/src/react/geoms/Heatmap.js +51 -0
- package/dist/src/react/geoms/Hexbin.d.ts +74 -0
- package/dist/src/react/geoms/Hexbin.js +89 -0
- package/dist/src/react/geoms/Icicle.d.ts +38 -0
- package/dist/src/react/geoms/Icicle.js +9 -0
- package/dist/src/react/geoms/Ideogram.d.ts +58 -0
- package/dist/src/react/geoms/Ideogram.js +77 -0
- package/dist/src/react/geoms/Interval.d.ts +28 -0
- package/dist/src/react/geoms/Interval.js +39 -0
- package/dist/src/react/geoms/Line.d.ts +39 -0
- package/dist/src/react/geoms/Line.js +52 -0
- package/dist/src/react/geoms/Parallel.d.ts +38 -0
- package/dist/src/react/geoms/Parallel.js +131 -0
- package/dist/src/react/geoms/Pie.d.ts +62 -0
- package/dist/src/react/geoms/Pie.js +59 -0
- package/dist/src/react/geoms/Points.d.ts +84 -0
- package/dist/src/react/geoms/Points.js +207 -0
- package/dist/src/react/geoms/Points3d.d.ts +49 -0
- package/dist/src/react/geoms/Points3d.js +58 -0
- package/dist/src/react/geoms/Radar.d.ts +39 -0
- package/dist/src/react/geoms/Radar.js +59 -0
- package/dist/src/react/geoms/Range.d.ts +31 -0
- package/dist/src/react/geoms/Range.js +20 -0
- package/dist/src/react/geoms/RingStack.d.ts +39 -0
- package/dist/src/react/geoms/RingStack.js +65 -0
- package/dist/src/react/geoms/Rule.d.ts +29 -0
- package/dist/src/react/geoms/Rule.js +51 -0
- package/dist/src/react/geoms/Sankey.d.ts +24 -0
- package/dist/src/react/geoms/Sankey.js +51 -0
- package/dist/src/react/geoms/Segment.d.ts +36 -0
- package/dist/src/react/geoms/Segment.js +39 -0
- package/dist/src/react/geoms/Sunburst.d.ts +46 -0
- package/dist/src/react/geoms/Sunburst.js +64 -0
- package/dist/src/react/geoms/Surface.d.ts +32 -0
- package/dist/src/react/geoms/Surface.js +49 -0
- package/dist/src/react/geoms/Text.d.ts +35 -0
- package/dist/src/react/geoms/Text.js +40 -0
- package/dist/src/react/geoms/Treemap.d.ts +39 -0
- package/dist/src/react/geoms/Treemap.js +16 -0
- package/dist/src/react/geoms/Violin.d.ts +56 -0
- package/dist/src/react/geoms/Violin.js +60 -0
- package/dist/src/react/geoms/Volume.d.ts +37 -0
- package/dist/src/react/geoms/Volume.js +40 -0
- package/dist/src/react/geoms/Waterfall.d.ts +43 -0
- package/dist/src/react/geoms/Waterfall.js +18 -0
- package/dist/src/react/geoms/cube-stage.d.ts +39 -0
- package/dist/src/react/geoms/cube-stage.js +85 -0
- package/dist/src/react/geoms/hierarchy-cells.d.ts +42 -0
- package/dist/src/react/geoms/hierarchy-cells.js +59 -0
- package/dist/src/react/geoms/sector-axis.d.ts +66 -0
- package/dist/src/react/geoms/sector-axis.js +99 -0
- package/dist/src/react/gl/GlMesh.d.ts +22 -0
- package/dist/src/react/gl/GlMesh.js +78 -0
- package/dist/src/react/gl/GlPoints.d.ts +45 -0
- package/dist/src/react/gl/GlPoints.js +117 -0
- package/dist/src/react/gl/GlVolume.d.ts +28 -0
- package/dist/src/react/gl/GlVolume.js +112 -0
- package/dist/src/react/gl/GlWalls.d.ts +24 -0
- package/dist/src/react/gl/GlWalls.js +55 -0
- package/dist/src/react/gl/context.d.ts +71 -0
- package/dist/src/react/gl/context.js +98 -0
- package/dist/src/react/gl/encode.d.ts +120 -0
- package/dist/src/react/gl/encode.js +215 -0
- package/dist/src/react/gl/index.d.ts +10 -0
- package/dist/src/react/gl/index.js +8 -0
- package/dist/src/react/gl/refresh.d.ts +7 -0
- package/dist/src/react/gl/refresh.js +19 -0
- package/dist/src/react/gl/renderer.d.ts +377 -0
- package/dist/src/react/gl/renderer.js +1081 -0
- package/dist/src/react/gl/shaders.d.ts +92 -0
- package/dist/src/react/gl/shaders.js +405 -0
- package/dist/src/react/gl/surface.d.ts +31 -0
- package/dist/src/react/gl/surface.js +73 -0
- package/dist/src/react/index.d.ts +12 -0
- package/dist/src/react/index.js +11 -0
- package/dist/src/react/orbit.d.ts +38 -0
- package/dist/src/react/orbit.js +81 -0
- package/dist/src/react/sides/DendrogramPanel.d.ts +32 -0
- package/dist/src/react/sides/DendrogramPanel.js +39 -0
- package/dist/src/react/sides/DensityPanel.d.ts +31 -0
- package/dist/src/react/sides/DensityPanel.js +37 -0
- package/dist/src/react/sides/HistogramPanel.d.ts +30 -0
- package/dist/src/react/sides/HistogramPanel.js +18 -0
- package/dist/src/react/sides/RugPanel.d.ts +28 -0
- package/dist/src/react/sides/RugPanel.js +21 -0
- package/dist/src/react/sides/TrackPanel.d.ts +37 -0
- package/dist/src/react/sides/TrackPanel.js +27 -0
- package/dist/src/react/theme.d.ts +48 -0
- package/dist/src/react/theme.js +148 -0
- package/dist/src/react/useFits.d.ts +26 -0
- package/dist/src/react/useFits.js +62 -0
- package/dist/src/react/useZoom.d.ts +50 -0
- package/dist/src/react/useZoom.js +141 -0
- package/package.json +164 -5
- package/theme/default.css +62 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The fitter, held against a chart's lifetime.
|
|
3
|
+
*
|
|
4
|
+
* A curve arrives long after the geoms do, so this is the one place that knows a chart can be
|
|
5
|
+
* drawn and correct while its fits are still in flight. What it turns a `Fitter` into is the
|
|
6
|
+
* `FitState` the frame derivation already reads, which is why nothing downstream has to learn that
|
|
7
|
+
* the answer came over a wire.
|
|
8
|
+
*
|
|
9
|
+
* Refits on `fitSignature` and on nothing else. A chart re-renders on a hover, a theme flip, a
|
|
10
|
+
* recolor and a resize, and a curve survives all of them; keying the effect on the signature is
|
|
11
|
+
* what keeps a pointer moving across a scatter from putting a solver under load.
|
|
12
|
+
*
|
|
13
|
+
* The fitter is read through a ref, so one written inline asks nothing new. A host swapping services
|
|
14
|
+
* under an unchanged signature changes the chart's `key`.
|
|
15
|
+
*/
|
|
16
|
+
import { useEffect, useRef, useState } from "react";
|
|
17
|
+
import { fitSignature } from "../core/internal.js";
|
|
18
|
+
/** No fit asked for, none in flight, nothing wrong. */
|
|
19
|
+
const IDLE = { byLayer: new Map(), pending: false, problem: null };
|
|
20
|
+
/** What the footer says when the service refused, in the words the service used where it gave any. */
|
|
21
|
+
const problemOf = (error) => error instanceof Error && error.message ? error.message : "fit unavailable";
|
|
22
|
+
/**
|
|
23
|
+
* Fits for the requests a frame produced.
|
|
24
|
+
*
|
|
25
|
+
* Idle where the consumer passed no fitter, which is the ordinary case: a chart with no `fit` on
|
|
26
|
+
* any series asks for nothing, and a chart that asks stays drawn and uncurved until a fitter
|
|
27
|
+
* reaches it. A response that lands after its question was replaced is dropped, so a slow answer to
|
|
28
|
+
* an old signature cannot overwrite a fast answer to the current one.
|
|
29
|
+
*/
|
|
30
|
+
export function useFits(requests, fitter) {
|
|
31
|
+
const signature = fitSignature(requests);
|
|
32
|
+
const [state, setState] = useState(IDLE);
|
|
33
|
+
/*
|
|
34
|
+
The requests themselves stay out of the effect's dependencies, since they are a new array on
|
|
35
|
+
each render and the signature is the question of whether they mean anything different.
|
|
36
|
+
*/
|
|
37
|
+
const latest = useRef(requests);
|
|
38
|
+
latest.current = requests;
|
|
39
|
+
const asked = useRef(fitter);
|
|
40
|
+
asked.current = fitter;
|
|
41
|
+
const fitting = fitter != null;
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
const current = asked.current;
|
|
44
|
+
if (!current || signature === "") {
|
|
45
|
+
setState(IDLE);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
let live = true;
|
|
49
|
+
setState({ byLayer: new Map(), pending: true, problem: null });
|
|
50
|
+
void current(latest.current).then((byLayer) => {
|
|
51
|
+
if (live)
|
|
52
|
+
setState({ byLayer, pending: false, problem: null });
|
|
53
|
+
}, (error) => {
|
|
54
|
+
if (live)
|
|
55
|
+
setState({ byLayer: new Map(), pending: false, problem: problemOf(error) });
|
|
56
|
+
});
|
|
57
|
+
return () => {
|
|
58
|
+
live = false;
|
|
59
|
+
};
|
|
60
|
+
}, [signature, fitting]);
|
|
61
|
+
return state;
|
|
62
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A wheel and a drag, in the shape the domain arithmetic reads.
|
|
3
|
+
*
|
|
4
|
+
* `zoomedAxes` has been able to turn a transform into the slice of a domain it leaves visible since
|
|
5
|
+
* the zoom was written, and nothing produced a transform. This is that half: the gesture, held
|
|
6
|
+
* inside the data it is reading, and no opinion about what a chart does with the result.
|
|
7
|
+
*
|
|
8
|
+
* It reports a transform and not a set of scales, which is what keeps the arithmetic in `/core` and
|
|
9
|
+
* testable without a pointer. See the ADR "A zoom rewrites the domain".
|
|
10
|
+
*/
|
|
11
|
+
import { type ZoomTransform } from "../core/internal.js";
|
|
12
|
+
type Area = {
|
|
13
|
+
left: number;
|
|
14
|
+
top: number;
|
|
15
|
+
right: number;
|
|
16
|
+
bottom: number;
|
|
17
|
+
};
|
|
18
|
+
export interface ZoomView {
|
|
19
|
+
/** Put this on the element the gesture is read against. */
|
|
20
|
+
surface: React.RefObject<HTMLDivElement | null>;
|
|
21
|
+
transform: ZoomTransform;
|
|
22
|
+
/** Whether the view has moved off rest, which is what decides whether the geoms want clipping. */
|
|
23
|
+
zoomed: boolean;
|
|
24
|
+
reset: () => void;
|
|
25
|
+
/** One step in or out about the plot area's center. */
|
|
26
|
+
zoomBy: (factor: number, area: Area) => void;
|
|
27
|
+
/** Fills the plot area with a box in the gesture's pixels. */
|
|
28
|
+
zoomTo: (box: Area, area: Area) => void;
|
|
29
|
+
/** Spread onto the same element. The wheel attaches itself; these cannot. */
|
|
30
|
+
handlers: {
|
|
31
|
+
onPointerDown: (event: React.PointerEvent) => void;
|
|
32
|
+
onPointerMove: (event: React.PointerEvent) => void;
|
|
33
|
+
onPointerUp: (event: React.PointerEvent) => void;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Whether the press that just ended was a pan.
|
|
37
|
+
*
|
|
38
|
+
* A drag across a scatter ends over a geom, and the click that follows would select it. The flag
|
|
39
|
+
* holds until the next press, so the click belonging to a pan is the only one it suppresses.
|
|
40
|
+
*/
|
|
41
|
+
panned: () => boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A viewport over a panel of this size.
|
|
45
|
+
*
|
|
46
|
+
* The box is the panel and not the plot area, since a gesture is read against the element it landed
|
|
47
|
+
* on and `zoomedAxes` carries the margin between the two. With `pan` off, a drag belongs to a brush.
|
|
48
|
+
*/
|
|
49
|
+
export declare function useZoom(enabled: boolean, width: number, height: number, pan?: boolean, wheel?: boolean): ZoomView;
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A wheel and a drag, in the shape the domain arithmetic reads.
|
|
3
|
+
*
|
|
4
|
+
* `zoomedAxes` has been able to turn a transform into the slice of a domain it leaves visible since
|
|
5
|
+
* the zoom was written, and nothing produced a transform. This is that half: the gesture, held
|
|
6
|
+
* inside the data it is reading, and no opinion about what a chart does with the result.
|
|
7
|
+
*
|
|
8
|
+
* It reports a transform and not a set of scales, which is what keeps the arithmetic in `/core` and
|
|
9
|
+
* testable without a pointer. See the ADR "A zoom rewrites the domain".
|
|
10
|
+
*/
|
|
11
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
12
|
+
import { AT_REST_ZOOM, isZoomed, MAX_SCALE, zoomedBy, zoomedTo } from "../core/internal.js";
|
|
13
|
+
/** How hard one notch of wheel closes in. Exponential, so a trackpad and a mouse read alike. */
|
|
14
|
+
const PER_NOTCH = 0.002;
|
|
15
|
+
/** Pointer travel that makes a press a pan and not a click, in pixels. */
|
|
16
|
+
const PAN_FLOOR = 3;
|
|
17
|
+
/**
|
|
18
|
+
* The transform held inside the data it reads.
|
|
19
|
+
*
|
|
20
|
+
* Scale below one would show a reader padding around a domain that already fits, and a translate
|
|
21
|
+
* past either end would put empty frame beside the geoms. Both are held here and not at the two
|
|
22
|
+
* gestures, so a wheel and a drag cannot disagree about where the edge of the data is.
|
|
23
|
+
*/
|
|
24
|
+
function held(next, width, height) {
|
|
25
|
+
const scaleX = Math.min(MAX_SCALE, Math.max(1, next.scaleX));
|
|
26
|
+
const scaleY = Math.min(MAX_SCALE, Math.max(1, next.scaleY));
|
|
27
|
+
return {
|
|
28
|
+
scaleX,
|
|
29
|
+
scaleY,
|
|
30
|
+
translateX: Math.min(0, Math.max(-(scaleX - 1) * width, next.translateX)),
|
|
31
|
+
translateY: Math.min(0, Math.max(-(scaleY - 1) * height, next.translateY)),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A viewport over a panel of this size.
|
|
36
|
+
*
|
|
37
|
+
* The box is the panel and not the plot area, since a gesture is read against the element it landed
|
|
38
|
+
* on and `zoomedAxes` carries the margin between the two. With `pan` off, a drag belongs to a brush.
|
|
39
|
+
*/
|
|
40
|
+
export function useZoom(enabled, width, height, pan = true, wheel = true) {
|
|
41
|
+
const surface = useRef(null);
|
|
42
|
+
const [transform, setTransform] = useState(AT_REST_ZOOM);
|
|
43
|
+
/*
|
|
44
|
+
One render per frame, however many wheel and pointer events arrive in it.
|
|
45
|
+
|
|
46
|
+
The first event of a frame renders at once and the rest land in `live`, which the frame's end
|
|
47
|
+
renders. A trackpad sends several events a frame, and each one rebuilt the scales.
|
|
48
|
+
*/
|
|
49
|
+
const live = useRef(AT_REST_ZOOM);
|
|
50
|
+
const queued = useRef(false);
|
|
51
|
+
const move = useCallback((next) => {
|
|
52
|
+
live.current = next(live.current);
|
|
53
|
+
if (queued.current)
|
|
54
|
+
return;
|
|
55
|
+
setTransform(live.current);
|
|
56
|
+
queued.current = true;
|
|
57
|
+
const flush = () => {
|
|
58
|
+
queued.current = false;
|
|
59
|
+
setTransform(live.current);
|
|
60
|
+
};
|
|
61
|
+
if (typeof requestAnimationFrame === "function")
|
|
62
|
+
requestAnimationFrame(flush);
|
|
63
|
+
else
|
|
64
|
+
setTimeout(flush, 16);
|
|
65
|
+
}, []);
|
|
66
|
+
const reset = useCallback(() => {
|
|
67
|
+
live.current = AT_REST_ZOOM;
|
|
68
|
+
setTransform(AT_REST_ZOOM);
|
|
69
|
+
}, []);
|
|
70
|
+
const zoomBy = useCallback((factor, area) => move((from) => held(zoomedBy(from, factor, area), width, height)), [move, width, height]);
|
|
71
|
+
const zoomTo = useCallback((box, area) => move((from) => held(zoomedTo(from, box, area), width, height)), [move, width, height]);
|
|
72
|
+
/* Back to rest wherever the caller turns the gesture off, so a prop cannot leave a figure zoomed. */
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (!enabled)
|
|
75
|
+
reset();
|
|
76
|
+
}, [enabled, reset]);
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
const element = surface.current;
|
|
79
|
+
if (!element || !enabled || !wheel)
|
|
80
|
+
return;
|
|
81
|
+
/*
|
|
82
|
+
Attached here and not through `onWheel`, because React registers that one passive and
|
|
83
|
+
`preventDefault` on a passive listener is ignored: the chart would zoom and the page would
|
|
84
|
+
scroll under it at the same time.
|
|
85
|
+
*/
|
|
86
|
+
const onWheel = (event) => {
|
|
87
|
+
event.preventDefault();
|
|
88
|
+
const box = element.getBoundingClientRect();
|
|
89
|
+
const at = { x: event.clientX - box.left, y: event.clientY - box.top };
|
|
90
|
+
const factor = Math.exp(-event.deltaY * PER_NOTCH);
|
|
91
|
+
move((from) => held({
|
|
92
|
+
scaleX: from.scaleX * factor,
|
|
93
|
+
scaleY: from.scaleY * factor,
|
|
94
|
+
/* The value under the cursor stays under it, which is what makes a wheel read as a zoom. */
|
|
95
|
+
translateX: at.x - (at.x - from.translateX) * factor,
|
|
96
|
+
translateY: at.y - (at.y - from.translateY) * factor,
|
|
97
|
+
}, width, height));
|
|
98
|
+
};
|
|
99
|
+
element.addEventListener("wheel", onWheel, { passive: false });
|
|
100
|
+
return () => element.removeEventListener("wheel", onWheel);
|
|
101
|
+
}, [enabled, wheel, width, height, move]);
|
|
102
|
+
const from = useRef(null);
|
|
103
|
+
const moved = useRef(false);
|
|
104
|
+
const onPointerDown = useCallback((event) => {
|
|
105
|
+
if (!enabled || !pan)
|
|
106
|
+
return;
|
|
107
|
+
from.current = { x: event.clientX, y: event.clientY };
|
|
108
|
+
moved.current = false;
|
|
109
|
+
/* Capture keeps the drag alive past the edge of the panel where the host has it. */
|
|
110
|
+
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
111
|
+
}, [enabled, pan]);
|
|
112
|
+
const onPointerMove = useCallback((event) => {
|
|
113
|
+
/* A gesture turned off mid-drag drops the drag with it. */
|
|
114
|
+
if (!enabled)
|
|
115
|
+
from.current = null;
|
|
116
|
+
const start = from.current;
|
|
117
|
+
if (!start)
|
|
118
|
+
return;
|
|
119
|
+
const dx = event.clientX - start.x;
|
|
120
|
+
const dy = event.clientY - start.y;
|
|
121
|
+
if (Math.abs(dx) >= PAN_FLOOR || Math.abs(dy) >= PAN_FLOOR)
|
|
122
|
+
moved.current = true;
|
|
123
|
+
from.current = { x: event.clientX, y: event.clientY };
|
|
124
|
+
move((at) => held({ ...at, translateX: at.translateX + dx, translateY: at.translateY + dy }, width, height));
|
|
125
|
+
}, [enabled, width, height, move]);
|
|
126
|
+
const onPointerUp = useCallback((event) => {
|
|
127
|
+
from.current = null;
|
|
128
|
+
event.currentTarget.releasePointerCapture?.(event.pointerId);
|
|
129
|
+
}, []);
|
|
130
|
+
const panned = useCallback(() => moved.current, []);
|
|
131
|
+
return {
|
|
132
|
+
surface,
|
|
133
|
+
transform,
|
|
134
|
+
zoomed: isZoomed(transform),
|
|
135
|
+
reset,
|
|
136
|
+
zoomBy,
|
|
137
|
+
zoomTo,
|
|
138
|
+
handlers: { onPointerDown, onPointerMove, onPointerUp },
|
|
139
|
+
panned,
|
|
140
|
+
};
|
|
141
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,165 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@tetrascience-npm/ts-lib-viz",
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/tetrascience/ts-lib-viz.git"
|
|
8
|
+
},
|
|
9
|
+
"packageManager": "yarn@4.1.0",
|
|
10
|
+
"workspaces": [
|
|
11
|
+
"demo"
|
|
12
|
+
],
|
|
13
|
+
"type": "module",
|
|
14
|
+
"sideEffects": [
|
|
15
|
+
"**/*.css"
|
|
16
|
+
],
|
|
17
|
+
"files": [
|
|
18
|
+
"dist/src/**/*.js",
|
|
19
|
+
"dist/src/**/*.d.ts",
|
|
20
|
+
"theme/*.css"
|
|
21
|
+
],
|
|
22
|
+
"exports": {
|
|
23
|
+
"./core": {
|
|
24
|
+
"types": "./dist/src/core/index.d.ts",
|
|
25
|
+
"default": "./dist/src/core/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./react": {
|
|
28
|
+
"types": "./dist/src/react/index.d.ts",
|
|
29
|
+
"default": "./dist/src/react/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./builder": {
|
|
32
|
+
"types": "./dist/src/builder/index.d.ts",
|
|
33
|
+
"default": "./dist/src/builder/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./graph": {
|
|
36
|
+
"types": "./dist/src/graph/index.d.ts",
|
|
37
|
+
"default": "./dist/src/graph/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./mcp": {
|
|
40
|
+
"types": "./dist/src/mcp/index.d.ts",
|
|
41
|
+
"node": "./dist/src/mcp/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./theme.css": "./theme/default.css",
|
|
44
|
+
"./package.json": "./package.json"
|
|
45
|
+
},
|
|
46
|
+
"typesVersions": {
|
|
47
|
+
"*": {
|
|
48
|
+
"core": [
|
|
49
|
+
"./dist/src/core/index.d.ts"
|
|
50
|
+
],
|
|
51
|
+
"react": [
|
|
52
|
+
"./dist/src/react/index.d.ts"
|
|
53
|
+
],
|
|
54
|
+
"builder": [
|
|
55
|
+
"./dist/src/builder/index.d.ts"
|
|
56
|
+
],
|
|
57
|
+
"graph": [
|
|
58
|
+
"./dist/src/graph/index.d.ts"
|
|
59
|
+
],
|
|
60
|
+
"mcp": [
|
|
61
|
+
"./dist/src/mcp/index.d.ts"
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"bin": {
|
|
66
|
+
"ts-lib-viz-mcp": "./dist/src/mcp/server.js"
|
|
67
|
+
},
|
|
68
|
+
"engines": {
|
|
69
|
+
"node": ">=18"
|
|
70
|
+
},
|
|
71
|
+
"devDependencies": {
|
|
72
|
+
"@cosmos.gl/graph": "^3.3.0",
|
|
73
|
+
"@luma.gl/core": "~9.3.6",
|
|
74
|
+
"@luma.gl/webgl": "~9.3.6",
|
|
75
|
+
"@testing-library/dom": "^10.4.1",
|
|
76
|
+
"@testing-library/react": "^16.3.2",
|
|
77
|
+
"@tetrascience-npm/tetrascience-react-ui": "^1.0.0",
|
|
78
|
+
"@types/d3-contour": "^3.0.6",
|
|
79
|
+
"@types/d3-format": "^3.0.4",
|
|
80
|
+
"@types/d3-quadtree": "^3.0.6",
|
|
81
|
+
"@types/d3-scale": "^4.0.9",
|
|
82
|
+
"@types/jsdom": "^30",
|
|
83
|
+
"@types/node": "^20.11.17",
|
|
84
|
+
"@types/react": "^19.2.18",
|
|
85
|
+
"@types/react-dom": "^19.2.4",
|
|
86
|
+
"@typescript-eslint/eslint-plugin": "^5.59.11",
|
|
87
|
+
"@typescript-eslint/parser": "^5.59.11",
|
|
88
|
+
"@uwdata/flechette": "^2.5.0",
|
|
89
|
+
"@vitest/coverage-v8": "^4.1.11",
|
|
90
|
+
"eslint": "^8.49.0",
|
|
91
|
+
"eslint-config-prettier": "^9.0.0",
|
|
92
|
+
"eslint-plugin-react-hooks": "^4.6.2",
|
|
93
|
+
"husky": "^8.0.3",
|
|
94
|
+
"jsdom": "^30.0.1",
|
|
95
|
+
"lint-staged": "^14.0.1",
|
|
96
|
+
"lucide-react": "^1.33.0",
|
|
97
|
+
"prettier": "^3.0.3",
|
|
98
|
+
"react": "^19.2.8",
|
|
99
|
+
"react-dom": "^19.2.8",
|
|
100
|
+
"typescript": "^5.3.3",
|
|
101
|
+
"vitest": "^4.1.11"
|
|
102
|
+
},
|
|
103
|
+
"scripts": {
|
|
104
|
+
"lint": "eslint .",
|
|
105
|
+
"test": "vitest run",
|
|
106
|
+
"test:watch": "vitest",
|
|
107
|
+
"test:coverage": "vitest run --coverage",
|
|
108
|
+
"build": "tsc -p tsconfig.build.json",
|
|
109
|
+
"clean": "tsc -b tsconfig.build.json --clean",
|
|
110
|
+
"check": "tsc --noEmit && tsc -p tsconfig.demo.json",
|
|
111
|
+
"prepare": "husky install || exit 0",
|
|
112
|
+
"docs:figures": "node docs/figures.mjs",
|
|
113
|
+
"palettes": "Rscript scripts/palette-sets.R > src/core/palette-sets.ts && prettier --write src/core/palette-sets.ts",
|
|
114
|
+
"check:demo": "tsc -p tsconfig.demo.json",
|
|
115
|
+
"verify": "node verify/run.mjs"
|
|
116
|
+
},
|
|
117
|
+
"prettier": {
|
|
118
|
+
"printWidth": 120,
|
|
119
|
+
"useTabs": true,
|
|
120
|
+
"bracketSpacing": false,
|
|
121
|
+
"trailingComma": "all"
|
|
122
|
+
},
|
|
123
|
+
"lint-staged": {
|
|
124
|
+
"*.{yml,yaml,json,js,ts,tsx,css,md,html}": "prettier --write"
|
|
125
|
+
},
|
|
126
|
+
"dependencies": {
|
|
127
|
+
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
128
|
+
"@resvg/resvg-js": "^2.6.2",
|
|
129
|
+
"@visx/annotation": "^4.0.0",
|
|
130
|
+
"d3-contour": "^4.0.2",
|
|
131
|
+
"d3-format": "^3.1.2",
|
|
132
|
+
"d3-quadtree": "^3.0.1",
|
|
133
|
+
"d3-scale": "^4.0.2",
|
|
134
|
+
"zod": "^3.25 || ^4.0"
|
|
135
|
+
},
|
|
136
|
+
"peerDependencies": {
|
|
137
|
+
"@cosmos.gl/graph": "^3.3.0",
|
|
138
|
+
"@luma.gl/webgl": "~9.3.6",
|
|
139
|
+
"@tetrascience-npm/tetrascience-react-ui": "^1.0.0",
|
|
140
|
+
"lucide-react": "^0.577.0 || ^1.0.0",
|
|
141
|
+
"react": "^18 || ^19",
|
|
142
|
+
"react-dom": "^18 || ^19"
|
|
143
|
+
},
|
|
144
|
+
"resolutions": {
|
|
145
|
+
"@tetrascience-npm/ts-connectors-sdk/uuid": "^11.1.1",
|
|
146
|
+
"@ai-sdk/provider-utils/undici": "^6.28.1",
|
|
147
|
+
"js-yaml": "^4.3.2",
|
|
148
|
+
"get-uri/basic-ftp": "^6.2.1",
|
|
149
|
+
"escodegen/source-map": "npm:source-map-js@^1.2.2"
|
|
150
|
+
},
|
|
151
|
+
"peerDependenciesMeta": {
|
|
152
|
+
"@cosmos.gl/graph": {
|
|
153
|
+
"optional": true
|
|
154
|
+
},
|
|
155
|
+
"@luma.gl/webgl": {
|
|
156
|
+
"optional": true
|
|
157
|
+
},
|
|
158
|
+
"@tetrascience-npm/tetrascience-react-ui": {
|
|
159
|
+
"optional": true
|
|
160
|
+
},
|
|
161
|
+
"lucide-react": {
|
|
162
|
+
"optional": true
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The values the package ships.
|
|
3
|
+
*
|
|
4
|
+
* Import once near the root of a consuming app. A host restyles a chart by declaring any of these
|
|
5
|
+
* properties further down the tree; nothing in the package names a color, so overriding the token
|
|
6
|
+
* is the whole of the mechanism.
|
|
7
|
+
*
|
|
8
|
+
* There is no chart background token. A chart draws on a transparent background per chart-design
|
|
9
|
+
* rule 3, and `--viz-paper` is the color of the page it is sitting on, read for the gap between
|
|
10
|
+
* stacked segments and the hairline around a large point.
|
|
11
|
+
*
|
|
12
|
+
* The tooltip tokens are the one surface the package does paint, because the hover card floats over
|
|
13
|
+
* marks and has to separate from them. It stays dark under both schemes, which is the treatment the
|
|
14
|
+
* reference charts record; a host that would sooner have the card match its own popover points
|
|
15
|
+
* these four at its surface colors.
|
|
16
|
+
*
|
|
17
|
+
* The dark values are declared twice and the media query is scoped. A host with its own switch
|
|
18
|
+
* writes `.dark` on the root and wants that to win; a host without one wants the system setting.
|
|
19
|
+
* Declaring the dark values in the media query alone left a light override unable to reach them,
|
|
20
|
+
* which is the `:root:not(.light)` guard below.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
:root {
|
|
24
|
+
--viz-paper: #ffffff;
|
|
25
|
+
--viz-ink: #171717;
|
|
26
|
+
--viz-ink-muted: #737373;
|
|
27
|
+
--viz-rule: #e5e5e5;
|
|
28
|
+
--viz-annotation: #404040;
|
|
29
|
+
--viz-leader: #a3a3a3;
|
|
30
|
+
--viz-status-fail: #dc2626;
|
|
31
|
+
--viz-status-warn: #d97706;
|
|
32
|
+
--viz-tooltip-bg: #171717;
|
|
33
|
+
--viz-tooltip-ink: #ffffff;
|
|
34
|
+
--viz-tooltip-ink-muted: #d4d4d4;
|
|
35
|
+
--viz-tooltip-ring: #ffffff1a;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@media (prefers-color-scheme: dark) {
|
|
39
|
+
:root:not(.light) {
|
|
40
|
+
--viz-paper: #0a0a0a;
|
|
41
|
+
--viz-ink: #fafafa;
|
|
42
|
+
--viz-ink-muted: #a3a3a3;
|
|
43
|
+
--viz-rule: #262626;
|
|
44
|
+
--viz-annotation: #d4d4d4;
|
|
45
|
+
--viz-leader: #525252;
|
|
46
|
+
--viz-status-fail: #f87171;
|
|
47
|
+
--viz-status-warn: #fbbf24;
|
|
48
|
+
--viz-tooltip-bg: #262626;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.dark {
|
|
53
|
+
--viz-paper: #0a0a0a;
|
|
54
|
+
--viz-ink: #fafafa;
|
|
55
|
+
--viz-ink-muted: #a3a3a3;
|
|
56
|
+
--viz-rule: #262626;
|
|
57
|
+
--viz-annotation: #d4d4d4;
|
|
58
|
+
--viz-leader: #525252;
|
|
59
|
+
--viz-status-fail: #f87171;
|
|
60
|
+
--viz-status-warn: #fbbf24;
|
|
61
|
+
--viz-tooltip-bg: #262626;
|
|
62
|
+
}
|