block by fogonwater 94adcbe1ef757aae78aa01e8e282bdaf

stratify tests

Full Screen

Mucking about with d3 nests to work out how to summarise data for a timeline viz.

Betterer nesting whatnot:

forked from fogonwater‘s block: nest tests

index.html

<!DOCTYPE html>
<head>
  <meta charset="utf-8">
  <script src="https://d3js.org/d3.v4.min.js"></script>
  <style>
    body { margin:0;top:0;right:0;bottom:0;left:0; }
  </style>
</head>

<body>
  <textarea id="out1" rows="40" cols="90"></textarea>
  <script>
    
var q = d3.queue()
  .defer(d3.csv, 'professions.csv')
	.defer(d3.csv, 'imports_2014.csv')
  .await(visualize);

function visualize(errors, prof, data) {
  
  
  var nested_data = d3.nest()
   .key(function(d) { return d['Median pay']; })
  	.rollup(function(leaves) { return {
      'count':leaves.length,
      'label':leaves.map(function(d) {return d['Category'] + ' (' + d['Sector'] +')'}).join(', '),
      'leaves':leaves
    };})
    .entries(data);
  	//.map(data);
  
  d3.select("#out1").
  	text(JSON.stringify(data, null, 4));
  
  var treeData = d3.stratify()
    .id(function(d) { return d.country_code; })
    .parentId(function(d) { return d.commodity_code; })
    (data);
  
  console.log(treeData)
  
}

  </script>
</body>

professions.csv