Skip to content

Programmatic Lasso/Polygon Selection #235

Closed

Description

@glebmoisseyev

name: 'Enhancement'
about: 'Add programmatic lasso selection API'
labels: 'Enhancement 🎉'

Goal

Enable programmatic selection of points using polygons in data space, complementing the existing interactive lasso tool.

Use Cases

  • 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.

Current Limitation

scatterplot.select() only accepts point indices, requiring users to manually implement point-in-polygon algorithms:

scatterplot.select([0, 5, 12, 47]); // Requires pre-computing which points are in region

Proposed Solution

Extend select() to accept polygon vertices in data space:

// Select points within a triangle (data coordinates)
scatterplot.select([
  [10, 20],
  [50, 80],
  [90, 30]
]);

// Works with merge/remove modes
scatterplot.select(rectanglePolygon, { merge: true });

Backward Compatible: Automatically detects polygon vs indices based on input type.

Implementation Details

Reuses existing findPointsInLasso()

const isPolygon = (arg) =>
  Array.isArray(arg) && arg.length >= 3 &&
  Array.isArray(arg[0]) && arg[0].length === 2;

const select = (pointIdxsOrPolygon, options = {}) => {
  if (isPolygon(pointIdxsOrPolygon)) {
    const polygonGl = transformDataToGl(pointIdxsOrPolygon);
    const points = findPointsInLasso(polygonGl);
    select(points, options); // Recurse with indices
    return;
  }
  // Existing logic...
};

Checklist

  • No duplicate issues
  • Use cases described
  • Backward compatible
  • Working demo included
  • Implementation prototyped

Activity

  1. glebmoisseyev commented on Jan 6, 2026

    @glebmoisseyev
    ContributorAuthor

    I went ahead and put together a draft PR implementing this here:
    #236

  2. flekschas commented on Jan 6, 2026

    @flekschas
    Owner

    I'm not sure we should overload the select function. I think it'd cleaner to add a new method called scatterplot.lasso() This public function could just call lassoEnd I think. I'll take a look at your PR.

  3. flekschas commented on Jan 13, 2026

    @flekschas
    Owner

    Closed via #236 and released in v1.15.0! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    new featureNew feature or functionality

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions