-
Notifications
You must be signed in to change notification settings - Fork 28
feat: implement programmatic lasso selection #236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: implement programmatic lasso selection #236
Conversation
- 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
There was a problem hiding this 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:
- data space lasso polygon
- GL space lasso polygon
- an open polygon
- 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
flekschas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! 🎉 Thanks for the adjustments
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 lassovertices- array of[x, y]coordinates (minimum 3 vertices)isGl: false(default) - vertices in data space, requires xScale/yScaleisGl: true- vertices in GL space, works without scalesHelper functions:
isVertices()- validates all vertices are valid[x, y]pairsverticesToPolygon()- auto-closes polygons if first/last vertices differverticesFromDataToGl()- converts data space → GL space coordinatesExample
Why is this PR necessary?
Checklist
CHANGELOG.mdupdatedREADME.mdadded or updated