Public
Edited
Jun 5, 2023
Paused
5 forks
25 stars
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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more