JSFiddle - React, Tailwind, and code Playground
by Vivid D
HTML
<form>
<label><input type="radio" name="mode" value="radialtree">Radial Tree</label>
<label><input type="radio" name="mode" value="radialcluster">Radial Cluster</label>
<label><input type="radio" name="mode" value="tree">Tree</label>
<label><input type="radio" name="mode" value="cluster" checked>Cluster</label>
</form>
CSS
label {
font: 12px sans-serif;
}
.node circle {
fill: #fff;
stroke: steelblue;
stroke-width: 1.5px;
}
.node {
font: 10px sans-serif;
}
.link {
fill: none;
stroke: #ccf;
stroke-width: 1.5px;
}
JavaScript
d3.selectAll("input").on("change", change);
function change() {
if (this.value === "radialtree") transitionToRadialTree();
else if (this.value === "radialcluster") transitionToRadialCluster();
else if (this.value === "tree") transitionToTree();
else transitionToCluster();
};
function transitionToRadialTree() {
alert("to radial tree");
};
function transitionToRadialCluster() {
alert("to radial cluster");
};
function transitionToTree() {
alert("to tree");
};
function transitionToCluster() {
alert("to cluster");
};
var width = 500,
height = 500;
var cluster = d3.layout.cluster()
.size([height, width - 160]);
var diagonal = d3.svg.diagonal()
.projection(function (d) {
return [d.y, d.x];
});
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(40,0)");
var root = getData(),
nodes = cluster.nodes(root),
links = cluster.links(nodes);
var link = svg.selectAll(".link")
.data(links)
.enter()
.append("path")
.attr("class", "link")
.attr("d", diagonal);
var node = svg.selectAll(".node")
.data(nodes)
.enter()
.append("g")
.attr("class", "node")
.attr("transform", function (d) {
return "translate(" + d.y + "," + d.x + ")";
})
node.append("circle")
.attr("r", 4.5);
node.append("text")
.attr("dx", function (d) { return d.children ? -8 : 8; })
.attr("dy", 3)
.style("text-anchor", function (d) { return d.children ? "end" : "start"; })
.text(function (d) { return d.name; });
function getData() {
return {
"name": "flare",
"children": [{
"name": "analytics",
"children": [{
"name": "cluster",
"children": []
}, {
"name": "graph",
"children":...