JSFiddle - React, Tailwind, and code Playground
CSS
.node circle {
fill: #fff;
stroke: steelblue;
stroke-width: 3px;
}
.node text { font: 12px sans-serif; }
.link {
fill: none;
stroke: #ccc;
stroke-width: 2px;
}
JavaScript
var treeData = [
{
"name": "Top Level",
"parent": "null",
"value": 10,
"type": "black",
"level": "red",
"icon": "http://www.bigbiz.com/bigbiz/icons/ultimate/Comic/Comic13.gif",
"children": [
{
"name": "Level 2: A",
"parent": "Top Level",
"value": 5,
"type": "grey",
"level": "red",
"icon": "http://www.bigbiz.com/bigbiz/icons/ultimate/Comic/Comic41.gif",
"children": [
{
"name": "Son of A",
"parent": "Level 2: A",
"value": 5,
"type": "steelblue",
"icon": "",
"level": "orange"
},
{
"name": "Daughter of A",
"parent": "Level 2: A",
"value": 18,
"type": "steelblue",
"icon": "http://www.bigbiz.com/bigbiz/icons/ultimate/Comic/Comic114.gif",
"level": "red"
}
]
},
{
"name": "Level 2: B",
"parent": "Top Level",
"value": 10,
"type": "grey",
"icon": "",
"level": "green"
}
]
}
];
// ************** Generate the tree diagram *****************
var margin = {top: 20, right: 120, bottom: 20, left: 120},
width = 960 - margin.right - margin.left,
height = 500 - margin.top - margin.bottom;
var i = 0;
var tree = d3.layout.tree()
.size([height, width]);
var diagonal = d3.svg.diagonal()
.projection(function(d) { return [d.y, d.x]; });
var svg = d3.select("body").append("svg")
.attr("width", width + margin.right + margin.left)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")");
root = treeData[0];
update(root);
function update(source) {
// Compute the new tree layout.
var nodes = tree.nodes(root).reverse(),
links = tree.links(nodes);
// Normalize for fixed-depth.
nodes.forEach(function(d) { d.y = d.depth * 180;...