JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<body>
<script src="http://d3js.org/d3.v2.min.js?2.9.6"></script>
</body>
CSS
.count1 {
stroke: #0F0;
}
.count2 {
stroke: #F00;
}
.count3 {
stroke: #00F;
}
.count4 {
stroke: #F0F;
}
.link {
fill: none;
}
.node circle {
stroke: #000;
stroke-width: 1.5px;
}
JavaScript
var width = 600,
height = 500;
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(-400)
.linkDistance(function (d) {
return radius(d.source.size) + radius(d.target.size) + 20;
});
var graph = {
"nodes": [{
"size": 12
}, {
"size": 12
}, {
"size": 12
}, {
"size": 12
}, {
"size": 12
}],
"links": [{
"source": 0,
"target": 1,
"count": 1
}, {
"source": 1,
"target": 2,
"count": 1
}, {
"source": 1,
"target": 3,
"count": 1
}, {
"source": 1,
"target": 4,
"count": 1
},
// same source and target with greater count
{
"source": 1,
"target": 4,
"count": 2
}, {
"source": 1,
"target": 4,
"count": 3
}, {
"source": 1,
"target": 4,
"count": 4
}]
};
var drawGraph = function (graph) {
force.nodes(graph.nodes)
.links(graph.links)
.on("tick", tick)
.start();
var link = svg.selectAll(".link")
.data(graph.links)
.enter().append("path")
.attr("class", function (d) {
return "link count" + d.count;
});
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 radius(d.size);
})
.style("fill", function (d) {
return color(d.atom);
});
function tick() {
link.attr("d", function...