Skip to content

Instantly share code, notes, and snippets.

@gunzapper
Last active August 29, 2015 13:56
Show Gist options
  • Save gunzapper/9068457 to your computer and use it in GitHub Desktop.
Save gunzapper/9068457 to your computer and use it in GitHub Desktop.
Ondarock network, first example
{
"directed": true,
"graph": [],
"nodes": [
{
"group": 1,
"id": "Jens Lekman\nI Know What Love Isn't "
},
{
"group": 1,
"id": "Sun Kil Moon\nAmong The Leaves "
},
{
"group": 1,
"id": "Phil Spector\nThe Essential "
},
{
"group": 1,
"id": "Peter Broderick\nHttp://www.itstartshear.com "
},
{
"group": 1,
"id": "Sun Kil Moon\nBenji "
},
{
"group": 1,
"id": "Peter Broderick\nThese Walls Of Mine "
},
{
"group": 1,
"id": "Daniel Rossen\nSilent Hour / Golden Mile "
},
{
"group": 1,
"id": "Grizzly Bear\nShields "
},
{
"group": 1,
"id": "Mark Kozelek & Desertshore\nMark Kozelek & Desertshore "
},
{
"group": 1,
"id": "Paul McCartney\nNew "
},
{
"group": 1,
"id": "Efterklang\nPiramida "
},
{
"group": 1,
"id": "Mark Kozelek & Jimmy LaValle\nPerils From The Sea "
}
],
"links": [
{
"source": 3,
"target": 0
},
{
"source": 4,
"target": 8
},
{
"source": 4,
"target": 9
},
{
"source": 4,
"target": 1
},
{
"source": 4,
"target": 11
},
{
"source": 5,
"target": 3
},
{
"source": 7,
"target": 6
},
{
"source": 8,
"target": 11
},
{
"source": 9,
"target": 2
},
{
"source": 10,
"target": 7
},
{
"source": 10,
"target": 5
},
{
"source": 11,
"target": 10
},
{
"source": 11,
"target": 1
},
{
"source": 11,
"target": 5
}
],
"multigraph": false
}
<!DOCTYPE html>
<!-- From D3 documentation page -->
<!-- here divided in two files, view network_control.js -->
<meta charset="utf-8">
<style>
.node {
stroke: #fff;
stroke-width: 1.5px;
}
.link {
stroke: #999;
stroke-opacity: .6;
stroke-width: 1.5px;
}
</style>
<body>
<h1>Network of linked albums</h1>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var width = 960,
height = 500;
var color = d3.scale.category20();
var force = d3.layout.force()
.charge(-120)
.linkDistance(30)
.size([width, height]);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("force.json", function(error, graph) {
force
.nodes(graph.nodes)
.links(graph.links)
.start();
var link = svg.selectAll(".link")
.data(graph.links)
.enter().append("line")
.attr("class", "link")
.style("stroke-width", function(d) { return Math.sqrt(d.value); });
//.attr("orient", "auto")
var node = svg.selectAll(".node")
.data(graph.nodes)
.enter().append("circle")
.attr("class", "node")
.attr("r", 5)
.style("fill", function(d) { return color(d.group); })
.call(force.drag);
node.append("title")
.text(function(d) { return d.id; });
force.on("tick", function() {
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