Coverage for src/ipyvizzu/template.py: 100%
44 statements
« prev ^ index » next coverage.py v7.4.3, created at 2024-02-26 10:12 +0000
« prev ^ index » next coverage.py v7.4.3, created at 2024-02-26 10:12 +0000
1"""A module for storing the JavaScript templates."""
3from enum import Enum
5VIZZU_VERSION: str = "0.9"
6"""A variable for storing the default version of the `vizzu` package."""
8VIZZU: str = f"https://cdn.jsdelivr.net/npm/vizzu@{VIZZU_VERSION}/dist/vizzu.min.js"
9"""A variable for storing the default url of the `vizzu` package."""
12class ChartProperty(Enum):
13 """An enum class for storing chart properties."""
15 CONFIG = "config"
16 """An enum key-value for storing config chart property."""
18 STYLE = "style"
19 """An enum key-value for storing style chart property."""
22class DisplayTarget(Enum):
23 """An enum class for storing chart display options."""
25 BEGIN = "begin"
26 """Display all animation steps after the constructor's cell."""
28 END = "end"
29 """Display all animation steps after the last running cell."""
31 ACTUAL = "actual"
32 """Display the actual animation step after the currently running cell."""
34 MANUAL = "manual"
35 """Display all animation steps after calling a show method."""
38class DisplayTemplate:
39 """A class for storing JavaScript snippet templates."""
41 # pylint: disable=too-few-public-methods
43 IPYVIZZUJS: str = "{ipyvizzujs}"
44 """ipyvizzu JavaScript class."""
46 INIT: str = (
47 "window.ipyvizzu.createChart(element, "
48 + "'{chart_id}', '{vizzu}', '{div_width}', '{div_height}');"
49 )
50 """Call createChart JavaScript method."""
52 CHANGE_ANALYTICS_TO: str = (
53 "if (window.IpyVizzu) window.IpyVizzu.changeAnalyticsTo({analytics});"
54 )
55 """Call changeAnalyticsTo JavaScript method."""
57 ANIMATE: str = (
58 "window.ipyvizzu.animate(element, "
59 + "'{chart_id}', '{anim_id}', '{display_target}', {scroll}, "
60 + "lib => {{ return {chart_target} }}, {chart_anim_opts});"
61 )
62 """Call animate JavaScript method."""
64 FEATURE: str = (
65 "window.ipyvizzu.feature(element, '{chart_id}', '{name}', {enabled});"
66 )
67 """Call feature JavaScript method."""
69 PLUGIN: str = (
70 "window.ipyvizzu.plugin(element, "
71 + "'{chart_id}', '{plugin}', {options}, '{name}', {enabled});"
72 )
73 """Call plugin JavaScript method."""
75 STORE: str = "window.ipyvizzu.store(element, '{chart_id}', '{id}');"
76 """Call store JavaScript method."""
78 SET_EVENT: str = (
79 "window.ipyvizzu.setEvent(element, "
80 + "'{chart_id}', '{id}', '{event}', event => {{ {handler} }});"
81 )
82 """Call setEvent JavaScript method."""
84 CLEAR_EVENT: str = (
85 "window.ipyvizzu.clearEvent(element, '{chart_id}', '{id}', '{event}');"
86 )
87 """Call clearEvent JavaScript method."""
89 LOG: str = "window.ipyvizzu.log(element, '{chart_id}', '{chart_property}');"
90 """Call log JavaScript method."""
92 CONTROL: str = "window.ipyvizzu.control(element, '{method}', {params});"
93 """Call animation control JavaScript methods."""
95 CLEAR_INHIBITSCROLL: str = (
96 "if (window.IpyVizzu) { window.IpyVizzu.clearInhibitScroll(element); }"
97 )
98 """Call clearInhibitScroll JavaScript method if ipyvizzu JavaScript class exists."""