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

44 statements  

« prev     ^ index     » next       coverage.py v7.4.3, created at 2024-02-26 10:12 +0000

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

2 

3from enum import Enum 

4 

5VIZZU_VERSION: str = "0.9" 

6"""A variable for storing the default version of the `vizzu` package.""" 

7 

8VIZZU: str = f"https://cdn.jsdelivr.net/npm/vizzu@{VIZZU_VERSION}/dist/vizzu.min.js" 

9"""A variable for storing the default url of the `vizzu` package.""" 

10 

11 

12class ChartProperty(Enum): 

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

14 

15 CONFIG = "config" 

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

17 

18 STYLE = "style" 

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

20 

21 

22class DisplayTarget(Enum): 

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

24 

25 BEGIN = "begin" 

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

27 

28 END = "end" 

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

30 

31 ACTUAL = "actual" 

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

33 

34 MANUAL = "manual" 

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

36 

37 

38class DisplayTemplate: 

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

40 

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

42 

43 IPYVIZZUJS: str = "{ipyvizzujs}" 

44 """ipyvizzu JavaScript class.""" 

45 

46 INIT: str = ( 

47 "window.ipyvizzu.createChart(element, " 

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

49 ) 

50 """Call createChart JavaScript method.""" 

51 

52 CHANGE_ANALYTICS_TO: str = ( 

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

54 ) 

55 """Call changeAnalyticsTo JavaScript method.""" 

56 

57 ANIMATE: str = ( 

58 "window.ipyvizzu.animate(element, " 

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

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

61 ) 

62 """Call animate JavaScript method.""" 

63 

64 FEATURE: str = ( 

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

66 ) 

67 """Call feature JavaScript method.""" 

68 

69 PLUGIN: str = ( 

70 "window.ipyvizzu.plugin(element, " 

71 + "'{chart_id}', '{plugin}', {options}, '{name}', {enabled});" 

72 ) 

73 """Call plugin JavaScript method.""" 

74 

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

76 """Call store JavaScript method.""" 

77 

78 SET_EVENT: str = ( 

79 "window.ipyvizzu.setEvent(element, " 

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

81 ) 

82 """Call setEvent JavaScript method.""" 

83 

84 CLEAR_EVENT: str = ( 

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

86 ) 

87 """Call clearEvent JavaScript method.""" 

88 

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

90 """Call log JavaScript method.""" 

91 

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

93 """Call animation control JavaScript methods.""" 

94 

95 CLEAR_INHIBITSCROLL: str = ( 

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

97 ) 

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