Skip to content

Programmatic Lasso/Polygon Selection #235

@glebmoisseyev

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

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