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

38 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-10-12 08:13 +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 CHANGE_ANALYTICS_TO: str = ( 

47 "if (window.IpyVizzu) window.IpyVizzu.changeAnalyticsTo({analytics});" 

48 ) 

49 """Call changeAnalyticsTo JavaScript method.""" 

50 

51 ANIMATE: str = ( 

52 "window.ipyvizzu.animate(element, " 

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

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

55 ) 

56 """Call animate JavaScript method.""" 

57 

58 FEATURE: str = ( 

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

60 ) 

61 """Call feature JavaScript method.""" 

62 

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

64 """Call store JavaScript method.""" 

65 

66 SET_EVENT: str = ( 

67 "window.ipyvizzu.setEvent(element, " 

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

69 ) 

70 """Call setEvent JavaScript method.""" 

71 

72 CLEAR_EVENT: str = ( 

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

74 ) 

75 """Call clearEvent JavaScript method.""" 

76 

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

78 """Call log JavaScript method.""" 

79 

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

81 """Call animation control JavaScript methods.""" 

82 

83 CLEAR_INHIBITSCROLL: str = ( 

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

85 ) 

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