From 47d8bb94a13df5460d81577c6355d0203b8fa5a9 Mon Sep 17 00:00:00 2001 From: Chris Modzelewski Date: Tue, 24 Oct 2023 17:08:45 -0400 Subject: [PATCH 1/2] Added FlagSeries.data property support. --- highcharts_stock/options/series/flags.py | 61 +++++++++++++++++++++++- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/highcharts_stock/options/series/flags.py b/highcharts_stock/options/series/flags.py index 0af861e..357db09 100644 --- a/highcharts_stock/options/series/flags.py +++ b/highcharts_stock/options/series/flags.py @@ -1,7 +1,11 @@ -from highcharts_stock.utility_functions import mro__to_untrimmed_dict +from typing import Optional, List + +from highcharts_stock.utility_functions import mro__to_untrimmed_dict, is_ndarray from highcharts_stock.options.series.base import NavigatorIndicatorSeries from highcharts_stock.options.plot_options.flags import FlagsOptions +from highcharts_stock.options.series.data.single_point import (SingleXData, + SingleXDataCollection) class FlagsSeries(NavigatorIndicatorSeries, FlagsOptions): @@ -15,7 +19,53 @@ class FlagsSeries(NavigatorIndicatorSeries, FlagsOptions): """ def __init__(self, **kwargs): + self._data = None + + self.data = kwargs.get('data', None) + super().__init__(**kwargs) + + @property + def data(self) -> Optional[List[SingleXData] | SingleXDataCollection]: + """Collection of data that represents the series. Defaults to + :obj:`None `. + + While the series type returns a collection of :class:`SingleXData` instances + or an :class:`SingleXDataCollection` instance, it accepts as input + two different types of data: + + .. tabs:: + + .. tab:: 1D Collection + + .. code-block:: + + series = FlagSeries() + series.data = [ + [1463753252], + [1563753252], + [1663753252] + ] + + A one-dimensional collection of values, corresponding to the position of + each flag on the x-axis. + + .. tab:: Object Collection + + A one-dimensional collection of :class:`SingleXData` objects, or objects + coercable. + + :rtype: :class:`list ` of :class:`SingleXData` or + :class:`SingleXDataCollection` or :obj:`None ` + """ + return self._data + + @data.setter + def data(self, value): + if not is_ndarray(value) and not value: + self._data = None + else: + self._data = SingleXData.from_array(value) @classmethod def _get_kwargs_from_dict(cls, as_dict): @@ -130,11 +180,18 @@ def _get_kwargs_from_dict(cls, as_dict): 'x_axis': as_dict.get('xAxis', None), 'y_axis': as_dict.get('yAxis', None), 'z_index': as_dict.get('zIndex', None), + + 'data': as_dict.get('data', None), } return kwargs def _to_untrimmed_dict(self, in_cls = None) -> dict: - untrimmed = mro__to_untrimmed_dict(self, in_cls = in_cls) or {} + untrimmed = { + 'data': self.data + } + untrimmed_parents = mro__to_untrimmed_dict(self, in_cls = in_cls) or {} + for key in untrimmed_parents: + untrimmed[key] = untrimmed_parents[key] return untrimmed From 42b62356a6aad01b5f5751566597ccaa88372656 Mon Sep 17 00:00:00 2001 From: Chris Modzelewski Date: Tue, 24 Oct 2023 17:08:57 -0400 Subject: [PATCH 2/2] Bumped version number and updated changelog. --- CHANGES.rst | 7 +++++++ highcharts_stock/__version__.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 7f54b21..9a507d7 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,10 @@ +Release 1.4.2 +========================================= + +* **BUGFIX**: Fixed missing ``.data`` property in ``FlagSeries`` objects (#43 ) + +--------------------- + Release 1.4.1 ========================================= diff --git a/highcharts_stock/__version__.py b/highcharts_stock/__version__.py index 2783701..4b5bf2c 100644 --- a/highcharts_stock/__version__.py +++ b/highcharts_stock/__version__.py @@ -1 +1 @@ -__version__ = '1.4.1' \ No newline at end of file +__version__ = '1.4.2' \ No newline at end of file