简体   繁体   English

使用 visNetwork 更改 fontAwesome 图标的颜色

[英]Changing color of fontAwesome icons with visNetwork

I tried the example proposed in the documentation of visNetwork R package regarding the usage of fontAwesome icons.我尝试了 visNetwork R package文档中提出的关于使用 fontAwesome 图标的示例。

In the example below I use the option of passing the node properties via a data.frame.在下面的示例中,我使用了通过 data.frame 传递节点属性的选项。 However, the color of the icons in the output gets a default blue color.但是,output 中图标的颜色默认为蓝色。

library(visNetwork)

nodes <- data.frame(id = 1:3, 
                    shape = "icon", 
                    icon.face = "FontAwesome",
                    color = c("#800000", "#0000ff", "#ffa500"), # doesn't have any effect on icon color
                    icon.code = c("f1ad", "f015", "f007"))
edges <- data.frame(from = c(1,2), to = c(2,3))

visNetwork(nodes, edges) %>%
  addFontAwesome()

节点无颜色效果

It seems that the alternative is to use the grouping option described in the documentation.似乎替代方法是使用文档中描述的分组选项。 However, I would want to have the data.frame option working as well and I can't figure out at the moment what I do wrong above.但是,我希望 data.frame 选项也能正常工作,目前我无法弄清楚我在上面做错了什么。

nodes <- data.frame(id = 1:3, 
                    shape = "icon", 
                    group = c("A", "B", "C"))
edges <- data.frame(from = c(1,2), to = c(2,3))

visNetwork(nodes, edges) %>%
  visGroups(groupname = "A", shape = "icon", 
            icon = list(code = "f1ad", color = "#800000")) %>%
  visGroups(groupname = "B", shape = "icon", 
            icon = list(code = "f015", color = "#0000ff")) %>%
  visGroups(groupname = "C", shape = "icon", 
            icon = list(code = "f007", color = "#ffa500")) %>%
  addFontAwesome()

选择

Change color to icon.color and everything works:color更改为icon.color一切正常:

library(visNetwork)

nodes <- data.frame(id = 1:3, 
                    shape = "icon", 
                    icon.face = "FontAwesome",
                    icon.color = c("#800000", "#0000ff", "#ffa500"), # doesn't have any effect on icon color
                    icon.code = c("f1ad", "f015", "f007"))
edges <- data.frame(from = c(1,2), to = c(2,3))

visNetwork(nodes, edges) %>%
  addFontAwesome()

彩色visNetwork

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM