christophergandrud / networkD3

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

Nodes Font Color #287

Closed higor-gomes93 closed 2 years ago

higor-gomes93 commented 2 years ago

Hi! I'm having trouble with my nodes labels. Nodes and nodes labels have the same colors when using forceNetwork. This was addressed in this issue , but I couldn't solve my problem. Any thoughs on how to solve this?

cjyetman commented 2 years ago

This works for me...

library(networkD3)
library(htmlwidgets)

net <- forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
             Target = "target", Value = "value", NodeID = "name",
             Group = "group", opacity = 1, fontSize = 24, 
             fontFamily = "helvetica", opacityNoHover = 1)

customJS <- 
  'function() { 
    d3.selectAll(".node text").attr("stroke-width", ".5px").attr("stroke", "#fff");
  }'

htmlwidgets::onRender(net, customJS)

can you provide a minimal reproducible example to demonstrate the problem you're having?

higor-gomes93 commented 2 years ago

That really worked for me, cjyetman! Thank you very much. Any clues on how to change de text colour inside the customJS function?

cjyetman commented 2 years ago

I don't know for sure the attribute or CSS names and values off the top of my head, but you can add more commands like

.attr("font-color", "blue")

or

.style("font-color", "blue")

to the existing chain above