function barX(
flow,
{
x: X,
y: Y,
width,
height,
step,
title,
colors = ["#CC4A6A", "#6EBD41", "#D6B152", "#56ADD3", "#AC5ADA", "#7DDEBB"]
}
) {
const [data] = flow.data();
const scaleX = d3.scaleLinear([0, d3.max(X)], [0, width]).nice();
flow.datum(0).append(cm.text, {
text: title,
x: width / 2,
y: -1,
textAlign: "center",
textBaseline: "bottom"
});
const axis = flow
.datum(0)
.append(cm.group, {
x: 0,
y: height
})
.data(scaleX.ticks(5));
axis.append(cm.link, {
x: (d) => scaleX(d),
x1: (d) => scaleX(d),
y: 0,
y1: -height - 1,
stroke: cm.cfb(":")
});
axis.datum(0).append(cm.link, {
x: 0,
x1: width,
y: 0,
y1: 0,
stroke: cm.cfb("-")
});
axis.append(cm.text, {
text: (d) => (d ? d.toFixed(1) + "" : d),
textAlign: "center",
y: 1,
x: (d) => scaleX(d)
});
flow.data(data).append(cm.rect, {
x: scaleX(0),
y: Y.map((y) => y * step),
width: X.map(scaleX),
height: step - 1,
fill: (_, i) => cm.cfb("#", colors[i % colors.length])
});
}