Coverage for src/ipyvizzu/method.py: 100%
27 statements
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-25 15:04 +0100
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-25 15:04 +0100
1"""A module for working with template methods."""
3import json
4from typing import Optional, Union
6from ipyvizzu.animation import PlainAnimation, Animation, AnimationMerger
7from ipyvizzu.event import EventHandler
8from ipyvizzu.template import ChartProperty
11class Method:
12 """A class for storing and dumping any kind of data."""
14 # pylint: disable=too-few-public-methods
16 _data: dict
18 def dump(self) -> dict:
19 """
20 A method for returning the stored data.
22 Returns:
23 The stored data.
24 """
26 return self._data
29class Animate(Method):
30 """
31 A class for dumping chart independent parameters to
32 [DisplayTemplate.ANIMATE][ipyvizzu.template.DisplayTemplate] template.
33 """
35 # pylint: disable=too-few-public-methods
37 def __init__(
38 self,
39 chart_target: Union[Animation, AnimationMerger],
40 chart_anim_opts: Optional[dict] = None,
41 ):
42 """
43 Animate constructor.
45 It stores and dumps `chart_target` and `chart_anim_opts` parameters.
47 Args:
48 chart_target:
49 Animation object such as
50 [Data][ipyvizzu.animation.Data]
51 [Config][ipyvizzu.animation.Config] or
52 [Style][ipyvizzu.animation.Style].
53 chart_anim_opts:
54 Animation options' dictionary. If it is not set, it dumps `undefined`.
55 """
57 self._data = {
58 "chart_target": chart_target.dump(),
59 "chart_anim_opts": PlainAnimation(chart_anim_opts).dump()
60 if chart_anim_opts
61 else "undefined",
62 }
65class Feature(Method):
66 """
67 A class for dumping chart independent parameters to
68 [DisplayTemplate.FEATURE][ipyvizzu.template.DisplayTemplate] template.
69 """
71 # pylint: disable=too-few-public-methods
73 def __init__(self, name: str, enabled: bool):
74 """
75 Feature constructor.
77 It stores and dumps `name` and `enabled` parameters.
79 Args:
80 name: The name of a chart feature.
81 enabled: The new state of a chart feature.
82 """
84 self._data = {"name": name, "enabled": json.dumps(enabled)}
87class Store(Method):
88 """
89 A class for dumping chart independent parameters to
90 [DisplayTemplate.STORE][ipyvizzu.template.DisplayTemplate] template.
91 """
93 # pylint: disable=too-few-public-methods
95 def __init__(self, snapshot_id: str):
96 """
97 Store constructor.
99 It stores and dumps `snapshot_id` parameter.
101 Args:
102 snapshot_id: The id of snapshot object.
103 """
105 self._data = {"id": snapshot_id}
108class EventOn(Method):
109 """
110 A class for dumping chart independent parameters to
111 [DisplayTemplate.SET_EVENT][ipyvizzu.template.DisplayTemplate] template.
112 """
114 # pylint: disable=too-few-public-methods
116 def __init__(self, event_handler: EventHandler):
117 """
118 EventOn constructor.
120 It stores and dumps the `id`, the `event` and the `handler` of the event handler object.
122 Args:
123 event_handler: An event handler object.
124 """
126 self._data = {
127 "id": event_handler.id,
128 "event": event_handler.event,
129 "handler": event_handler.handler,
130 }
133class EventOff(Method):
134 """
135 A class for dumping chart independent parameters to
136 [DisplayTemplate.CLEAR_EVENT][ipyvizzu.template.DisplayTemplate] template.
137 """
139 # pylint: disable=too-few-public-methods
141 def __init__(self, event_handler: EventHandler):
142 """
143 EventOff constructor.
145 It stores and dumps the `id` and the `event` of the event handler object.
147 Args:
148 event_handler: An event handler object.
149 """
151 self._data = {"id": event_handler.id, "event": event_handler.event}
154class Log(Method):
155 """
156 A class for dumping chart independent parameters to
157 [DisplayTemplate.LOG][ipyvizzu.template.DisplayTemplate] template.
158 """
160 # pylint: disable=too-few-public-methods
162 def __init__(self, chart_property: ChartProperty):
163 """
164 Log constructor.
166 It stores and dumps the value of the chart property object.
168 Args:
169 chart_property:
170 A chart property such as
171 [CONFIG][ipyvizzu.template.ChartProperty] and
172 [STYLE][ipyvizzu.template.ChartProperty].
173 """
175 self._data = {"chart_property": chart_property.value}