Published
Edited
Oct 10, 2022
Fork of Hello, CoLa!
Insert cell
Insert cell
Insert cell
color = d3.scaleOrdinal(d3.schemeCategory10)
Insert cell
height = 640
Insert cell
things = ["A", "B", "C", "D", "E", "F", "G"]
Insert cell
Insert cell
data = {
const TAU = Math.PI * 2;
const width2 = width * 0.5;
const height2 = height * 0.5;

const nodes = getCombinations(things).map((arr, index) => {
const group = arr.length;
const id = arr.join("");
const label = arr.join(", ");
// The initial group are fixed around a circle
if (group === 1) {
const x = Math.cos((index / things.length) * TAU) * 300 + width2;
const y = Math.sin((index / things.length) * TAU) * 300 + height2;
return {
group,
id,
label,
fixed: true,
x,
y
};
}
return {
group,
id,
label
};
});

const links = [];
nodes.forEach((node) => {
if (node.group > 1) {
node.id.split("").forEach((id) => {
links.push({
source: id,
target: node.id
// length: (things.length - node.group + 1) * 20
});
});
}
});

return {
nodes,
links
};
}
Insert cell
cola = require("webcola@3/WebCola/cola.min.js")
Insert cell
d3 = require("d3@5")
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