Coverage for src/ipyvizzustory/env/st/story.py: 100%
13 statements
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-25 13:56 +0100
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-25 13:56 +0100
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 `ipyvizzustory.storylib.story.Story.set_size()` method.
34 In Streamlit environment `width` and `height` must be specified in pixels.
36 Args:
37 width: Width of the presentation story in pixels.
38 height: Height of the presentation story in pixels.
40 Raises:
41 ValueError: If `width` or `height` is not instance of `int`.
42 """
44 if any([not isinstance(width, int), not isinstance(height, int)]):
45 raise ValueError("width and height should be in pixels as int")
46 super().set_size(width=str(width) + "px", height=str(height) + "px")
48 def play(self) -> None:
49 """A method for displaying the assembled html code in Streamlit environment."""
51 html(
52 self.to_html(),
53 width=int(self._size.width[:-2]), # type: ignore
54 height=int(self._size.height[:-2]), # type: ignore
55 )