-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(vega): Wrap vega module from pywebvue
- Loading branch information
1 parent
7f97d49
commit 222ca66
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from trame import get_app_instance | ||
from trame.html import AbstractElement | ||
|
||
from pywebvue.modules import VegaEmbed | ||
|
||
# Make sure used module is available | ||
_app = get_app_instance() | ||
_app.enableModule(VegaEmbed) | ||
|
||
|
||
class VegaEmbed(AbstractElement): | ||
@staticmethod | ||
def altair_to_spec(chart): | ||
return chart.to_dict() | ||
|
||
def __init__(self, chart=None, name=None, **kwargs): | ||
super().__init__("VegaEmbed", **kwargs) | ||
self._chart = chart | ||
self._name = name or f"chart_{self._id}" | ||
self._attributes["spec"] = f':spec="{self._name}"' | ||
|
||
def update(self, chart=None): | ||
if chart: | ||
self._chart = chart | ||
if self._chart: | ||
_app = get_app_instance() | ||
_app.set(self._name, VegaEmbed.altair_to_spec(self._chart)) |