JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://d3js.org/d3.v2.js"></script>
<div id="nav">
<div id="wood">
<a onclick="render(wood)">Woodworking</a>
</div>
<div id="metal">
<a onclick="render(metal)">Metalworking</a>
</div>
<div id="cnc">
<a onclick="render(cnc)">CNC</a>
</div>
<div id="print">
<a onclick="render(print)">3D Printing</a>
</div>
<div id="draft">
<a onclick="render(draft)">Drafting</a>
</div>
<div id="weld">
<a onclick="render(weld)">Welding</a>
</div>
<div id="sand">
<a onclick="render(sand)">Sand Blast</a>
</div>
<div id="finishing">
<a onclick="render(finishing)">Finishing</a>
</div>
<div id="laser">
<a onclick="render(laser)">Laser Cutting</a>
</div>
<div id="all">
<a onclick="render(all)">All</a>
</div>
</div>
CSS
.link {
fill: none;
stroke: #666;
stroke-width: 1.5px;
}
.node circle {
fill: #ccc;
stroke: #fff;
stroke-width: 1.5px;
}
text {
font: 10px sans-serif;
pointer-events: none;
}
JavaScript
var all = [
{source: "Tockwotton", target: "List", type: "woodworking"},
{source: "Tockwotton", target: "Prince Lab", type: "woodworking"},
{source: "Prince Lab", target: "Prince Lab", type: "metalworking"},
{source: "Tockwotton", target: "List", type: "cnc"},
{source: "Granoff", target: "Prince Lab", type: "3d-printing"},
{source: "Tockwotton", target: "List", type: "drafting"},
{source: "List", target: "Prince Lab", type: "welding"},
{source: "Prince Lab", target: "Prince Lab", type: "sand-blaster"},
{source: "Tockwotton", target: "List", type: "finishing"},
{source: "Tockwotton", target: "Prince Lab", type: "finishing"},
{source: "Tockwotton", target: "Tockwotton", type: "laser-cutter"}
];
var wood = [
{source: "Tockwotton", target: "List", type: "woodworking"},
{source: "Tockwotton", target: "Prince Lab", type: "woodworking"}
];
var metal = [
{source: "Prince Lab", target: "Prince Lab", type: "metalworking"}
];
var cnc = [
{source: "Tockwotton", target: "List", type: "cnc"}
];
var print = [
{source: "Granoff", target: "Prince Lab", type: "3d-printing"}
];
var draft = [
{source: "Tockwotton", target: "List", type: "drafting"}
];
var weld = [
{source: "List", target: "Prince Lab", type: "welding"}
];
var sand = [
{source: "Prince Lab", target: "Prince Lab", type: "sand-blaster"}
];
var finishing = [
{source: "Tockwotton", target: "List", type: "finishing"},
{source: "Tockwotton", target: "Prince Lab", type: "finishing"}
];
var laser = [
{source: "Tockwotton", target: "Tockwotton", type: "laser-cutter"}
];
function render(linkdata){
d3.selectAll("svg").remove();
links = linkdata;
nodes = {};
// Compute the distinct nodes from the links.
links.forEach(function(link) {
link.source = nodes[link.source] || (nodes[link.source] = {name: link.source, type: link.type});
link.target = nodes[link.target] || (nodes[link.target] = {name: link.target, type: link.type});
});
width = 960,
height =...