veg / phylotree.js

Interactive viewer of phylogenetic trees
http://phylotree.hyphy.org
MIT License
169 stars 72 forks source link

Node popup with invalid position when tree is not at the top of a page (fix included) #356

Closed guignonv closed 3 years ago

guignonv commented 3 years ago

I have a page that includes the phylotree SVG after a couple of other HTML elements (page headers, menus, paragraphs, etc.) so I need to scroll down on my page to watch the tree. When I click on a node to get its popup, the popup "appears" at the top of my page, in my page header, instead of next to the tree node I clicked. I investigated the source code and fixed it on my instance. I believe you should integrate that change but I can't run heavy testings so I let you consider the change: Orignal code (main.js, line 1048):

        var tree_container = $(self.container);
        var coordinates = d3.mouse(tree_container[0]);
        menu_object
          .style("position", "absolute")
          .style("left", "" + coordinates[0] + "px")
          .style("top", "" + coordinates[1] + "px")
          .style("display", "block");

Should be turned into:

        var tree_container = $(self.container);
        var coordinates = d3.mouse(tree_container[0]);
        menu_object
          .style("position", "absolute")
          .style("left", "" + (coordinates[0] + tree_container.position().left) + "px")
          .style("top", "" + (coordinates[1] + tree_container.position().top) + "px")
          .style("display", "block");
spond commented 3 years ago

Dear @guignonv,

Thanks! You can go ahead and issue a pull request if you don't mind.

Best, Sergei

guignonv commented 3 years ago

@spond I'll do that. ;)