Unlisted
Edited
May 16, 2023
Insert cell
Insert cell
Insert cell
teams = [
"Ohio_State",
"Michigan_State",
"Maryland",
"Rutgers",
"Michigan",
"Penn_State",
"Indiana"
]
Insert cell
Insert cell
M = [
[0, 1, 1, 1, 1, 1, 1],
[0, 0, 1, 1, 1, 1, 1],
[0, 0, 0, 0, 1, 1, 1],
[0, 0, 1, 0, 1, 0, 1],
[0, 0, 0, 0, 0, 1, 1],
[0, 0, 0, 1, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 0]
]
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
strengths = {
let A = math.matrix(M);
let step = math.ones(M.length);
for (let i = 0; i < 100; i++) {
step = math.multiply(M, step);
step = math.divide(step, math.norm(step));
}
return step.toArray();
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
table_code = {
let table_code = "|Rank|Team|Rating|\n|---|---|---|\n";

d3.sort(d3.zip(teams, strengths), (a) => a[1])
.reverse()
.forEach(
(a, i) =>
(table_code =
table_code + `|${i + 1}|${a[0]}|${d3.format("0.3f")(a[1])}|\n`)
);
// .forEach(function (a, i) {});
return table_code;
}
Insert cell
dot_source = {
let edges = [];
for (let i = 0; i < M.length; i++) {
for (let j = 0; j < M.length; j++) {
if (M[i][j] > 0) {
edges.push(`${teams[i]} -> ${teams[j]} [label=${M[i][j]}]`);
}
}
}
return `digraph{
${edges.join("\n ")}
}`;
}
Insert cell
math = require("mathjs")
Insert cell
{
let div = d3.create("div");
d3.graphviz(div.node()).renderDot(dot_source);
return div.node();
}
Insert cell
d3 = require("d3@7", "d3-graphviz@2")
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