Visulalize authors relationships based upon not-hiragana-kanji rubis on Aozorabunko.
Last active
December 15, 2015 11:09
-
-
Save satomacoto/5251189 to your computer and use it in GitHub Desktop.
Authors Relationships based upon Not-kanji-hiragana Rubis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<script src="http://d3js.org/d3.v2.min.js?2.9.3"></script> | |
<style> | |
.link { | |
stroke: #ccc; | |
} | |
.node text { | |
fill: #333; | |
pointer-events: none; | |
font: 10px sans-serif; | |
} | |
body { | |
fill: #fff; | |
} | |
</style> | |
<body> | |
<script> | |
var width = 960, | |
height = 500, | |
nodes, _nodes, | |
links, _links; | |
var color = d3.scale.category20(); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height) | |
.append("svg:g") | |
.call(d3.behavior.zoom().on("zoom", redraw)) | |
.append("svg:g"); | |
svg.append('svg:rect') | |
.attr('x', -100000) | |
.attr('y', -100000) | |
.attr('width', 200000) | |
.attr('height', 200000); | |
function redraw() { | |
svg.attr("transform", | |
"translate(" + d3.event.translate + ")" | |
+ " scale(" + d3.event.scale + ")"); | |
} | |
var force = d3.layout.force() | |
.gravity(.05) | |
.distance(100) | |
.charge(-100) | |
.size([width, height]); | |
d3.json("authors.json", function(json) { | |
nodes = json.nodes; | |
links = json.links; | |
update(); | |
}); | |
function update() { | |
force | |
.nodes(nodes) | |
.links(links) | |
.linkDistance(function(d) { return d.coauthor ? 10 : 50; }) | |
// .charge(function(d) { return -Math.sqrt(d.weight)*10; }) | |
// .gravity(function(d) { return Math.sqrt(d.weight)/100; }) | |
.start(); | |
var link = svg.selectAll(".link") | |
.data(links) | |
.enter().append("line") | |
.attr("class", "link") | |
.style("stroke", function(d) { return d.coauthor ? "#f77" : "#ccc"; }) | |
.style("stroke-width", function(d) { return Math.sqrt(d.weight); }); | |
var node = svg.selectAll(".node") | |
.data(nodes) | |
.enter().append("g") | |
.attr("class", "node") | |
.on("click", click) | |
.call(force.drag); | |
node.append("circle") | |
// .attr("r", 4) | |
.attr("r", function(d) { return Math.sqrt(d.weight) * 5; }) | |
.style("fill", function(d) { return color(d.group); }); | |
node.append("text") | |
.attr("dx", 12) | |
.attr("dy", ".35em") | |
.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("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; }); | |
}); | |
} | |
function click(d) { | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment