JSFiddle - React, Tailwind, and code Playground

by sijoma

HTML

<script src="http://d3js.org/d3.v3.js?2.9.1"></script>
<p id="chart"></p>

CSS

#chart {
  width: 960px;
  height: 500px;
  background: #bbb;
}

text {
  pointer-events: none;
}

.grandparent text {
  font-weight: bold;
}

rect {
  fill: none;
  stroke: #fff;
}

rect.parent,
.grandparent rect {
  stroke-width: 2px;
}

.grandparent rect {
  fill: orange;
}

.grandparent:hover rect {
  fill: #ee9700;
}

.children rect.parent,
.grandparent rect {
  cursor: pointer;
}

rect.parent {
  pointer-events: all;
}

.children:hover rect.child {
  fill: #aaa;
}

/* This is an exact copy of the style.css from Bostock's example.  No changes except this comment. */
@import url(http://fonts.googleapis.com/css?family=PT+Serif|PT+Serif:b|PT+Serif:i|PT+Sans|PT+Sans:b);

html {
  min-width: 1040px;
}

body {
  background: #fcfcfa;
  color: #333;
  font-family: "PT Serif", serif;
  margin: 1em auto 4em auto;
  position: relative;
  width: 960px;
}

header,
footer,
h1,
h2,
h3,
h4,
aside {
  color: #000;
  font-family: "PT Sans", sans-serif;
}

h1 {
  font-size: 64px;
  font-weight: 300;
  letter-spacing: -2px;
  margin: .3em 0 .1em 0;
}

h2 {
  margin-top: 2em;
}

h1, h2 {
  text-rendering: optimizeLegibility;
}

h2 a {
  color: #ccc;
  left: -20px;
  position: absolute;
  width: 740px;
}

footer {
  font-size: small;
  margin-top: 8em;
}

header aside {
  margin-top: 88px;
}

header aside,
footer aside {
  color: #636363;
  text-align: right;
}

aside {
  font-size: small;
  right: 0;
  position: absolute;
  width: 180px;
}

.attribution {
  font-size: small;
  margin-bottom: 2em;
}

body > p, li > p {
  line-height: 1.5em;
}

body > p {
  width: 720px;
}

body > blockquote {
  width: 640px;
}

blockquote q {
  display: block;
  font-style: oblique;
}

li {
  width: 680px;
}

a {
  color: steelblue;
}

a:not(:hover) {
  text-decoration: none;
}

pre, code, textarea {
  font-family: "Menlo", monospace;
}

code {
  line-height: 1em;
}

textarea {
  font-size: 100%;
}

body > pre {
  border-left: solid 2px #ccc;
  padding-left: 18px;
  margin: 2em 0 2em...

JavaScript

var margin = {top: 20, right: 0, bottom: 0, left: 0},
    width = 960,
    height = 500 - margin.top - margin.bottom,
    //formatNumber = d3.format(",d"),
    formatNumber = function(val) {return val},
    transitioning;

var x = d3.scale.linear()
    .domain([0, width])
    .range([0, width]);
788
var y = d3.scale.linear()
    .domain([0, height])
    .range([0, height]);

var svg = d3.select("#chart").append("svg")
    .attr("width", width + margin.left + margin.right)
    .attr("height", height + margin.bottom + margin.top)
    .style("margin-left", -margin.left + "px")
    .style("margin.right", -margin.right + "px")
  .append("g")
    .attr("transform", "translate(" + margin.left + "," + margin.top + ")")
    .style("shape-rendering", "crispEdges");

var grandparent = svg.append("g")
    .attr("class", "grandparent");

grandparent.append("rect")
    .attr("y", -margin.top)
    .attr("width", width)
    .attr("height", margin.top);

grandparent.append("text")
    .attr("x", 6)
    .attr("y", 6 - margin.top)
    .attr("dy", ".75em");


//d3.json("flare.json", function(root) {
d3.csv("https://raw.githubusercontent.com/sijoma0/Treemap/master/hier.csv", function(hier) {
//d3.json(myRoot, function(root) {

console.log("Before:");
console.log(hier);

var root = {"key":"Medical Specialty"
        , "values":d3.nest()
                .key(function (d) { return d.thedad; })
                .entries(hier)
            }
 
console.log("After:");
console.log(root);
 
  //var data = root;
 
var treemap = d3.layout.treemap()
    //.children(function(d, depth) { return depth ? null : d.children; })
    .children(function(d, depth) { return depth ? null : d.values; })
    //.text(function(d) { return d.key; })
    .value(function(d) { return d.value; })
    .sort(function(a, b) { return a.value - b.value; })
    .ratio(height / width * 0.5 * (1 + Math.sqrt(5)))
    .round(false);

  initialize(root);
  accumulate(root);
  layout(root);
  display(root);

  function...