Skip to content

Commit b0ddd9a

Browse files
committed
Added error handling for series unsupported for export.
1 parent bf56ab2 commit b0ddd9a

File tree

5 files changed

+59
-1
lines changed

5 files changed

+59
-1
lines changed

docs/errors.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,18 @@ HighchartsUnsupportedProtocolError (from :class:`ValueError <python:ValueError>`
230230

231231
--------------
232232

233+
HighchartsUnsupportedExportError (from :class:`ValueError <python:ValueError>`)
234+
==========================================================================================
235+
236+
.. autoexception:: HighchartsUnsupportedExportError
237+
238+
.. collapse:: Class Inheritance
239+
240+
.. inheritance-diagram:: HighchartsUnsupportedExportError
241+
:parts: -1
242+
243+
--------------
244+
233245
HighchartsUnsupportedExportTypeError (from :class:`ValueError <python:ValueError>`)
234246
==========================================================================================
235247

docs/using.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,14 @@ environment. The actual file itself is produced using a
701701

702702
.. include:: using/download_visualizations/_using_custom.rst
703703

704+
705+
.. warning::
706+
707+
As of Highcharts for Python v.1.1.0, the Highcharts :term:`Export Server` does not yet fully
708+
support all of the series types added in Highcharts (JS) v.11. Attempting to programmatically download
709+
one of those new as-yet-unsupported visualizations will generate a
710+
:exc:`HighchartsUnsupportedExportError <highcharts_core.errors.HighchartsUnsupportedExportError>`.
711+
704712
-----------------------------
705713

706714
.. target-notes::

highcharts_core/constants.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,4 +916,11 @@ def __eq__(self, other):
916916
'noise',
917917
'filteredNoise',
918918
'wind',
919+
]
920+
921+
EXPORT_SERVER_UNSUPPORTED_SERIES_TYPES = [
922+
'pictorial',
923+
'flowmap',
924+
'geoheatmap',
925+
'treegraph',
919926
]

highcharts_core/errors.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ class HighchartsUnsupportedProtocolError(HighchartsExportServerError):
108108
pass
109109

110110

111+
class HighchartsUnsupportedExportError(HighchartsExportServerError):
112+
""":exc:`ValueError <python:ValueError>` encountered when trying to export a series type that
113+
is not yet supported by the :term:`Export Server`.
114+
"""
115+
pass
116+
111117
class HighchartsUnsupportedExportTypeError(HighchartsExportServerError):
112118
""":exc:`ValueError <python:ValueError>` encountered when requesting an unsupported
113119
image type from a :term:`Export Server`."""

highcharts_core/headless_export.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import requests
1212
from validator_collection import validators
1313

14-
from highcharts_core import errors
14+
from highcharts_core import errors, constants
1515
from highcharts_core.decorators import class_sensitive
1616
from highcharts_core.metaclasses import HighchartsMeta
1717
from highcharts_core.utility_classes.javascript_functions import CallbackFunction
@@ -531,6 +531,25 @@ def custom_code(self) -> Optional[CallbackFunction]:
531531
def custom_code(self, value):
532532
self._custom_code = value
533533

534+
@classmethod
535+
def is_export_supported(cls, options) -> bool:
536+
"""Evaluates whether the Highcharts Export Server supports exporting the series types in ``options``.
537+
538+
:rtype: :class:`bool <python:bool>`
539+
"""
540+
if not isinstance(options, HighchartsOptions):
541+
return False
542+
543+
if not options.series:
544+
return True
545+
546+
series_types = [x.type for x in options.series]
547+
for item in series_types:
548+
if item in constants.EXPORT_SERVER_UNSUPPORTED_SERIES_TYPES:
549+
return False
550+
551+
return True
552+
534553
@classmethod
535554
def _get_kwargs_from_dict(cls, as_dict):
536555
url = as_dict.get('url', None)
@@ -693,6 +712,12 @@ def request_chart(self,
693712

694713
as_json = json.dumps(payload)
695714

715+
if not self.is_export_supported(self.options):
716+
raise errors.HighchartsUnsupportedExportError('The Highcharts Export Server currently only supports '
717+
'exports from Highcharts (Javascript) v.10. You are '
718+
'using a series type introduced in v.11. Sorry, but '
719+
'that functionality is still forthcoming.')
720+
696721
options_as_json = self.options.to_json()
697722
if isinstance(options_as_json, bytes):
698723
options_as_str = str(options_as_json, encoding = 'utf-8')

0 commit comments

Comments
 (0)