function groupedBarChart(data, {
x = "key",
fx = "group",
y = "value",
fy,
keys,
groups,
colorRange,
color = { domain: keys, range: colorRange },
type = "bars",
grid = type !== "lollipop",
...rest
}) {
return Plot.plot({
marginLeft: 50,
color,
facet: {
data,
x: fx,
y: fy
},
fx: {
domain: groups,
axis: "bottom",
label: null,
},
y: {
tickFormat: "s",
nice: true,
grid
},
x: {
axis: null,
domain: keys,
},
marks: type === "lollipop"
? [
Plot.link(data, {x1: x, x2: x, y1: () => 0, y2: y, stroke: x, strokeWidth: 3}),
Plot.dot(data, {x, y, fill: x, r: 5}),
Plot.ruleY([0])
]
: [
Plot.barY(data, {x, x2: x, y, fill: x}),
Plot.ruleY([0])
],
...rest
});
}