0

I have an issue on triggering mouse event on a svg.

I am using the library d3.js to handle some graphic tasks. Specifically, when I manually click on a position on the svg, d3 draws a red or blue (depending on the path I am clicking on) circle on it and then returns the d3.mouse coordinates of the click.

Now, suppose I have a set of coordinates and want to trigger programmatically click on the corresponding point on the svg, so that it draws a red or blue circle automatically. How can I achieve that?

I read many solutions here but none allows to click on specific coordinates (while I can easily click on a specific path, for example).

My ideal function would be:

    var svgd3 = d3.select('svg#id_svg')

    function d3click(x,y,svgd3){

    //does the click on [x,y, x,y are relative coord. depending only svg viewBox
    ...
    }

Any idea?

Thanks a lot!

MBerra
  • 13
  • 3
  • I'd talk about `d3.dispatch`, but on a second thought that seems to be a [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) to me. What do you want, just to get the path under a given coordinate? – Gerardo Furtado Sep 14 '17 at 15:22
  • I have listeners on each svg path that triggers specific functions when the user clicks on them. Namely: draw a circle, fill the path, return the specific coordinates of the click. The "automated" click should trigger the same action. – MBerra Sep 14 '17 at 15:36
  • @GerardoFurtado Having the path under the given coordinates would help. The main reason why I want to "exactly" mimic the click is because I want that the user has the same feel when he insert the position with the mouse or when he does it from a source (i.e., using the trigger I describe). Anyway this is what happens when the user clicks: 1) the path fills with blue. all the path of the same group gets filled by light blue. Then, a circle is drawn on the coordinate. Path name and coordinates are returned and used elsewhere. Hope now the picture is clear. – MBerra Sep 14 '17 at 16:03
  • Please show us what you have tried. Edit: Please also describe how the point that you want to trigger the click event for is determined. – Pytth Sep 14 '17 at 18:00
  • @Pytth I used this solution https://stackoverflow.com/questions/9063383/how-to-invoke-click-event-programmatically-in-d3 but I was only able to click on a general point of a svg path. The point is determined by an external file that contains coordinates – MBerra Sep 15 '17 at 06:29

0 Answers0