{
let w = 600;
let h = 400;
let margin = 60;
let game_height = 30;
let team_width = 120;
let div = d3
.create("div")
.style("width", `${w}px`)
.attr("height", `${h}px`)
.style("position", "relative");
let svg = div
.append("svg")
.attr("width", w)
.attr("height", h)
.style("overflow", "visible");
let g = svg.append("g");
let scale = d3
.scaleLinear()
.domain([0, w])
.range([w - margin, margin]);
let root = d3.hierarchy(d3.stratify()(links));
d3.tree().size([h, w])(root);
let link_display = g.append("g").attr("id", "links");
link_display
.selectAll("path")
.data(root.links())
.join("path")
.attr("d", function (o) {
let x1 = scale(o.source.y);
let y1 = o.source.x;
let x2 = scale(o.target.y);
let y2 = o.target.x;
let line = d3.line()([
[x1, y1],
[x1, y2],
[x2, y2]
]);
return line;
})
.attr("fill", "none")
.attr("stroke", "#222")
.attr("stroke-width", 1.5);
let game_containers = div
.selectAll("div.game")
.data(root.descendants())
.enter()
.append(function (d) {
d.left = scale(d.y) - team_width / 2 + "px";
d.top = d.x - game_height / 2 + "px";
return game_container(d, {
game_height,
team_width,
game_data: games ? games.get(d.data.data.id) : null
});
});
return div.node();
}