Public
Edited
Jun 6
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
selectedArticles
Insert cell
Insert cell
Insert cell
// Fonction pour obtenir la couleur des nœuds selon leur profondeur
getNodeColor = (depth, maxDepth) => {
const colorScale = d3.scaleSequential(d3.interpolateViridis)
.domain([0, maxDepth]);
return colorScale(depth);
}
Insert cell
// Fonction pour obtenir la couleur des liens
getLinkColor = (source, target, maxDepth) => {
const colorScale = d3.scaleSequential(d3.interpolateViridis)
.domain([0, maxDepth]);
return colorScale(source.depth);
}
Insert cell
// Sélection des nœuds et recherche d'ancêtre commun
selectedNodes = new Set()
Insert cell
array = [...selectedNodes];
Insert cell
mutable commonAncestor = null
Insert cell
function findCommonAncestor() {
if (selectedNodes.size !== 2) return null;
const nodes = Array.from(selectedNodes);
let [node1, node2] = nodes;
// Ensemble des identifiants des ancêtres du premier nœud
const ancestors1 = new Set();
let current = node1;
while (current) {
ancestors1.add(current.data["@id"]);
current = current.parent;
}
// Recherche de l'ancêtre commun le plus proche
current = node2;
while (current) {
if (ancestors1.has(current.data["@id"])) {
return current;
}
current = current.parent;
}
return null;
}
Insert cell
treeData = {
// Créer la hiérarchie
const root = d3.hierarchy(chosenRoot);
// Calculer la position des nœuds
const radius = Math.min(width, height) / 2 - 100;
const tree = d3.tree()
.size([2 * Math.PI, radius])
.separation((a, b) => (a.parent === b.parent ? 1 : 2) / a.depth);
tree(root);
// Calculer la profondeur maximale
const maxDepth = root.height;
return { root, maxDepth, radius };
}
Insert cell
savoirs_hierachical = FileAttachment("savoirs_hierachical.json").json()
Insert cell
Insert cell
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