Fixed in 13.0
Background
Following up on how TimelinePlot
can be used to plot GanttCharts (176012) I noted some peculiarities with the way TimelinePlot
automatically draws Ticks and Gridlines.
Minimum Examples
Here are two simple examples that demonstrate, that Ticks and Gridlines are dependent on the length of some labels.
Now let's plot a simple project schedule using TimelinePlot
:
$schedule1 = {
Labeled[Interval[{DateObject[{2020, 10, 1}], DateObject[{2021, 10, 1}]}], "Step 1", Bottom],
Labeled[Interval[{DateObject[{2021, 4, 1}], DateObject[{2022, 4, 1}]}], "Step 2", Bottom],
Labeled[Interval[{DateObject[{2022, 4, 1}], DateObject[{2023, 4, 1}]}], "Step 3", Bottom],
Labeled[Interval[{DateObject[{2023, 4, 1}], DateObject[{2023, 10, 1}]}], "Step 4", Bottom]
};
$chart1 = TimelinePlot[ $schedule1,
AxesOrigin -> Top,
GridLines -> {Automatic, None},
PlotLayout -> "Stacked",
DateTicksFormat -> {"MonthNameShort", " ", "YearShort"}
]
That looks reasonable enough: The gridlines separate the years and the ticks are drawn every two months.
Let's now plot the same schedule, but now we rename Step 4 to the longer Implementation:
$schedule2 = {
Labeled[Interval[{DateObject[{2020, 10, 1}], DateObject[{2021, 10, 1}]}], "Step 1", Bottom],
Labeled[Interval[{DateObject[{2021, 4, 1}], DateObject[{2022, 4, 1}]}], "Step 2", Bottom],
Labeled[Interval[{DateObject[{2022, 4, 1}], DateObject[{2023, 4, 1}]}], "Step 3", Bottom],
Labeled[Interval[{DateObject[{2023, 4, 1}], DateObject[{2023, 10, 1}]}], "Implementation", Bottom]
};
$chart2 = TimelinePlot[ $schedule2,
AxesOrigin -> Top,
GridLines -> {Automatic, None},
PlotLayout -> "Stacked",
DateTicksFormat -> {"MonthNameShort", " ", "YearShort"}
]
This does not look right or at least not nice. Note, that using the following explicit sepcification for GridLines
will give the exact same result:
GridLines -> {DateRange[{2021, 1, 1}, {2024, 1, 1}, Quantity[12, "Months"]], None}
So, in $chart2
the month January obviously extends from the small tick to the left to the small tick to the right of any label Jan 2x
, but the gridlines that are supposed to mark the first day of each January sit right in the middle of that month.
Is this a bug? And what can be done about this?