christophergandrud / networkD3

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

Zoom feature for saveNetwork #249

Closed MayaGans closed 5 years ago

MayaGans commented 5 years ago

Hi! Firstly I wanted to thank you for such a wonderful package; as a student new to network analyses it produces beautiful visualizations!

When using the saveNetwork function it seems I've lost the ability to zoom in and out of the graph through scrolling/pinching. Is there some code/javascript I can include within the html file that will allow me to pinch (in example #196 in the shiny app this feature does seem to work)??

Thank you, again!

cjyetman commented 5 years ago

Can you provide a minimal reproducible example so we know we’re on the same page please?

MayaGans commented 5 years ago

Well this is a frustrating turn of events. When I run the code using the example network it works as expected. The graph I am working on however is a lot larger. It seems I can zoom in but I can't zoom out to see the network in its entirety.

Unfortunately, this is my first foray into network analysis so I'm unsure how to create a larger simulation than the one provided by the package. I know it's far too much information but I've attached the html file I created (as a .txt because github wont support html).

This works:


repex <- forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
             Target = "target", Value = "value", NodeID = "name",
             Group = "group", opacity = 1, zoom = FALSE,
             bounded = TRUE)

saveNetwork(repex, "repex.html", selfcontained = TRUE)

This does not: networkd3_weight.txt

Any help is greatly appreciated!!

cjyetman commented 5 years ago

Your first example is not reproducible because you did not provide MyClickScript.

Your second example is not reproducible either because you only included the HTML output, not the code used to create it.

MayaGans commented 5 years ago

I removed the clickAction statement from my comment above, that shouldn't matter for the issue I'm having. As I mentioned in my comment I am struggling to provide a reproducible example and supplied only the html because the data for my network is large and within Neo4J.

Without being able to reproduce my network the code I used to produce it was:

forceNetwork(edges, nodes, Source = "source", Target = "target", 
             NodeID = "name", Group = "group", Nodesize = "Nodesize",
             linkWidth = edges$weight, zoom = TRUE, fontSize = 50, opacity = 0.8)

If this is too difficult to work with I understand and I'll close the issue.

cjyetman commented 5 years ago

The "minimal" in minimal reproducible example means that the dataset and the complexity of the example code has been reduced as much as possible while still demonstrating the problem. So I don't need your full dataset and your full project code, just enough to demonstrate the problem. If you can't or won't provide that, then I will have to create one myself to analyze the problem and test potential solutions... which just means that it will take longer before I find the time and motivation to do so. Also, please do not discount the effect of things like what is passed to the clickAction parameter... adding custom JavaScript into the mix most definitely can have an effect on the zooming function, which is also achieved through JavaScript.

MayaGans commented 5 years ago

I changed the scale parameter in forceNetwork and now I'm able to pan/zoom! Not sure that's an actual resolution to the issue but enough to make me happy