function barY(
flow,
{
x,
y,
fill = "steelblue",
marginLeft = 40,
marginTop = 30,
marginRight = 0,
marginBottom = 30,
...rest
}
) {
const app = flow.app();
const [data] = flow.data();
const width = app.prop("width");
const height = app.prop("height");
const scaleX = d3
.scaleBand(Array.from(new Set(x)), [marginLeft, width - marginRight])
.padding(0.1);
const scaleY = d3.scaleLinear(
[0, d3.max(y)],
[height - marginBottom, marginTop]
);
const I = d3.range(data.length);
const X = x.map(scaleX);
const Y = y.map(scaleY);
flow.data(I).append(cm.rect, {
x: (i) => X[i],
y: (i) => Y[i],
width: scaleX.bandwidth(),
height: (i) => scaleY(0) - Y[i],
fill,
...rest
});
flow
.datum(0)
.append(cm.group, { x: 0, y: height - marginBottom })
.call(axisX, { scale: scaleX });
flow
.datum(0)
.append(cm.group, { x: marginLeft, y: 0 })
.call(axisY, { scale: scaleY });
}