         .entries(data)
       #nested.sort((a, b) -> d3.descending(a.values.extent[1], b.values.extent[1]))
 
+
   cache = cachingLoad(100)
+  purposesByCode = null
+
+  expandPurposes = (data) ->
+    for obj in data
+      obj.purpose = purposesByCode[obj.key]
+    data
+
+  flatten = (purposeTree) ->
+    codeToName = {}
+    recurse = (node) ->
+      codeToName[node.code] = node.name
+      if node.values?
+        recurse(n) for n in node.values
+    recurse purposeTree
+    codeToName
+
+
 
   (filters) ->
     loadingStarted()

        .datum(purposes)
        .call(purposesChart)

      #console.log purposeTree

      loadingFinished()


  bandWidth = 350
  valueFormat = formatMagnitudeLong
  interval = d3.time.year
  labelAttr = "key"

  title = ""
  eventListeners = {}
