@hema-to/regl-scatterplot 1.14.1-hemato.3 → 1.16.0-hemato.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/README.md +94 -0
- package/dist/regl-scatterplot.esm.d.ts +2 -0
- package/dist/regl-scatterplot.esm.js +1782 -1624
- package/dist/regl-scatterplot.js +1745 -1743
- package/dist/regl-scatterplot.min.js +3 -8
- package/dist/types.d.ts +5 -6
- package/package.json +27 -27
- package/src/constants.js +1 -0
- package/src/index.js +216 -42
- package/src/kdbush-worker.js +0 -1
- package/src/kdbush.js +2 -3
- package/src/lasso-manager/index.js +6 -8
- package/src/renderer.js +0 -2
- package/src/spline-curve-worker.js +0 -3
- package/src/types.d.ts +5 -6
- package/src/utils.js +40 -4
package/README.md
CHANGED
|
@@ -516,6 +516,85 @@ scatterplot.draw([
|
|
|
516
516
|
scatterplot.select([0, 1]);
|
|
517
517
|
```
|
|
518
518
|
|
|
519
|
+
<a name="scatterplot.lassoSelect" href="#scatterplot.lassoSelect">#</a> scatterplot.<b>lassoSelect</b>(<i>vertices</i>, <i>options = {}</i>)
|
|
520
|
+
|
|
521
|
+
Programmatically select points within a polygon region. This enables automated point selection without manual lasso interaction. This will trigger a `select` event (and `lassoEnd` event) unless `options.preventEvent === true`.
|
|
522
|
+
|
|
523
|
+
**Arguments:**
|
|
524
|
+
|
|
525
|
+
- `vertices` is an array of `[x, y]` coordinate pairs defining the polygon (minimum 3 vertices required). Coordinates are in **data space** by default (requires `xScale` and `yScale`), or **GL space** if `options.isGl === true`.
|
|
526
|
+
- `options` [optional] is an object with the following properties:
|
|
527
|
+
- `merge`: if `true`, add the selected points to the current selection instead of replacing it.
|
|
528
|
+
- `remove`: if `true`, remove the selected points from the current selection.
|
|
529
|
+
- `isGl`: if `true`, interpret vertices as GL space coordinates (NDC). If `false` (default), interpret vertices as data space coordinates.
|
|
530
|
+
- `preventEvent`: if `true` the `select` and `lassoEnd` events will not be published.
|
|
531
|
+
|
|
532
|
+
**Notes:**
|
|
533
|
+
|
|
534
|
+
- Polygons are automatically closed if the first and last vertices differ.
|
|
535
|
+
- Data space coordinates require `xScale` and `yScale` to be defined during scatterplot initialization.
|
|
536
|
+
- GL space coordinates work without scales and are useful for direct NDC coordinate selection.
|
|
537
|
+
|
|
538
|
+
**Examples:**
|
|
539
|
+
|
|
540
|
+
```javascript
|
|
541
|
+
import { scaleLinear } from 'd3-scale';
|
|
542
|
+
|
|
543
|
+
// Create scatterplot with scales for data space coordinates
|
|
544
|
+
const scatterplot = createScatterplot({
|
|
545
|
+
canvas,
|
|
546
|
+
xScale: scaleLinear().domain([0, 100]),
|
|
547
|
+
yScale: scaleLinear().domain([0, 100]),
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
// Draw points (internally stored in NDC, but we think in data space)
|
|
551
|
+
scatterplot.draw([
|
|
552
|
+
[-0.8, -0.8], // corresponds to data coords ~[10, 10]
|
|
553
|
+
[0.8, 0.8], // corresponds to data coords ~[90, 90]
|
|
554
|
+
[0, 0], // corresponds to data coords [50, 50]
|
|
555
|
+
]);
|
|
556
|
+
|
|
557
|
+
// Select points within a triangular region (data space coordinates)
|
|
558
|
+
scatterplot.lassoSelect([
|
|
559
|
+
[10, 20],
|
|
560
|
+
[50, 80],
|
|
561
|
+
[90, 30]
|
|
562
|
+
]);
|
|
563
|
+
|
|
564
|
+
// Select points within a rectangle, merging with current selection
|
|
565
|
+
scatterplot.lassoSelect(
|
|
566
|
+
[
|
|
567
|
+
[0, 0],
|
|
568
|
+
[100, 0],
|
|
569
|
+
[100, 100],
|
|
570
|
+
[0, 100]
|
|
571
|
+
],
|
|
572
|
+
{ merge: true }
|
|
573
|
+
);
|
|
574
|
+
|
|
575
|
+
// Remove points in a polygon from the current selection
|
|
576
|
+
scatterplot.lassoSelect(
|
|
577
|
+
[
|
|
578
|
+
[40, 40],
|
|
579
|
+
[60, 40],
|
|
580
|
+
[60, 60],
|
|
581
|
+
[40, 60]
|
|
582
|
+
],
|
|
583
|
+
{ remove: true }
|
|
584
|
+
);
|
|
585
|
+
|
|
586
|
+
// Use GL space coordinates (useful without scales)
|
|
587
|
+
scatterplot.lassoSelect(
|
|
588
|
+
[
|
|
589
|
+
[-0.5, -0.5],
|
|
590
|
+
[0.5, -0.5],
|
|
591
|
+
[0.5, 0.5],
|
|
592
|
+
[-0.5, 0.5]
|
|
593
|
+
],
|
|
594
|
+
{ isGl: true }
|
|
595
|
+
);
|
|
596
|
+
```
|
|
597
|
+
|
|
519
598
|
<a name="scatterplot.deselect" href="#scatterplot.deselect">#</a> scatterplot.<b>deselect</b>(<i>options = {}</i>)
|
|
520
599
|
|
|
521
600
|
Deselect all selected points. This will trigger a `deselect` event unless `options.preventEvent === true`.
|
|
@@ -764,6 +843,7 @@ can be read and written via [`scatterplot.get()`](#scatterplot.get) and [`scatte
|
|
|
764
843
|
| colorBy | string | `null` | See [data encoding](#property-by) | `true` | `true` |
|
|
765
844
|
| sizeBy | string | `null` | See [data encoding](#property-by) | `true` | `true` |
|
|
766
845
|
| opacityBy | string | `null` | See [data encoding](#property-by) | `true` | `true` |
|
|
846
|
+
| pointOrder | int[] | `null` | Array of point indices defining draw order | `true` | `true` |
|
|
767
847
|
| deselectOnDblClick | boolean | `true` | | `true` | `false` |
|
|
768
848
|
| deselectOnEscape | boolean | `true` | | `true` | `false` |
|
|
769
849
|
| opacity | float | `1` | Must be in ]0, 1] | `true` | `false` |
|
|
@@ -890,6 +970,20 @@ example go to [dynamic-opacity.html](https://flekschas.github.io/regl-scatterplo
|
|
|
890
970
|
The implementation is an extension of [Ricky Reusser's awesome notebook](https://observablehq.com/@rreusser/selecting-the-right-opacity-for-2d-point-clouds).
|
|
891
971
|
Huuuge kudos Ricky! 🙇♂️
|
|
892
972
|
|
|
973
|
+
<a name="property-point-order" href="#property-point-order">#</a> <b>pointOrder:</b>
|
|
974
|
+
|
|
975
|
+
By default, points are drawn in the order they appear in the input data. Since depth testing is disabled, later-drawn points render on top of earlier ones. To control the draw order, set `pointOrder` to an array of point indices. Points are drawn in array order, so the last index renders on top. Any indices not included in the array are appended in sequential order.
|
|
976
|
+
|
|
977
|
+
```javascript
|
|
978
|
+
// Ensure point 3 is drawn on top
|
|
979
|
+
scatterplot.set({ pointOrder: [0, 1, 2, 4, 3] });
|
|
980
|
+
|
|
981
|
+
// Reset to default input order
|
|
982
|
+
scatterplot.set({ pointOrder: null });
|
|
983
|
+
```
|
|
984
|
+
|
|
985
|
+
The point order is respected when [filtering](#scatterplot.filter), and resets automatically when `draw()` is called with a different number of points.
|
|
986
|
+
|
|
893
987
|
<a name="property-point-conntection-by" href="#property-point-conntection-by">#</a> <b>pointConnectionColorBy, pointConnectionOpacityBy, and pointConnectionSizeBy:</b>
|
|
894
988
|
|
|
895
989
|
In addition to the properties understood by [`colorBy`, etc.](#property-by),
|
|
@@ -65,6 +65,7 @@ export function createSpatialIndex(points: import("./types").Points, useWorker?:
|
|
|
65
65
|
*/
|
|
66
66
|
export function createTextureFromUrl(regl: import("regl").Regl, url: string, timeout?: number): Promise<import("regl").Texture2D>;
|
|
67
67
|
declare function createScatterplot(initialProperties?: Partial<import("./types").Properties>): {
|
|
68
|
+
attachSpatialIndex: (buffer: any) => void;
|
|
68
69
|
/**
|
|
69
70
|
* Get whether the browser supports all necessary WebGL features
|
|
70
71
|
* @return {boolean} If `true` the browser supports all necessary WebGL features
|
|
@@ -85,6 +86,7 @@ declare function createScatterplot(initialProperties?: Partial<import("./types")
|
|
|
85
86
|
get: <Key extends keyof import("./types").Properties>(property: Key) => import("./types").Properties[Key];
|
|
86
87
|
getScreenPosition: (pointIdx: number) => [number, number] | undefined;
|
|
87
88
|
hover: (point: number, { showReticleOnce, preventEvent }?: import("./types").ScatterplotMethodOptions["hover"]) => void;
|
|
89
|
+
lassoSelect: (vertices: [number, number][], { merge, remove, isGl }?: import("./types").ScatterplotMethodOptions["lasso"]) => void;
|
|
88
90
|
redraw: () => void;
|
|
89
91
|
refresh: () => void;
|
|
90
92
|
reset: (args_0?: Partial<{
|