Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I word wrap in timevis?

I’ve made a gantt chart with timevis in R. Some of the bars in my gantt chart have quite long text in, so anything after about the 10th word is cut off. Is there a way to wrap the words into second or third lines?

gantt <- structure(list(group = c("How FAN1 stabilises repeats", "How FAN1 stabilises repeats"
), content = c("CRISPR nuclease and SPYF", "Effect of FAN1 SPAA and MIM mutant on MLH1 binding, ICL repair and CAG instability"
), start = structure(c(1662516351.36, 1662516351.36), tzone = "UTC", class = c("POSIXct", 
                                                                               "POSIXt")), end = structure(c(1677242989.44, 1677242989.44), tzone = "UTC", class = c("POSIXct", 
                                                                                                                                                                     "POSIXt")), style = c("color: white; background-color: maroon;font-size:9px;word-break: break-all;", 
                                                                                                                                                                                           "color: white; background-color: maroon;font-size:9px;word-break: break-all;"
                                                                                                                                                                     ), type = c("range", "range")), row.names = c(NA, -2L), class = c("tbl_df", 
                                                                                                                                                                                                                                       "tbl", "data.frame"))    


groups <- data.frame(id = unique(gantt$group),
                     content = unique(gantt$group),
                     style = "font-weight: bold; font-size:10px")

timevis(data = gantt, groups = groups,
        options = list(editable = TRUE, height = "600px"))

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can use stringr::str_wrap to nicely wrap the text to the desired maximum width. It works by inserting newline characters which won’t work in this context though, so you’ll need to substitute these with <br>:

library(tidyverse)

gantt %>%
  mutate(content = gsub("\n", "<br>", str_wrap(content, 30))) %>%
  timevis(groups = groups, options = list(editable = TRUE, height = "600px"))

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading