christophergandrud / networkD3

D3 JavaScript Network Graphs from R
http://christophergandrud.github.io/networkD3
652 stars 268 forks source link

Keep legend fixed when zooming/panning #192

Open sirallen opened 7 years ago

sirallen commented 7 years ago

This is a wonderful package.

Currently the legend (legend = TRUE) moves around and scales with a forceNetwork when the user pans and zooms, which--I think it's fair to say--is not ideal. Would be better if the legend were fixed in the top left of the plot area.

cjyetman commented 7 years ago

I think this is a reasonable suggestion, even if not as easy to implement as it may sound. Would anyone miss the old behavior? Not sure it would be worth the hassle supporting both?

Iirc, everything is put in an SVG group that can pan and zoom, so it might be as easy as putting the legend in a different group.

christophergandrud commented 7 years ago

Continuing to support the non-fixed-location behaviour does seem strange.

sirallen commented 7 years ago

Hey, so I took a look at the htmlwidget for forceNetwork. Looks like a very simple change; just

var legend = d3.select(el).select('svg').selectAll('.legend')...