Skip to content

Commit

Permalink
Cleanup make MacroElements from Elements (#2066)
Browse files Browse the repository at this point in the history
* 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.

* Fix missing import

* Update folium/features.py

Co-authored-by: Frank Anema <[email protected]>

* Update folium/features.py

Co-authored-by: Frank Anema <[email protected]>

---------

Co-authored-by: Frank Anema <[email protected]>
  • Loading branch information
hansthen and Conengmo authored Jan 4, 2025
1 parent 29062dd commit 3a2afb1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions folium/elements.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
from typing import List, Tuple

from branca.element import CssLink, Element, Figure, JavascriptLink, MacroElement
from branca.element import (
CssLink,
Element, # NoQA: F401 needed as a reexport
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
4 changes: 2 additions & 2 deletions folium/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def __init__(
)


class Vega(JSCSSMixin, Element):
class Vega(JSCSSMixin):
"""
Creates a Vega chart element.
Expand Down Expand Up @@ -234,7 +234,7 @@ def render(self, **kwargs):
)


class VegaLite(Element):
class VegaLite(MacroElement):
"""
Creates a Vega-Lite chart element.
Expand Down
2 changes: 1 addition & 1 deletion folium/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def render(self):
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 3a2afb1

Please sign in to comment.