title: Flatten an Object hierarchy created with d3.js nesting
body: <p>I am trying to visualize team collaboration data, in a way like this:</p>
  
  <p><img src="https://i.stack.imgur.com/43YaL.png" alt="Chart that displays the share of the different collaboration artifact types for each team and week"></p>
  
  <p>Different colors in the chart are different collaboration artifact types.</p>
  
  <p>The data from the source looks like this:</p>
  
  <pre><code>var json = [
      {
          "teamLabel": "Team 1",
          "created_date": "2013-01-09",
          "typeLabel": "Email"
          "count": "5"
      },
      {
          "teamLabel": "Team 1",
          "created_date": "2013-01-10",
          "typeLabel": "Email"
          "count": "7"
      },
      /* and of course, a lot more data of this kind */
  ]
  </code></pre>
  
  <p>Note that the data is given for single days. So for the above visualization, I need to aggregate the data based on the week of year first. The team name and the artifact type need to be preserved though and are used as grouping attributes. Here's the code:</p>
  
  <pre><code>// "2013-01-09"
  var dateFormat = d3.time.format.utc("%Y-%m-%d");
  
  // "2013-02" for the 2nd week of the year
  var yearWeek = d3.time.format.utc("%Y-%W");
  
  var data = d3.nest().key(function(d) {
          return d.teamLabel;
      }).key(function(d) {
          var created_date = dateFormat.parse(d.created_date);
          return yearWeek(created_date);
      })
      .key(function(d) {
          return d.typeLabel;
      }).rollup(function(leaves) {
          return d3.sum(leaves, function(d) {
                  return parseInt(d.count);    // parse the integer
              });
          }
      )
      .map(json);
  </code></pre>
  
  <p>This results in an Object hierarchy based on the nesting keys. I do not see how to create the above chart from this, so I am rather looking for a way to convert <code>data</code> into the following structure:</p>
  
  <pre><code>[
      // This list contains an element for each donut
      {
          "teamLabel": "Team 1",
          "createdWeek": "2013-02",
          "values": [
              // This list contains one element for each type we found
              {
                  "typeLabel": "Email",
                  "count": 12
              },
              {
              ...
              }
          ]
      },
      {
      ...
      }
  ]
  </code></pre>
  
  <p>This way, I can use <code>createdWeek</code> and <code>teamLabel</code> for the positioning on x- and y-Axis respectively, and the information under <code>values</code> can be passed to <code>d3.layout.pie()</code>.</p>
  
  <p>Is there a clean way to do this data transformation? If you need any clarification or further details, please let me know.</p>