Closed
Description
Now that we support multi-line ticks, it’d be nice if time scales used them by default. For example, rather than this (ref. https://observablehq.com/@hrbrmstr/cdc-avian-flu-outbreak-tracker):
Plot.plot({
x: {
label: null
},
y: {
label: "↑ Cumulative culls (millions)",
transform: d => d / 1e6
},
marks: [
Plot.ruleY([0]),
Plot.lineY(aflu, Plot.mapY("cumsum", {reverse: true, x: "outbreak_date", y: "flock_size"}))
]
})
You might get this:
Plot.plot({
x: {
label: null,
tickFormat: (
(formatYear, formatMonth) => (x) =>
d3.utcMonth.count(d3.utcYear(x), x) < 1
? `${formatMonth(x)}\n${formatYear(x)}`
: formatMonth(x)
)(d3.utcFormat("%Y"), d3.utcFormat("%b"))
},
y: {
label: "↑ Cumulative culls (millions)",
transform: d => d / 1e6
},
marks: [
Plot.ruleY([0]),
Plot.lineY(aflu, Plot.mapY("cumsum", {reverse: true, x: "outbreak_date", y: "flock_size"}))
]
})
I think this means rolling our own time format, rather than relying on d3-scale’s default.