Published
Edited
Sep 9, 2020
1 fork
Importers
7 stars
Insert cell
Insert cell
chart = {
const base = vl.markRect({ tooltip: true }).encode(
vl.x().fieldO('source').sort(vl.field('source_group')).title(null).axis({ orient: 'top' }),
vl.y().fieldO('target').sort(vl.field('source_group')).title(null),
vl.color().fieldN('source_group').title('group')
);

const reverse = base.encode(
vl.x().fieldO('target').sort(vl.field('source_group')),
vl.y().fieldO('source').sort(vl.field('source_group'))
);

return vl
.layer(base, reverse)
.data(data.links)
.width(700)
.height(700)
.render();
}
Insert cell
// load data, update links data to include node group data
data = FileAttachment("miserables.json")
.json()
.then(data => {
const nodesMap = new Map(data.nodes.map(n => [n.id, n]));
return {
nodes: data.nodes,
links: data.links.map(l => ({
...l,
source_group: nodesMap.get(l.source).group,
target_group: nodesMap.get(l.target).group
}))
};
})
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