Public
Edited
Jun 5, 2023
Paused
5 forks
25 stars
Also listed in…
Plot Experiments
Insert cell
Insert cell
barchart = bars.plot({
y: { _domain: [0, 10] },
color: { scheme: "bupu", domain: [-2, 10] }
})
Insert cell
bars = barY(data, { x: (d, i) => i, fill: (d) => d })
Insert cell
data = Array.from({ length: 10 }, d3.randomInt(1, 10))
Insert cell
{
barchart;
do {
const updated = data.map(d3.randomInt(1, 10));
yield updated;
await bars
.transition({ Y: updated, F: updated }, { delay: 1300, duration: 750 })
.end();
} while (true);
}
Insert cell
barY = function (data, options) {
const B = Plot.barY(data, options);
const { render } = B;
const G = [];
let c;
let that;

B.render = function (I, scales, channels, dimensions) {
c = { scales, dimensions };
that = this;

const g = render.apply(this, arguments);
G.push(g);

return g;
};

B.transition = ({ Y, F }, { delay = 500, duration = 1000 } = {}) => {
const y1 = Array.from(Y, () => c.scales.y(0));
const y2 = Array.from(Y, c.scales.y);

// here's how bars dimensions are controlled within Plot.BarY:
const y = that._y(c.scales, { y1, y2 }, c.dimensions);
const height = that._height(c.scales, { y1, y2 }, c.dimensions);

return d3
.selectAll(G)
.selectAll("rect")
.transition()
.delay(delay)
.duration(duration)
.attr("height", height)
.attr("fill", (i) => c.scales.color(F[i]))
.attr("y", y);
};

return B;
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more