Skip to content

Commit 5555543

Browse files
author
Martin Journois
committed
Map and Vega positioning (along side)
1 parent f8981c5 commit 5555543

1 file changed

Lines changed: 32 additions & 4 deletions

File tree

folium/features.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ def _parse_size(value):
341341

342342
class Map(MacroElement):
343343
def __init__(self, location=None, width='100%', height='100%',
344+
left="0%", top="0%", position='relative',
344345
tiles='OpenStreetMap', API_key=None, max_zoom=18, min_zoom=1,
345346
zoom_start=10, attr=None, min_lat=-90, max_lat=90,
346347
min_lon=-180, max_lon=180):
@@ -412,6 +413,9 @@ def __init__(self, location=None, width='100%', height='100%',
412413
# Map Size Parameters.
413414
self.width = _parse_size(width)
414415
self.height = _parse_size(height)
416+
self.left = _parse_size(left)
417+
self.top = _parse_size(top)
418+
self.position = position
415419

416420
self.min_lat = min_lat
417421
self.max_lat = max_lat
@@ -422,9 +426,17 @@ def __init__(self, location=None, width='100%', height='100%',
422426
attr=attr, API_key=API_key)
423427

424428
self._template = Template(u"""
429+
{% macro header(this, kwargs) %}
430+
<style> #{{this.get_name()}} {
431+
position : {{this.position}};
432+
width : {{this.width[0]}}{{this.width[1]}};
433+
height: {{this.height[0]}}{{this.height[1]}};
434+
left: {{this.left[0]}}{{this.left[1]}};
435+
top: {{this.top[0]}}{{this.top[1]}};
436+
</style>
437+
{% endmacro %}
425438
{% macro html(this, kwargs) %}
426-
<div class="folium-map" id="{{this.get_name()}}"
427-
style="width: {{this.width[0]}}{{this.width[1]}}; height: {{this.height[0]}}{{this.height[1]}}"></div>
439+
<div class="folium-map" id="{{this.get_name()}}" ></div>
428440
{% endmacro %}
429441
430442
{% macro script(this, kwargs) %}
@@ -740,14 +752,20 @@ def render(self, **kwargs):
740752
self._template.render(this=self, kwargs=kwargs)), name=self.get_name())
741753

742754
class Vega(Element):
743-
def __init__(self, data, width="100%", height="100%"):
755+
def __init__(self, data, width='100%', height='100%',
756+
left="0%", top="0%", position='relative'):
744757
"""TODO : docstring here"""
745758
super(Vega, self).__init__()
746759
self._name = 'Vega'
747760
self.data = data
748761

762+
# Size Parameters.
749763
self.width = _parse_size(width)
750-
self.height = _parse_size(height)
764+
self.height = _parse_size(height)
765+
self.left = _parse_size(left)
766+
self.top = _parse_size(top)
767+
self.position = position
768+
751769

752770
self._template = Template(u"")
753771
def render(self, **kwargs):
@@ -767,6 +785,16 @@ def render(self, **kwargs):
767785
assert isinstance(figure,Figure), ("You cannot render this Element "
768786
"if it's not in a Figure.")
769787

788+
figure.header.add_children(Element(Template("""
789+
<style> #{{this.get_name()}} {
790+
position : {{this.position}};
791+
width : {{this.width[0]}}{{this.width[1]}};
792+
height: {{this.height[0]}}{{this.height[1]}};
793+
left: {{this.left[0]}}{{this.left[1]}};
794+
top: {{this.top[0]}}{{this.top[1]}};
795+
</style>
796+
""").render(this=self, **kwargs)), name=self.get_name())
797+
770798
figure.header.add_children(\
771799
JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"),
772800
name='d3')

0 commit comments

Comments
 (0)