Animation
ipyvizzu.animation
A module for working with chart animations.
ipyvizzu.animation.Animation
An abstract class for representing animation objects
that have dump
and build
methods.
Source code in ipyvizzu/animation.py
class Animation:
"""
An abstract class for representing animation objects
that have `dump` and `build` methods.
"""
def dump(self) -> str:
"""
A method for converting the built dictionary into string.
Returns:
An str that has been json dumped with
[RawJavaScriptEncoder][ipyvizzu.json.RawJavaScriptEncoder] from a dictionary.
"""
return json.dumps(self.build(), cls=RawJavaScriptEncoder)
@abc.abstractmethod
def build(self) -> dict:
"""
An abstract method for returning a dictionary with values
that can be converted into json string.
Returns:
A dictionary that stored in the animation object.
"""
dump()
A method for converting the built dictionary into string.
Returns:
Type | Description |
---|---|
str
|
An str that has been json dumped with RawJavaScriptEncoder from a dictionary. |
Source code in ipyvizzu/animation.py
def dump(self) -> str:
"""
A method for converting the built dictionary into string.
Returns:
An str that has been json dumped with
[RawJavaScriptEncoder][ipyvizzu.json.RawJavaScriptEncoder] from a dictionary.
"""
return json.dumps(self.build(), cls=RawJavaScriptEncoder)
build()
abstractmethod
An abstract method for returning a dictionary with values that can be converted into json string.
Returns:
Type | Description |
---|---|
dict
|
A dictionary that stored in the animation object. |
Source code in ipyvizzu/animation.py
@abc.abstractmethod
def build(self) -> dict:
"""
An abstract method for returning a dictionary with values
that can be converted into json string.
Returns:
A dictionary that stored in the animation object.
"""
ipyvizzu.animation.PlainAnimation
A class for representing plain animation. It can build any dictionary.
Source code in ipyvizzu/animation.py
class PlainAnimation(dict, Animation):
"""
A class for representing plain animation.
It can build any dictionary.
"""
def build(self) -> dict:
"""
A method for returning the plain animation dictionary.
Returns:
A dictionary that stored in the plain animation object.
"""
return self
build()
A method for returning the plain animation dictionary.
Returns:
Type | Description |
---|---|
dict
|
A dictionary that stored in the plain animation object. |
Source code in ipyvizzu/animation.py
def build(self) -> dict:
"""
A method for returning the plain animation dictionary.
Returns:
A dictionary that stored in the plain animation object.
"""
return self
ipyvizzu.animation.InferType
Bases: Enum
An enum class for storing data infer types.
Source code in ipyvizzu/animation.py
class InferType(Enum):
"""An enum class for storing data infer types."""
DIMENSION = "dimension"
"""An enum key-value for storing dimension infer type."""
MEASURE = "measure"
"""An enum key-value for storing measure infer type."""
DIMENSION = 'dimension'
class-attribute
An enum key-value for storing dimension infer type.
MEASURE = 'measure'
class-attribute
An enum key-value for storing measure infer type.
ipyvizzu.animation.Data
A class for representing data animation. It can build data option of the chart.
Source code in ipyvizzu/animation.py
class Data(dict, Animation):
"""
A class for representing data animation.
It can build data option of the chart.
"""
@classmethod
def filter(cls, filter_expr: Optional[str] = None): # -> Data:
"""
A class method for creating a [Data][ipyvizzu.animation.Data]
class instance with a data filter.
Args:
filter_expr: The JavaScript data filter expression.
Returns:
(Data): A data animation instance that contains a data filter.
Example:
Create a [Data][ipyvizzu.animation.Data] class with a data filter:
filter = Data.filter("record['Genres'] == 'Pop'")
"""
data = cls()
data.set_filter(filter_expr)
return data
def set_filter(self, filter_expr: Optional[str] = None) -> None:
"""
A method for adding a filter to an existing
[Data][ipyvizzu.animation.Data] class instance.
Args:
filter_expr: The JavaScript data filter expression.
Example:
Add a data filter to a [Data][ipyvizzu.animation.Data] class instance:
data = Data()
data.set_filter("record['Genres'] == 'Pop'")
"""
filter_expr_raw_js = (
RawJavaScript(f"record => {{ return ({' '.join(filter_expr.split())}) }}")
if filter_expr is not None
else filter_expr
)
self.update({"filter": filter_expr_raw_js})
@classmethod
def from_json(cls, filename: Union[str, bytes, PathLike]): # -> Data:
"""
A method for returning a [Data][ipyvizzu.animation.Data]
class instance which has been created from a json file.
Args:
filename: The path of the data source json file.
Returns:
(Data): A data animation instance that has been created from a json file.
"""
with open(filename, "r", encoding="utf8") as file_desc:
return cls(json.load(file_desc))
def add_record(self, record: list) -> None:
"""
A method for adding a record to an existing
[Data][ipyvizzu.animation.Data] class instance.
Args:
record: A list that contains data values.
Example:
Adding a record to a [Data][ipyvizzu.animation.Data] class instance:
data = Data()
record = ["Pop", "Hard", 114]
data.add_record(record)
"""
self._add_value("records", record)
def add_records(self, records: List[list]) -> None:
"""
A method for adding records to an existing
[Data][ipyvizzu.animation.Data] class instance.
Args:
records: A list that contains data records.
Example:
Adding records to a [Data][ipyvizzu.animation.Data] class instance:
data = Data()
records = [
["Pop", "Hard", 114],
["Rock", "Hard", 96],
["Pop", "Experimental", 127],
["Rock", "Experimental", 83],
]
data.add_records(records)
"""
list(map(self.add_record, records))
def add_series(self, name: str, values: Optional[list] = None, **kwargs) -> None:
"""
A method for adding a series to an existing
[Data][ipyvizzu.animation.Data] class instance.
Args:
name: The name of the series.
values: The data values of the series.
**kwargs (Optional):
Arbitrary keyword arguments.
For example infer type can be set with the `type` keywod argument.
Example:
Adding a series without values to a [Data][ipyvizzu.animation.Data] class instance:
data = Data()
data.add_series("Genres")
Adding a series without values and with infer type to
a [Data][ipyvizzu.animation.Data] class instance:
data = Data()
data.add_series("Kinds", type="dimension")
Adding a series with values to a [Data][ipyvizzu.animation.Data] class instance:
data = Data()
data.add_series(
"Popularity", [114, 96, 127, 83]
)
"""
self._add_named_value("series", name, values, **kwargs)
def add_dimension(self, name: str, values: Optional[list] = None, **kwargs) -> None:
"""
A method for adding a dimension to an existing
[Data][ipyvizzu.animation.Data] class instance.
Args:
name: The name of the dimension.
values: The data values of the dimension.
**kwargs (Optional): Arbitrary keyword arguments.
Example:
Adding a dimension with values to a [Data][ipyvizzu.animation.Data] class instance:
data = Data()
data.add_dimension("Genres", ["Pop", "Rock"])
"""
self._add_named_value("dimensions", name, values, **kwargs)
def add_measure(self, name: str, values: Optional[list] = None, **kwargs) -> None:
"""
A method for adding a measure to an existing
[Data][ipyvizzu.animation.Data] class instance.
Args:
name: The name of the measure.
values: The data values of the measure.
**kwargs (Optional): Arbitrary keyword arguments.
Example:
Adding a measure with values to a [Data][ipyvizzu.animation.Data] class instance:
data = Data()
data.add_measure(
"Popularity",
[
[114, 96],
[127, 83],
],
)
"""
self._add_named_value("measures", name, values, **kwargs)
def add_data_frame(
self,
data_frame: Union[pd.DataFrame, pd.Series],
default_measure_value: Optional[Any] = 0,
default_dimension_value: Optional[Any] = "",
) -> None:
"""
A method for adding data frame to an existing
[Data][ipyvizzu.animation.Data] class instance.
Args:
data_frame: The pandas data frame object.
default_measure_value: The default measure value to fill the empty values.
default_dimension_value: The default dimension value to fill the empty values.
Raises:
TypeError: If `data_frame` is not instance of [pd.DataFrame][pandas.DataFrame]
or [pd.Series][pandas.Series].
Example:
Adding a data frame to a [Data][ipyvizzu.animation.Data] class instance:
data_frame = pd.DataFrame(
{
"Genres": ["Pop", "Rock", "Pop", "Rock"],
"Kinds": ["Hard", "Hard", "Experimental", "Experimental"],
"Popularity": [114, 96, 127, 83],
}
)
data = Data()
data.add_data_frame(data_frame)
"""
if not isinstance(data_frame, type(None)):
if isinstance(data_frame, pd.Series):
data_frame = pd.DataFrame(data_frame)
if not isinstance(data_frame, pd.DataFrame):
raise TypeError(
"data_frame must be instance of pandas.DataFrame or pandas.Series"
)
for name in data_frame.columns:
values = []
if is_numeric_dtype(data_frame[name].dtype):
infer_type = InferType.MEASURE
values = (
data_frame[name]
.fillna(default_measure_value)
.astype(float)
.values.tolist()
)
else:
infer_type = InferType.DIMENSION
values = (
data_frame[name]
.fillna(default_dimension_value)
.astype(str)
.values.tolist()
)
self.add_series(
name,
values,
type=infer_type.value,
)
def add_data_frame_index(
self,
data_frame: Union[pd.DataFrame, pd.Series],
name: Optional[str],
) -> None:
"""
A method for adding data frame's index to an existing
[Data][ipyvizzu.animation.Data] class instance.
Args:
data_frame: The pandas data frame object.
name: The name of the index series.
Raises:
TypeError: If `data_frame` is not instance of [pd.DataFrame][pandas.DataFrame]
or [pd.Series][pandas.Series].
Example:
Adding a data frame's index to a [Data][ipyvizzu.animation.Data] class instance:
data_frame = pd.DataFrame(
{"Popularity": [114, 96]},
index=["x", "y"]
)
data = Data()
data.add_data_frame_index(data_frame, "DataFrameIndex")
data.add_data_frame(data_frame)
"""
if data_frame is not None:
if isinstance(data_frame, pd.Series):
data_frame = pd.DataFrame(data_frame)
if not isinstance(data_frame, pd.DataFrame):
raise TypeError(
"data_frame must be instance of pandas.DataFrame or pandas.Series"
)
self.add_series(
str(name),
[str(i) for i in data_frame.index],
type=InferType.DIMENSION.value,
)
def _add_named_value(
self, dest: str, name: str, values: Optional[list] = None, **kwargs
) -> None:
value = {"name": name, **kwargs}
if values is not None:
value["values"] = values # type: ignore
self._add_value(dest, value)
def _add_value(self, dest: str, value: Union[dict, list]) -> None:
self.setdefault(dest, []).append(value)
def build(self) -> dict:
"""
A method for validating and returning the data animation dictionary.
Returns:
A dictionary that stored in the data animation object.
It contains a `data` key whose value is the stored animation.
"""
jsonschema.validate(self, DATA_SCHEMA)
return {"data": self}
filter(filter_expr=None)
classmethod
A class method for creating a Data class instance with a data filter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filter_expr |
Optional[str]
|
The JavaScript data filter expression. |
None
|
Returns:
Type | Description |
---|---|
Data
|
A data animation instance that contains a data filter. |
Source code in ipyvizzu/animation.py
@classmethod
def filter(cls, filter_expr: Optional[str] = None): # -> Data:
"""
A class method for creating a [Data][ipyvizzu.animation.Data]
class instance with a data filter.
Args:
filter_expr: The JavaScript data filter expression.
Returns:
(Data): A data animation instance that contains a data filter.
Example:
Create a [Data][ipyvizzu.animation.Data] class with a data filter:
filter = Data.filter("record['Genres'] == 'Pop'")
"""
data = cls()
data.set_filter(filter_expr)
return data
set_filter(filter_expr=None)
A method for adding a filter to an existing Data class instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filter_expr |
Optional[str]
|
The JavaScript data filter expression. |
None
|
Example
Add a data filter to a Data class instance:
data = Data()
data.set_filter("record['Genres'] == 'Pop'")
Source code in ipyvizzu/animation.py
def set_filter(self, filter_expr: Optional[str] = None) -> None:
"""
A method for adding a filter to an existing
[Data][ipyvizzu.animation.Data] class instance.
Args:
filter_expr: The JavaScript data filter expression.
Example:
Add a data filter to a [Data][ipyvizzu.animation.Data] class instance:
data = Data()
data.set_filter("record['Genres'] == 'Pop'")
"""
filter_expr_raw_js = (
RawJavaScript(f"record => {{ return ({' '.join(filter_expr.split())}) }}")
if filter_expr is not None
else filter_expr
)
self.update({"filter": filter_expr_raw_js})
from_json(filename)
classmethod
A method for returning a Data class instance which has been created from a json file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
Union[str, bytes, PathLike]
|
The path of the data source json file. |
required |
Returns:
Type | Description |
---|---|
Data
|
A data animation instance that has been created from a json file. |
Source code in ipyvizzu/animation.py
@classmethod
def from_json(cls, filename: Union[str, bytes, PathLike]): # -> Data:
"""
A method for returning a [Data][ipyvizzu.animation.Data]
class instance which has been created from a json file.
Args:
filename: The path of the data source json file.
Returns:
(Data): A data animation instance that has been created from a json file.
"""
with open(filename, "r", encoding="utf8") as file_desc:
return cls(json.load(file_desc))
add_record(record)
A method for adding a record to an existing Data class instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record |
list
|
A list that contains data values. |
required |
Example
Adding a record to a Data class instance:
data = Data()
record = ["Pop", "Hard", 114]
data.add_record(record)
Source code in ipyvizzu/animation.py
def add_record(self, record: list) -> None:
"""
A method for adding a record to an existing
[Data][ipyvizzu.animation.Data] class instance.
Args:
record: A list that contains data values.
Example:
Adding a record to a [Data][ipyvizzu.animation.Data] class instance:
data = Data()
record = ["Pop", "Hard", 114]
data.add_record(record)
"""
self._add_value("records", record)
add_records(records)
A method for adding records to an existing Data class instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
records |
List[list]
|
A list that contains data records. |
required |
Example
Adding records to a Data class instance:
data = Data()
records = [
["Pop", "Hard", 114],
["Rock", "Hard", 96],
["Pop", "Experimental", 127],
["Rock", "Experimental", 83],
]
data.add_records(records)
Source code in ipyvizzu/animation.py
def add_records(self, records: List[list]) -> None:
"""
A method for adding records to an existing
[Data][ipyvizzu.animation.Data] class instance.
Args:
records: A list that contains data records.
Example:
Adding records to a [Data][ipyvizzu.animation.Data] class instance:
data = Data()
records = [
["Pop", "Hard", 114],
["Rock", "Hard", 96],
["Pop", "Experimental", 127],
["Rock", "Experimental", 83],
]
data.add_records(records)
"""
list(map(self.add_record, records))
add_series(name, values=None, **kwargs)
A method for adding a series to an existing Data class instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the series. |
required |
values |
Optional[list]
|
The data values of the series. |
None
|
**kwargs |
Optional
|
Arbitrary keyword arguments. For example infer type can be set with the |
{}
|
Example
Adding a series without values to a Data class instance:
data = Data()
data.add_series("Genres")
Adding a series without values and with infer type to a Data class instance:
data = Data()
data.add_series("Kinds", type="dimension")
Adding a series with values to a Data class instance:
data = Data()
data.add_series(
"Popularity", [114, 96, 127, 83]
)
Source code in ipyvizzu/animation.py
def add_series(self, name: str, values: Optional[list] = None, **kwargs) -> None:
"""
A method for adding a series to an existing
[Data][ipyvizzu.animation.Data] class instance.
Args:
name: The name of the series.
values: The data values of the series.
**kwargs (Optional):
Arbitrary keyword arguments.
For example infer type can be set with the `type` keywod argument.
Example:
Adding a series without values to a [Data][ipyvizzu.animation.Data] class instance:
data = Data()
data.add_series("Genres")
Adding a series without values and with infer type to
a [Data][ipyvizzu.animation.Data] class instance:
data = Data()
data.add_series("Kinds", type="dimension")
Adding a series with values to a [Data][ipyvizzu.animation.Data] class instance:
data = Data()
data.add_series(
"Popularity", [114, 96, 127, 83]
)
"""
self._add_named_value("series", name, values, **kwargs)
add_dimension(name, values=None, **kwargs)
A method for adding a dimension to an existing Data class instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the dimension. |
required |
values |
Optional[list]
|
The data values of the dimension. |
None
|
**kwargs |
Optional
|
Arbitrary keyword arguments. |
{}
|
Example
Adding a dimension with values to a Data class instance:
data = Data()
data.add_dimension("Genres", ["Pop", "Rock"])
Source code in ipyvizzu/animation.py
def add_dimension(self, name: str, values: Optional[list] = None, **kwargs) -> None:
"""
A method for adding a dimension to an existing
[Data][ipyvizzu.animation.Data] class instance.
Args:
name: The name of the dimension.
values: The data values of the dimension.
**kwargs (Optional): Arbitrary keyword arguments.
Example:
Adding a dimension with values to a [Data][ipyvizzu.animation.Data] class instance:
data = Data()
data.add_dimension("Genres", ["Pop", "Rock"])
"""
self._add_named_value("dimensions", name, values, **kwargs)
add_measure(name, values=None, **kwargs)
A method for adding a measure to an existing Data class instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the measure. |
required |
values |
Optional[list]
|
The data values of the measure. |
None
|
**kwargs |
Optional
|
Arbitrary keyword arguments. |
{}
|
Example
Adding a measure with values to a Data class instance:
data = Data()
data.add_measure(
"Popularity",
[
[114, 96],
[127, 83],
],
)
Source code in ipyvizzu/animation.py
def add_measure(self, name: str, values: Optional[list] = None, **kwargs) -> None:
"""
A method for adding a measure to an existing
[Data][ipyvizzu.animation.Data] class instance.
Args:
name: The name of the measure.
values: The data values of the measure.
**kwargs (Optional): Arbitrary keyword arguments.
Example:
Adding a measure with values to a [Data][ipyvizzu.animation.Data] class instance:
data = Data()
data.add_measure(
"Popularity",
[
[114, 96],
[127, 83],
],
)
"""
self._add_named_value("measures", name, values, **kwargs)
add_data_frame(data_frame, default_measure_value=0, default_dimension_value='')
A method for adding data frame to an existing Data class instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_frame |
Union[pd.DataFrame, pd.Series]
|
The pandas data frame object. |
required |
default_measure_value |
Optional[Any]
|
The default measure value to fill the empty values. |
0
|
default_dimension_value |
Optional[Any]
|
The default dimension value to fill the empty values. |
''
|
Raises:
Type | Description |
---|---|
TypeError
|
If |
Example
Adding a data frame to a Data class instance:
data_frame = pd.DataFrame(
{
"Genres": ["Pop", "Rock", "Pop", "Rock"],
"Kinds": ["Hard", "Hard", "Experimental", "Experimental"],
"Popularity": [114, 96, 127, 83],
}
)
data = Data()
data.add_data_frame(data_frame)
Source code in ipyvizzu/animation.py
def add_data_frame(
self,
data_frame: Union[pd.DataFrame, pd.Series],
default_measure_value: Optional[Any] = 0,
default_dimension_value: Optional[Any] = "",
) -> None:
"""
A method for adding data frame to an existing
[Data][ipyvizzu.animation.Data] class instance.
Args:
data_frame: The pandas data frame object.
default_measure_value: The default measure value to fill the empty values.
default_dimension_value: The default dimension value to fill the empty values.
Raises:
TypeError: If `data_frame` is not instance of [pd.DataFrame][pandas.DataFrame]
or [pd.Series][pandas.Series].
Example:
Adding a data frame to a [Data][ipyvizzu.animation.Data] class instance:
data_frame = pd.DataFrame(
{
"Genres": ["Pop", "Rock", "Pop", "Rock"],
"Kinds": ["Hard", "Hard", "Experimental", "Experimental"],
"Popularity": [114, 96, 127, 83],
}
)
data = Data()
data.add_data_frame(data_frame)
"""
if not isinstance(data_frame, type(None)):
if isinstance(data_frame, pd.Series):
data_frame = pd.DataFrame(data_frame)
if not isinstance(data_frame, pd.DataFrame):
raise TypeError(
"data_frame must be instance of pandas.DataFrame or pandas.Series"
)
for name in data_frame.columns:
values = []
if is_numeric_dtype(data_frame[name].dtype):
infer_type = InferType.MEASURE
values = (
data_frame[name]
.fillna(default_measure_value)
.astype(float)
.values.tolist()
)
else:
infer_type = InferType.DIMENSION
values = (
data_frame[name]
.fillna(default_dimension_value)
.astype(str)
.values.tolist()
)
self.add_series(
name,
values,
type=infer_type.value,
)
add_data_frame_index(data_frame, name)
A method for adding data frame's index to an existing Data class instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_frame |
Union[pd.DataFrame, pd.Series]
|
The pandas data frame object. |
required |
name |
Optional[str]
|
The name of the index series. |
required |
Raises:
Type | Description |
---|---|
TypeError
|
If |
Example
Adding a data frame's index to a Data class instance:
data_frame = pd.DataFrame(
{"Popularity": [114, 96]},
index=["x", "y"]
)
data = Data()
data.add_data_frame_index(data_frame, "DataFrameIndex")
data.add_data_frame(data_frame)
Source code in ipyvizzu/animation.py
def add_data_frame_index(
self,
data_frame: Union[pd.DataFrame, pd.Series],
name: Optional[str],
) -> None:
"""
A method for adding data frame's index to an existing
[Data][ipyvizzu.animation.Data] class instance.
Args:
data_frame: The pandas data frame object.
name: The name of the index series.
Raises:
TypeError: If `data_frame` is not instance of [pd.DataFrame][pandas.DataFrame]
or [pd.Series][pandas.Series].
Example:
Adding a data frame's index to a [Data][ipyvizzu.animation.Data] class instance:
data_frame = pd.DataFrame(
{"Popularity": [114, 96]},
index=["x", "y"]
)
data = Data()
data.add_data_frame_index(data_frame, "DataFrameIndex")
data.add_data_frame(data_frame)
"""
if data_frame is not None:
if isinstance(data_frame, pd.Series):
data_frame = pd.DataFrame(data_frame)
if not isinstance(data_frame, pd.DataFrame):
raise TypeError(
"data_frame must be instance of pandas.DataFrame or pandas.Series"
)
self.add_series(
str(name),
[str(i) for i in data_frame.index],
type=InferType.DIMENSION.value,
)
build()
A method for validating and returning the data animation dictionary.
Returns:
Type | Description |
---|---|
dict
|
A dictionary that stored in the data animation object.
It contains a |
Source code in ipyvizzu/animation.py
def build(self) -> dict:
"""
A method for validating and returning the data animation dictionary.
Returns:
A dictionary that stored in the data animation object.
It contains a `data` key whose value is the stored animation.
"""
jsonschema.validate(self, DATA_SCHEMA)
return {"data": self}
ipyvizzu.animation.ConfigAttr
Bases: type
A metaclass class for the Config class.
Returns a Config class with a chart preset
if the __getattr__
method called.
For information on all available chart presets see the Vizzu Code reference.
Source code in ipyvizzu/animation.py
class ConfigAttr(type):
"""
A metaclass class for the [Config][ipyvizzu.animation.Config] class.
Returns a [Config][ipyvizzu.animation.Config] class with a chart preset
if the `__getattr__` method called.
For information on all available chart presets see the
[Vizzu Code reference](https://lib.vizzuhq.com/latest/reference/modules/presets/#interfaces).
"""
@classmethod
def __getattr__(mcs, name):
config_attr = mcs("ConfigAttr", (object,), {"name": name})
return config_attr._get_preset # pylint: disable=no-member
def _get_preset(cls, preset):
config = Config(RawJavaScript(f"lib.presets.{cls.name}({preset})"))
return config
ipyvizzu.animation.Config
Bases: Animation
A class for representing config animation. It can build config option of the chart.
Source code in ipyvizzu/animation.py
class Config(Animation, metaclass=ConfigAttr):
"""
A class for representing config animation.
It can build config option of the chart.
"""
def __init__(self, data: Optional[dict]):
"""
Config constructor.
Args:
data:
A config animation dictionary.
For information on all available config parameters see the
[Vizzu Code reference](https://lib.vizzuhq.com/latest/reference/interfaces/vizzu.Config.Chart/#properties).
""" # pylint: disable=line-too-long
self._data = data
def build(self) -> dict:
"""
A method for returning the config animation dictionary.
Returns:
A dictionary that stored in the config animation object.
It contains a `config` key whose value is the stored animation.
"""
return {"config": self._data}
__init__(data)
Config constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Optional[dict]
|
A config animation dictionary. For information on all available config parameters see the Vizzu Code reference. |
required |
Source code in ipyvizzu/animation.py
def __init__(self, data: Optional[dict]):
"""
Config constructor.
Args:
data:
A config animation dictionary.
For information on all available config parameters see the
[Vizzu Code reference](https://lib.vizzuhq.com/latest/reference/interfaces/vizzu.Config.Chart/#properties).
""" # pylint: disable=line-too-long
self._data = data
build()
A method for returning the config animation dictionary.
Returns:
Type | Description |
---|---|
dict
|
A dictionary that stored in the config animation object.
It contains a |
Source code in ipyvizzu/animation.py
def build(self) -> dict:
"""
A method for returning the config animation dictionary.
Returns:
A dictionary that stored in the config animation object.
It contains a `config` key whose value is the stored animation.
"""
return {"config": self._data}
ipyvizzu.animation.Style
Bases: Animation
A class for representing style animation. It can build style option of the chart.
Source code in ipyvizzu/animation.py
class Style(Animation):
"""
A class for representing style animation.
It can build style option of the chart.
"""
def __init__(self, data: Optional[dict]):
"""
Style constructor.
Args:
data:
A style animation dictionary.
For information on all available style parameters see the [Style][styling-properties]
chapter or the
[Vizzu Code reference](https://lib.vizzuhq.com/latest/reference/interfaces/vizzu.Styles.Chart/#properties).
""" # pylint: disable=line-too-long
self._data = data
def build(self) -> dict:
"""
A method for returning the style animation dictionary.
Returns:
A dictionary that stored in the style animation object.
It contains a `style` key whose value is the stored animation.
"""
return {"style": self._data}
__init__(data)
Style constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Optional[dict]
|
A style animation dictionary. For information on all available style parameters see the Style chapter or the Vizzu Code reference. |
required |
Source code in ipyvizzu/animation.py
def __init__(self, data: Optional[dict]):
"""
Style constructor.
Args:
data:
A style animation dictionary.
For information on all available style parameters see the [Style][styling-properties]
chapter or the
[Vizzu Code reference](https://lib.vizzuhq.com/latest/reference/interfaces/vizzu.Styles.Chart/#properties).
""" # pylint: disable=line-too-long
self._data = data
build()
A method for returning the style animation dictionary.
Returns:
Type | Description |
---|---|
dict
|
A dictionary that stored in the style animation object.
It contains a |
Source code in ipyvizzu/animation.py
def build(self) -> dict:
"""
A method for returning the style animation dictionary.
Returns:
A dictionary that stored in the style animation object.
It contains a `style` key whose value is the stored animation.
"""
return {"style": self._data}
ipyvizzu.animation.Snapshot
Bases: Animation
A class for representing snapshot animation. It can build the snapshot id of the chart.
Source code in ipyvizzu/animation.py
class Snapshot(Animation):
"""
A class for representing snapshot animation.
It can build the snapshot id of the chart.
"""
def __init__(self, name: str):
"""
Snapshot constructor.
Args:
name: A snapshot id.
"""
self._name = name
def dump(self) -> str:
"""
A method for overwriting the
[Animation.dump][ipyvizzu.animation.Animation.dump] method.
It dumps the stored snapshot id as a string.
Returns:
An str that contains the stored snapshot id.
"""
return f"'{self._name}'"
def build(self):
"""
A method for preventing to merge [Snapshot][ipyvizzu.animation.Snapshot]
with other animations.
Raises:
NotImplementedError: If the [build][ipyvizzu.animation.Snapshot.build] method
has been called, because [Snapshot][ipyvizzu.animation.Snapshot]
cannot be merged with other animations.
"""
raise NotImplementedError("Snapshot cannot be merged with other animations")
__init__(name)
Snapshot constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
A snapshot id. |
required |
Source code in ipyvizzu/animation.py
def __init__(self, name: str):
"""
Snapshot constructor.
Args:
name: A snapshot id.
"""
self._name = name
dump()
A method for overwriting the Animation.dump method. It dumps the stored snapshot id as a string.
Returns:
Type | Description |
---|---|
str
|
An str that contains the stored snapshot id. |
Source code in ipyvizzu/animation.py
def dump(self) -> str:
"""
A method for overwriting the
[Animation.dump][ipyvizzu.animation.Animation.dump] method.
It dumps the stored snapshot id as a string.
Returns:
An str that contains the stored snapshot id.
"""
return f"'{self._name}'"
build()
A method for preventing to merge Snapshot with other animations.
Raises:
Type | Description |
---|---|
NotImplementedError
|
If the build method has been called, because Snapshot cannot be merged with other animations. |
Source code in ipyvizzu/animation.py
def build(self):
"""
A method for preventing to merge [Snapshot][ipyvizzu.animation.Snapshot]
with other animations.
Raises:
NotImplementedError: If the [build][ipyvizzu.animation.Snapshot.build] method
has been called, because [Snapshot][ipyvizzu.animation.Snapshot]
cannot be merged with other animations.
"""
raise NotImplementedError("Snapshot cannot be merged with other animations")
ipyvizzu.animation.AnimationMerger
A class for merging different types of animations.
Source code in ipyvizzu/animation.py
class AnimationMerger(dict, Animation):
"""A class for merging different types of animations."""
def merge(self, animation: Animation) -> None:
"""
A method for merging an animation with the previously merged animations.
Args:
animation: An animation to be merged with with previously merged animations.
Raises:
ValueError: If the type of an animation is already merged.
"""
data = self._validate(animation)
self.update(data)
def _validate(self, animation: Animation) -> dict:
data = animation.build()
common_keys = set(data).intersection(self)
if common_keys:
raise ValueError(f"Animation is already merged: {common_keys}")
return data
def build(self) -> dict:
"""
A method for returning a merged dictionary from different types of animations.
Returns:
A merged dictionary from
[Data][ipyvizzu.animation.Data],
[Config][ipyvizzu.animation.Config] and
[Style][ipyvizzu.animation.Style] animations.
"""
return self
merge(animation)
A method for merging an animation with the previously merged animations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
animation |
Animation
|
An animation to be merged with with previously merged animations. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the type of an animation is already merged. |
Source code in ipyvizzu/animation.py
def merge(self, animation: Animation) -> None:
"""
A method for merging an animation with the previously merged animations.
Args:
animation: An animation to be merged with with previously merged animations.
Raises:
ValueError: If the type of an animation is already merged.
"""
data = self._validate(animation)
self.update(data)
build()
A method for returning a merged dictionary from different types of animations.
Returns:
Type | Description |
---|---|
dict
|
Source code in ipyvizzu/animation.py
def build(self) -> dict:
"""
A method for returning a merged dictionary from different types of animations.
Returns:
A merged dictionary from
[Data][ipyvizzu.animation.Data],
[Config][ipyvizzu.animation.Config] and
[Style][ipyvizzu.animation.Style] animations.
"""
return self