Published
Edited
Feb 11, 2021
3 stars
Insert cell
Insert cell
Insert cell
chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);

let i = 0;
while (true) {
await Promises.tick(900);
yield svg.node();
drawData(svg, data.map(e => ({ ...e, value: Math.random() * e.value })));
}

return svg.node();
}
Insert cell
drawData = (selection, data) => {
const root = pack(data);

const arrayOfBubbles = root
.descendants()
.filter(d => d.depth > 0)
.map((e, i) => {
const { x, y, r } = e;
return CircleComponent({
key: e.data.title,
cx: x,
cy: y,
r: r,
fill: e.data.group
});
});
render(selection, arrayOfBubbles);
}
Insert cell
CircleComponent = ({ key, r, fill, cx, cy }) => ({
append: 'circle',
key,
r,
fill,
cx,
cy,
fill: color(fill),
duration: 1000,
delay: Math.random() * 50
//ease: d3.easeBack
})
Insert cell
Insert cell
oldchart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);

svg.node().drawData = function(data) {
const root = pack(data);

const circles = svg
.selectAll('circle')
.data(root.descendants().filter(d => d.depth > 0));

circles.join(
enter =>
enter
.append('circle')
.attr('cx', d => d.x)
.attr('cy', d => d.y)
.attr('fill', d => color(d.data.group))
.attr('r', d => d.r),
update =>
update
.transition()
.duration(1000)
.delay(Math.random() * 50)
.attr('cx', d => d.x)
.attr('cy', d => d.y)
.attr('fill', d => color(d.data.group))
.attr('r', d => d.r)
);
};

return svg.node();
}
Insert cell
renderoldchart = {
let i = 0;
while (true) {
await Promises.tick(900);
i++;
oldchart.drawData(
data.map(e => ({ ...e, value: Math.random() * e.value }))
);

yield oldchart.nodeName;
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
render = d3render.default
Insert cell
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