@pluot/react 0.1.16 → 0.1.18
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/dist/index.js +1066 -110
- package/dist-tsc/BrushOverlay.d.ts +31 -0
- package/dist-tsc/BrushOverlay.d.ts.map +1 -0
- package/dist-tsc/BrushOverlay.js +95 -0
- package/dist-tsc/Pluot.d.ts +2 -1
- package/dist-tsc/Pluot.d.ts.map +1 -1
- package/dist-tsc/Pluot.js +118 -22
- package/dist-tsc/Tooltip.d.ts +2 -1
- package/dist-tsc/Tooltip.d.ts.map +1 -1
- package/dist-tsc/Tooltip.js +15 -1
- package/dist-tsc/brush.d.ts +155 -0
- package/dist-tsc/brush.d.ts.map +1 -0
- package/dist-tsc/brush.js +312 -0
- package/dist-tsc/brush.test.d.ts +2 -0
- package/dist-tsc/brush.test.d.ts.map +1 -0
- package/dist-tsc/brush.test.js +487 -0
- package/dist-tsc/index.d.ts +3 -1
- package/dist-tsc/index.d.ts.map +1 -1
- package/dist-tsc/index.js +1 -0
- package/dist-tsc/types.d.ts +283 -0
- package/dist-tsc/types.d.ts.map +1 -0
- package/dist-tsc/types.js +11 -0
- package/dist-tsc/use-brush.d.ts +55 -0
- package/dist-tsc/use-brush.d.ts.map +1 -0
- package/dist-tsc/use-brush.js +361 -0
- package/package.json +5 -3
- package/src/BrushOverlay.tsx +258 -0
- package/src/{Pluot.jsx → Pluot.tsx} +200 -47
- package/src/{Tooltip.jsx → Tooltip.tsx} +19 -3
- package/src/brush.test.ts +590 -0
- package/src/brush.ts +435 -0
- package/src/index.ts +26 -0
- package/src/types.ts +412 -0
- package/src/use-brush.ts +505 -0
- package/src/index.js +0 -2
package/src/types.ts
ADDED
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import type {
|
|
3
|
+
AspectRatioMode,
|
|
4
|
+
AspectRatioAlignmentMode,
|
|
5
|
+
CameraMatrix,
|
|
6
|
+
StoreInput,
|
|
7
|
+
StoresInput,
|
|
8
|
+
StoresOutput,
|
|
9
|
+
} from "@pluot/core";
|
|
10
|
+
|
|
11
|
+
// TODO: auto-generate the types that mirror Rust structs/enums:
|
|
12
|
+
// https://github.com/keller-mark/pluot/issues/133
|
|
13
|
+
|
|
14
|
+
// === Plot params ===
|
|
15
|
+
|
|
16
|
+
/** Mirrors the Rust `ViewMode` enum (serde-renamed to lowercase). */
|
|
17
|
+
export type ViewMode = "2d" | "3d";
|
|
18
|
+
|
|
19
|
+
/** Mirrors the Rust `GraphicsFormat` enum. */
|
|
20
|
+
export type GraphicsFormat = "Raster" | "Vector";
|
|
21
|
+
|
|
22
|
+
/** Mirrors the adjacently-tagged Rust `PlotParams` enum discriminant. */
|
|
23
|
+
export type PlotType = "LayeredPlot";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* One entry of `PlotParams.layers`, mirroring the adjacently-tagged Rust
|
|
27
|
+
* `LayerParams` enum: `{ "layer_type": "PointLayer", "layer_params": { ... } }`.
|
|
28
|
+
*
|
|
29
|
+
* `layer_type` must name a registered layer (see the `LayerParams` enum in
|
|
30
|
+
* `crates/pluot/src/render_params.rs`), and the shape of `layer_params`
|
|
31
|
+
* depends on which layer was named.
|
|
32
|
+
*/
|
|
33
|
+
export type LayerParams = {
|
|
34
|
+
layer_type: string;
|
|
35
|
+
layer_params: Record<string, unknown>;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** Mirrors the Rust `LayeredPlotRenderParams` struct. */
|
|
39
|
+
export type PlotParams = {
|
|
40
|
+
layers: LayerParams[];
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The object handed to the wasm `render_wasm` / `pick_wasm` functions.
|
|
45
|
+
* Mirrors the Rust `RenderParams` struct (snake_case, unlike the props of
|
|
46
|
+
* the {@link PluotProps} React API).
|
|
47
|
+
*/
|
|
48
|
+
export type RenderParams = {
|
|
49
|
+
schema_version: string | null;
|
|
50
|
+
width: number;
|
|
51
|
+
height: number;
|
|
52
|
+
format: GraphicsFormat;
|
|
53
|
+
margin_top: number;
|
|
54
|
+
margin_right: number;
|
|
55
|
+
margin_bottom: number;
|
|
56
|
+
margin_left: number;
|
|
57
|
+
device_pixel_ratio: number;
|
|
58
|
+
aspect_ratio_mode: AspectRatioMode;
|
|
59
|
+
aspect_ratio_alignment_mode: AspectRatioAlignmentMode;
|
|
60
|
+
view_mode: ViewMode;
|
|
61
|
+
pickable: boolean;
|
|
62
|
+
camera_view: CameraMatrix | null;
|
|
63
|
+
plot_id: string;
|
|
64
|
+
plot_type: PlotType;
|
|
65
|
+
stores: StoresOutput | undefined;
|
|
66
|
+
plot_params: PlotParams;
|
|
67
|
+
/** In milliseconds. Has no effect when `wait_for_store_gets` is false. */
|
|
68
|
+
timeout: number | null;
|
|
69
|
+
wait_for_store_gets: boolean;
|
|
70
|
+
cache_enabled: boolean;
|
|
71
|
+
svg_compression_enabled: boolean;
|
|
72
|
+
svg_include_document: boolean;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// === Picking results ===
|
|
76
|
+
|
|
77
|
+
/** Mirrors the Rust `ScreenCoord` struct. Y increases upwards. */
|
|
78
|
+
export type ScreenCoord = {
|
|
79
|
+
x: number;
|
|
80
|
+
y: number;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/** Mirrors the externally-tagged Rust `DataCoord` enum. */
|
|
84
|
+
export type DataCoord =
|
|
85
|
+
| { TwoD: { x: number; y: number } }
|
|
86
|
+
| { ThreeD: { x: number; y: number; z: number } };
|
|
87
|
+
|
|
88
|
+
/** Mirrors the Rust `LayerPickingResult` struct. */
|
|
89
|
+
export type LayerPickingResult = {
|
|
90
|
+
layer_id: string;
|
|
91
|
+
info: Record<string, string>;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Mirrors the Rust `PickingResult` struct, after normalization
|
|
96
|
+
* of the `info` Maps (produced by serde-wasm-bindgen) to plain objects.
|
|
97
|
+
*
|
|
98
|
+
* Note: `serde_wasm_bindgen` serializes a Rust `None` as `undefined`
|
|
99
|
+
* (not `null`), so `data_coord` is absent rather than null when picking
|
|
100
|
+
* did not resolve to a data coordinate.
|
|
101
|
+
*/
|
|
102
|
+
export type PickingResult = {
|
|
103
|
+
data_coord: DataCoord | undefined;
|
|
104
|
+
screen_coord: ScreenCoord;
|
|
105
|
+
layer_results: LayerPickingResult[];
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The un-normalized shape that `pick_wasm` actually resolves to. It is typed
|
|
110
|
+
* `any` on the wasm-bindgen side, so this type is what documents the wire
|
|
111
|
+
* format: `serde_wasm_bindgen` converts the Rust `HashMap` behind `info` into
|
|
112
|
+
* a JS `Map`, which {@link PickingResult} flattens to a plain object.
|
|
113
|
+
*/
|
|
114
|
+
export type RawLayerPickingResult = Omit<LayerPickingResult, "info"> & {
|
|
115
|
+
info: Map<string, string>;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/** Mirrors the Rust `LayerBrushingResult` struct. */
|
|
119
|
+
export type LayerBrushingResult = {
|
|
120
|
+
layer_id: string;
|
|
121
|
+
info: Record<string, string>;
|
|
122
|
+
element_info: Record<string, string[]>;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Mirrors the Rust `BrushingResult` struct, after normalization of the `info`
|
|
127
|
+
* and `element_info` maps (produced by serde-wasm-bindgen) to plain objects.
|
|
128
|
+
*/
|
|
129
|
+
export type BrushingResult = {
|
|
130
|
+
layer_results: LayerBrushingResult[];
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* The un-normalized shape that `brush_wasm` actually resolves to. It is typed
|
|
135
|
+
* `any` on the wasm-bindgen side, so this type is what documents the wire
|
|
136
|
+
* format: `serde_wasm_bindgen` converts the Rust `HashMap`s behind `info` and
|
|
137
|
+
* `element_info` into JS `Map`s, which {@link BrushingResult} flattens to
|
|
138
|
+
* plain objects.
|
|
139
|
+
*/
|
|
140
|
+
export type RawLayerBrushingResult = Omit<LayerBrushingResult, "info" | "element_info"> & {
|
|
141
|
+
info: Map<string, string>;
|
|
142
|
+
element_info: Map<string, string[]>;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export type RawBrushingResult = Omit<BrushingResult, "layer_results"> & {
|
|
146
|
+
layer_results: RawLayerBrushingResult[];
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export type RawPickingResult = Omit<PickingResult, "layer_results"> & {
|
|
150
|
+
layer_results: RawLayerPickingResult[];
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
// === Tooltip ===
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* What a {@link PluotProps.onHover} callback may return for the tooltip to
|
|
157
|
+
* render. A plain object is rendered as a key/value table when `asTable`
|
|
158
|
+
* is set, and as pretty-printed JSON otherwise.
|
|
159
|
+
*/
|
|
160
|
+
export type TooltipContent =
|
|
161
|
+
| string
|
|
162
|
+
| number
|
|
163
|
+
| ReactElement
|
|
164
|
+
| Record<string, unknown>
|
|
165
|
+
| null
|
|
166
|
+
| undefined;
|
|
167
|
+
|
|
168
|
+
export type TooltipProps = {
|
|
169
|
+
content: TooltipContent;
|
|
170
|
+
/** Render a plain-object `content` as a two-column key/value table. */
|
|
171
|
+
asTable?: boolean;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
/** The hovered point plus the tooltip content to show for it. */
|
|
175
|
+
export type HoverInfo = {
|
|
176
|
+
content: TooltipContent;
|
|
177
|
+
/** Mouse position in the coordinate space of the outer (width x height) container. */
|
|
178
|
+
mouseX: number;
|
|
179
|
+
mouseY: number;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
// === Brushing ===
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Which representation of a {@link BrushVertex} is authoritative for an axis.
|
|
186
|
+
*
|
|
187
|
+
* - `Pixels`: relative to the top-left of the outer (width x height) container,
|
|
188
|
+
* with Y increasing downwards (the DOM/SVG convention). Unaffected by the camera.
|
|
189
|
+
* - `Data`: the data coordinate under the current camera, as reported by
|
|
190
|
+
* `getBounds`, with Y increasing upwards. A brush in this mode is pinned to the
|
|
191
|
+
* data, so it moves on screen as the user zooms/pans.
|
|
192
|
+
* - `Normalized`: a 0-to-1 fraction of the brushable region, with Y increasing
|
|
193
|
+
* upwards (0 at the bottom edge, 1 at the top edge). Unaffected by the camera.
|
|
194
|
+
*/
|
|
195
|
+
export type BrushUnitsMode = "Pixels" | "Data" | "Normalized";
|
|
196
|
+
|
|
197
|
+
// For each brushed rect/polygon vertex,
|
|
198
|
+
// we represent it using all units modes simultaneously.
|
|
199
|
+
// Only the representation matching `brushUnitsModeX`/`brushUnitsModeY` is
|
|
200
|
+
// authoritative; the other two are derived from it and are recomputed whenever
|
|
201
|
+
// the camera, the container size, or the margins change.
|
|
202
|
+
export type BrushVertex = {
|
|
203
|
+
// Data unitsMode.
|
|
204
|
+
x_data: number,
|
|
205
|
+
y_data: number,
|
|
206
|
+
// Pixels unitsMode.
|
|
207
|
+
x_pixels: number,
|
|
208
|
+
y_pixels: number,
|
|
209
|
+
// Normalized unitsMode.
|
|
210
|
+
x_normalized: number,
|
|
211
|
+
y_normalized: number,
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* The shape the user draws, and which the resulting {@link BrushState} holds.
|
|
216
|
+
*
|
|
217
|
+
* - `Rect`: click and drag to draw a rectangle.
|
|
218
|
+
* - `Polygon`: click and drag to draw a lasso, defining vertices as the user
|
|
219
|
+
* drags. The number of vertices is limited by using lodash-es throttle.
|
|
220
|
+
* - `RangeX`: select a horizontal range. The overlay renders as a rectangle
|
|
221
|
+
* which takes up the full brush height, according to the brush margins.
|
|
222
|
+
* - `RangeY`: select a vertical range. The overlay renders as a rectangle
|
|
223
|
+
* which takes up the full brush width, according to the brush margins.
|
|
224
|
+
*/
|
|
225
|
+
export type BrushMode = 'Rect' | 'Polygon' | 'RangeX' | 'RangeY';
|
|
226
|
+
|
|
227
|
+
/** The axis-aligned modes, all of which are stored as four rectangle corners. */
|
|
228
|
+
export type RectLikeBrushMode = Exclude<BrushMode, 'Polygon'>;
|
|
229
|
+
|
|
230
|
+
export type BrushState = {
|
|
231
|
+
// Is the user still drawing, or have they completed their drag interaction?
|
|
232
|
+
status: 'Drawing' | 'Complete';
|
|
233
|
+
shape: BrushMode,
|
|
234
|
+
// For every shape but Polygon, always four corners ordered clockwise in pixel
|
|
235
|
+
// space starting from the top-left, so corner `i` is diagonally opposite
|
|
236
|
+
// corner `(i + 2) % 4`.
|
|
237
|
+
// For RangeX and RangeY, the axis that is not being selected always spans the
|
|
238
|
+
// full brushable extent, so it is re-pinned whenever that extent changes.
|
|
239
|
+
vertices: BrushVertex[],
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* The value of {@link PluotProps.brush} meaning "controlled, but nothing is
|
|
244
|
+
* brushed right now".
|
|
245
|
+
*
|
|
246
|
+
* `undefined` cannot play this role: a prop that was never passed is
|
|
247
|
+
* indistinguishable from one explicitly set to `undefined`, and an absent
|
|
248
|
+
* `brush` has to mean uncontrolled. A parent that controls the brush therefore
|
|
249
|
+
* passes `NO_BRUSH` rather than `undefined` to show no brush, which keeps it
|
|
250
|
+
* controlled across the empty state instead of silently handing control back.
|
|
251
|
+
*/
|
|
252
|
+
export const NO_BRUSH = "NoBrush";
|
|
253
|
+
export type NoBrush = typeof NO_BRUSH;
|
|
254
|
+
|
|
255
|
+
// TODO: On the rust side, define a Brushable.brush trait, analogous to Pickable.pick.
|
|
256
|
+
export type BrushResult = {
|
|
257
|
+
// Similar to picking, upon brush, the Rust side can return a per-layer Map with essentially any data
|
|
258
|
+
// (such as the list of entity IDs within the brushed region).
|
|
259
|
+
// The rust side can also return a new rect/polygon to "snap"/quantize to.
|
|
260
|
+
// TODO: fill in the rest of this struct.
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
// === Component props ===
|
|
264
|
+
|
|
265
|
+
export type PluotProps = {
|
|
266
|
+
/**
|
|
267
|
+
* The schema version used to generate the plot, for forward compatibility.
|
|
268
|
+
* A mismatch with the Rust crate version logs a warning.
|
|
269
|
+
*/
|
|
270
|
+
schemaVersion?: string | null;
|
|
271
|
+
/** Width of the plot, in pixels. */
|
|
272
|
+
width: number;
|
|
273
|
+
/** Height of the plot, in pixels. */
|
|
274
|
+
height: number;
|
|
275
|
+
/**
|
|
276
|
+
* Unique-per-page plot ID, used to key caches of intermediate values.
|
|
277
|
+
* Also the default store name when `store` is used without `storeName`.
|
|
278
|
+
*/
|
|
279
|
+
plotId: string;
|
|
280
|
+
plotType: PlotType;
|
|
281
|
+
plotParams: PlotParams;
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* A single Zarr store: a URL string, a zarrita store instance,
|
|
285
|
+
* or already-derived `ZarrStoreInfo` metadata.
|
|
286
|
+
* Mutually exclusive with `stores`.
|
|
287
|
+
*/
|
|
288
|
+
store?: StoreInput;
|
|
289
|
+
/** The name to register `store` under. Defaults to `plotId`. */
|
|
290
|
+
storeName?: string;
|
|
291
|
+
/** Multiple Zarr stores, keyed by store name. Mutually exclusive with `store`. */
|
|
292
|
+
stores?: StoresInput;
|
|
293
|
+
/**
|
|
294
|
+
* Whether to register the store(s) with the wasm module.
|
|
295
|
+
* Set to false when they have already been registered elsewhere.
|
|
296
|
+
*/
|
|
297
|
+
registerStores?: boolean;
|
|
298
|
+
|
|
299
|
+
viewMode?: ViewMode;
|
|
300
|
+
format?: GraphicsFormat;
|
|
301
|
+
marginTop?: number;
|
|
302
|
+
marginRight?: number;
|
|
303
|
+
marginBottom?: number;
|
|
304
|
+
marginLeft?: number;
|
|
305
|
+
aspectRatioMode?: AspectRatioMode;
|
|
306
|
+
aspectRatioAlignmentMode?: AspectRatioAlignmentMode;
|
|
307
|
+
/** Outline the margin box and the plot area, to help debug layout. */
|
|
308
|
+
debugMargins?: boolean;
|
|
309
|
+
backgroundColor?: string;
|
|
310
|
+
|
|
311
|
+
/** Lower bound (in ms) of the exponential backoff between bailed-early renders. */
|
|
312
|
+
minTimeout?: number;
|
|
313
|
+
/** Upper bound (in ms) of the exponential backoff between bailed-early renders. */
|
|
314
|
+
maxTimeout?: number;
|
|
315
|
+
/** Whether a new render may start while a previous one is still in flight. */
|
|
316
|
+
allowSimultaneousRenders?: boolean;
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* The 4x4 camera matrix. Without `setCameraMatrix`, this is treated as the
|
|
320
|
+
* initial value only, and the camera is managed internally.
|
|
321
|
+
*/
|
|
322
|
+
cameraMatrix?: CameraMatrix | null;
|
|
323
|
+
/** Provide to take control of the camera matrix. */
|
|
324
|
+
setCameraMatrix?: ((cameraMatrix: CameraMatrix) => void) | null;
|
|
325
|
+
|
|
326
|
+
/** Whether clicking should run a picking query and call `onClick`. */
|
|
327
|
+
enableClick?: boolean;
|
|
328
|
+
/** Whether hovering should run a picking query and show a tooltip via `onHover`. */
|
|
329
|
+
enableTooltip?: boolean;
|
|
330
|
+
onClick?: ((result: PickingResult) => void) | null;
|
|
331
|
+
onHover?: ((result: PickingResult) => TooltipContent) | null;
|
|
332
|
+
|
|
333
|
+
// Brushing supports both a rectangular brush and a lasso (i.e., polygonal) brush.
|
|
334
|
+
// We draw a brush overlay as an SVG to indicate the drawn rect/polygon (both during the draw interactions and following completion).
|
|
335
|
+
// The brush overlay consists of either a rectangle with circle elements at its corner vertices,
|
|
336
|
+
// or a circle element at each polygon vertex, with lines connecting the polygon vertices.
|
|
337
|
+
|
|
338
|
+
// When the brush units mode is "Data", the brushed overlay rect/polygon is dependent on the camera matrix and responds to camera state updates.
|
|
339
|
+
// As the user zooms/pans, the overlay updates if the unitsMode is "Data" in either the X, Y, or XY directions.
|
|
340
|
+
// Both default to "Data".
|
|
341
|
+
brushUnitsModeX?: BrushUnitsMode;
|
|
342
|
+
brushUnitsModeY?: BrushUnitsMode;
|
|
343
|
+
|
|
344
|
+
// The brush margins restrict the brushable region to within the specified brush bounds.
|
|
345
|
+
// Each defaults to the corresponding layer margin, so by default the brushable region is the layer region.
|
|
346
|
+
// However, when brushUnitsModeY is "Data", we ignore brushMarginTop and brushMarginBottom, and instead the layer (i.e., camera) bounds (marginTop and marginBottom) take precedence.
|
|
347
|
+
brushMarginTop?: number;
|
|
348
|
+
brushMarginBottom?: number;
|
|
349
|
+
// However, when brushUnitsModeX is "Data", we ignore brushMarginLeft and brushMarginRight, and instead the layer (i.e., camera) bounds (marginLeft and marginRight) take precedence.
|
|
350
|
+
brushMarginLeft?: number;
|
|
351
|
+
brushMarginRight?: number;
|
|
352
|
+
|
|
353
|
+
// When true, the user can draw a brush rect/polygon by long-clicking and then dragging.
|
|
354
|
+
enableBrushCreate?: boolean;
|
|
355
|
+
// When true, the user can modify the vertices of persisted brushes (uncontrolled) or brushes passed via `brush` prop (controlled) by interacting with the overlay.
|
|
356
|
+
// For Rect, RangeX and RangeY, the user can also drag a side of the overlay to extend the brush in that direction alone.
|
|
357
|
+
// A range brush only exposes the two sides on the axis it selects, since the other axis always spans the whole brushable region.
|
|
358
|
+
enableBrushEdit?: boolean;
|
|
359
|
+
// When true, we display a clear button upon hovering the brush rect/polygon, to allow the user to clear/cancel the brush.
|
|
360
|
+
enableBrushClear?: boolean;
|
|
361
|
+
|
|
362
|
+
// Long-click of 1.5s to trigger a brushing interaction. If the user long-clicks for this amount of milliseconds, then they can being drawing the brush rect/lasso.
|
|
363
|
+
// Only relevant when enableBrushCreate is true.
|
|
364
|
+
// By default, 1500 ms.
|
|
365
|
+
brushDelay?: number;
|
|
366
|
+
|
|
367
|
+
// When a user has begun to click-and-hold for this amount of ms, we render a small circle at the current mouse cursor position, and animate the circle "filling" by rendering a wedge (slice of pie) with a larger angle until the wedge fills the whole pie (finishing at the specified brushDelay duration).
|
|
368
|
+
// Only relevant when enableBrushCreate is true.
|
|
369
|
+
// By default, 250ms.
|
|
370
|
+
maybeBrushDelay?: number;
|
|
371
|
+
|
|
372
|
+
// If true, the brush overlay should remain after the drag interaction.
|
|
373
|
+
// If false, the brush overlay should be removed upon the end of the drag interaction, after calling onBrushEnd.
|
|
374
|
+
persistBrush?: boolean;
|
|
375
|
+
|
|
376
|
+
// Which shape the user draws. By default, "Rect".
|
|
377
|
+
brushMode?: BrushMode;
|
|
378
|
+
|
|
379
|
+
// Color of the brush overlay (outline and vertex/edge handles). The fill uses
|
|
380
|
+
// this same color at reduced opacity. By default, "#3b6ea5".
|
|
381
|
+
brushColor?: string;
|
|
382
|
+
|
|
383
|
+
// For brushing, we support both controlled and uncontrolled (similar to the cameraMatrix/setCameraMatrix).
|
|
384
|
+
// When controlled, the parent provides the brush state (rect/polygon vertices) or `NO_BRUSH`.
|
|
385
|
+
// When uncontrolled, the value of `brush` is `null` (or the prop is omitted), so the brush state will be managed internally.
|
|
386
|
+
// When controlled via parent, we ignore the persistBrush prop; instead, the brush persists while the BrushState is specified/present.
|
|
387
|
+
// If null or absent, we take this to mean uncontrolled.
|
|
388
|
+
// If a BrushState object or `NO_BRUSH` is provided, we take this to mean controlled.
|
|
389
|
+
// A controlled parent must use `NO_BRUSH` rather than `undefined` for the empty
|
|
390
|
+
// state, since `undefined` is indistinguishable from the prop being omitted and
|
|
391
|
+
// would hand control back mid-interaction, resurfacing whatever the internal
|
|
392
|
+
// (uncontrolled) state last held.
|
|
393
|
+
// Note that when controlled, enableBrushCreate can be false (the user cannot long-click to draw a new brush),
|
|
394
|
+
// but the parent may still provide a brush value.
|
|
395
|
+
// When controlled, we only emit onBrush/onBrushEnd for internally-triggered updates (e.g., if enableBrushEdit is true) or clearing (e.g., if enableBrushClear is true).
|
|
396
|
+
brush?: BrushState | NoBrush | null;
|
|
397
|
+
|
|
398
|
+
// Called on drag interactions, as the user is drawing the brush rect/polygon.
|
|
399
|
+
// Also called if the brushed rect/polygon is edited (e.g., by dragging a vertex of a persisted brush, if enableBrushEdit is true).
|
|
400
|
+
// `brushingResult` is the result of running the brush query (via `brush_wasm`)
|
|
401
|
+
// against the current `state`.
|
|
402
|
+
onBrush?: (state: BrushState, brushingResult: BrushingResult|undefined) => BrushResult,
|
|
403
|
+
// Called at the conclusion of the drag interaction, with the final (i.e., complete) brush rect/polygon.
|
|
404
|
+
onBrushEnd?: (state: BrushState, brushingResult: BrushingResult|undefined) => BrushResult,
|
|
405
|
+
|
|
406
|
+
// Called upon the user cancelling the brush, e.g., by clicking a clear button which appears when hovering the drawn rect/polygon.
|
|
407
|
+
onBrushClear?: (state: BrushState) => void,
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
shouldClearCache?: boolean,
|
|
411
|
+
|
|
412
|
+
};
|