Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom context menu in d3 and svg

I would like to have custom context menu appearing when I right click on an svg circle. For now I have found this answer that helps me to handle the right click with the following code:

.on("contextmenu", function(data, index) {
   //handle right click

   //stop showing browser menu
   d3.event.preventDefault()
});

Now I would like to know how I can show a box containing some HTML.

Thanks in advance.

like image 703
Christopher Chiche Avatar asked Oct 26 '12 15:10

Christopher Chiche


1 Answers

d3.select('#stock_details .sym').on("contextmenu", function(data, index) {
    var position = d3.mouse(this);
    d3.select('#my_custom_menu')
      .style('position', 'absolute')
      .style('left', position[0] + "px")
      .style('top', position[1] + "px")
      .style('display', 'block');

    d3.event.preventDefault();
});
like image 160
meetamit Avatar answered Sep 25 '22 22:09

meetamit