编程语言
首页 > 编程语言> > javascript-R collapsibleTree:在工具提示中动态添加图像

javascript-R collapsibleTree:在工具提示中动态添加图像

作者:互联网

这是一个很好的软件包,可以显示层次结构级别.

根据提供的文件collapsibleTree Package

在下面的代码中,他在工具提示中使用了图像.

org$tooltip <- paste0(
org$Employee,
"<br>Title:",
org$Title,
"<br><img src='https://source.unsplash.com/collection/385548/150x100'>"
)

collapsibleTreeNetwork(
org,
attribute = "Title",
fill = "Color",
nodeSize = "leafCount",
tooltipHtml = "tooltip"
)

此处在每个气泡处显示单个图像.

在我的桌子上,每个员工都有一列图像.
enter image description here

现在例如A Employee->应显示图像A.
同样,它应该显示给所有员工.

可能吗.

任何建议将是可取的.

谢谢
莫汉五世

解决方法:

Here a single image is shown at every bubble. […] Can we show
dynamically those images to their respected employee bubble.

根据软件包作者的example on GitHub,以下是每个节点具有不同图片的图片:

library(collapsibleTree)
org <- data.frame(
  Manager = c(
    NA, "Ana", "Ana", "Bill", "Bill", "Bill", "Claudette", "Claudette", "Danny",
    "Fred", "Fred", "Grace", "Larry", "Larry", "Nicholas", "Nicholas"
  ),
  Employee = c(
    "Ana", "Bill", "Larry", "Claudette", "Danny", "Erika", "Fred", "Grace",
    "Henri", "Ida", "Joaquin", "Kate", "Mindy", "Nicholas", "Odette", "Peter"
  ),
  Title = c(
    "President", "VP Operations", "VP Finance", "Director", "Director", "Scientist",
    "Manager", "Manager", "Jr Scientist", "Operator", "Operator", "Associate",
    "Analyst", "Director", "Accountant", "Accountant"
  )
)

# Add in colors and sizes
org$Color <- org$Title
levels(org$Color) <- colorspace::rainbow_hcl(11)

org$tooltip <- sprintf("
  %s<br>Title: %s<br><img src='%s'>", 
  org$Employee, 
  org$Title, 
  paste0("https://github.com/twitter/twemoji/blob/gh-pages/72x72/1f19", c(1, 1:9, letters[1:6]), ".png?raw=true")
)

collapsibleTreeNetwork(
  org,
  attribute = "Title",
  fill = "Color",
  nodeSize = "leafCount",
  tooltipHtml = "tooltip"
)

enter image description here

标签:html,javascript,r
来源: https://codeday.me/bug/20191110/2014263.html