Coverage for src/ipyvizzustory/env/st/story.py: 100%
13 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-10 09:08 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-10 09:08 +0000
1"""A module for working with presentation stories in `Streamlit` environment."""
3from typing import Optional
5from streamlit.components.v1 import html
7from ipyvizzu import Data, Style
9from ipyvizzustory.storylib.story import Story as StoryLib
12class Story(StoryLib):
13 """A class for representing a presentation story in `Streamlit` environment."""
15 def __init__(self, data: Data, style: Optional[Style] = None):
16 """
17 Presentation Story constructor.
19 Args:
20 data: Data set for the whole presentation story.
21 After initialization `data` can not be modified,
22 but it can be filtered.
23 style: Style settings for the presentation story.
24 `style` can be changed at each presentation step.
25 """
27 super().__init__(data=data, style=style)
29 def set_size( # type: ignore # pylint: disable=signature-differs
30 self, width: int, height: int
31 ) -> None:
32 """
33 A method for overwriting
34 [storylib.story.Story.set_size][ipyvizzustory.storylib.story.Story.set_size] method.
35 In `Streamlit` environment `width` and `height` must be specified in pixels.
37 Args:
38 width: Width of the presentation story in pixels.
39 height: Height of the presentation story in pixels.
41 Raises:
42 ValueError: If `width` or `height` is not instance of `int`.
43 """
45 if any([not isinstance(width, int), not isinstance(height, int)]):
46 raise ValueError("width and height should be in pixels as int")
47 super().set_size(width=str(width) + "px", height=str(height) + "px")
49 def play(self) -> None:
50 """A method for displaying the assembled `HTML` code in `Streamlit` environment."""
52 html(
53 self.to_html(),
54 width=int(self._size.width[:-2]), # type: ignore
55 height=int(self._size.height[:-2]), # type: ignore
56 )