Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def render(self, **kwargs):
super(ImageOverlay, self).render()
figure = self.get_root()
assert isinstance(figure, Figure), ('You cannot render this Element '
'if it is not in a Figure.')
pixelated = """<style>
.leaflet-image-layer {
image-rendering: -webkit-optimize-contrast; /* old android/safari*/
image-rendering: crisp-edges; /* safari */
image-rendering: pixelated; /* chrome */
image-rendering: -moz-crisp-edges; /* firefox */
image-rendering: -o-crisp-edges; /* opera */
-ms-interpolation-mode: nearest-neighbor; /* ie */
}
</style>"""
if self.pixelated:
figure.header.add_child(Element(pixelated), name='leaflet-image-layer') # noqa
figure = self.get_root()
assert isinstance(figure, Figure), ('You cannot render this Element '
'if it is not in a Figure.')
pixelated = """<style>
.leaflet-image-layer {
image-rendering: -webkit-optimize-contrast; /* old android/safari*/
image-rendering: crisp-edges; /* safari */
image-rendering: pixelated; /* chrome */
image-rendering: -moz-crisp-edges; /* firefox */
image-rendering: -o-crisp-edges; /* opera */
-ms-interpolation-mode: nearest-neighbor; /* ie */
}
</style>"""
if self.pixelated:
figure.header.add_child(Element(pixelated), name='leaflet-image-layer') # noqa
def test_marker_function():
f = branca.element.Figure()
c = crossfolium.Crossfilter([{'lat': 0, 'lng': 0}]).add_to(f)
m = folium.Map().add_to(c)
g = crossfolium.FeatureGroupFilter(c).add_to(m)
crossfolium.marker_function.MarkerFunction(
lat='Latitude',
lng='Longitude',
popup='Popup',
).add_to(g)
out = ''.join(f.render().split())
tmp = ''.join("""
.marker_function = function (d) {
return L.marker([d["Latitude"], d["Longitude"]])
.bindPopup(d["Popup"]);
}
""".split())
def test_no_marker_function():
f = branca.element.Figure()
c = crossfolium.Crossfilter([{'lat': 0, 'lng': 0}]).add_to(f)
m = folium.Map().add_to(c)
crossfolium.FeatureGroupFilter(c).add_to(m)
out = ''.join(f.render().split())
tmp = ''.join("""
.marker_function = function(d) {
return L.marker([0, 0]);}
""".split())
assert tmp in out
def test_rendering_figure_notebook():
"""Verify special characters are correctly rendered in Jupyter notebooks."""
text = '5/7 %, Линейная улица, "\u00e9 Berdsk"'
figure = elem.Figure()
elem.Html(text).add_to(figure.html)
html = figure._repr_html_()
filepath = 'temp_test_rendering_figure_notebook.html'
filepath = os.path.abspath(filepath)
with open(filepath, 'w') as f:
f.write(html)
options = Options()
options.add_argument('-headless')
driver = Firefox(options=options)
try:
driver.get('file://' + filepath)
driver.switch_to.frame(0)
text_div = driver.find_element_by_css_selector('div')
assert text_div.text == text
def test_divicon():
html = """<svg width="100" height="100">
<circle fill="red" stroke-width="3" stroke="black" r="40" cy="50" cx="50"></circle>
</svg>""" # noqa
div = folium.DivIcon(html=html)
assert isinstance(div, Element)
assert div.options['className'] == 'empty'
assert div.options['html'] == html
def test_figure_creation():
f = folium.Figure()
assert isinstance(f, Element)
bounds = f.get_bounds()
assert bounds == [[None, None], [None, None]], bounds
def test_simple_linear():
linear = cm.LinearColormap(['green', 'yellow', 'red'], vmin=3., vmax=10.)
linear = cm.LinearColormap(['red', 'orange', 'yellow', 'green'],
index=[0, 0.1, 0.9, 1.])
linear._repr_html_()
def test_step_to_linear():
step = cm.StepColormap(['green', 'yellow', 'red'],
vmin=3., vmax=10.,
index=[3, 4, 8, 10], caption='step')
step.to_linear()
def test_simple_step():
step = cm.StepColormap(['green', 'yellow', 'red'],
vmin=3., vmax=10.,
index=[3, 4, 8, 10], caption='step')
step = cm.StepColormap(['r', 'y', 'g', 'c', 'b', 'm'])
step._repr_html_()