Skip to content

Commit

Permalink
enhanced the default datetimeformatter with a dynamic one (bokeh#13854)
Browse files Browse the repository at this point in the history
* enhanced the default datetimeformatter with a dynamic one

* adjusted defaults

* avoid InstanceDefault

* removed unnecessary imports

* fixed order

* Update src/bokeh/models/formatters.py

Co-authored-by: Bryan Van de Ven <[email protected]>

* fixed formatting

* removed separate kwargs function

* renamed function

* added release note entry

---------

Co-authored-by: muendlein <[email protected]>
Co-authored-by: Bryan Van de Ven <[email protected]>
  • Loading branch information
3 people authored Jan 9, 2025
1 parent dbdd75f commit c1d37ca
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/bokeh/source/docs/releases/3.7.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/bokeh/models/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
)
from ..core.property_mixins import ScalarFillProps, ScalarLineProps, ScalarTextProps
from .formatters import (
CONTEXTUAL_DATETIME_FORMATTER,
BasicTickFormatter,
CategoricalTickFormatter,
DatetimeTickFormatter,
LogTickFormatter,
MercatorTickFormatter,
TickFormatter,
Expand Down Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions src/bokeh/models/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
#-----------------------------------------------------------------------------
Expand Down
53 changes: 52 additions & 1 deletion tests/baselines/defaults.json5
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit c1d37ca

Please sign in to comment.