## 2018-04-16 Treemaps

```javascript

async function urlToTree (url) {
  console.log('url to tree: ' + url)
  try {
    var dir = await fetch(url, {method: "OPTIONS"}).then(r => r.json())
  } catch(e) {
    dir = {
      contents: []
    }
  }
  var children = []
  for(var ea of dir.contents) {
    if (ea.type == "directory" && !ea.name.match(/^\./)) {
      children.push(await urlToTree(url + "/"+ ea.name))    
    }
    children.push(ea)
  }
  return {
    name: url.replace(/\/$/,"").replace(/.*\//,""),
    children: children
  }
}

var tree;
var url = lively4url +"/";
(async () => {
  tree  = await urlToTree(url)  
  
  var vis = await lively.openComponentInWindow("d3-treemap")  
  vis.setTreeData(tree)
})()

```
