sunnygugl.blogg.se

D3 mouse coordinates
D3 mouse coordinates







d3 mouse coordinates

Same as event is the current touch event. Same as event is the current mouse event.

d3 mouse coordinates

The user space is usually defined by a parent container element, such as or It can also be defined by a shape (for example, a if positioned with a transform attribute (instead of its x and y attributes). Returns an array with the coordinates of the provided event relative to the coordinates of the user space of the selected component. A better option is to use one of the functions listed in the following table, which returns coordinates that are relative to the parent container: The browser's viewport is usually not the same as the SVG viewport (unless you position the SVG element absolutely at 0,0 and make its height and width occupy all the available space), but clicking a container element in a translated coordinate space will still return absolute coordinates, which will need to be translated to local coordinates.

#D3 mouse coordinates code#

In a listener that captures for example, you can capture the mouse pointer's coordinates, (relative to the browser's viewport) using the d3.event object, as shown in the following code (see You can use it to access standard Event fields, such as or fields of the specific interface type (for if and methods, such as preventDefault() and The global d3.event object is a generic event wrapper that contains the current event during the execution of a listener.









D3 mouse coordinates