Skip to content

Commit

Permalink
Cleanup make MacroElements from Elements
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hansthen committed Jan 1, 2025
1 parent d04d4ba commit 344b30f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions folium/elements.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import List, Tuple

from branca.element import CssLink, Element, Figure, JavascriptLink, MacroElement
from branca.element import CssLink, Figure, JavascriptLink, MacroElement

from folium.template import Template
from folium.utilities import JsCode


class JSCSSMixin(Element):
class JSCSSMixin(MacroElement):
"""Render links to external Javascript and CSS resources."""

default_js: List[Tuple[str, str]] = []
Expand Down
9 changes: 7 additions & 2 deletions folium/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(
)


class Vega(JSCSSMixin, Element):
class Vega(JSCSSMixin):
"""
Creates a Vega chart element.
Expand Down Expand Up @@ -193,6 +193,8 @@ def render(self, **kwargs) -> None:
name=self.get_name(),
)

# TODO: this could be rewritten to use the facilities of MacroElement
# and the facilities of JSCSSMixin
figure = self.get_root()
assert isinstance(
figure, Figure
Expand Down Expand Up @@ -224,7 +226,7 @@ def render(self, **kwargs) -> None:
)


class VegaLite(Element):
class VegaLite(MacroElement):
"""
Creates a Vega-Lite chart element.
Expand Down Expand Up @@ -297,6 +299,9 @@ def render(self, **kwargs) -> None:
name=self.get_name(),
)

# TODO: this could be rewritten to use the facilities of MacroElement
# and the facilities of JSCSSMixin

figure = self.get_root()
assert isinstance(
figure, Figure
Expand Down
2 changes: 1 addition & 1 deletion folium/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def render(self) -> None:
super().render()


class Popup(Element):
class Popup(MacroElement):
"""Create a Popup instance that can be linked to a Layer.
Parameters
Expand Down

0 comments on commit 344b30f

Please sign in to comment.