Skip to content

Instantly share code, notes, and snippets.

@peterneish
Last active December 1, 2017 11:27
Show Gist options
  • Save peterneish/30adfae404d2ec7f5fbaf96f6e005a0c to your computer and use it in GitHub Desktop.
Save peterneish/30adfae404d2ec7f5fbaf96f6e005a0c to your computer and use it in GitHub Desktop.
DMP issues
license: mit
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
.links line { stroke:#999;stroke-opacity: 0.6; }
.nodes circle {stroke: #fff; stroke-width: 1.5px; }
</style>
</head>
<body>
<svg width="960" height="600"></svg>
<script>
// can only fetch 100 at a time - the link header has url for rest TODO
var url = "https://api.github.com/repos/RDA-DMP-Common/user-stories/issues?per_page=100"
var nodes = []
var links = []
var svg = d3.select("svg"),
width = +svg.attr("width"),
height = +svg.attr("height");
var simulation = d3.forceSimulation()
.force("charge", d3.forceManyBody().strength(-200))
//.force("link", d3.forceLink().id(function(d) { return d.id; }).distance(40))
.force("x", d3.forceX(width / 2))
.force("y", d3.forceY(height / 2))
.on("tick", ticked);
var link = svg.selectAll(".link"),
node = svg.selectAll(".node");
function load(url){
d3.json(url, function(error, j){
if (error) throw error;
j.forEach(function(i){
i.type="issue"
nodes[i.id]=i
i.labels.forEach(function(l){
l.type="label"
if(nodes[l.id]){
nodes[l.id].no += 1
}else{
l.no = 1
nodes[l.id] = l
}
links.push({source: i.id, target: l.id})
})
})
simulation.nodes(nodes);
simulation.force("link").links(links);
link = link
.data(links)
.enter().append("line")
.attr("class", "link");
node = node
.data(nodes)
.enter().append("circle")
.attr("class", "node")
.attr("r", 6)
.style("fill", function(d) { return d.color; });
console.log(nodes)
});
}
load(url)
function ticked() {
link.attr("x1", function(d) { return d.source.x; })
.attr("y1", function(d) { return d.source.y; })
.attr("x2", function(d) { return d.target.x; })
.attr("y2", function(d) { return d.target.y; });
node.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; });
}
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment