JSFiddle - React, Tailwind, and code Playground
HTML
<div id="main">
<table>
<tr>
<td>
<div class="intgraph"/>
</td>
</tr>
</table>
</div>
CSS
circle.node {
cursor: pointer;
stroke: #000;
stroke-width: .5px;
}
line.link {
fill: none;
stroke: #9ecae1;
stroke-width: 1.5px;
}
JavaScript
var w = 800,
h = 800,
node,
link,
root;
var force = d3.layout.force()
.on("tick", tick)
.charge(function(d) { return d._children ? -d.size / 100 : -50; })
.linkDistance(function(d) { return d.target._children ? 80 : 30; })
.size([w, h - 160]);
function zoom() {
console.log("here", d3.event.translate, d3.event.scale);
console.log("transform", d3.event.translate, d3.event.scale);
//vis.attr("transform", transform);
node.attr("transform", transform);
link.attr("transform", transform);
}
function transform(d){
return "translate(" + d3.event.translate + ")" + " scale(" + d3.event.scale + ")";
}
var vis = d3.select(".intgraph").append("svg:svg")
.attr("width", w)
.attr("height", h)
.append("svg:g")
.call(d3.behavior.zoom().on("zoom", zoom));
// the area to zoom
var rect = vis.append("rect")
.attr("width", w)
.attr("height", h)
.style("fill", "none")
.style("pointer-events", "all");
function readfile(json) {
root = json;
root.fixed = true;
root.x = w / 2;
root.y = h / 2 - 80;
update();
};
function update() {
var nodes = flatten(root),
links = d3.layout.tree().links(nodes);
// Restart the force layout.
force
.nodes(nodes)
.links(links)
.start();
// Update the links…
link = vis.selectAll("line.link")
.data(links, function(d) { return d.target.id; });
// Enter any new links.
link.enter().insert("svg:line", ".node")
.attr("class", "link")
.attr("x1", function(d) { return d.source.x; })
.attr("y1", function(d) { return d.source.y; })
.attr("x2", function(d) { return d.target.x; })
.attr("y2", function(d) { return d.target.y; });
// Exit any old links.
link.exit().remove();
// Update the nodes
node = vis.selectAll("circle.node")
.data(nodes, function(d) { return d.id; })
.style("fill", color);
node.transition()
.attr("r", function(d) { return d.children ? 4.5 :...