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
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@

Release 1.3.5
=========================================

* **BUGFIX:** Fixed validation of style properties in the ``Legend`` class (#93).

---------------------


Release 1.3.4
=========================================

Expand Down
2 changes: 1 addition & 1 deletion highcharts_core/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.3.4'
__version__ = '1.3.5'
44 changes: 33 additions & 11 deletions highcharts_core/options/legend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,18 +319,24 @@ def floating(self, value):
self._floating = bool(value)

@property
def item_checkbox_style(self) -> Optional[str]:
def item_checkbox_style(self) -> Optional[str | dict]:
"""Default styling for the checkbox next to a legend item when
:meth:`Legend.show_checkbox` is ``True``. Defaults to:
``'{"width": "13px", "height": "13px", "position":"absolute"}'``.

:rtype: :class:`str <python:str>` or :obj:`None <python:None>`
:rtype: :class:`str <python:str>` or :class:`dict <python:dict>` or
:obj:`None <python:None>`
"""
return self._item_checkbox_style

@item_checkbox_style.setter
def item_checkbox_style(self, value):
self._item_checkbox_style = validators.string(value, allow_empty = True)
try:
self._item_checkbox_style = validators.dict(value, allow_empty = True)
except (ValueError, TypeError):
self._item_checkbox_style = validators.string(value,
allow_empty = True,
coerce_value = True)

@property
def item_distance(self) -> Optional[int | float | Decimal]:
Expand All @@ -348,7 +354,7 @@ def item_distance(self, value):
minimum = 0)

@property
def item_hidden_style(self) -> Optional[str]:
def item_hidden_style(self) -> Optional[str | dict]:
"""Default styling for the legend item when the corresponding series or data
point is hidden. Defaults to:
``'{"color": "#cccccc"}'``.
Expand All @@ -367,10 +373,15 @@ def item_hidden_style(self) -> Optional[str]:

@item_hidden_style.setter
def item_hidden_style(self, value):
self._item_hidden_style = validators.string(value, allow_empty = True)
try:
self._item_hidden_style = validators.dict(value, allow_empty = True)
except (ValueError, TypeError):
self._item_hidden_style = validators.string(value,
allow_empty = True,
coerce_value = True)

@property
def item_hover_style(self) -> Optional[str]:
def item_hover_style(self) -> Optional[str | dict]:
"""Default styling for the legend item when the corresponding series or data
point is in a hover state. Defaults to:
``'{"color": "#000000"}'``.
Expand All @@ -383,13 +394,19 @@ def item_hover_style(self) -> Optional[str]:

Properties are inherited from :meth:`Legend.style` unless overridden here.

:rtype: :class:`str <python:str>` or :obj:`None <python:None>`
:rtype: :class:`str <python:str>` or :class:`dict <python:dict>` or
:obj:`None <python:None>`
"""
return self._item_hover_style

@item_hover_style.setter
def item_hover_style(self, value):
self._item_hover_style = validators.string(value, allow_empty = True)
try:
self._item_hover_style = validators.dict(value, allow_empty = True)
except (ValueError, TypeError):
self._item_hover_style = validators.string(value,
allow_empty = True,
coerce_value = True)

@property
def item_margin_bottom(self) -> Optional[int | float | Decimal]:
Expand Down Expand Up @@ -422,9 +439,9 @@ def item_margin_top(self, value):
minimum = 0)

@property
def item_style(self) -> Optional[str]:
def item_style(self) -> Optional[str | dict]:
"""Default styling for each legend item. Defaults to:
``'{"color": "#333333", "cursor": "pointer", "fontSize": "12px", "fontWeight": "bold", "textOverflow": "ellipsis"}'``.
``{"color": "#333333", "cursor": "pointer", "fontSize": "12px", "fontWeight": "bold", "textOverflow": "ellipsis"}``.

.. warning::

Expand All @@ -442,7 +459,12 @@ def item_style(self) -> Optional[str]:

@item_style.setter
def item_style(self, value):
self._item_style = validators.string(value, allow_empty = True)
try:
self._item_style = validators.dict(value, allow_empty = True)
except (ValueError, TypeError):
self._item_style = validators.string(value,
allow_empty = True,
coerce_value = True)

@property
def item_width(self) -> Optional[int | float | Decimal]:
Expand Down
7 changes: 7 additions & 0 deletions tests/options/legend/test_legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@
'x': 0,
'y': 0
}, None),
({
'item_style': {
'color': '#5f5e5e',
'fontFamily': 'Roboto',
'fontSize': '12px'
}
}, None),
]


Expand Down