I'm just started with D3.js, and I want to create something like what we do in Paint to draw a line. The steps are should be the same: - Click on a point on the screen - Drag to the destination to create a line.
What I'm having troubles now is when you drag your mouse to the destination, the line should move according to your mouse. How can I do that?
Thanks.
Here's a simple example. Also see live version.
I think the part you're looking for is in the
mousemove
event handler where we select the current line and adjust it's destination point based on the current mouse location. Note that we only enablemousemove
inmousedown
to avoid superfluous processing.