Timevis - make different boxes have colour dependent on name in different groups

若如初见. 提交于 2021-01-29 08:07:34

问题


Hi So what i'd like to be able to do is make all the ranges which contain open appear say "red" and Staff meeting appear blue. Is it possible to do this, could only see documentation on changing the colour based off the group. I know I can use style to change the text but that only changes the colour of the text inside the box and not the background shading of the box.

 library(timevis)
    # Data for groups example
    dataGroups <- data.frame(
      id = 1:11,
      content = c("Open", "Open",
                  "Open", "Open", "Half price entry",
                  "Staff meeting", "Open", "Adults only", "Open", "Hot tub closes",
                  "Siesta"),
      start = c("2016-05-01 07:30:00", "2016-05-01 14:00:00",
                "2016-05-01 06:00:00", "2016-05-01 14:00:00", "2016-05-01 08:00:00",
                "2016-05-01 08:00:00", "2016-05-01 08:30:00", "2016-05-01 14:00:00",
                "2016-05-01 16:00:00", "2016-05-01 19:30:00",
                "2016-05-01 12:00:00"),
      end   = c("2016-05-01 12:00:00", "2016-05-01 20:00:00",
                "2016-05-01 12:00:00", "2016-05-01 22:00:00", "2016-05-01 10:00:00",
                "2016-05-01 08:30:00", "2016-05-01 12:00:00", "2016-05-01 16:00:00",
                "2016-05-01 20:00:00", NA,
                "2016-05-01 14:00:00"),
      group = c(rep("lib", 2), rep("gym", 3), rep("pool", 5), NA),
      type = c(rep("range", 9), "point", "background")
    )

    groups <- data.frame(
      id = c("lib", "gym", "pool"),
      content = c("Library", "Gym", "Pool")
      )

    timevis(data = dataGroups, groups = groups)

回答1:


you need to do something like this:

 tags$head(
    tags$style(HTML(".vis-item.blah { color: black; background-color: #1ac6ff; border-color: #1ac6ff; }"))

where .blah is an items className



来源:https://stackoverflow.com/questions/54885083/timevis-make-different-boxes-have-colour-dependent-on-name-in-different-groups

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!