44
55from highcharts_core .chart import Chart as ChartBase
66
7- from highcharts_maps import constants , errors
7+ from highcharts_maps import constants , errors , utility_functions
88from highcharts_maps .options import HighchartsOptions , HighchartsMapsOptions
99from highcharts_maps .decorators import validate_types
1010from highcharts_maps .js_literal_functions import serialize_to_js_literal
@@ -218,6 +218,14 @@ def to_js_literal(self,
218218 if self .is_async :
219219 urls = []
220220 topologies = []
221+ if self .options .chart and self .options .chart .map :
222+ url = self .options .chart .map .url
223+ urls .append (url )
224+ self .options .chart .map .fetch_counter = 1
225+
226+ map_data_as_str = self .options .chart .map .to_js_literal (encoding = encoding )
227+ topologies .append (map_data_as_str )
228+
221229 for index , series in enumerate (self .options .series ):
222230 if series .is_async :
223231 url = series .map_data .url
@@ -229,10 +237,7 @@ def to_js_literal(self,
229237 map_data_as_str = series .map_data .to_js_literal (encoding = encoding )
230238 topologies .append (map_data_as_str )
231239
232- fetch_as_str = ''
233- for topology in topologies :
234- fetch_request = topology .to_js_literal (encoding = encoding )
235- fetch_as_str += f"""{ fetch_request } \n """
240+ fetch_as_str = '\n ' .join (topologies )
236241
237242 custom_projection_as_str = ''
238243 if self .uses_custom_projection :
@@ -249,6 +254,11 @@ def to_js_literal(self,
249254 options_as_str = ''
250255 if self .options :
251256 options_as_str = self .options .to_js_literal (encoding = encoding )
257+ if self .options .chart and self .options .chart .map and self .options .chart .is_async :
258+ chart_map_str = self .options .chart .map .to_js_literal (encoding = encoding )
259+ chart_map_str = f"""'{ chart_map_str } '"""
260+ fetch_counter = self .options .chart .map .fetch_counter
261+ options_as_str = options_as_str .replace (chart_map_str , f'topology{ fetch_counter } ' )
252262 options_as_str = f"""{ options_as_str } """
253263 else :
254264 options_as_str = """{}"""
@@ -285,7 +295,7 @@ def to_js_literal(self,
285295 prefix = """document.addEventListener('DOMContentLoaded', function() {\n """
286296 if custom_projection_as_str :
287297 prefix += custom_projection_as_str
288- prefix += """(async () => """
298+ prefix += """(async () => { """
289299 suffix = """})()});"""
290300 as_str = fetch_as_str + '\n ' + as_str
291301 else :
@@ -1043,6 +1053,9 @@ def is_async(self) -> bool:
10431053 if not self .options or not self .options .series :
10441054 return False
10451055
1056+ if self .options .chart and self .options .chart .is_async :
1057+ return True
1058+
10461059 for series in self .options .series :
10471060 if hasattr (series , 'is_async' ) and series .is_async :
10481061 return True
0 commit comments