Pindar
Pindar

Reputation: 51

How to disable the mouseover effect in networkD3 / d3Network network diagrams (GNU R package)

I would like to disable the mouseover effect in network diagrams as provided on http://christophergandrud.github.io/d3Network/ (search for 'enlarge'). Even if there is no native option I guess it is possible by using htmltools or htmlwidget inserting the appropriate javascript functions (e.g. http://bl.ocks.org/PandaRider/84b9c096e37334c2a4fd945a66b8ccf9).

Update: Just noticed that the annoying effect shows up in Chrome not in Edge.

Upvotes: 2

Views: 463

Answers (1)

CJ Yetman
CJ Yetman

Reputation: 8848

It is not supported "natively", but you can achieve this with htmlwidgets::onRender...

for forceNetwork():

library(networkD3)
library(htmlwidgets)

data(MisLinks)
data(MisNodes)

fn <- forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source", 
                   Target = "target", Value = "value", NodeID = "name",
                   Group = "group")

onRender(fn, "function(el,x) { d3.selectAll('.node').on('mouseover', null); }")

for diagonalNetwork() and radialNetwork():

library(networkD3)
library(htmlwidgets)

URL <- paste0("https://cdn.rawgit.com/christophergandrud/networkD3/",
              "master/JSONdata//flare.json")

Flare <- jsonlite::fromJSON(URL, simplifyDataFrame = FALSE)
Flare$children = Flare$children[1:3]

rn <- radialNetwork(List = Flare, fontSize = 10, opacity = 0.9)
onRender(rn, "function(el, x) { d3.selectAll('.node').on('mouseover', null); }")

dn <- diagonalNetwork(List = Flare, fontSize = 10, opacity = 0.9)
onRender(dn, "function(el, x) { d3.selectAll('.node').on('mouseover', null); }")

Upvotes: 1

Related Questions