Molecular clusters
by b_g_v
HTML
<p>JA, Full size content-type, min frequency 20, max 4 words distance, without intermediate nodes, value is pop-word's digest rank</p>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script type="application/json" id="data">
{
"nodes": [
{
"size": 24,
"atom": "2連覇"
},
{
"size": 1,
"atom": "_0"
},
{
"size": 1,
"atom": "_1"
},
{
"size": 1,
"atom": "_10"
},
{
"size": 1,
"atom": "_100"
},
{
"size": 1,
"atom": "_101"
},
{
"size": 1,
"atom": "_102"
},
{
"size": 1,
"atom": "_103"
},
{
"size": 1,
"atom": "_104"
},
{
"size": 1,
"atom": "_105"
},
{
"size": 1,
"atom": "_106"
},
{
"size": 1,
"atom": "_107"
},
{
"size": 1,
"atom": "_108"
},
{
"size": 1,
"atom": "_109"
},
{
"size": 1,
"atom": "_11"
},
{
"size": 1,
"atom": "_110"
},
{
"size": 1,
"atom": "_111"
},
{
"size": 1,
"atom": "_112"
},
{
"size": 1,
"atom": "_113"
},
{
"size": 1,
"atom": "_114"
},
{
"size": 1,
"atom": "_115"
},
{
"size": 1,
"atom": "_116"
},
{
"size": 1,
"atom": "_117"
},
{
"size": 1,
"atom": "_118"
},
{
"size": 1,
"atom": "_119"
},
{
"size": 1,
"atom": "_12"
},
{
"size": 1,
"atom": "_120"
},
{
"size": 1,
"atom": "_121"
},
{
"size": 1,
"atom": "_122"
},
{
"size": 1,
"atom": "_123"
},
{
"size": 1,
"atom": "_124"
},
{
"size": 1,
"atom": "_125"
},
{
"size": 1,
"atom": "_126"
},
{
...
CSS
.link line {
/*stroke: #696969;*/
/*stroke: #EEEDED;*/
stroke: #BFBEBE;
/*stroke-dasharray: 0,2 1;*/
}
.link1 line {
/*stroke-dasharray: 0,2 1;*/
stroke: gray;
}
.link line.separator {
stroke: #fff;
stroke-width: 1px;
}
.node circle {
stroke: gray;
stroke-width: 1.5px;
}
.node text {
font: 10px sans-serif;
pointer-events: none;
}
div.tooltip {
position: absolute;
text-align: center;
/*width: 200px;*/
/*height: 10px;*/
min-height: 10px;
padding: 8px;
font: 10px sans-serif;
background: #ffff99;
border: solid 1px #aaa;
border-radius: 8px;
pointer-events: none;
}
JavaScript
var data = document.getElementById('data').innerHTML,
graph = JSON.parse(data);
var width = 1900,
height = 1000;
var color = d3.scale.category20();
var radius = d3.scale.sqrt()
.range([0, 6]);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var force = d3.layout.force()
.size([width, height])
.gravity(0.08)
.charge(-100)
//.charge(0)
.linkDistance(function(d) { return radius(d.source.size) + radius(d.target.size) + 10; });
//.linkDistance(function(d) { return 10; });
force
.nodes(graph.nodes)
.links(graph.links)
.on("tick", tick)
.start();
var link = svg.selectAll(".link")
.data(graph.links)
.enter().append("g")
.attr("class", "link");
//Draw line
link.append("line")
.attr("marker-end", function(link, idx){ return 'url(#triangle-' + idx+')'})
.style("stroke-width", function(d) { return (d.bond * 2 - 1) * 2 + "px"; })
.style("stroke", function(d) {
if(typeof(d.source.color) === 'undefined') d.source.color = color(d.source.atom);
return !isSelected(d.source) && (d.source.atom.charAt(0) == '_' ||
d.target.atom.charAt(0) == '_') ? ''/*'#BFBEBE'*/ : d.source.color; })
.style("stroke-dasharray", function(d) {return d.source.atom.charAt(0) == '_' ||
d.target.atom.charAt(0) == '_' ? '0,2 1' : ''; });
//link.filter(function(d) { return d.bond > 1; }).append("line")
// .attr("class", "separator");
var node = svg.selectAll(".node")
.data(graph.nodes)
.enter().append("g")
.attr("class", "node")
.call(force.drag);
//Draw circles
node.append("circle")
.attr("r", function(d) { return d.atom.charAt(0) == '_' ? 1 : radius(d.size); })
.style("fill", function(d) {
if(typeof(d.color) === 'undefined') d.color = color(d.atom);
...