-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #289 from vizzuhq/plugin
Added: `chart.plugin` method
- Loading branch information
Showing
6 changed files
with
189 additions
and
37 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 |
---|---|---|
|
@@ -9,8 +9,13 @@ | |
|
||
from ipyvizzu.animation import AbstractAnimation, Snapshot, AnimationMerger | ||
from ipyvizzu.animationcontrol import AnimationControl | ||
from ipyvizzu.method import Animate, Feature, Store, EventOn, EventOff, Log | ||
from ipyvizzu.template import ChartProperty, DisplayTarget, DisplayTemplate | ||
from ipyvizzu.method import Animate, Feature, Plugin, Store, EventOn, EventOff, Log | ||
from ipyvizzu.template import ( | ||
ChartProperty, | ||
DisplayTarget, | ||
DisplayTemplate, | ||
VIZZU as VIZZU_URL, | ||
) | ||
from ipyvizzu.event import EventHandler | ||
from ipyvizzu.__version__ import __version__ | ||
|
||
|
@@ -20,8 +25,8 @@ class Chart: | |
|
||
# pylint: disable=too-many-instance-attributes | ||
|
||
VIZZU: str = "https://cdn.jsdelivr.net/npm/[email protected]/dist/vizzu.min.js" | ||
"""A variable for storing the default url of vizzu package.""" | ||
VIZZU: str = VIZZU_URL | ||
"""A variable for storing the default url of the `vizzu` package.""" | ||
|
||
def __init__( | ||
self, | ||
|
@@ -225,6 +230,30 @@ def feature(self, name: str, enabled: bool) -> None: | |
) | ||
) | ||
|
||
def plugin( | ||
self, | ||
plugin: str, | ||
options: Optional[dict] = None, | ||
name: str = "default", | ||
enabled: bool = True, | ||
) -> None: | ||
""" | ||
A method for register/unregister plugins of the chart. | ||
Args: | ||
plugin: The package name or the url of the plugin. | ||
options: The plugin constructor options. | ||
name: The name of the plugin (default `default`). | ||
enabled: The state of the plugin (default `True`). | ||
""" | ||
|
||
self._display( | ||
DisplayTemplate.PLUGIN.format( | ||
chart_id=self._chart_id, | ||
**Plugin(plugin, options, name, enabled).dump(), | ||
) | ||
) | ||
|
||
def store(self) -> Snapshot: | ||
""" | ||
A method for saving and storing the actual state of the chart. | ||
|
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
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
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
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 |
---|---|---|
|
@@ -158,7 +158,7 @@ class IPy: | |
) | ||
|
||
|
||
class TestChartMethods(TestChart): | ||
class TestChartAnimateMethod(TestChart): | ||
def test_animate_chart_target_has_to_be_passed(self) -> None: | ||
with self.assertRaises(ValueError): | ||
self.chart.animate() | ||
|
@@ -312,6 +312,54 @@ def test_animate_with_not_default_scroll_into_view(self) -> None: | |
+ "undefined);", | ||
) | ||
|
||
|
||
class TestChartPluginMethod(TestChart): | ||
URL = "https://cdn.jsdelivr.net/npm/@vizzu/[email protected]/dist/mjs/index.min.js" | ||
|
||
def test_plugin_with_package_name(self) -> None: | ||
with unittest.mock.patch(self.mock) as output: | ||
self.chart.plugin("marker-dropshadow") | ||
self.assertEqual( | ||
self.normalizer.normalize_output(output), | ||
f"window.ipyvizzu.plugin(element, id, '{self.URL}', {{}}, 'default', true);", | ||
) | ||
|
||
def test_plugin_with_package_url(self) -> None: | ||
with unittest.mock.patch(self.mock) as output: | ||
self.chart.plugin(self.URL) | ||
self.assertEqual( | ||
self.normalizer.normalize_output(output), | ||
f"window.ipyvizzu.plugin(element, id, '{self.URL}', {{}}, 'default', true);", | ||
) | ||
|
||
def test_plugin_with_options(self) -> None: | ||
with unittest.mock.patch(self.mock) as output: | ||
self.chart.plugin("marker-dropshadow", options={"debug": True}) | ||
self.assertEqual( | ||
self.normalizer.normalize_output(output), | ||
"window.ipyvizzu.plugin(element, id, " | ||
+ f"'{self.URL}', {{\"debug\": true}}, 'default', true);", | ||
) | ||
|
||
def test_plugin_with_name(self) -> None: | ||
with unittest.mock.patch(self.mock) as output: | ||
name = "MarkerDropshadow" | ||
self.chart.plugin("marker-dropshadow", name=name) | ||
self.assertEqual( | ||
self.normalizer.normalize_output(output), | ||
f"window.ipyvizzu.plugin(element, id, '{self.URL}', {{}}, '{name}', true);", | ||
) | ||
|
||
def test_plugin_with_enabled(self) -> None: | ||
with unittest.mock.patch(self.mock) as output: | ||
self.chart.plugin("marker-dropshadow", enabled=False) | ||
self.assertEqual( | ||
self.normalizer.normalize_output(output), | ||
f"window.ipyvizzu.plugin(element, id, '{self.URL}', {{}}, 'default', false);", | ||
) | ||
|
||
|
||
class TestChartFeatureMethod(TestChart): | ||
def test_feature(self) -> None: | ||
with unittest.mock.patch(self.mock) as output: | ||
self.chart.feature("tooltip", True) | ||
|
@@ -320,6 +368,8 @@ def test_feature(self) -> None: | |
"window.ipyvizzu.feature(element, id, 'tooltip', true);", | ||
) | ||
|
||
|
||
class TestChartStoreMethod(TestChart): | ||
def test_store(self) -> None: | ||
with unittest.mock.patch(self.mock) as output: | ||
self.chart.store() | ||
|
@@ -329,7 +379,7 @@ def test_store(self) -> None: | |
) | ||
|
||
|
||
class TestChartEvents(TestChart): | ||
class TestChartEventMethods(TestChart): | ||
def test_on(self) -> None: | ||
with unittest.mock.patch(self.mock) as output: | ||
handler_method = """event.renderingContext.fillStyle = | ||
|
@@ -355,7 +405,7 @@ def test_off(self) -> None: | |
) | ||
|
||
|
||
class TestChartLogs(TestChart): | ||
class TestChartLogMethod(TestChart): | ||
def test_log_config(self) -> None: | ||
with unittest.mock.patch(self.mock) as output: | ||
self.chart.log(ChartProperty.CONFIG) | ||
|
Oops, something went wrong.