Skip to content

Commit 1fd0c29

Browse files
committed
Aligned Jupyter display to Highcharts Core.
1 parent 35eaa1c commit 1fd0c29

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

highcharts_gantt/chart.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def _jupyter_include_scripts(self):
7070
def _jupyter_javascript(self,
7171
global_options = None,
7272
container = None,
73+
random_slug = None,
7374
retries = 3,
7475
interval = 1000):
7576
"""Return the JavaScript code which Jupyter Labs will need to render the chart.
@@ -84,6 +85,10 @@ def _jupyter_javascript(self,
8485
property if set, and ``'highcharts_target_div'`` if not set.
8586
:type container: :class:`str <python:str>` or :obj:`None <python:None>`
8687
88+
:param random_slug: The random sequence of characters to append to the container name to ensure uniqueness.
89+
Defaults to :obj:`None <python:None>`
90+
:type random_slug: :class:`str <python:str>` or :obj:`None <python:None>`
91+
8792
:param retries: The number of times to retry rendering the chart. Used to avoid race conditions with the
8893
Highcharts script. Defaults to 3.
8994
:type retries: :class:`int <python:int>`
@@ -95,7 +100,11 @@ def _jupyter_javascript(self,
95100
:rtype: :class:`str <python:str>`
96101
"""
97102
original_container = self.container
98-
self.container = container or self.container or 'highcharts_target_div'
103+
new_container = container or self.container or 'highcharts_target_div'
104+
if not random_slug:
105+
self.container = new_container
106+
else:
107+
self.container = f'{new_container}_{random_slug}'
99108

100109
if global_options is not None:
101110
global_options = validate_types(global_options,
@@ -109,6 +118,7 @@ def _jupyter_javascript(self,
109118

110119
js_str += utility_functions.prep_js_for_jupyter(self.to_js_literal(),
111120
container = self.container,
121+
random_slug = random_slug,
112122
retries = retries,
113123
interval = interval)
114124

@@ -894,10 +904,13 @@ def from_options(cls,
894904
chart_kwargs['is_gantt_chart'] = True
895905
elif checkers.is_type(options, 'HighchartsOptions'):
896906
options = options
897-
elif ('navigator' in value
898-
or 'range_selector' in value
899-
or 'rangeSelector' in value
900-
or 'connectors' in value):
907+
elif ('navigator' in options
908+
or 'range_selector' in options
909+
or 'rangeSelector' in options
910+
or 'connectors' in options):
911+
options = validate_types(options, HighchartsGanttOptions)
912+
chart_kwargs['is_gantt_chart'] = True
913+
elif chart_kwargs.get('is_gantt_chart', False):
901914
options = validate_types(options, HighchartsGanttOptions)
902915
chart_kwargs['is_gantt_chart'] = True
903916
else:

0 commit comments

Comments
 (0)