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

11 statements  

« 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 Panel environment.""" 

2 

3from typing import Optional 

4 

5from panel.pane import HTML 

6 

7from ipyvizzu import Data, Style 

8 

9from ipyvizzustory.storylib.story import StorySize, Story as StoryLib 

10 

11 

12class Story(StoryLib): 

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

14 

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

16 """ 

17 Presentation Story constructor. 

18 

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 """ 

26 

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

28 

29 def play(self) -> None: 

30 """ 

31 A method for displaying the assembled html code in Panel environment. 

32 

33 Raises: 

34 ValueError: If `width` or `height` is not in pixel. 

35 """ 

36 

37 if any( 

38 [ 

39 not StorySize.is_pixel(self._size.width), 

40 not StorySize.is_pixel(self._size.height), 

41 ] 

42 ): 

43 raise ValueError("width and height should be in pixels") 

44 

45 HTML( 

46 self.to_html(), 

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

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

49 ).servable()