drawGraph = () => {
document.getElementById("div-1").innerHTML = `
<div>
${graph.members.length}
(
${d3.mean(graph, (d) => d.count).toFixed(2)}
|
${Math.sqrt(d3.variance(graph, (d) => d.count)).toFixed(2)}
)
</div>
`;
const lines = graph.traceList.map((trace, i) =>
Plot.line(
trace.map((d) => graph[d]),
{
x: "x",
y: "y",
stroke: d3.schemeTableau10[i % 10] + (showTrace ? "FF" : "50")
}
)
);
return [
Plot.plot({
aspectRatio: 1.0,
width: width / 2.5,
grid: true,
x: { nice: true },
y: { nice: true },
color: { legend: true, scheme: "Blues" },
marks: [
Plot.dot(graph, { x: "x", y: "y", stroke: "gray", r: 1 }),
Plot.voronoi(graph, {
x: "x",
y: "y",
fill: "count",
stroke: "gray",
fillOpacity: (d) => (d.count === 0 ? 0.5 : 0.5)
}),
Plot.dot(graph.slice(graph.enter, graph.enter + 1), {
x: "x",
y: "y",
r: 5,
fill: "red"
}),
Plot.dot(
graph.exits.map((d) => graph[d]),
{
x: "x",
y: "y",
r: 5,
fill: "orange"
}
),
Plot.frame()
].concat(lines)
}),
Plot.plot({
grid: true,
x: { nice: true },
y: { nice: true, domain: [0, 6] },
color: { legend: true, scheme: "Oranges" },
marks: [
Plot.dot(
graph,
Plot.bin(
{ r: "count", stroke: "count" },
{
x: "neighbors",
y: "count"
}
)
)
]
})
];
}