Skip to content

Commit 57e3d80

Browse files
committed
Added bugfix for empty string handling in YAxis.title.text. Closes #171.
1 parent 4029075 commit 57e3d80

File tree

4 files changed

+427
-386
lines changed

4 files changed

+427
-386
lines changed

highcharts_core/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,7 @@ def __repr__(self):
953953

954954
EMPTY_STRING_CONTEXTS = [
955955
'Annotation.draggable',
956+
'YAxisTitle.text',
956957
]
957958

958959

highcharts_core/options/axes/title.py

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Optional
22
from decimal import Decimal
33

4-
from validator_collection import validators
4+
from validator_collection import validators, checkers
55

66
from highcharts_core import errors, constants
77
from highcharts_core.metaclasses import HighchartsMeta
@@ -372,3 +372,76 @@ def _to_untrimmed_dict(self, in_cls = None) -> dict:
372372
}
373373

374374
return untrimmed
375+
376+
377+
class YAxisTitle(AxisTitle):
378+
"""The axis title, shown next to the axis line."""
379+
380+
def __init__(self, **kwargs):
381+
super().__init__(**kwargs)
382+
383+
@property
384+
def _dot_path(self) -> Optional[str]:
385+
"""The dot-notation path to the options key for the current class.
386+
387+
:rtype: :class:`str <python:str>` or :obj:`None <python:None>`
388+
"""
389+
return "yAxis.title"
390+
391+
@property
392+
def text(self) -> Optional[str | constants.EnforcedNullType]:
393+
"""The actual text of the title.
394+
395+
.. note::
396+
397+
A subset of HTML is supported, e.g. ``<b>``, ``<i>``, ``<span>`` (with in-line
398+
styles), etc.
399+
400+
.. warning::
401+
402+
A :meth:`.text <highcharts_core.options.axes.title.YAxisTitle.text>` of
403+
:obj:`None <python:None>` will default to ``'Values'``. To clear the Y-Axis title
404+
on your chart, set its value to an empty string (``''``).
405+
406+
:rtype: :class:`str <python:str>` or :obj:`None <python:None>`
407+
"""
408+
return self._text
409+
410+
@text.setter
411+
def text(self, value):
412+
if isinstance(value, constants.EnforcedNullType):
413+
self._text = constants.EnforcedNull
414+
elif value == '':
415+
self._text = ""
416+
else:
417+
self._text = validators.string(value, allow_empty=True)
418+
419+
@classmethod
420+
def _get_kwargs_from_dict(cls, as_dict):
421+
kwargs = {
422+
"align": as_dict.get("align", None),
423+
"margin": as_dict.get("margin", None),
424+
"offset": as_dict.get("offset", None),
425+
"position_3d": as_dict.get("position3d", None),
426+
"reserve_space": as_dict.get("reserveSpace", None),
427+
"rotation": as_dict.get("rotation", None),
428+
"skew_3d": as_dict.get("skew3d", None),
429+
"style": as_dict.get("style", None),
430+
"text": as_dict.get("text", None),
431+
"text_align": as_dict.get("textAlign", None),
432+
"use_html": as_dict.get("useHTML", None),
433+
"x": as_dict.get("x", None),
434+
"y": as_dict.get("y", None),
435+
}
436+
437+
return kwargs
438+
439+
def _to_untrimmed_dict(self, in_cls=None) -> dict:
440+
untrimmed = {
441+
}
442+
443+
parent_as_dict = super()._to_untrimmed_dict(in_cls=in_cls)
444+
for key in parent_as_dict:
445+
untrimmed[key] = parent_as_dict[key]
446+
447+
return untrimmed

highcharts_core/options/axes/y_axis.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from highcharts_core.utility_functions import validate_color
1313

1414
from highcharts_core.options.axes.x_axis import XAxis
15+
from highcharts_core.options.axes.title import AxisTitle, YAxisTitle
1516

1617

1718
class StackShadow(HighchartsMeta):
@@ -287,6 +288,25 @@ def stops(self, value):
287288

288289
self._stops = processed_items
289290

291+
@property
292+
def title(self) -> Optional[AxisTitle | YAxisTitle]:
293+
"""The axis title, displayed next to the axis line. Defaults to
294+
:obj:`None <python:None>`, which applies the default title of ``'Values'``.
295+
296+
.. tip::
297+
298+
To clear the y-axis value title, set its ``text`` property to an empty string
299+
(``''``).
300+
301+
:rtype: :class:`YAxisTitle` or :obj:`None <python:None>`
302+
"""
303+
return self._title
304+
305+
@title.setter
306+
@class_sensitive(YAxisTitle)
307+
def title(self, value):
308+
self._title = value
309+
290310
@property
291311
def tooltip_value_format(self) -> Optional[str]:
292312
"""Format string that will be used for ``point.y`` and available in (JavaScript)

0 commit comments

Comments
 (0)