1- from typing import Optional
1+ from typing import Optional , List
22
33from validator_collection import validators , checkers
44
55from highcharts_stock .chart import Chart as ChartBase
66
7- from highcharts_gantt import constants , errors , utility_functions
7+ from highcharts_gantt import errors , utility_functions
88from highcharts_gantt .options import (HighchartsOptions ,
99 HighchartsStockOptions ,
1010 HighchartsGanttOptions )
@@ -30,43 +30,6 @@ def __init__(self, **kwargs):
3030
3131 super ().__init__ (** kwargs )
3232
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-
7033 def _jupyter_javascript (self ,
7134 global_options = None ,
7235 container = None ,
@@ -126,6 +89,27 @@ def _jupyter_javascript(self,
12689
12790 return js_str
12891
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+
129113 def _repr_html_ (self ):
130114 """Produce the HTML representation of the chart.
131115
0 commit comments