@sophistry/charts 0.0.0-stage → 0.1.0
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 +21 -0
- package/README.md +32 -2
- package/dist/3d/bar-chart3d.d.ts +55 -0
- package/dist/3d/definitions.d.ts +37 -0
- package/dist/3d/definitions.js +14 -0
- package/dist/3d/forward.d.ts +64 -0
- package/dist/3d/index.d.ts +30 -0
- package/dist/3d/index.js +1 -0
- package/dist/3d/quiver3d.d.ts +52 -0
- package/dist/3d/scatter3d.d.ts +44 -0
- package/dist/3d/stem3d.d.ts +45 -0
- package/dist/3d/surface-grid3d.d.ts +33 -0
- package/dist/3d/tri-surface3d.d.ts +45 -0
- package/dist/3d/voxels3d.d.ts +25 -0
- package/dist/3d/wireframe3d.d.ts +30 -0
- package/dist/band.d.ts +20 -0
- package/dist/bars/bar-chart.d.ts +143 -0
- package/dist/bars/bar-labels.d.ts +116 -0
- package/dist/bars/bars.d.ts +223 -0
- package/dist/bars/bullet.d.ts +157 -0
- package/dist/bars/candlestick.d.ts +97 -0
- package/dist/bars/funnel.d.ts +90 -0
- package/dist/bars/histogram.d.ts +108 -0
- package/dist/bars/index.d.ts +22 -0
- package/dist/bars/race.d.ts +28 -0
- package/dist/bars/rules.d.ts +121 -0
- package/dist/bars/shared.d.ts +41 -0
- package/dist/bars/transforms.d.ts +249 -0
- package/dist/bars/waterfall.d.ts +106 -0
- package/dist/batch.d.ts +142 -0
- package/dist/channels-_Xf-p6Lx.js +56 -0
- package/dist/chart.d.ts +87 -0
- package/dist/color-norm.d.ts +90 -0
- package/dist/context.d.ts +111 -0
- package/dist/curves/density.d.ts +125 -0
- package/dist/curves/ecdf.d.ts +72 -0
- package/dist/curves/fill-between.d.ts +100 -0
- package/dist/curves/index.d.ts +15 -0
- package/dist/curves/line-plot.d.ts +104 -0
- package/dist/curves/regression.d.ts +124 -0
- package/dist/curves/shared.d.ts +52 -0
- package/dist/curves/stack-plot.d.ts +140 -0
- package/dist/curves/stairs.d.ts +170 -0
- package/dist/data/channels.d.ts +170 -0
- package/dist/end-space.d.ts +81 -0
- package/dist/entries/definitions.d.ts +20 -0
- package/dist/entries/definitions.js +6 -0
- package/dist/frame/band-axis.d.ts +42 -0
- package/dist/frame/coords.d.ts +111 -0
- package/dist/frame/fit.d.ts +170 -0
- package/dist/frame/format.d.ts +40 -0
- package/dist/frame/guide-metrics.d.ts +36 -0
- package/dist/frame/guides.d.ts +67 -0
- package/dist/frame/keys.d.ts +96 -0
- package/dist/frame/layout.d.ts +145 -0
- package/dist/frame/registry.d.ts +31 -0
- package/dist/frame/reports.d.ts +53 -0
- package/dist/frame/secondary-axes.d.ts +73 -0
- package/dist/frame/secondary.d.ts +56 -0
- package/dist/frame/tooltip-overlay.d.ts +64 -0
- package/dist/frame/types.d.ts +658 -0
- package/dist/grids/barbs.d.ts +51 -0
- package/dist/grids/cell-rects.d.ts +37 -0
- package/dist/grids/cells.d.ts +130 -0
- package/dist/grids/contour-f.d.ts +80 -0
- package/dist/grids/contour-shared.d.ts +53 -0
- package/dist/grids/contour.d.ts +84 -0
- package/dist/grids/dendrogram.d.ts +104 -0
- package/dist/grids/heatmap.d.ts +163 -0
- package/dist/grids/hex-bin.d.ts +93 -0
- package/dist/grids/hist2d.d.ts +107 -0
- package/dist/grids/imshow.d.ts +84 -0
- package/dist/grids/index.d.ts +26 -0
- package/dist/grids/pcolormesh.d.ts +90 -0
- package/dist/grids/ramp-cells.d.ts +66 -0
- package/dist/grids/tri-contour.d.ts +120 -0
- package/dist/grids/tri-shared.d.ts +61 -0
- package/dist/grids/tripcolor.d.ts +73 -0
- package/dist/guides/colorbar.d.ts +110 -0
- package/dist/guides/index.d.ts +11 -0
- package/dist/guides/legend.d.ts +118 -0
- package/dist/guides/nodes.d.ts +13 -0
- package/dist/guides/size-legend.d.ts +233 -0
- package/dist/hierarchy/breadcrumbs.d.ts +133 -0
- package/dist/hierarchy/circle-pack.d.ts +72 -0
- package/dist/hierarchy/drill.d.ts +245 -0
- package/dist/hierarchy/frame.d.ts +67 -0
- package/dist/hierarchy/icicle.d.ts +76 -0
- package/dist/hierarchy/index.d.ts +20 -0
- package/dist/hierarchy/labels.d.ts +24 -0
- package/dist/hierarchy/mosaic.d.ts +130 -0
- package/dist/hierarchy/own-tooltip.d.ts +12 -0
- package/dist/hierarchy/props.d.ts +13 -0
- package/dist/hierarchy/sankey.d.ts +132 -0
- package/dist/hierarchy/shared.d.ts +247 -0
- package/dist/hierarchy/sunburst.d.ts +74 -0
- package/dist/hierarchy/tree.d.ts +124 -0
- package/dist/hierarchy/treemap.d.ts +76 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +5 -0
- package/dist/item-tooltip.d.ts +33 -0
- package/dist/join.d.ts +223 -0
- package/dist/math/3d/bar3d.d.ts +27 -0
- package/dist/math/3d/quiver3d.d.ts +26 -0
- package/dist/math/3d/scatter3d.d.ts +15 -0
- package/dist/math/3d/stem3d.d.ts +22 -0
- package/dist/math/3d/surfaceGrid3d.d.ts +33 -0
- package/dist/math/3d/trisurface.d.ts +11 -0
- package/dist/math/3d/voxels.d.ts +17 -0
- package/dist/math/aggregate.d.ts +68 -0
- package/dist/math/bar.d.ts +31 -0
- package/dist/math/barLabels.d.ts +83 -0
- package/dist/math/barbs.d.ts +36 -0
- package/dist/math/boxplot.d.ts +36 -0
- package/dist/math/breadcrumbs.d.ts +128 -0
- package/dist/math/bubble.d.ts +38 -0
- package/dist/math/bullet.d.ts +110 -0
- package/dist/math/chord.d.ts +103 -0
- package/dist/math/cluster.d.ts +88 -0
- package/dist/math/contour.d.ts +48 -0
- package/dist/math/contourf.d.ts +50 -0
- package/dist/math/dodge.d.ts +36 -0
- package/dist/math/ecdf.d.ts +41 -0
- package/dist/math/errorbar.d.ts +27 -0
- package/dist/math/eventplot.d.ts +26 -0
- package/dist/math/facet.d.ts +90 -0
- package/dist/math/fillBetween.d.ts +28 -0
- package/dist/math/gauge.d.ts +71 -0
- package/dist/math/hexbin.d.ts +20 -0
- package/dist/math/hierarchy.d.ts +179 -0
- package/dist/math/hierarchyJoin.d.ts +59 -0
- package/dist/math/histogram.d.ts +36 -0
- package/dist/math/histogram2d.d.ts +44 -0
- package/dist/math/imshow.d.ts +26 -0
- package/dist/math/index.d.ts +139 -0
- package/dist/math/index.js +3 -0
- package/dist/math/jitter.d.ts +16 -0
- package/dist/math/join.d.ts +135 -0
- package/dist/math/keyframes.d.ts +127 -0
- package/dist/math/legend.d.ts +120 -0
- package/dist/math/line.d.ts +53 -0
- package/dist/math/morph.d.ts +81 -0
- package/dist/math/mosaic.d.ts +119 -0
- package/dist/math/ordinal.d.ts +79 -0
- package/dist/math/parallel.d.ts +38 -0
- package/dist/math/pcolormesh.d.ts +22 -0
- package/dist/math/pie.d.ts +105 -0
- package/dist/math/polarArea.d.ts +34 -0
- package/dist/math/radar.d.ts +110 -0
- package/dist/math/range.d.ts +98 -0
- package/dist/math/regression.d.ts +109 -0
- package/dist/math/reveal.d.ts +63 -0
- package/dist/math/sankey.d.ts +154 -0
- package/dist/math/scatter.d.ts +14 -0
- package/dist/math/shared/binning.d.ts +23 -0
- package/dist/math/shared/gridCells.d.ts +41 -0
- package/dist/math/shared/gridExtent.d.ts +5 -0
- package/dist/math/shared/pairs.d.ts +2 -0
- package/dist/math/shared/polar.d.ts +23 -0
- package/dist/math/stack.d.ts +69 -0
- package/dist/math/stackplot.d.ts +35 -0
- package/dist/math/stairs.d.ts +17 -0
- package/dist/math/stem.d.ts +21 -0
- package/dist/math/symbol.d.ts +25 -0
- package/dist/math/tree.d.ts +117 -0
- package/dist/math/tricontour.d.ts +76 -0
- package/dist/math/violin.d.ts +99 -0
- package/dist/math/waffle.d.ts +48 -0
- package/dist/math/waterfall.d.ts +28 -0
- package/dist/math-CSHNpGej.js +3648 -0
- package/dist/mix.d.ts +24 -0
- package/dist/multiview/brush.d.ts +165 -0
- package/dist/multiview/chart-group.d.ts +265 -0
- package/dist/multiview/chart-link.d.ts +188 -0
- package/dist/multiview/chart-zoom.d.ts +144 -0
- package/dist/multiview/facet.d.ts +238 -0
- package/dist/multiview/group-guides.d.ts +99 -0
- package/dist/multiview/index.d.ts +17 -0
- package/dist/multiview/joint-plot.d.ts +114 -0
- package/dist/multiview/pair-plot.d.ts +153 -0
- package/dist/multiview/panels.d.ts +22 -0
- package/dist/multiview/parallel-coordinates.d.ts +109 -0
- package/dist/points/event-plot.d.ts +67 -0
- package/dist/points/index.d.ts +19 -0
- package/dist/points/labels.d.ts +70 -0
- package/dist/points/links.d.ts +123 -0
- package/dist/points/rects.d.ts +80 -0
- package/dist/points/rug.d.ts +72 -0
- package/dist/points/scatter.d.ts +169 -0
- package/dist/points/segment-marks.d.ts +39 -0
- package/dist/points/shared.d.ts +34 -0
- package/dist/points/stem.d.ts +75 -0
- package/dist/points/strip.d.ts +145 -0
- package/dist/points/symbol-marker.d.ts +33 -0
- package/dist/points/ticks.d.ts +102 -0
- package/dist/props.d.ts +126 -0
- package/dist/radial/chord.d.ts +148 -0
- package/dist/radial/gauge.d.ts +126 -0
- package/dist/radial/index.d.ts +15 -0
- package/dist/radial/pie-chart.d.ts +143 -0
- package/dist/radial/polar-area-chart.d.ts +135 -0
- package/dist/radial/radar-chart.d.ts +176 -0
- package/dist/radial/radial-bar-chart.d.ts +116 -0
- package/dist/radial/shared.d.ts +78 -0
- package/dist/radial/waffle.d.ts +130 -0
- package/dist/raster.d.ts +43 -0
- package/dist/series.d.ts +71 -0
- package/dist/src-CwGo1bes.js +19221 -0
- package/dist/stagger.d.ts +54 -0
- package/dist/statistics/box-plot.d.ts +151 -0
- package/dist/statistics/error-bar.d.ts +148 -0
- package/dist/statistics/groups.d.ts +140 -0
- package/dist/statistics/index.d.ts +7 -0
- package/dist/statistics/violin-plot.d.ts +143 -0
- package/dist/text-width.d.ts +9 -0
- package/dist/tooltip.d.ts +276 -0
- package/dist/util.d.ts +33 -0
- package/dist/voxels-9lJ2TZS4.js +235 -0
- package/dist/wireframe3d-D157GZAq.js +345 -0
- package/package.json +86 -3
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chart tooltips, the state half: what a tooltip shows (rows, templates,
|
|
3
|
+
* formats), which datum is showing, the handlers marks attach, and the
|
|
4
|
+
* shared nearest-x mode's points. The panel itself is drawn by the chart
|
|
5
|
+
* (`frame/tooltip-overlay.ts`).
|
|
6
|
+
*
|
|
7
|
+
* A chart provides one {@link TooltipState} through {@link tooltipContext};
|
|
8
|
+
* marks read it with `ctx.context(tooltipContext)`.
|
|
9
|
+
*/
|
|
10
|
+
import type { ContextKey, Readable, ScenePointerEvent } from "@sophistry/core";
|
|
11
|
+
import type { BandKey, Bounds, Point } from "@sophistry/core/geometry";
|
|
12
|
+
/** Gap between a tooltip panel and the point it describes, scene units. */
|
|
13
|
+
export declare const TIP_GAP = 0.18;
|
|
14
|
+
/**
|
|
15
|
+
* One line of a tooltip: a channel's name and its formatted value.
|
|
16
|
+
*
|
|
17
|
+
* @category Charts
|
|
18
|
+
*/
|
|
19
|
+
export interface TooltipRow {
|
|
20
|
+
/** The channel the value comes from (`"x"`, `"y"`, `"series"`, `"size"`, `"value"`, …); `"text"` for a sentence. */
|
|
21
|
+
channel: string;
|
|
22
|
+
/** The row's name: the field's name when the channel is a key of the datum, else the channel's. Empty for none. */
|
|
23
|
+
name: string;
|
|
24
|
+
/** The value, formatted. */
|
|
25
|
+
value: string;
|
|
26
|
+
/** The value before formatting, when there is one. */
|
|
27
|
+
raw?: number | BandKey;
|
|
28
|
+
/** A swatch drawn before the row: the datum's series colour. */
|
|
29
|
+
color?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* What a tooltip shows: one line of text (`\n` breaks it), or rows of names
|
|
33
|
+
* and values in two columns.
|
|
34
|
+
*
|
|
35
|
+
* @category Charts
|
|
36
|
+
*/
|
|
37
|
+
export type TooltipContent = string | readonly TooltipRow[];
|
|
38
|
+
/**
|
|
39
|
+
* Per-channel formatters replacing the chart's own, keyed by channel
|
|
40
|
+
* (`{ y: (v) => `$${v}` }`). A band axis's value is its category key.
|
|
41
|
+
*
|
|
42
|
+
* @category Charts
|
|
43
|
+
*/
|
|
44
|
+
export type TooltipFormat = {
|
|
45
|
+
readonly [channel: string]: ((value: number | BandKey) => string) | undefined;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* A mark's `tooltip` as an object: the default rows, reformatted or rewritten.
|
|
49
|
+
*
|
|
50
|
+
* @see https://sophistry.dev/guides/charts/#tooltips
|
|
51
|
+
* @category Charts
|
|
52
|
+
*/
|
|
53
|
+
export interface TooltipOptions<T> {
|
|
54
|
+
/** Formatters for some channels, replacing the axis's or legend's format. */
|
|
55
|
+
format?: TooltipFormat;
|
|
56
|
+
/** Your own content from the formatted default rows: return text, or rows (filtered, reordered, renamed or added to). */
|
|
57
|
+
content?: (rows: readonly TooltipRow[], datum: T, index: number) => TooltipContent;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A mark's `tooltip` prop: `true` for its default rows (one per channel,
|
|
61
|
+
* formatted as the chart's axes write them); a template such as
|
|
62
|
+
* `"{series}: {y}"`; `(d, i) => string`; a {@link TooltipOptions} object;
|
|
63
|
+
* or `false` for none. Omitted, the enclosing `<Chart tooltip>` decides.
|
|
64
|
+
*
|
|
65
|
+
* @see https://sophistry.dev/guides/charts/#tooltips
|
|
66
|
+
* @category Charts
|
|
67
|
+
*/
|
|
68
|
+
export type TooltipSpec<T> = boolean | string | ((datum: T, index: number) => string) | TooltipOptions<T>;
|
|
69
|
+
/**
|
|
70
|
+
* Where a hover tooltip stands: by the pointer, following it, or above its datum.
|
|
71
|
+
*
|
|
72
|
+
* @category Charts
|
|
73
|
+
*/
|
|
74
|
+
export type TooltipAnchor = "pointer" | "datum";
|
|
75
|
+
/**
|
|
76
|
+
* A chart's tooltip settings (`<Chart tooltip>`), as its {@link TooltipState} carries them.
|
|
77
|
+
*
|
|
78
|
+
* @category Extending
|
|
79
|
+
*/
|
|
80
|
+
export interface TooltipConfig {
|
|
81
|
+
/** Marks without a `tooltip` of their own show their default. */
|
|
82
|
+
all: boolean;
|
|
83
|
+
/** Formatters for some channels; a mark's own win. */
|
|
84
|
+
format?: TooltipFormat;
|
|
85
|
+
/** Where a hover tooltip stands. @default "pointer" */
|
|
86
|
+
anchor?: TooltipAnchor;
|
|
87
|
+
/**
|
|
88
|
+
* `"x"`: one shared tooltip for every series at the x nearest the pointer,
|
|
89
|
+
* with a crosshair; marks' own tooltips are off.
|
|
90
|
+
* @default "item"
|
|
91
|
+
*/
|
|
92
|
+
mode?: "item" | "x";
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* What a tooltip shows and where, in scene units.
|
|
96
|
+
*
|
|
97
|
+
* @category Extending
|
|
98
|
+
*/
|
|
99
|
+
export interface ActiveTooltip {
|
|
100
|
+
owner: object;
|
|
101
|
+
/** The content as one string: the accessible name. */
|
|
102
|
+
text: string;
|
|
103
|
+
content: TooltipContent;
|
|
104
|
+
at: Point;
|
|
105
|
+
/** Opened by a hovering pointer, so it follows it. */
|
|
106
|
+
follow: boolean;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* One point a mark offers a chart's shared nearest-x tooltip
|
|
110
|
+
* (`<Chart tooltip={{ mode: "x" }}>`).
|
|
111
|
+
*
|
|
112
|
+
* @category Extending
|
|
113
|
+
*/
|
|
114
|
+
export interface TooltipPoint {
|
|
115
|
+
/** Where it is drawn, in scene units. */
|
|
116
|
+
at: Point;
|
|
117
|
+
/** Its x, as the x axis writes it: the tooltip's heading. */
|
|
118
|
+
x: string;
|
|
119
|
+
/** The row it adds: its series' name and its formatted y. */
|
|
120
|
+
row: TooltipRow;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* One chart's tooltip: which datum, if any, it is showing.
|
|
124
|
+
*
|
|
125
|
+
* @category Extending
|
|
126
|
+
*/
|
|
127
|
+
export interface TooltipState {
|
|
128
|
+
/** What is showing, if anything; the overlay binds to it. */
|
|
129
|
+
active: Readable<ActiveTooltip | null>;
|
|
130
|
+
/** Shows `content` about the point `at` on behalf of `owner`; with `follow`, by the pointer while it hovers. */
|
|
131
|
+
show(owner: object, content: TooltipContent, at: Point, follow?: boolean): void;
|
|
132
|
+
/** Hides the tooltip, if `owner` is the one showing it. */
|
|
133
|
+
hide(owner: object): void;
|
|
134
|
+
/** The chart's settings (`chart`'s `tooltip`): undefined for none, false to turn tooltips off. */
|
|
135
|
+
config(): TooltipConfig | false | undefined;
|
|
136
|
+
/**
|
|
137
|
+
* Sets the points `owner` offers the shared nearest-x tooltip (a mark
|
|
138
|
+
* calls it from each update); `null` withdraws them (on dispose).
|
|
139
|
+
*/
|
|
140
|
+
offerPoints(owner: object, points: readonly TooltipPoint[] | null): void;
|
|
141
|
+
/** Every point offered, from every mark, in the order they were first offered. */
|
|
142
|
+
points(): readonly TooltipPoint[];
|
|
143
|
+
/** Bumps whenever the offered points change: the overlay binds to it. */
|
|
144
|
+
pointsVersion: Readable<number>;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Creates a {@link TooltipState}.
|
|
148
|
+
*
|
|
149
|
+
* @param config - The chart's tooltip settings, read when asked.
|
|
150
|
+
* @category Extending
|
|
151
|
+
*/
|
|
152
|
+
export declare function createTooltipState(config?: () => TooltipConfig | false | undefined): TooltipState;
|
|
153
|
+
/**
|
|
154
|
+
* The enclosing chart's tooltip state, or null outside a chart. Read it with
|
|
155
|
+
* `ctx.context(tooltipContext)`.
|
|
156
|
+
*
|
|
157
|
+
* @category Extending
|
|
158
|
+
*/
|
|
159
|
+
export declare const tooltipContext: ContextKey<TooltipState | null>;
|
|
160
|
+
/**
|
|
161
|
+
* One channel a mark's default tooltip reports, before formatting.
|
|
162
|
+
*
|
|
163
|
+
* @category Extending
|
|
164
|
+
*/
|
|
165
|
+
export interface TooltipField {
|
|
166
|
+
/** The channel's prop name: `"x"`, `"y"`, `"series"`, `"size"`, … */
|
|
167
|
+
channel: string;
|
|
168
|
+
/** The channel prop as given; a key of the datum names the row. */
|
|
169
|
+
of?: unknown;
|
|
170
|
+
/** The row's name, overriding the one `of` gives. */
|
|
171
|
+
name?: string;
|
|
172
|
+
/** The value; null or undefined drops the row. */
|
|
173
|
+
value: number | BandKey | null | undefined;
|
|
174
|
+
/**
|
|
175
|
+
* How the chart writes the value (`useChart().format(…)`). Defaults to `formatTick` for
|
|
176
|
+
* numbers.
|
|
177
|
+
*/
|
|
178
|
+
format?: (value: number | BandKey) => string;
|
|
179
|
+
/** A swatch before the row. */
|
|
180
|
+
color?: string;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* A tooltip's content as one string, its accessible name: text as is, rows
|
|
184
|
+
* as `name: value` joined by commas.
|
|
185
|
+
*
|
|
186
|
+
* @category Extending
|
|
187
|
+
*/
|
|
188
|
+
export declare function tooltipLabel(content: TooltipContent): string;
|
|
189
|
+
/**
|
|
190
|
+
* Resolves a {@link TooltipSpec} to one datum's content, or undefined for
|
|
191
|
+
* none. `fallback` is the mark's default; with `state`, the chart's
|
|
192
|
+
* `<Chart tooltip>` settings apply.
|
|
193
|
+
*/
|
|
194
|
+
export declare function tooltipText<T>(spec: TooltipSpec<T> | undefined, fallback: (datum: T, index: number) => string | readonly TooltipField[], datum: T, index: number, state?: TooltipState): TooltipContent | undefined;
|
|
195
|
+
/**
|
|
196
|
+
* Interaction props that make a shape show its tooltip on hover, tap or
|
|
197
|
+
* Enter; spread onto the shape. A mark whose `tooltip` is off registers no
|
|
198
|
+
* interaction. Outside a chart, only the accessible `label` is set.
|
|
199
|
+
*
|
|
200
|
+
* @param tooltip - The chart's tooltip state, if any.
|
|
201
|
+
* @param text - The content, or undefined for none; read reactively.
|
|
202
|
+
* @param at - Where the tooltip points, in scene units.
|
|
203
|
+
* @category Extending
|
|
204
|
+
*/
|
|
205
|
+
export declare function tooltipHandlers(tooltip: TooltipState | undefined, text: () => TooltipContent | undefined, at: () => Point): {
|
|
206
|
+
readonly label?: string;
|
|
207
|
+
readonly onEnter?: (event: ScenePointerEvent) => void;
|
|
208
|
+
readonly onLeave?: (event: ScenePointerEvent) => void;
|
|
209
|
+
readonly onTap?: (event: ScenePointerEvent) => void;
|
|
210
|
+
};
|
|
211
|
+
/** Width and height of a tooltip's panel, padding included. */
|
|
212
|
+
interface TooltipSize {
|
|
213
|
+
width: number;
|
|
214
|
+
height: number;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* A tooltip panel's bounds: `"above"` centred over `at`, `"right"` beside it,
|
|
218
|
+
* flipped when `frame`'s edge would cut it, then clamped inside `frame`.
|
|
219
|
+
*
|
|
220
|
+
* @internal
|
|
221
|
+
*/
|
|
222
|
+
export declare function placeTooltip(size: TooltipSize, at: Point, frame: Bounds | undefined, side?: "above" | "right", gap?: number): Bounds;
|
|
223
|
+
/**
|
|
224
|
+
* The points at the scene x nearest `x` (all within a hair of it, so series
|
|
225
|
+
* on one grid share a tooltip). Undefined for none.
|
|
226
|
+
*
|
|
227
|
+
* @internal
|
|
228
|
+
*/
|
|
229
|
+
export declare function nearestX(points: readonly TooltipPoint[], x: number): {
|
|
230
|
+
x: number;
|
|
231
|
+
points: TooltipPoint[];
|
|
232
|
+
} | undefined;
|
|
233
|
+
/**
|
|
234
|
+
* {@link nearestX} over one set of points, for a pointer that asks on every
|
|
235
|
+
* move: the points are sorted by x once and each query bisects, rather than
|
|
236
|
+
* scanning and filtering them all. Answers exactly as the scan did: the
|
|
237
|
+
* nearest finite point wins, a tie going to the one offered first, and the
|
|
238
|
+
* group is every point within a hair of its x, in the order offered.
|
|
239
|
+
*
|
|
240
|
+
* @internal
|
|
241
|
+
*/
|
|
242
|
+
export declare function nearestXIndex(points: readonly TooltipPoint[]): (x: number) => {
|
|
243
|
+
x: number;
|
|
244
|
+
points: TooltipPoint[];
|
|
245
|
+
} | undefined;
|
|
246
|
+
/**
|
|
247
|
+
* One datum's channel value: a key, or `(d, i) => value`; undefined for an
|
|
248
|
+
* omitted or constant channel.
|
|
249
|
+
*
|
|
250
|
+
* @internal
|
|
251
|
+
*/
|
|
252
|
+
export declare function datumValue<T>(of: unknown, datum: T, index: number): number | BandKey | undefined;
|
|
253
|
+
/** One datum a mark offers the shared nearest-x tooltip, before formatting. @internal */
|
|
254
|
+
export interface SharedTooltipDatum {
|
|
255
|
+
/** Data units. */
|
|
256
|
+
x: number;
|
|
257
|
+
y: number;
|
|
258
|
+
/** Where it is drawn, in scene units. */
|
|
259
|
+
at: Point;
|
|
260
|
+
/** Its series, naming its row; omitted, the row is named by the `y` channel. */
|
|
261
|
+
series?: BandKey;
|
|
262
|
+
color?: string;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* The points a mark offers the shared nearest-x tooltip: one row each, named
|
|
266
|
+
* by series (else the `y` channel). Empty unless the chart's tooltip mode is
|
|
267
|
+
* `"x"`, so `data` is only read while it is on. Pass the result to
|
|
268
|
+
* `tooltip.offerPoints(owner, points)`.
|
|
269
|
+
*
|
|
270
|
+
* @internal
|
|
271
|
+
*/
|
|
272
|
+
export declare function sharedTooltipPoints(tooltip: TooltipState | null | undefined, data: () => readonly SharedTooltipDatum[], channels: {
|
|
273
|
+
y: unknown;
|
|
274
|
+
format?: (channel: "x" | "y" | "series") => (value: number | BandKey) => string;
|
|
275
|
+
}): readonly TooltipPoint[];
|
|
276
|
+
export {};
|
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Small helpers the chart components share: value equality for memo
|
|
3
|
+
* boundaries, point mixing, bisection. Internal; not exported from the
|
|
4
|
+
* package entry.
|
|
5
|
+
*/
|
|
6
|
+
import type { Point } from "@sophistry/core/geometry";
|
|
7
|
+
/**
|
|
8
|
+
* Whether two values are equal one level deep: the same value, or arrays
|
|
9
|
+
* (or plain objects) whose members are identical (`Object.is`).
|
|
10
|
+
*/
|
|
11
|
+
export declare function shallowEqual(a: unknown, b: unknown): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Whether two values are equal by structure (arrays, plain objects,
|
|
14
|
+
* primitives; functions and class instances by identity). For reports and
|
|
15
|
+
* other small configuration values, never for large data.
|
|
16
|
+
*/
|
|
17
|
+
export declare function deepEqual(a: unknown, b: unknown): boolean;
|
|
18
|
+
/** `a + (b − a)·t`. */
|
|
19
|
+
export declare function mix(a: number, b: number, t: number): number;
|
|
20
|
+
/** Two points mixed by `t`. */
|
|
21
|
+
export declare function mixPoint(a: Point, b: Point, t: number): Point;
|
|
22
|
+
/** The first index of sorted `values` whose value is `>= target`. */
|
|
23
|
+
export declare function lowerBound(values: readonly number[], target: number): number;
|
|
24
|
+
/**
|
|
25
|
+
* A last-value cache by equality: returns the previous value while
|
|
26
|
+
* `equals(previous, next)` holds, so identity-keyed caches downstream hit.
|
|
27
|
+
*/
|
|
28
|
+
export declare function stableValue<T>(equals?: (a: T, b: T) => boolean): (next: T) => T;
|
|
29
|
+
/**
|
|
30
|
+
* A last-input cache over a dependency list: `make()` runs only when `deps`
|
|
31
|
+
* differ (shallowly) from the last call's, else the last result is returned.
|
|
32
|
+
*/
|
|
33
|
+
export declare function keyedMemo<T>(): (deps: readonly unknown[], make: () => T) => T;
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
//#region src/math/shared/pairs.ts
|
|
2
|
+
function e(e, t) {
|
|
3
|
+
return Math.min(e.length, t.length);
|
|
4
|
+
}
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/math/3d/bar3d.ts
|
|
7
|
+
function t(e, t) {
|
|
8
|
+
return typeof e == "number" ? e : e[t] ?? NaN;
|
|
9
|
+
}
|
|
10
|
+
function n(e) {
|
|
11
|
+
return typeof e == "number" ? null : e.length;
|
|
12
|
+
}
|
|
13
|
+
function r(r, i, a, o, s, c) {
|
|
14
|
+
let l = e(r, i);
|
|
15
|
+
l = Math.min(l, a.length);
|
|
16
|
+
for (let e of [
|
|
17
|
+
o,
|
|
18
|
+
s,
|
|
19
|
+
c
|
|
20
|
+
]) {
|
|
21
|
+
let t = n(e);
|
|
22
|
+
t !== null && (l = Math.min(l, t));
|
|
23
|
+
}
|
|
24
|
+
let u = [];
|
|
25
|
+
for (let e = 0; e < l; e++) {
|
|
26
|
+
let n = r[e], l = i[e], d = a[e], f = t(o, e), p = t(s, e), m = t(c, e);
|
|
27
|
+
Number.isFinite(n) && Number.isFinite(l) && Number.isFinite(d) && Number.isFinite(f) && Number.isFinite(p) && Number.isFinite(m) && u.push({
|
|
28
|
+
index: e,
|
|
29
|
+
x0: Math.min(n, n + f),
|
|
30
|
+
x1: Math.max(n, n + f),
|
|
31
|
+
y0: Math.min(l, l + p),
|
|
32
|
+
y1: Math.max(l, l + p),
|
|
33
|
+
z0: Math.min(d, d + m),
|
|
34
|
+
z1: Math.max(d, d + m)
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return u;
|
|
38
|
+
}
|
|
39
|
+
function i(t, n, r, i, a, o, s = {}) {
|
|
40
|
+
let c = s.scale ?? 1, l = e(t, n);
|
|
41
|
+
l = Math.min(l, r.length, i.length, a.length, o.length);
|
|
42
|
+
let u = [];
|
|
43
|
+
for (let e = 0; e < l; e++) {
|
|
44
|
+
let s = t[e], l = n[e], d = r[e];
|
|
45
|
+
if (!Number.isFinite(s) || !Number.isFinite(l) || !Number.isFinite(d)) continue;
|
|
46
|
+
let f = i[e] * c, p = a[e] * c, m = o[e] * c;
|
|
47
|
+
Number.isFinite(f) && Number.isFinite(p) && Number.isFinite(m) && u.push({
|
|
48
|
+
index: e,
|
|
49
|
+
origin: {
|
|
50
|
+
x: s,
|
|
51
|
+
y: l,
|
|
52
|
+
z: d
|
|
53
|
+
},
|
|
54
|
+
vector: {
|
|
55
|
+
x: f,
|
|
56
|
+
y: p,
|
|
57
|
+
z: m
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return u;
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/math/3d/scatter3d.ts
|
|
65
|
+
function a(t, n, r) {
|
|
66
|
+
let i = e(t, n);
|
|
67
|
+
i = Math.min(i, r.length);
|
|
68
|
+
let a = [];
|
|
69
|
+
for (let e = 0; e < i; e++) {
|
|
70
|
+
let i = t[e], o = n[e], s = r[e];
|
|
71
|
+
Number.isFinite(i) && Number.isFinite(o) && Number.isFinite(s) && a.push({
|
|
72
|
+
index: e,
|
|
73
|
+
x: i,
|
|
74
|
+
y: o,
|
|
75
|
+
z: s
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return a;
|
|
79
|
+
}
|
|
80
|
+
function o(t, n, r, i = {}) {
|
|
81
|
+
let a = i.baseline ?? 0, o = e(t, n);
|
|
82
|
+
o = Math.min(o, r.length);
|
|
83
|
+
let s = [];
|
|
84
|
+
for (let e = 0; e < o; e++) {
|
|
85
|
+
let i = t[e], o = n[e], c = r[e];
|
|
86
|
+
Number.isFinite(i) && Number.isFinite(o) && Number.isFinite(c) && s.push({
|
|
87
|
+
index: e,
|
|
88
|
+
drop: [{
|
|
89
|
+
x: i,
|
|
90
|
+
y: a,
|
|
91
|
+
z: c
|
|
92
|
+
}, {
|
|
93
|
+
x: i,
|
|
94
|
+
y: o,
|
|
95
|
+
z: c
|
|
96
|
+
}],
|
|
97
|
+
marker: {
|
|
98
|
+
x: i,
|
|
99
|
+
y: o,
|
|
100
|
+
z: c
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return s;
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/math/3d/surfaceGrid3d.ts
|
|
108
|
+
function s(e, t, n) {
|
|
109
|
+
let r = n.length;
|
|
110
|
+
if (e.length !== r || t.length !== r) throw Error(`surfaceGrid: X/Y/Z must have the same row count (X=${e.length}, Y=${t.length}, Z=${r}).`);
|
|
111
|
+
let i = r > 0 ? n[0].length : 0;
|
|
112
|
+
for (let a = 0; a < r; a++) if (e[a].length !== i || t[a].length !== i || n[a].length !== i) throw Error(`surfaceGrid: row ${a} of X/Y/Z must all have length ${i} (the grid's column count).`);
|
|
113
|
+
return {
|
|
114
|
+
nrows: r,
|
|
115
|
+
ncols: i
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function c(e, t, n, r, i) {
|
|
119
|
+
return {
|
|
120
|
+
x: e[r][i],
|
|
121
|
+
y: t[r][i],
|
|
122
|
+
z: n[r][i]
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function l(e, t, n) {
|
|
126
|
+
let { nrows: r, ncols: i } = s(e, t, n), a = [];
|
|
127
|
+
for (let o = 0; o < r - 1; o++) for (let r = 0; r < i - 1; r++) {
|
|
128
|
+
let i = c(e, t, n, o, r), s = c(e, t, n, o, r + 1), l = c(e, t, n, o + 1, r + 1), u = c(e, t, n, o + 1, r);
|
|
129
|
+
a.push({ points: [
|
|
130
|
+
i,
|
|
131
|
+
u,
|
|
132
|
+
l,
|
|
133
|
+
s
|
|
134
|
+
] });
|
|
135
|
+
}
|
|
136
|
+
return a;
|
|
137
|
+
}
|
|
138
|
+
function u(e, t, n) {
|
|
139
|
+
let { nrows: r, ncols: i } = s(e, t, n), a = [];
|
|
140
|
+
for (let o = 0; o < r; o++) {
|
|
141
|
+
let r = Array(i);
|
|
142
|
+
for (let a = 0; a < i; a++) r[a] = c(e, t, n, o, a);
|
|
143
|
+
a.push(r);
|
|
144
|
+
}
|
|
145
|
+
for (let o = 0; o < i; o++) {
|
|
146
|
+
let i = Array(r);
|
|
147
|
+
for (let a = 0; a < r; a++) i[a] = c(e, t, n, a, o);
|
|
148
|
+
a.push(i);
|
|
149
|
+
}
|
|
150
|
+
return a;
|
|
151
|
+
}
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/math/3d/voxels.ts
|
|
154
|
+
function d(e, t, n, r) {
|
|
155
|
+
return e[t]?.[n]?.[r] === !0;
|
|
156
|
+
}
|
|
157
|
+
function f(e) {
|
|
158
|
+
let t = [];
|
|
159
|
+
for (let n = 0; n < e.length; n++) {
|
|
160
|
+
let r = e[n];
|
|
161
|
+
if (r) for (let i = 0; i < r.length; i++) {
|
|
162
|
+
let a = r[i];
|
|
163
|
+
if (a) for (let r = 0; r < a.length; r++) {
|
|
164
|
+
if (a[r] !== !0) continue;
|
|
165
|
+
let o = n, s = n + 1, c = i, l = i + 1, u = r, f = r + 1, p = {
|
|
166
|
+
x: o,
|
|
167
|
+
y: c,
|
|
168
|
+
z: u
|
|
169
|
+
}, m = {
|
|
170
|
+
x: o,
|
|
171
|
+
y: c,
|
|
172
|
+
z: f
|
|
173
|
+
}, h = {
|
|
174
|
+
x: o,
|
|
175
|
+
y: l,
|
|
176
|
+
z: u
|
|
177
|
+
}, g = {
|
|
178
|
+
x: o,
|
|
179
|
+
y: l,
|
|
180
|
+
z: f
|
|
181
|
+
}, _ = {
|
|
182
|
+
x: s,
|
|
183
|
+
y: c,
|
|
184
|
+
z: u
|
|
185
|
+
}, v = {
|
|
186
|
+
x: s,
|
|
187
|
+
y: c,
|
|
188
|
+
z: f
|
|
189
|
+
}, y = {
|
|
190
|
+
x: s,
|
|
191
|
+
y: l,
|
|
192
|
+
z: u
|
|
193
|
+
}, b = {
|
|
194
|
+
x: s,
|
|
195
|
+
y: l,
|
|
196
|
+
z: f
|
|
197
|
+
};
|
|
198
|
+
d(e, n + 1, i, r) || t.push({ points: [
|
|
199
|
+
_,
|
|
200
|
+
y,
|
|
201
|
+
b,
|
|
202
|
+
v
|
|
203
|
+
] }), d(e, n - 1, i, r) || t.push({ points: [
|
|
204
|
+
p,
|
|
205
|
+
m,
|
|
206
|
+
g,
|
|
207
|
+
h
|
|
208
|
+
] }), d(e, n, i + 1, r) || t.push({ points: [
|
|
209
|
+
h,
|
|
210
|
+
g,
|
|
211
|
+
b,
|
|
212
|
+
y
|
|
213
|
+
] }), d(e, n, i - 1, r) || t.push({ points: [
|
|
214
|
+
p,
|
|
215
|
+
_,
|
|
216
|
+
v,
|
|
217
|
+
m
|
|
218
|
+
] }), d(e, n, i, r + 1) || t.push({ points: [
|
|
219
|
+
m,
|
|
220
|
+
v,
|
|
221
|
+
b,
|
|
222
|
+
g
|
|
223
|
+
] }), d(e, n, i, r - 1) || t.push({ points: [
|
|
224
|
+
p,
|
|
225
|
+
h,
|
|
226
|
+
y,
|
|
227
|
+
_
|
|
228
|
+
] });
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return t;
|
|
233
|
+
}
|
|
234
|
+
//#endregion
|
|
235
|
+
export { a, e as c, o as i, l as n, i as o, u as r, r as s, f as t };
|