Published
Edited
Feb 18, 2019
5 forks
Insert cell
Insert cell
{
const width=400;
const height = 400;
const svgNode = svg`<svg width=${width+200} height=${height+200}></svg>`
const svgSelection = d3.select(svgNode);
const line = d3.line()
.curve(d3.curveCatmullRom)
.x(d => d.x*width)
.y(d => d.y*height);
const g = svgSelection.append('g').attr('transform',`translate(${100},${100})`)

g.append('g')
.selectAll('path')
.data(links)
.enter()
.append('path')
.attr('d', ({ source, target, data }) =>
line([
{
x: source.x,
y: source.y
}
].concat(
data.points || [],
[ {
x: target.x,
y: target.y
}
])
))
.attr('fill','none')
.attr('stroke','black')
const nodes = g.append('g')
.selectAll('g')
.data(descendants)
.enter()
.append('g')
.attr('transform', ({x, y}) => `translate(${x*width}, ${y*height})`);
nodes.append('circle')
.attr('r',20)
.attr('fill','white')
.attr('stroke','black')


// Add text, which screws up measureement
nodes.append('text').text(d => d.id).attr('text-anchor','middle').attr('alignment-baseline','middle')
yield svgNode;
}
Insert cell
Insert cell
dag = d3.dratify()(grafo)
Insert cell
dagAfter = {
d3.sugiyama()
.coord(d3.coordVert())
(dag);

return dag;
}
Insert cell
Insert cell
descendants = {
return dagAfter.descendants()
}
Insert cell
Insert cell
grafo = [
{
"id": "0",
"parentIds": ["8"]
},
{
"id": "1",
"parentIds": []
},
{
"id": "2",
"parentIds": []
},
{
"id": "3",
"parentIds": ["11"]
},
{
"id": "4",
"parentIds": ["12"]
},
{
"id": "5",
"parentIds": ["18"]
},
{
"id": "6",
"parentIds": ["9", "15", "17"]
},
{
"id": "7",
"parentIds": ["3", "17", "20", "21"]
},
{
"id": "8",
"parentIds": []
},
{
"id": "9",
"parentIds": ["4"]
},
{
"id": "10",
"parentIds": ["16", "21"]
},
{
"id": "11",
"parentIds": ["2"]
},
{
"id": "12",
"parentIds": ["21"]
},
{
"id": "13",
"parentIds": ["4", "12"]
},
{
"id": "14",
"parentIds": ["1", "8"]
},
{
"id": "15",
"parentIds": []
},
{
"id": "16",
"parentIds": ["0"]
},
{
"id": "17",
"parentIds": ["19"]
},
{
"id": "18",
"parentIds": ["9"]
},
{
"id": "19",
"parentIds": []
},
{
"id": "20",
"parentIds": ["13"]
},
{
"id": "21",
"parentIds": []
}
]
Insert cell
Insert cell
Insert cell
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