Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<style>
.node circle {
  fill: #fff;
  stroke: steelblue;
  stroke-width: 1.5px;
}
.node {
  font: 10px sans-serif;
}
.link {
  fill: none;
  stroke: #ccc;
  stroke-width: 1.5px;
}
</style>
  <script>
    var json = {
 "name": "flare with a space",
 "children": [
  {
   "name": "analytics a very long description",
   "children": [
    {
     "name": "cluster",
     "children": [
      {"name": "AgglomerativeCluster", "size": 3938},
      {"name": "CommunityStructure", "size": 3812},
      {"name": "HierarchicalCluster", "size": 6714},
      {"name": "MergeEdge", "size": 743}
     ]
    },
    {
     "name": "graph",
     "children": [
      {"name": "BetweennessCentrality", "size": 3534},
      {"name": "LinkDistance", "size": 5731},
      {"name": "MaxFlowMinCut", "size": 7840},
      {"name": "ShortestPaths", "size": 5914},
      {"name": "SpanningTree", "size": 3416}
     ]
    },
    {
     "name": "optimization",
     "children": [
      {"name": "AspectRatioBanker", "size": 7074}
     ]
    }
   ]
  }
 ]
};
    
  </script>
  
  
<script src="http://mbostock.github.com/d3/d3.v2.js?2.8.1"></script>
</head>
<body>
<h1 id='dendrogram'>Dendrogram</h1>
<div class='gallery' id='chart'> </div>
<script type='text/javascript'>
     var width = 960, height = 500;
var cluster = d3.layout.tree()
    .size([height, width - 160]);
var diagonal = d3.svg.diagonal()
    .projection(function(d) { return [d.y, d.x]; });//flip it onto its side!
  //var diagonal = d3.svg.line()
  //.x(function(d) { return d.y; })
  //.y(function(d) { return d.x; })
  //.interpolate("basis");
//set up the visualisation:
var vis = d3.select("#chart").append("svg")
    .attr("width", width)
    .attr("height", height)
  .append("g")
    .attr("transform", "translate(50, 0)"); //once the graph is materialised, transform it 50 to the right (x), 0 up (y)
  var nodes = cluster.nodes(json);
  var link = vis.selectAll("path.link")
      .data(cluster.links(nodes))
    .enter().append("path")
      .attr("class", "link")
      .attr("d", diagonal);
  var node = vis.selectAll("g.node")
      .data(nodes)
    .enter().append("g")
      .attr("class", "node")
      .attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; })
  //the circles on the nodes:
  node.append("circle")
      .attr("r", 4.5);
    //where to put the text, if it has children, then place -8 to the left of the node, otherwise, +8 to the right
  node.append("text")
      .attr("dx", function(d) { return d.children ? -8 : 8; })
      .attr("dy", 3)
      .attr("text-anchor", function(d) { return d.children ? "end" : "start"; })
      .text(function(d) { var sz = (d.size == undefined ? '': ' => '+d.size+' classes');
 return d.name + sz; });
</script>
</body>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers