sunburstR icon indicating copy to clipboard operation
sunburstR copied to clipboard

legend font

Open ssalimi opened this issue 4 years ago • 1 comments

Hello, We developed a SunbusrtR code for ShinyApp but I do not know how to change the legend font. The code is as below:

sunburst(dat_lst[[2]], 
         # make the breadcrumbs smaller but doesn't wrap the long tails
         # breadcrumb = list(w=25, h=15, s=3, t=2),
         legend = list(w=27, h=10, s=3)
         ) 

How I can add the legend font size here? Thanks

ssalimi avatar Dec 19 '20 10:12 ssalimi

I don't believe that sunburstR has a built-in option to adjust the font size of the legend, however, you could achieve this by using htmlwidgets::onRender() to inject JavaScript when the sunburst is rendered that sets the font size (as well as other styles potentially) of the legend, for example...

library(sunburstR)

csv_path <- system.file("examples/visit-sequences.csv", package = "sunburstR")
sequences <- read.csv(csv_path, header = FALSE, stringsAsFactors = FALSE)[1:100, ]

sunburst_obj <- sunburst(sequences)

onrender_js <- 
  'function(el) { 
    [...el.querySelectorAll(".sunburst-legend svg text")].forEach((text) => { text.style.fontSize = "22px"; }); 
  }'

htmlwidgets::onRender(sunburst_obj, onrender_js)

cjyetman avatar Dec 19 '20 12:12 cjyetman