Public
Edited
Feb 2, 2023
1 fork
1 star
Insert cell
Insert cell
Insert cell
Insert cell
container = {
const div = d3.create("div")
const details = [
{ topic: "gitlab", projects: ["Project / GitLab navigator", "GitLab Organizational Showcase"] },
{ topic: "javascript", projects: [ "something" ] },
{ topic: "finance", projects: ["else"] }
]
div.selectAll("section")
.data(topic_objects)
.enter()
.append(tag => display(tag))
div.selectAll("h2").style("font", "20px 'Courier New'")
return div.node()
}
Insert cell
topic_details = gitlab_com_data.reduce(reducer, {})
Insert cell
Insert cell
gitlab_com_data = {
return (await fetch(`https://gitlab.com/api/v4/projects?topic=${input_tag}&per_page=20`)).json()
}
Insert cell
display = function(tag){
const section = d3.create("section")
section.append("h2").html(`${tag.topic} <a href="https://gitlab.com/explore/projects?topic=${tag.topic}" target="_blank">↗</a>`)
// section.append("p").html(`<a href="https://gitlab.com/explore/projects?topic=${tag.topic}">[more]</a>`)
const ul = section.append("ul")
ul.selectAll("li")
.data(tag.projects)
.enter()
.append("li")
.html(
project => `<a href="${project.web_url}">${project.name_with_namespace}</a> <span class='description'>${ellipsis(project.description, 30)}<span>`
)
return section.node()
}
Insert cell
reducer = function(aggregate, project){
project.topics.forEach(t => aggregate[t] !== undefined ? aggregate[t].push(project.name) : aggregate[t] = [project.name]);
return aggregate;
}
Insert cell
linksOld = d3.csvParse(await FileAttachment("suits.csv").text())
Insert cell
names_and_topics = gitlab_com_data.map(
project => ({
id: project.id,
name: project.name,
topics: project.topics
}))
Insert cell
topic_sets = gitlab_com_data.map(project => project.topics)
Insert cell
cartesian =
(...a) => a.reduce((a, b) => a.flatMap(d => b.map(e => [d, e].flat())));
Insert cell
topic_pairs = topic_sets.flatMap(set => cartesian(set,set)).filter(pair => pair[0] !== pair[1]).map(pair => pair[0] > pair[1] ? [pair[1], pair[0]] : [pair[0], pair[1]])
Insert cell
Insert cell
types = Array.from(new Set(topic_links.map(d => d.type)))
Insert cell
data = ({
nodes: Array.from(new Set(topic_links.flatMap(l => [l.source, l.target])), id => ({id})),
links: topic_links
})
Insert cell
height = 600
Insert cell
color = d3.scaleOrdinal(types, d3.schemeCategory10)
Insert cell
function linkArc(d) {
const r = Math.hypot(d.target.x - d.source.x, d.target.y - d.source.y);
return `
M${d.source.x},${d.source.y}
A${r},${r} 0 0,1 ${d.target.x},${d.target.y}
`;
}
Insert cell
drag = simulation => {
function dragstarted(event, d) {
if (!event.active) simulation.alphaTarget(0.3).restart();
d.fx = d.x;
d.fy = d.y;
}
function dragged(event, d) {
d.fx = event.x;
d.fy = event.y;
}
function dragended(event, d) {
if (!event.active) simulation.alphaTarget(0);
d.fx = null;
d.fy = null;
}
return d3.drag()
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended);
}
Insert cell
d3 = require("d3@6")
Insert cell
ellipsis = {
return (input, length=40) => input.length > length ? `${input.substring(0, length).trim()}...` : input
}
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