Skip to content

Commit 344b30f

Browse files
committed
Cleanup make MacroElements from Elements
This change involves several classes that require being added to a Figure. Since these classes follow the `render` semantics of a MacroElement it makes more sense to make them also inherit from MacroElement. Excluded from this change is actually making use of the template mechanics of the MacroElement.
1 parent d04d4ba commit 344b30f

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

folium/elements.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from typing import List, Tuple
22

3-
from branca.element import CssLink, Element, Figure, JavascriptLink, MacroElement
3+
from branca.element import CssLink, Figure, JavascriptLink, MacroElement
44

55
from folium.template import Template
66
from folium.utilities import JsCode
77

88

9-
class JSCSSMixin(Element):
9+
class JSCSSMixin(MacroElement):
1010
"""Render links to external Javascript and CSS resources."""
1111

1212
default_js: List[Tuple[str, str]] = []

folium/features.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def __init__(
101101
)
102102

103103

104-
class Vega(JSCSSMixin, Element):
104+
class Vega(JSCSSMixin):
105105
"""
106106
Creates a Vega chart element.
107107
@@ -193,6 +193,8 @@ def render(self, **kwargs) -> None:
193193
name=self.get_name(),
194194
)
195195

196+
# TODO: this could be rewritten to use the facilities of MacroElement
197+
# and the facilities of JSCSSMixin
196198
figure = self.get_root()
197199
assert isinstance(
198200
figure, Figure
@@ -224,7 +226,7 @@ def render(self, **kwargs) -> None:
224226
)
225227

226228

227-
class VegaLite(Element):
229+
class VegaLite(MacroElement):
228230
"""
229231
Creates a Vega-Lite chart element.
230232
@@ -297,6 +299,9 @@ def render(self, **kwargs) -> None:
297299
name=self.get_name(),
298300
)
299301

302+
# TODO: this could be rewritten to use the facilities of MacroElement
303+
# and the facilities of JSCSSMixin
304+
300305
figure = self.get_root()
301306
assert isinstance(
302307
figure, Figure

folium/map.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ def render(self) -> None:
409409
super().render()
410410

411411

412-
class Popup(Element):
412+
class Popup(MacroElement):
413413
"""Create a Popup instance that can be linked to a Layer.
414414
415415
Parameters

0 commit comments

Comments
 (0)