Public
Edited
Mar 2, 2023
Insert cell
Insert cell
graph(
d3.hierarchy(
d3
.stratify()
.id((o) => o.expected_seeds)
.parentId((o) => o.expected_preseeds)(assignment_links)
),
{
label: function (game) {
let expected_seeds = game.data.data.expected_seeds;
if (assignment_games.get(expected_seeds)) {
return assignment_games.get(expected_seeds);
}
},
marginLeft: 60
}
)

Insert cell
assignment_games = new Map([
["16-17", "UNCA df TX So"],
["1-16", "TX df UNCA"],
["8-9", "Pur df LSU"],
["5-12", "Conn df BYU"],
["4-13", "Stan df SD"],
["1-8", "TX df Pur"],
["4-5", "Conn df Stan"],
["1-4", "TX df Conn"]
])
Insert cell
Insert cell
graph(
d3.hierarchy(
d3
.stratify()
.id((o) => o.expected_seeds)
.parentId((o) => o.expected_preseeds)(links)
),
{
label: function (game) {
let expected_seeds = game.data.data.expected_seeds;
if (games.get(expected_seeds)) {
return games.get(expected_seeds);
}
},
marginLeft: 60
}
)
Insert cell
games = new Map([
["8-9", "Char So df HP"],
["1-8", "UNCA vs Char So"],
["4-5", "SC Up vs GW"],
["7-10", "Camp df Pres"],
["2-7", "Long vs Camp"],
["3-6", "Rad vs Win"]
])
Insert cell
Insert cell
// Modified only slightly from
// https://observablehq.com/@d3/d3-hierarchy
graph = {
let dx = 12;
let dy = 120;
let tree = d3
.tree()
.separation(() => 3)
.nodeSize([dx, dy]);
let treeLink = d3
.linkHorizontal()
.x((d) => d.y)
.y((d) => d.x);

return graph;

function graph(
root,
{ label = (d) => d.data.id, highlight = () => false, marginLeft = 40 } = {}
) {
root = tree(root);

let x0 = Infinity;
let x1 = -x0;
root.each((d) => {
if (d.x > x1) x1 = d.x;
if (d.x < x0) x0 = d.x;
});

const svg = d3
.create("svg")
.attr("viewBox", [0, 0, width, x1 - x0 + dx * 2])
.style("overflow", "visible");

const g = svg
.append("g")
.attr("font-family", "sans-serif")
.attr("font-size", 10)
.attr("transform", `translate(${marginLeft},${dx - x0})`);

const link = g
.append("g")
.attr("fill", "none")
.attr("stroke", "#555")
.attr("stroke-opacity", 0.4)
.attr("stroke-width", 1.5)
.selectAll("path")
.data(root.links())
.join("path")
.attr("stroke", (d) =>
highlight(d.source) && highlight(d.target) ? "red" : null
)
.attr("stroke-opacity", (d) =>
highlight(d.source) && highlight(d.target) ? 1 : null
)
.attr("d", treeLink);

const node = g
.append("g")
.attr("stroke-linejoin", "round")
.attr("stroke-width", 3)
.selectAll("g")
.data(root.descendants())
.join("g")
.attr("transform", (d) => `translate(${d.y},${d.x})`);

node
.append("circle")
.attr("fill", (d) =>
highlight(d) ? "red" : d.children ? "#555" : "#999"
)
.attr("r", 2.5);

node
.append("text")
.attr("fill", (d) => (highlight(d) ? "red" : null))
.attr("stroke", "white")
.attr("paint-order", "stroke")
.attr("dy", "0.31em")
.attr("x", (d) => (d.children ? -6 : 6))
.attr("text-anchor", (d) => (d.children ? "end" : "start"))
.text(label);

return svg.node();
}
}
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