8
$\begingroup$

Bug introduced in 12.0 or earlier, partially fixed in 12.1.0

The Part::partw: error has been fixed in 12.1.0. Tooltip bug has not.


Update 2019-11-28

WRI has confirmed that this is a bug.

Update 2019-11-25

The workaround suggested by @alx works if all of the dates have the same granularity. While experimenting with the workaround suggested by @kglr I ran into another issue.

TimelinePlot[{
  DateObject[{2019}, "Year"] -> "Foo",
  DateObject[{2019, 11}, "Month"] -> "Bar"
  }]

Generates the error

Part::partw: Part 2 of {{3.75529*10^9,2019,{0.01,0}}} does not exist.

Reported to WRI CASE:4360060

Original question

The tooltip shows "Day: 2019" even though the DateObject represents a Year. Is this a bug? How to show "Year: 2019" in the tooltip?

TimelinePlot[DateObject[{2019}, "Year"] -> "Foo"]

enter image description here

DateObject[{2019}, "Year"]

enter image description here

$\endgroup$
5
$\begingroup$

Update: For input data with mixed date granularity:

dates = {DateObject[{2019, 11}, "Month"] -> "Month", 
  DateObject[{2019}, "Year"] -> "Year", 
  DateObject[{2019, 5, 15}, "Week"] -> "Week", 
  DateObject[{2020, 10}, "Year"] -> "Year2", 
  DateObject[{2019, 10}, "Quarter"] -> "Quarter"}; 

TimelinePlot[Tooltip[#, #] -> #2 & @@@ Sort[dates]]

enter image description here

Original answer:

An alternative work-around is to wrap DateObjects with Tooltip:

TimelinePlot[Tooltip[#, #] & @ DateObject[{2019}, "Year"] -> "Foo"]

enter image description here

TimelinePlot[Tooltip[#, #]& @ DateObject[{2019, 11}, "Month"] -> "Foo"]

enter image description here

|improve this answer|||||
$\endgroup$
5
$\begingroup$

From InputForm[TimelinePlot[DateObject[{2019}, "Year"] -> "Foo"]] one can see, that MMA uses Day as granularity for DateObjects. So, one possible solution is to change these objects to the needed form:

TimelinePlot[DateObject[{2019}, "Year"] -> "Foo"] /. 
 DateObject[a__, "Day", b__] :> DateObject[a, "Year", b]

Another possibility is using custom LabelingFunction:

TimelinePlot[DateObject[{2019}, "Year"] -> "Foo", 
 LabelingFunction -> (DateObject[FromAbsoluteTime@First@#, "Year"] &)]
|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.