diff --git a/docs/bokeh/source/docs/releases/3.7.0.rst b/docs/bokeh/source/docs/releases/3.7.0.rst index 9bdeea70526..eb656edb604 100644 --- a/docs/bokeh/source/docs/releases/3.7.0.rst +++ b/docs/bokeh/source/docs/releases/3.7.0.rst @@ -11,6 +11,7 @@ Bokeh version ``3.7.0`` (January 2025) is a minor milestone of Bokeh project. * Added support for dual canvas and DOM rendering to ``Legend`` annotation (:bokeh-pull:`14028`) * Added support for custom marker definitions to ``Scatter`` glyph (:bokeh-pull:`14165`) * Added support for stateful action tools, especially ``CustomAction`` (:bokeh-pull:`14143`) +* Enhanced default ``DatetimeTickFormatter`` by providing additional context (:bokeh-pull:`13854`) API and breaking changes ------------------------ diff --git a/src/bokeh/models/axes.py b/src/bokeh/models/axes.py index 3b85d12acb7..a746e80f8e0 100644 --- a/src/bokeh/models/axes.py +++ b/src/bokeh/models/axes.py @@ -46,9 +46,9 @@ ) from ..core.property_mixins import ScalarFillProps, ScalarLineProps, ScalarTextProps from .formatters import ( + CONTEXTUAL_DATETIME_FORMATTER, BasicTickFormatter, CategoricalTickFormatter, - DatetimeTickFormatter, LogTickFormatter, MercatorTickFormatter, TickFormatter, @@ -369,7 +369,7 @@ def __init__(self, *args, **kwargs) -> None: ticker = Override(default=InstanceDefault(DatetimeTicker)) - formatter = Override(default=InstanceDefault(DatetimeTickFormatter)) + formatter = Override(default=CONTEXTUAL_DATETIME_FORMATTER) class MercatorAxis(LinearAxis): ''' An axis that picks nice numbers for tick locations on a diff --git a/src/bokeh/models/formatters.py b/src/bokeh/models/formatters.py index 05219ec40ae..04da03f8f23 100644 --- a/src/bokeh/models/formatters.py +++ b/src/bokeh/models/formatters.py @@ -683,6 +683,52 @@ def RELATIVE_DATETIME_CONTEXT() -> DatetimeTickFormatter: years = "", ) +def CONTEXTUAL_DATETIME_FORMATTER() -> DatetimeTickFormatter: + return DatetimeTickFormatter( + microseconds = "%fus", + milliseconds = "%3Nms", + seconds = "%T", + minsec = "%T", + minutes = "%H:%M", + hourmin = "%H:%M", + hours = "%H:%M", + days = "%b %d", + months = "%b %Y", + years = "%Y", + strip_leading_zeros = ["microseconds", "milliseconds", "seconds"], + boundary_scaling = False, + context_which = "all", + context = DatetimeTickFormatter( + microseconds="%T", + milliseconds="%T", + seconds="%b %d, %Y", + minsec="%b %d, %Y", + minutes="%b %d, %Y", + hourmin="%b %d, %Y", + hours="%b %d, %Y", + days="%Y", + months="", + years="", + boundary_scaling=False, + hide_repeats=True, + context_which="all", + context=DatetimeTickFormatter( + microseconds="%b %d, %Y", + milliseconds="%b %d, %Y", + seconds="", + minsec="", + minutes="", + hourmin="", + hours="", + days="", + months="", + years="", + boundary_scaling=False, + hide_repeats=True, + context=None, + ), + ), + ) #----------------------------------------------------------------------------- # Dev API #----------------------------------------------------------------------------- diff --git a/tests/baselines/defaults.json5 b/tests/baselines/defaults.json5 index a911aaca0b3..389012e79ce 100644 --- a/tests/baselines/defaults.json5 +++ b/tests/baselines/defaults.json5 @@ -1792,7 +1792,58 @@ formatter: { type: "object", name: "DatetimeTickFormatter", - attributes: {}, + attributes: { + seconds: "%T", + minsec: "%T", + minutes: "%H:%M", + hours: "%H:%M", + days: "%b %d", + months: "%b %Y", + strip_leading_zeros: [ + "microseconds", + "milliseconds", + "seconds", + ], + boundary_scaling: false, + context: { + type: "object", + name: "DatetimeTickFormatter", + attributes: { + microseconds: "%T", + milliseconds: "%T", + seconds: "%b %d, %Y", + minsec: "%b %d, %Y", + minutes: "%b %d, %Y", + hourmin: "%b %d, %Y", + hours: "%b %d, %Y", + days: "%Y", + months: "", + years: "", + boundary_scaling: false, + hide_repeats: true, + context: { + type: "object", + name: "DatetimeTickFormatter", + attributes: { + microseconds: "%b %d, %Y", + milliseconds: "%b %d, %Y", + seconds: "", + minsec: "", + minutes: "", + hourmin: "", + hours: "", + days: "", + months: "", + years: "", + boundary_scaling: false, + hide_repeats: true, + }, + }, + context_which: "all", + }, + }, + context_which: "all", + }, }, }, LinearAxis: {