-
Notifications
You must be signed in to change notification settings - Fork 19
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
Support any number of points in SelectionTool #1430
Conversation
Thanks @PeterC-DLS, this feature is very welcome! However, this is not the right implementation approach, in my opinion.
It would have been great to discuss the naming of the component and the user needs it fulfils in an issue ahead of time. 😅 For instance, I'm not sure I get the need for being able to limit the number of points, and how this setting affects the overall interaction. I'm also not sure how drawing polylines vs polygons should be handled, both in terms of user freedom (i.e. should the user be able to do both at any time, or should this be controlled by a prop?) and interaction (e.g. ending the shape by clicking on the last point for a polyline or the first point for a polygon, or always the last point and auto-closing, or double-clicking, or pressing Enter, or ...) As a starting point, could you please maybe describe the situations that require your users to draw polylines and polygons? |
e09002d
to
c3462c6
Compare
The story with polylines is solely for demonstration. A real example of using unlimited number of points to fit an ellipse manually by selecting points on its outline in a diffraction pattern. As the user selects more points, the fit may improve. |
Another easy example is allowing a user to define a tilted ellipse by three points: its centre, major semi-axis, then minor semi-axes. |
Makes sense. So the interaction comes down to creating the outline of a polygon one point at a time. Closing the polygonThe main decision I see is how to close the polygon when you're done drawing it. In Inkscape, this is done by clicking on the first point of the path: If you double click instead (which is similar to clicking again on the last point of the path), you make a polyline, not a polygon. Personally, I find clicking on the first point to be more natural. Of course, this doesn't necessarily mean adding the starting point twice in the resulting array. Closing the polygon with the Enter key is a great shortcut for power users, with which I'm fully on board. AffordanceA couple of other things we can learn from Inkscape:
Concerning the second point, we could go a step further and always render the polygon closed as if the user were about to close it, and connect the mouse position to the polygon with two additional, more subtle lines (one to the starting point and one to the last-added point). ValidationI'm not sure about this. I'd be more incline to let consumers implement their own validation through a I suggest we wait for a more concrete validation use case. For now, we can allow closing the polygon (and show the corresponding affordance mechanism) once the user has added at least 3 points. CancellationWhen it comes to cancelling the creation of the polygon, I'm on board with using Escape like in ImplementationWith all this in mind, here is what I'm thinking for a first implementation:
This is a very interesting use case. The adjective "tilted" is crucial, as it explains why the ellipse cannot be drawn with the Clearly, here, clicking on the first point to close the polygon makes no sense. This makes me think that we shouldn't try to solve the two use cases with the same component. Perhaps we can abstract a custom hook from |
I think the polygon case is special in the sense that the shape is closed so "last" point is automatically the first. In an earlier version of my PR, I used a SVG |
c3462c6
to
af577e9
Compare
This adds a capability to define selections that need different number of points: 1. Can specify minimum number of points 2. Can specify maximum number of points, can be -1 for no limit 3. When number of points is at least minimum - set status boolean - end selection on enter/return key press - pointer down on same position sets last point (within maxMovement) Also make SVG selections compatible using new type, add SvgPolyline and use in new story
af577e9
to
b3ba08c
Compare
Closing this, sorry. To reiterate, modifying You will have a much easier time implementing your own interaction component directly in your project (rather than in your fork of H5Web) so that H5Web's |
This adds a capability to define selections that need different number of points:
- set status boolean
- end selection on enter/return key press
- pointer down on same position sets last point (within maxMovement)
Also make SVG selections compatible using new type, add SvgPolyline and use in new story