Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Release 1.4.0
=========================================

* **MAJOR** performance gains in the ``.to_js_literal()`` method. Implementation seems to
improve performance by 50 - 90%. (#51)
* *SIGNIFICANT* performance gains in the ``.to_json()`` method. Implementation seems to
improve performance by 30 - 90%.
* **ENHANCEMENT:** Added one-shot chart creation and rendering from Series objects (#89).
* **ENHANCEMENT:** Added one-shot chart creation using ``series`` and ``data``/``series_type`` keywords. (#90).

Expand Down
29 changes: 25 additions & 4 deletions highcharts_core/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,8 @@ def _to_untrimmed_dict(self, in_cls = None) -> dict:

def to_js_literal(self,
filename = None,
encoding = 'utf-8') -> Optional[str]:
encoding = 'utf-8',
careful_validation = False) -> Optional[str]:
"""Return the object represented as a :class:`str <python:str>` containing the
JavaScript object literal.

Expand All @@ -468,6 +469,18 @@ def to_js_literal(self,
to ``'utf-8'``.
:type encoding: :class:`str <python:str>`

:param careful_validation: if ``True``, will carefully validate JavaScript values
along the way using the
`esprima-python <https://github.com/Kronuz/esprima-python>`__ library. Defaults
to ``False``.

.. warning::

Setting this value to ``True`` will significantly degrade serialization
performance, though it may prove useful for debugging purposes.

:type careful_validation: :class:`bool <python:bool>`

.. note::

If :meth:`variable_name <Chart.variable_name>` is set, will render a string as
Expand All @@ -487,7 +500,9 @@ def to_js_literal(self,
as_dict = {}
for key in untrimmed:
item = untrimmed[key]
serialized = serialize_to_js_literal(item, encoding = encoding)
serialized = serialize_to_js_literal(item,
encoding = encoding,
careful_validation = careful_validation)
if serialized is not None:
as_dict[key] = serialized

Expand All @@ -499,13 +514,19 @@ def to_js_literal(self,
container_as_str = """null"""

if self.options:
options_as_str = "{}".format(self.options.to_js_literal(encoding = encoding))
options_as_str = "{}".format(
self.options.to_js_literal(encoding = encoding,
careful_validation = careful_validation)
)
else:
options_as_str = """null"""

callback_as_str = ''
if self.callback:
callback_as_str = "{}".format(self.callback.to_js_literal(encoding = encoding))
callback_as_str = "{}".format(
self.callback.to_js_literal(encoding = encoding,
careful_validation = careful_validation)
)
signature_elements += 1

signature = """Highcharts.chart("""
Expand Down
18 changes: 16 additions & 2 deletions highcharts_core/global_options/shared_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class SharedOptions(HighchartsOptions):

def to_js_literal(self,
filename = None,
encoding = 'utf-8') -> Optional[str]:
encoding = 'utf-8',
careful_validation = False) -> Optional[str]:
"""Return the object represented as a :class:`str <python:str>` containing the
JavaScript object literal.

Expand All @@ -28,6 +29,18 @@ def to_js_literal(self,
to ``'utf-8'``.
:type encoding: :class:`str <python:str>`

:param careful_validation: if ``True``, will carefully validate JavaScript values
along the way using the
`esprima-python <https://github.com/Kronuz/esprima-python>`__ library. Defaults
to ``False``.

.. warning::

Setting this value to ``True`` will significantly degrade serialization
performance, though it may prove useful for debugging purposes.

:type careful_validation: :class:`bool <python:bool>`

.. note::

Returns a JavaScript string which applies the Highcharts global options. The
Expand All @@ -40,7 +53,8 @@ def to_js_literal(self,
:rtype: :class:`str <python:str>`
"""
prefix = 'Highcharts.setOptions('
options_body = super().to_js_literal(encoding = encoding)
options_body = super().to_js_literal(encoding = encoding,
careful_validation = careful_validation)

as_str = prefix + options_body + ');'

Expand Down
Loading