1
- from typing import Optional
1
+ from typing import Optional , List
2
2
3
3
from validator_collection import validators , checkers
4
4
5
5
from highcharts_stock .chart import Chart as ChartBase
6
6
7
- from highcharts_gantt import constants , errors , utility_functions
7
+ from highcharts_gantt import errors , utility_functions
8
8
from highcharts_gantt .options import (HighchartsOptions ,
9
9
HighchartsStockOptions ,
10
10
HighchartsGanttOptions )
@@ -30,43 +30,6 @@ def __init__(self, **kwargs):
30
30
31
31
super ().__init__ (** kwargs )
32
32
33
- def _jupyter_include_scripts (self ):
34
- """Return the JavaScript code that is used to load the Highcharts JS libraries.
35
-
36
- .. note::
37
-
38
- Currently includes *all* `Highcharts JS <https://www.highcharts.com/>`_ modules
39
- in the HTML. This issue will be addressed when roadmap issue :issue:`2` is
40
- released.
41
-
42
- :rtype: :class:`str <python:str>`
43
- """
44
- js_str = ''
45
- if self .is_gantt_chart :
46
- for item in constants .GANTT_INCLUDE_LIBS :
47
- js_str += utility_functions .jupyter_add_script (item )
48
- js_str += """.then(() => {"""
49
-
50
- for item in constants .GANTT_INCLUDE_LIBS :
51
- js_str += """});"""
52
- elif self .is_stock_chart :
53
- for item in constants .STOCK_INCLUDE_LIBS :
54
- js_str += utility_functions .jupyter_add_script (item )
55
- js_str += """.then(() => {"""
56
-
57
- for item in constants .STOCK_INCLUDE_LIBS :
58
- js_str += """});"""
59
-
60
- else :
61
- for item in constants .INCLUDE_LIBS :
62
- js_str += utility_functions .jupyter_add_script (item )
63
- js_str += """.then(() => {"""
64
-
65
- for item in constants .INCLUDE_LIBS :
66
- js_str += """});"""
67
-
68
- return js_str
69
-
70
33
def _jupyter_javascript (self ,
71
34
global_options = None ,
72
35
container = None ,
@@ -126,6 +89,27 @@ def _jupyter_javascript(self,
126
89
127
90
return js_str
128
91
92
+ def get_required_modules (self , include_extension = False ) -> List [str ]:
93
+ """Return the list of URLs from which the Highcharts JavaScript modules
94
+ needed to render the chart can be retrieved.
95
+
96
+ :param include_extension: if ``True``, will return script names with the
97
+ ``'.js'`` extension included. Defaults to ``False``.
98
+ :type include_extension: :class:`bool <python:bool>`
99
+
100
+ :rtype: :class:`list <python:list>`
101
+ """
102
+ initial_scripts = ['highcharts' ]
103
+ if self .is_gantt_chart :
104
+ initial_scripts .extend (['gantt/modules/gantt' ])
105
+ has_stock_tools = hasattr (self .options , 'stock_tools' ) and self .options .stock_tools
106
+ if self .is_stock_chart or has_stock_tools :
107
+ initial_scripts .append ('modules/stock' )
108
+
109
+ scripts = self ._process_required_modules (initial_scripts , include_extension )
110
+
111
+ return scripts
112
+
129
113
def _repr_html_ (self ):
130
114
"""Produce the HTML representation of the chart.
131
115
0 commit comments