læasdæ - TheisGregersen/theisgregersen.github.io GitHub Wiki

<div id="byte_freq"></div> <script> var language_bytes = <%= language_byte_count %> var childrenFunction = function(d){return d.elements}; var sizeFunction = function(d){return d.count;}; var colorFunction = function(d){return Math.floor(Math.random()*20)}; var nameFunction = function(d){return d.name;};

var color = d3.scale.linear()
            .domain([0,10,15,20])
            .range(["grey","green","yellow","red"]);
drawTreemap(5000, 2000, '#byte_freq', language_bytes, childrenFunction, nameFunction, sizeFunction, colorFunction, color);
function drawTreemap(height,width,elementSelector,language_bytes,childrenFunction,nameFunction,sizeFunction,colorFunction,colorScale){
var treemap = d3.layout.treemap()
    .children(childrenFunction)
    .size([width,height])
    .value(sizeFunction);
var div = d3.select(elementSelector)
    .append("div")
    .style("position","relative")
    .style("width",width + "px")
    .style("height",height + "px");
    div.data(language_bytes).selectAll("div")
        .data(function(d){return treemap.nodes(d);})
        .enter()
        .append("div")
        .attr("class","cell")
        .style("background",function(d){ return colorScale(colorFunction(d));})
        .call(cell)
        .text(nameFunction);
}
  function cell(){
      this
          .style("left",function(d){return d.x + "px";})
          .style("top",function(d){return d.y + "px";})
          .style("width",function(d){return d.dx - 1 + "px";})
          .style("height",function(d){return d.dy - 1 + "px";});
  }
</script>
⚠️ **GitHub.com Fallback** ⚠️