Molecular clusters
by b_g_v
HTML
<p>Limited synonyms-type, max four words distance with intermediate nodes</p>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script type="application/json" id="data">
{
"nodes": [
{
"color": "green",
"size": 11,
"atom": "AAP VIDEO"
},
{
"color": "green",
"size": 7,
"atom": "AAP Video"
},
{
"color": "blue",
"size": 4,
"atom": "ABC News"
},
{
"color": "magenta",
"size": 2,
"atom": "Aaron Bunch"
},
{
"color": "magenta",
"size": 2,
"atom": "Abdel Fattah"
},
{
"color": "green",
"size": 2,
"atom": "African American"
},
{
"color": "magenta",
"size": 2,
"atom": "Alex Jones"
},
{
"color": "magenta",
"size": 3,
"atom": "Alex Murray"
},
{
"color": "blue",
"size": 5,
"atom": "Alexander Petrov"
},
{
"color": "blue",
"size": 3,
"atom": "Alphabet CEO Larry"
},
{
"color": "magenta",
"size": 5,
"atom": "Alphabet CEO Larry Page"
},
{
"color": "magenta",
"size": 11,
"atom": "Attorney General Jeff Sessions"
},
{
"color": "magenta",
"size": 5,
"atom": "Ayanna Pressley"
},
{
"color": "green",
"size": 16,
"atom": "Bob Woodward"
},
{
"color": "magenta",
"size": 2,
"atom": "Boston City"
},
{
"color": "magenta",
"size": 5,
"atom": "Brett M. Kavanaugh"
},
{
"color": "blue",
"size": 35,
"atom": "Bush White House"
},
{
"color": "magenta",
"size": 8,
"atom": "Capitol Hill"
},
{
"color": "magenta",
"size": 7,
"atom": "Chairman Chuck Grassley"
},
{
"color": "green",
"size": 2,
"atom": "Charlie Rowley"
},
{
...
CSS
.link line {
/*stroke: #696969;*/
/*stroke: #EEEDED;*/
stroke: #BFBEBE;
}
.link1 line {
/*stroke-dasharray: 0,2 1;*/
stroke: blue;
}
.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 = 1700,
height = 900;
*/
var width = 2800,
height = 1850;
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])
.charge(-200)
//.linkDistance(function(d) { return radius(d.source.size) + radius(d.target.size) + 10; });
.linkDistance(function(d) { return 20; });
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"; });
//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);
node.append("circle")
.attr("r", function(d) { return d.atom.charAt(0) == '_' ? 1 : radius(d.size); })
.style("fill", function(d) { return d.atom.charAt(0) == '_' ? 'gray' : (typeof(d.color) === 'undefined' ? color(d.atom) : d.color); });
node.append("text")
.attr("dy", ".35em")
.attr("text-anchor", "middle")
.text(function(d) { return d.atom.charAt(0) == '_' ? '' : d.atom; })
.style("font-size", adaptLabelFontSize);
svg.append("svg:defs").selectAll("marker")
.data(force.links())
.enter().append("svg:marker")
.attr("id", function(link, idx){ return 'triangle-' + idx})
.attr("viewBox", "0 -5 10 10")
.attr("refX", function(link, idx){
return (link.target.atom.charAt(0) ==...