-
I'm doing a month graph with rect with { x, interval }, want to place text on top of each bar at center, if I don't specify Plot.rectY(tagsAllPerMonth, {
x: "month", interval: d3.utcMonth, y: "count",
stroke: "black", rx: 8, }),
Plot.text(tagsAllPerMonth, {
x: "month", interval: d3.utcMonth, y: "count",
text: "count", dy: -6, textAnchor: "start",
}), I think the correct Plot.text(tagsAllPerMonth, {
x: "month", interval: d3.utcMonth, y: "count",
text: "count", dy: -6, // textAnchor: "start", // leave textAnchor default to "center"
dx: d => (xNextMonth - xCurrentMonth) / 2,
}), |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Plot.textY doesn't have the interval transform (#597), but you might want to do one of: add 14 days: x: d => +d3.utcMonth.floor(d["date_of_birth"]) + 14 * 24 * 3600 * 1000 compute the middle of the month: x: d => (+d3.utcMonth.floor(d["date_of_birth"]) + +d3.utcMonth.ceil(1 + +d["date_of_birth"])) / 2 see https://observablehq.com/@fil/plot-center-text-on-an-interval |
Beta Was this translation helpful? Give feedback.
Plot.textY doesn't have the interval transform (#597), but you might want to do one of:
add 14 days:
compute the middle of the month:
see https://observablehq.com/@fil/plot-center-text-on-an-interval