Coverage for src/ipyvizzustory/env/st/story.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2023-03-25 14:02 +0100

1"""A module for working with ipyvizzu-story presentations.""" 

2 

3from typing import Optional 

4 

5from streamlit.components.v1 import html 

6 

7from ipyvizzu import Data, Style 

8 

9from ipyvizzustory.storylib.story import Story as StoryLib 

10 

11 

12class Story(StoryLib): 

13 """A class for representing a presentation story in Streamlit environment.""" 

14 

15 def __init__(self, data: Data, style: Optional[Style] = None): 

16 super().__init__(data=data, style=style) 

17 self.set_size(800, 480) 

18 

19 def set_size( # type: ignore # pylint: disable=signature-differs 

20 self, width: int, height: int 

21 ) -> None: 

22 """A method for overwriting StoryLib().set_size() method.""" 

23 

24 if any([not isinstance(width, int), not isinstance(height, int)]): 

25 raise ValueError("width and height should be in pixels as int") 

26 super().set_size(width=str(width) + "px", height=str(height) + "px") 

27 

28 def play(self) -> None: 

29 """A method for displaying the html code.""" 

30 

31 html( 

32 self.to_html(), 

33 width=int(self._size.width[:-2]), # type: ignore 

34 height=int(self._size.height[:-2]), # type: ignore 

35 )