<!DOCTYPE html>
<head>
<meta charset="utf-8">
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">

<style>
h1 {
  font-family: "Open Sans", sans-serif;
  /*text-align: left;*/
}
h3 {
  font-family: "Open Sans", Arial, sans-serif;
  /*text-align: left;*/
}
h5 {
  font-family: "Open Sans", Arial, sans-serif;
  /*text-align: left;*/
  
}
h4 {
  font-family: "Open Sans", Arial, sans-serif;
  position: absolute;
  left: 62%;
  top: 10%;
  /*color: RGB(247, 247, 195);*/
  size: 2em;
}
span {
  color: white;
  padding: 1.5px;
}
.title {
  /*text-align: left;*/
  margin-left: 10%;
  
}
#wrapper {
  margin-left: auto;
  margin-right: auto;
  width: 100%;
}
#visual {
  /*display: block;*/
  float: left;
  /*margin-left: 8%;*/
  margin-right: auto;
  width: 60%;
  /*padding: 2%;*/
}
.Parsons {
  background: rgb(61, 144, 200);
}
.NewS {
  background: rgb(112, 197, 226);
}
svg {
  display: block;
  margin-left: 2%;
  width: 100%;
}
.node--root {
  pointer-events: none;
}
.node {
  cursor: pointer;
}
.node:hover {
  stroke: #fff;
  stroke-width: 3px;
}
.node--leaf {
  fill: #F4201B;
}
.circleLabel {
  font: 8px "Open Sans", Helvetica, Arial, sans-serif;
  text-anchor: middle;
  pointer-events: auto;
}
.tooltext {
  font: 12px "Open Sans", Helvetica, Arial, sans-serif;
  /*text-align: center;*/
}
.sizeText {
  font-family: "Open Sans", Helvetica, Arial, sans-serif;
  text-anchor: middle;
}
#numbers {
  margin-left: auto;
  margin-right: auto;
  margin-top: 5%;
  /*float: left;*/
  padding-left: 2em;
}
</style>
</head>
<body>
<div id="wrapper"><div id='visual'>
<svg width="600" height="600"></svg>
<script src="https://d3js.org/d3.v4.min.js"></script>

<script>
 function sizeIn(d) {
    return function(d) {
      document.getElementById(d.data.name+d.data.size).style.visibility = 'visible';
      document.getElementById(d.data.size+d.data.name).style.visibility = 'hidden';
    };
  }
function sizeOut(d) {
    return function(d) {
      document.getElementById(d.data.name+d.data.size).style.visibility = 'hidden';
      document.getElementById(d.data.size+d.data.name).style.visibility = 'visible';
    };
  }
  
var svg = d3.select("svg"),
    margin = 0,
    diameter = +svg.attr("width"),
    g = svg.append("g").attr("transform", "translate(" + diameter / 2 + "," + diameter / 2 + ")");
    
var color = d3.scaleLinear()
    .domain([0, 1])
    .range(["rgb(254,186,187)","rgb(204,3,0)"])  //"hsl(152,80%,60%)", "hsl(228,30%,40%)"
    .interpolate(d3.interpolateRgb);

var pack = d3.pack()
    .size([diameter - margin, diameter - margin])
    .padding(2);


    
var tooltip = d3.select("body")
	.append("div")
	.attr("class", "tooltext")
	.style("position", "absolute");
	
d3.json("flareLink.json", function(error, root) {
  if (error) throw error;
  root = d3.hierarchy(root)
      .sum(function(d) { return d.size; })
      .sort(function(a, b) { return b.value - a.value; });
  var focus = root,
      nodes = pack(root).descendants(),
      view;
  var circle = g.selectAll("circle")
    .data(nodes)
    .enter().append("circle")
      .attr("class", function(d) { return d.parent ? d.children ? "node" : "node node--leaf" : "node node--root"; })
      .attr('text-align','center')
      .style("fill", function(d) { return d.children ? color(d.depth) : "null"; })
      .on("click", function(d) { if (focus !== d) zoom(d), d3.event.stopPropagation(); })
      .on("mouseover", sizeIn(this.value))
      .on("mouseout", sizeOut(this.value));
     
     
  var text = g.selectAll("text")
    .data(nodes)
    .enter().append("text")
    .attr("class", "circleLabel")
    .style("font-size", function(d) { return Math.min(.4*d.r, (.4*d.r - 8) / this.getComputedTextLength() *48) + "px"; })
    .attr("dy", ".35em")
    .style("fill", "rgb(255,255,255)")
    .style("fill-opacity", function(d) { return d.parent === node, root ? 1 : 0; })
    .attr("id", function(d) { return d.data.size+d.data.name})
    .style("display", function(d) { return d.parent === node, root ? "inline" : "none"; })
    .text(function(d) { return d.data.name;});
  
  var size = g.selectAll("size")
    .data(nodes)
    .enter().append("text")
    .attr("class", "sizeText")
    .style("font-size", function(d) { return Math.min(.5*d.r, (.5*d.r - 8) / this.getComputedTextLength() *48) + "px"; })
    .attr("dy", ".35em")
    .style("visibility", "hidden")
    .style("fill", "rgb(255,255,255)")
    .attr('id', function(d) { return d.data.name+d.data.size})
    .style("display", function(d) { return d.parent === node, root ? "inline" : "none"; })
    .text(function(d) { return d.data.size;});
   
  var node = g.selectAll("circle,text");
    
  svg
      .style("background", "rgb(255,255,255)")
      .on("click", function() { zoom(root); });
  zoomTo([root.x, root.y, root.r * 2.3 + margin]);
  function zoom(d) {
    var focus0 = focus; focus = d;
    var transition = d3.transition()
        .duration(d3.event.altKey ? 7500 : 750)
        .tween("zoom", function(d) {
          var i = d3.interpolateZoom(view, [focus.x, focus.y, focus.r * 2.3 + margin]);
          return function(t) { zoomTo(i(t)); };
        });
    transition.selectAll("text")
        .filter(function(d) { return d.parent === focus || this.style.display === "inline"; })
        .attr('text-align','middle')
        .style("font-size", function(d) { return Math.min(d.r, (d.r - 8) / this.getComputedTextLength() * 48) + "px"; })
        .attr("dy", ".35em")
        .style("fill-opacity", function(d) { return d.parent === focus, node, root ? 1 : 0; })
        .on("start", function(d) { if (d.parent === focus, node, root) this.style.display = "inline"; })
        .on("end", function(d) { if (d.parent === focus, node, root) this.style.display = "inline"; });
  }
  function zoomTo(v) {
    var k = diameter / v[2]; view = v;
    node.attr("transform", function(d) { return "translate(" + (d.x - v[0]) * k + "," + (d.y - v[1]) * k + ")"; });
    circle.attr("r", function(d) { return d.r * k; });
  }
  
  function hovered(hover) {
  return function(d) {
	d3.selectAll(d.ancestors().map(function(d) {}));
  };
  
}
});
</script>
</div>
</body>