I am using Plot.barX()
with stacked data, which ends up looking like:
There are 3 values in the block, and I am using a Plot.text()
to display the value above the bar, but when the 3rd value is very small, the text marks end up on top of each other.
I am already using the dx
option to offset them slightly but dx
can’t vary by value (as far as I can tell) so I can’t dynamically offset each text mark based on its value (or other values), it only accepts an integer, not a function.
I would love to be able to calculate/resolve some better spacing around my text marks.
I thought about using a different data set (derived from the main stackedTypes
) to use with the Text mark that would force different offsets for those marks, but this feels convoluted.
Any thoughts on a better idea? Or is that my best option?
Here’s my whole (relevant) code:
Plot.plot({
title: "Content Types Used / Created / Available",
width,
x: { label: null },
y: { label: null },
height: 100,
marks: [
Plot.barX(stackedTypes, {
x: "barValue",
tick: null
}),
Plot.axisY({ ticks: [] }),
Plot.text(stackedTypes, {
x: "value",
y: "name",
dx: -10,
dy: -35,
textAnchor: "end"
}),
Plot.text(stackedTypes, {
x: "value",
y: "name",
text: (d) => (d.barValue == 0) ? '' : d.label,
dx: -10,
dy: -50,
textAnchor: "end"
}),
Plot.ruleX([0])
],
})