Skip to content

Commit 5e49d13

Browse files
committed
Added date and datetime support to axis min and max.
1 parent 241f2d0 commit 5e49d13

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

highcharts_core/options/axes/generic.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from typing import Optional, List
22
from decimal import Decimal
3+
import datetime
34

4-
from validator_collection import validators
5+
from validator_collection import validators, checkers
56

67
from highcharts_core import constants, errors
78
from highcharts_core.decorators import class_sensitive
@@ -395,7 +396,7 @@ def margin(self, value):
395396
self._margin = validators.numeric(value, allow_empty = True)
396397

397398
@property
398-
def max(self) -> Optional[int | float | Decimal]:
399+
def max(self) -> Optional[int | float | Decimal | datetime.date | datetime.datetime]:
399400
"""The maximum value of the axis. If :obj:`None <python:None>`, the ``max`` value
400401
is automatically calculated. Defaults to :obj:`None <python:None>`.
401402
@@ -417,7 +418,14 @@ def max(self) -> Optional[int | float | Decimal]:
417418

418419
@max.setter
419420
def max(self, value):
420-
self._max = validators.numeric(value, allow_empty = True)
421+
if value is None:
422+
self._max = None
423+
elif checkers.is_date(value):
424+
self._max = validators.date(value)
425+
elif checkers.is_datetime(value):
426+
self._max = validators.datetime(value)
427+
else:
428+
self._max = validators.numeric(value, allow_empty = True)
421429

422430
@property
423431
def max_padding(self) -> Optional[int | float | Decimal]:
@@ -447,7 +455,7 @@ def max_padding(self, value):
447455
minimum = 0)
448456

449457
@property
450-
def min(self) -> Optional[int | float | Decimal]:
458+
def min(self) -> Optional[int | float | Decimal | datetime.date | datetime.datetime]:
451459
"""The minimum value of the axis. If :obj:`None <python:None>`, the ``min`` value
452460
is automatically calculated. Defaults to :obj:`None <python:None>`.
453461
@@ -473,7 +481,14 @@ def min(self) -> Optional[int | float | Decimal]:
473481

474482
@min.setter
475483
def min(self, value):
476-
self._min = validators.numeric(value, allow_empty = True)
484+
if value is None:
485+
self._min = None
486+
elif checkers.is_date(value):
487+
self._min = validators.date(value)
488+
elif checkers.is_datetime(value):
489+
self._min = validators.datetime(value)
490+
else:
491+
self._min = validators.numeric(value, allow_empty = True)
477492

478493
@property
479494
def minor_grid_line_color(self) -> Optional[str | Gradient | Pattern]:

0 commit comments

Comments
 (0)