r-tmap / tmap

R package for thematic maps
https://r-tmap.github.io/tmap
GNU General Public License v3.0
856 stars 119 forks source link

Auto-wrap text to prevent very wide text boxes? #705

Closed Robinlovelace closed 1 year ago

Robinlovelace commented 1 year ago

This has appeared many times before in my workflow and imagine others have reported it so apologies if this is a duplicate. Real usability issue: when textboxes are way bigger than the screen size, as shown below.

image

Imagine a function to detect n. chars and auto break, not sure how and may involve an additional package/complexity so may be a won't fix, asking as question: worth fixing this on tmap side?

tim-salabim commented 1 year ago

Probably solvable with https://leafletjs.com/reference.html#popup-maxheight

Robinlovelace commented 1 year ago

Surely minWidth?

tim-salabim commented 1 year ago

A combination of any of these should work, can't remember which exactly

Robinlovelace commented 1 year ago

This could help on the R side:

> x = "here's a verrrry long sentence of excessive length lllllllllllllllllllllll bllllllllllllllaaaaaaaaaaaaa"
> gsub('(.{1,90})(\\s|$)', '\\1\n', x)
[1] "here's a verrrry long sentence of excessive length lllllllllllllllllllllll\nbllllllllllllllaaaaaaaaaaaaa\n"
> x = paste0(x, x, x, collapse = " ")
> x
[1] "here's a verrrry long sentence of excessive length lllllllllllllllllllllll bllllllllllllllaaaaaaaaaaaaahere's a verrrry long sentence of excessive length lllllllllllllllllllllll bllllllllllllllaaaaaaaaaaaaahere's a verrrry long sentence of excessive length lllllllllllllllllllllll bllllllllllllllaaaaaaaaaaaaa"
> gsub('(.{1,90})(\\s|$)', '\\1\n', x)
[1] "here's a verrrry long sentence of excessive length lllllllllllllllllllllll\nbllllllllllllllaaaaaaaaaaaaahere's a verrrry long sentence of excessive length\nlllllllllllllllllllllll bllllllllllllllaaaaaaaaaaaaahere's a verrrry long sentence of\nexcessive length lllllllllllllllllllllll bllllllllllllllaaaaaaaaaaaaa\n"
Robinlovelace commented 1 year ago

Source: https://stackoverflow.com/questions/2351744/insert-line-breaks-in-long-string-word-wrap

Robinlovelace commented 1 year ago

Update: neither \n nor <br> in the text worked. So just going to use str_sub() for now is plan.

tim-salabim commented 1 year ago

My hunch is that this should really be controlled via CSS