datastorm-open / visNetwork

R package, using vis.js library for network visualization
Other
545 stars 125 forks source link

[Bug] Nested selfReference parameters #379

Closed julianstanley closed 4 years ago

julianstanley commented 4 years ago

Recently, I've needed nodes to have two self-referencing edges.

Ideally, they would look like this:

image

In vis.js, I do this by setting the edge.selfReference.angle parameter, e.g.:

{ from":1,"to":1,"arrows":"to","label":"Edge 1", selfReference: {angle: 2*Math.PI} }

See full jsbin example here.

As stated here the dot notation should work for this, right? But it doesn't seem to work in my hands, on visNetwork 2.1.0.

Example:

visNetwork(nodes = data.frame(label = "Node 1", id = 1), 
           edges = data.frame(id = c("Edge1", "Edge2"),
                              label = c("Edge 1", "Edge 2"),
                              to = c(1, 1), 
                              from = c(1,1), 
                              selfReference.angle = c(2*pi, pi)))

Should output the same as above, but instead outputs:

image

I noticed while experimenting that the selfReference.angle parameter doesn't work with some vis-network versions, but it does work with 7.5.2.

bthieurmel commented 4 years ago

Hi,

Fix on github (removing some controls on allowed split columns...) :

# using DF and dot notation
nodes <- data.frame(id = 1:3)
edges <- data.frame(from = c(1, 1, 2), 
                    to = c(1,1, 3), 
                    selfReference.angle = c(2*pi, pi, NA))
visNetwork(nodes, edges)

And using a list, it's ok to with this structure :

# using a list
nodes <- list(list(id = 1), list(id = 2), list(id = 3))
edges <- list(list(from = 1, to = 1, selfReference = list(angle = pi)), 
              list(from = 1, to = 1, selfReference = list(angle = 2 *pi)), 
              list(from = 2, to = 3))

visNetwork(nodes, edges)
julianstanley commented 4 years ago

This now works brilliantly:

visNetwork(nodes = data.frame(label = "Node 1", id = 1), 
           edges = data.frame(id = c("Edge1", "Edge2"),
                              label = c("Edge 1", "Edge 2"),
                              to = c(1, 1), 
                              from = c(1,1), 
                              selfReference.angle = c(2*pi, pi),
                              selfReference.size = c(30, 30)))

image

Thank you!!!