-
Notifications
You must be signed in to change notification settings - Fork 53
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
Pass along mode to BrushEvent #75
Conversation
We are almost ready to release d3-brush@2 with a modified API, so you will probably have to rebase it on #71 (or wait a few days for it to be merged). Can you share a (real world) example of how this is useful? |
Hi @Fil , Sure, here is our real world scenario: We allow our users to draw 2D boxes in the plot, to indicate areas of interest. For example: if the user is using the "north" handle to vertically expand the selection, and at some point reaches an existing box, then we ensure that the "north" handle does not move past the border of the existing box. The way that the selection needs to be Hope this makes sense, and explains why we need information about the mode. |
I've created this notebook to illustrate the problem: |
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.
Looks good. Would benefit from updating the README to mention the new mode field.
v2 is now in master. It emits a specific brushEvent on each event. That event is structured like so: {
type: "brush", // or "start", "end"…
sourceEvent: MouseEvent {…},
target: …,
selection: [[x0, y0], [x1, y1]]
} I think that this is where we would now add |
Thanks @Fil
|
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.
Works well 👍
Co-authored-by: Philippe Rivière <[email protected]>
Co-authored-by: Philippe Rivière <[email protected]>
Co-authored-by: Philippe Rivière <[email protected]>
Good catch in the review, how did I miss this?? |
FYI: here's my attempt at a solution to stop the brush from intersecting other rectangles, using the newly added functionality. Some improvements can be made, but I will need more information from the brush's state to achieve it. https://observablehq.com/@woutervh-/brush-with-collision-solution-continued |
Hello.
In my project I need to know the
mode
of the brush in the event handler.This is because depending on which axis (x/y) the user is resizing the selection in, or whether the user is moving the selection without resizing (dragging), I need to change my logic on the snapping/clipping of the brush selection.
In this PR is my attempt at including the
mode
inBrushEvent
.I've tested it in my local project and it works fine.
Not sure if this is how you would solve it, so feel free to edit it.