Published
Edited
Dec 3, 2021
Insert cell
Insert cell
dataset = d3.json("https://gist.githubusercontent.com/emanueles/1dc73efc65b830f111723e7b877efdd5/raw/2c7a42b5d27789d74c8708e13ed327dc52802ec6/lesmiserables.json")
Insert cell
popularity = {
let counter = {};

// para cada link, adiciona 1 a popularidade de target e source.
dataset.links.forEach(function(link) {
counter[link.source] == null ? counter[link.source] = 1 : counter[link.source] += 1;
counter[link.target] == null ? counter[link.target] = 1 : counter[link.target] += 1;
});
return counter;
}
Insert cell
nodeRadiusScale = d3.scaleSqrt()
.domain(d3.extent(Object.values(popularity)))
.range([5, 20])
Insert cell
graph = ForceGraph(dataset, {
height: 800,
width: width,
nodeRadius: node => nodeRadiusScale(popularity[node.id]),
nodeGroup: node => node.group,
nodeTitle: node => `${node.id}: ${popularity[node.id]} ${plurazire('connection', popularity[node.id])}`,
nodeDistanceMax: 270,
nodeStrenght: -50,
linkDistance: 50,
})
Insert cell
function plurazire(word, n) {
return n > 1 ? word + 's' : word;
}
Insert cell
Insert cell
import {ForceGraph} from "@emanueles/force-directed-graph"
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