python-visualization / branca

This library is a spinoff from folium, that would host the non-map-specific features.
https://python-visualization.github.io/branca/
MIT License
111 stars 63 forks source link

Branca colormap caption with apostrophe makes map does not show #111

Closed iladan0 closed 1 year ago

iladan0 commented 2 years ago

Describe the bug When the caption of the colormap contains an apostrophe, the folium map does not show (I get a white rectangle)

To Reproduce

mymap= folium.Map(tiles = "Stamen Toner")

colormap = branca.colormap.LinearColormap(['red','yellow', 'green'], vmin=0.0, vmax=5.0)
colormap.caption = "Agency's rating"
colormap.add_to(mymap)

mymap

Expected behavior The expected behavior is to get a folium map with red to green colormap having the caption "Agency's rating" but i got a white rectangle

Environment (please complete the following information):

Additional context The code works perfectly fine if the caption does not have an apostrophe.

Possible solutions List any solutions you may have come up with.

folium is maintained by volunteers. Can you help making a fix for this issue?

Conengmo commented 2 years ago

Thanks for the report! This is indeed an issue in branca's colormap functionality.

Looking into it very shortly, the issue seems to be in https://github.com/python-visualization/branca/blob/master/branca/templates/color_scale.js. My first intuition is to use Jinja2's tojson filter, which we use throughout folium already for the same purpose.