d3.js - d3.event.y has strange values during drag behavior -
I show a layout with resizeable cells using D3 drag behavior and CSS {display: table Is making an example}
Styles This works fine to pull horizontally, but not vertical for vertical resizing, d3.event.y
is providing those values Which I do not understand.
The horizontal drag and working vertical drag shows here, take a look at the console output when to see the values returned by d3.event
to Drag the values returned by d3.mouse ()
for the horizontal drag, but get distracted for the vertical drag.
I can correct the behavior by using d3.mouse ()
y-coordinate using d3.event
y -coordinate. To see it, comment the line "does not work" and remove the "Works" line, however, I do not understand why I need to do this, and it seems that I have more general D3 . Instead of using the event, you have to accept mouse input.
Is this a bug, or have I failed to understand something here?
Note that to hit the same problem, but using the HTML table instead of CSS tables, I thought it would be helpful for the document that this problem is happening in both contexts.
Also keep in mind that commenting on two lines, which actually do vertical resizing, comment with "RESIZE CELLS", D3. Event
work properly Of course, if the table does not resize again, then it shows that it is something about divs-shaped work which is wandering d3.event
.
OK, I think I have understood this issue. If you look at the drag behavior, you will notice in dragstart
that the value used to calculate the mouse offset is based on the this.parentNode
. In essence, it uses this.parentNode
as a reference point, and assumes that it is going to be stable for the duration of the drag you are modifying parental nodes during drag , So its reference point, technically, beautiful bourgeoard is inserted. In this case, using d3.mouse
is your best bet, since d3.event.y
is only going to be trustworthy until the parent node is in place Lives in / P>
The reason for this is for you in the y direction that it is that the x position of all the rows, which have parental nodes here, remain constant, while the y component changes during drag.
Position (parent, drag idd), dx, DE; // ... Send ({type: "drag", X: position 1 [0] + drag offset [0], Y: position 1 [1] + drag offset [1], dx: dx, DE: DI});
Comments
Post a Comment