Coverage for src/ipyvizzu/template.py: 100%

36 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-10 09:30 +0000

1"""A module for storing the JavaScript templates.""" 

2 

3from enum import Enum 

4 

5 

6class ChartProperty(Enum): 

7 """An enum class for storing chart properties.""" 

8 

9 CONFIG = "config" 

10 """An enum key-value for storing config chart property.""" 

11 

12 STYLE = "style" 

13 """An enum key-value for storing style chart property.""" 

14 

15 

16class DisplayTarget(Enum): 

17 """An enum class for storing chart display options.""" 

18 

19 BEGIN = "begin" 

20 """Display all animation steps after the constructor's cell.""" 

21 

22 END = "end" 

23 """Display all animation steps after the last running cell.""" 

24 

25 ACTUAL = "actual" 

26 """Display the actual animation step after the currently running cell.""" 

27 

28 MANUAL = "manual" 

29 """Display all animation steps after calling a show method.""" 

30 

31 

32class DisplayTemplate: 

33 """A class for storing JavaScript snippet templates.""" 

34 

35 # pylint: disable=too-few-public-methods 

36 

37 IPYVIZZUJS: str = "{ipyvizzujs}" 

38 """ipyvizzu JavaScript class.""" 

39 

40 INIT: str = ( 

41 "window.ipyvizzu.createChart(element, " 

42 + "'{chart_id}', '{vizzu}', '{div_width}', '{div_height}');" 

43 ) 

44 """Call createChart JavaScript method.""" 

45 

46 ANIMATE: str = ( 

47 "window.ipyvizzu.animate(element, " 

48 + "'{chart_id}', '{anim_id}', '{display_target}', {scroll}, " 

49 + "lib => {{ return {chart_target} }}, {chart_anim_opts});" 

50 ) 

51 """Call animate JavaScript method.""" 

52 

53 FEATURE: str = ( 

54 "window.ipyvizzu.feature(element, '{chart_id}', '{name}', {enabled});" 

55 ) 

56 """Call feature JavaScript method.""" 

57 

58 STORE: str = "window.ipyvizzu.store(element, '{chart_id}', '{id}');" 

59 """Call store JavaScript method.""" 

60 

61 SET_EVENT: str = ( 

62 "window.ipyvizzu.setEvent(element, " 

63 + "'{chart_id}', '{id}', '{event}', event => {{ {handler} }});" 

64 ) 

65 """Call setEvent JavaScript method.""" 

66 

67 CLEAR_EVENT: str = ( 

68 "window.ipyvizzu.clearEvent(element, '{chart_id}', '{id}', '{event}');" 

69 ) 

70 """Call clearEvent JavaScript method.""" 

71 

72 LOG: str = "window.ipyvizzu.log(element, '{chart_id}', '{chart_property}');" 

73 """Call log JavaScript method.""" 

74 

75 CONTROL: str = "window.ipyvizzu.control(element, '{method}', {params});" 

76 """Call animation control JavaScript methods.""" 

77 

78 CLEAR_INHIBITSCROLL: str = ( 

79 "if (window.IpyVizzu) { window.IpyVizzu.clearInhibitScroll(element); }" 

80 ) 

81 """Call clearInhibitScroll JavaScript method if ipyvizzu JavaScript class exists."""