Skip to content

Conversation

@glebmoisseyev
Copy link

@glebmoisseyev glebmoisseyev commented Jan 6, 2026

  • Add dedicated lassoSelect() method for programmatic polygon selection
  • Accepts array of [x,y] coordinate pairs in data space (default) or GL space
  • Supports merge, remove, and isGl options
  • Auto-closes open polygons via verticesToPolygon() helper
  • Add test suite (8 tests)
  • Add programmatic-lasso.js example with interactive demo
  • Update README with API documentation and examples
  • Add to Examples menu in Tweakpane

Description

Adds scatterplot.lassoSelect(vertices, options) method to enable automated point selection without manual interaction. Vertices can be specified in data space (using xScale/yScale) or GL space (isGl: true). This provides a programmatic alternative to the interactive lasso tool.

What was changed in this pull request?

New API:

  • lassoSelect(vertices, { merge, remove, isGl }) - dedicated method for programmatic lasso
  • vertices - array of [x, y] coordinates (minimum 3 vertices)
  • isGl: false (default) - vertices in data space, requires xScale/yScale
  • isGl: true - vertices in GL space, works without scales

Helper functions:

  • isVertices() - validates all vertices are valid [x, y] pairs
  • verticesToPolygon() - auto-closes polygons if first/last vertices differ
  • verticesFromDataToGl() - converts data space → GL space coordinates

Example

Screenshot 2026-01-05 at 9 54 00 PM
// Data space (requires xScale/yScale)
scatterplot.lassoSelect([
  [10, 20],
  [50, 80],
  [90, 30]
]);

// GL space (works without scales)
scatterplot.lassoSelect(
  [[-0.5, -0.5], [0.5, -0.5], [0.5, 0.5], [-0.5, 0.5]],
  { isGl: true }
);

// Merge and remove modes
scatterplot.lassoSelect(polygon, { merge: true });
scatterplot.lassoSelect(polygon, { remove: true });

Why is this PR necessary?

  • Annotation replay: load an existing session and re-apply the saved lasso region so the same points get selected again.
  • Predefined regions: select a known ROI polygon (e.g., “this cluster boundary”) as part of a workflow.
  • Reproducible selections: store the polygon vertices and get consistent results across runs.

Checklist

  • Provided a concise title as a semantic commit message (e.g. "fix: correctly handle undefined properties")
  • CHANGELOG.md updated
  • Tests added or updated
  • Documentation in README.md added or updated
  • Example(s) added or updated
  • Screenshot, gif, or video attached for visual changes

- Add polygon selection API to select() method
- Accepts array of [x,y] coordinate pairs in data space
- Reuses existing findPointsInLasso() with KD-tree
- Supports merge and remove modes
- Add programmatic-lasso.js example with interactive demo
- Update README with API documentation and examples
- Add to Examples menu in Tweakpane
Copy link
Owner

@flekschas flekschas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌 Thanks for putting this together! 🎉 I really like this feature 👏 but I would say we should expose it as a new function: scatterplot.lasso(). I tried to flesh out the details as PR comments but there's more docs adjustments needed.

Most critically, we need a test :) You could add one that's essentially identical to https://github.com/flekschas/regl-scatterplot/blob/main/tests/events.test.js#L312-L399 but uses the new lasso method instead of emitting events. We should be testing:

  1. data space lasso polygon
  2. GL space lasso polygon
  3. an open polygon
  4. edge cases like when less than 3 vertices are passed to the lasso() function or the user uses vertices in data space without xScale and yScale

  - Replace overloaded select(polygon) with lassoSelect(vertices) API
  - Add isVertices() validation checking all vertices
  - Add verticesToPolygon() helper to auto-close polygons
  - Rename polygonDataToGl to verticesFromDataToGl for clarity
  - Addtests
  - Update programmatic-lasso example to use new API
  - Update changelog.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants