Published
Edited
Apr 1, 2022
3 forks
18 stars
Insert cell
Insert cell
Insert cell
Insert cell
viewof filteredNodes = navio(network.nodes)
Insert cell
Insert cell
chartNodes = vl.markCircle().encode(
vl
.x()
.fieldQ("x")
.axis(null),
vl
.y()
.fieldQ("y")
.axis(null),
vl
.color()
.fieldN("cluster")
.scale({ scheme: "spectral" }),
vl.size().fieldQ("value"),
vl.text(vl.fieldN("name")),
vl.tooltip(vl.fieldN("name"))
)
Insert cell
Insert cell
Insert cell
Insert cell
update = (doLinks) => {
const specs = [];
if (doLinks) {
specs.push(chartLinks.data(filteredNetwork.links));
}
if (filteredNetwork.nodes.length<200) {
specs.push(chartNodes.markText().data(filteredNetwork.nodes));
} else {
specs.push(chartNodes.data(filteredNetwork.nodes));
}
vl.layer(specs)
.width(width - 100)
.height(width/2)
.render({container: target})

}
Insert cell
Insert cell
simulation = {
console.log("Start simulation");
const simulation = d3.forceSimulation(filteredNetwork.nodes)
.force("center", d3.forceCenter())
.force("charge", d3.forceManyBody().strength(-300))
.force("links", d3.forceLink(filteredNetwork.links).strength(0.05).distance(100));
simulation
.on("tick", () => update(simulation.alpha()<0.1));
invalidation.then(() => simulation.stop());
return simulation;
}
Insert cell
Insert cell
network = d3
.json(
"https://gist.githubusercontent.com/john-guerra/6b11c24ca722dba7a8d87e827a457084/raw/0d052d64cb86321bd72b1da01fe7ed96ae82f663/citationsNetwork2018.min.json"
)
.then(net => {
net.nodes.forEach(n => (n.cluster = +n.cluster));
return net;
})
.then(net => ({
...net,
links: net.links.map(l => ({
//convert the links to objects
source: net.nodes[l.source],
target: net.nodes[l.target]
}))
}))
Insert cell
filteredNetwork = {
return {
nodes: filteredNodes,
links: getFilteredLinks(filteredNodes)
};
}
Insert cell
Insert cell
Insert cell
{
return showMatrix
? vl
.markCircle()
.data(filteredNetwork.links)
.encode(
vl
.y()
.fieldO("source.name")
.sort("source.cluster")
.axis(null),
vl
.x()
.fieldO("target.name")
.sort("source.cluster")
.axis(null),
vl
.color()
.fieldN("source.cluster")
.scale({ scheme: "spectral" }),
vl.tooltip([
vl.fieldO("source.cluster"),
vl.fieldO("source.name"),
vl.fieldO("target.name")
])
)
.width(width * .8)
.height(width * .8)
.render()
: md`Click the checkbox to see the matrix 👆`;
}
Insert cell
Insert cell
Insert cell
checkbox = title => {
const control = html`<label><strong>${title} </strong><input type="checkbox"/></label>`;
const input = control.querySelector("input");

input.addEventListener("change", () => {
control.value = input.checked;
control.dispatchEvent(new CustomEvent("input"));
});
control.value = input.checked;
return control;
}
Insert cell
import {navio} from "@john-guerra/navio"
Insert cell
import { vl } from "@vega/vega-lite-api"
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