title: D3js filter selection
body: <p>I am creating an interactive <a href="https://github.com/mbostock/d3/wiki/Pack-Layout" rel="nofollow noreferrer">bubble chart</a> of <a href="http://gomashup.com/cms/fortune_500_companies" rel="nofollow noreferrer">fortune 500</a> data. I am trying to reduce a selection but can't figure out why it's not working as I expect.</p>
  
  <pre><code>var bubble = d3.layout.pack()
      ...
  
  d3.json("js/data/fortune2009.json", function(json) {
  
      var node = svg.data([json]).selectAll("g.node")
          .data(bubble.nodes); // filter here?
  
      node.enter()
          .append("g")
          .attr("class", "node")
          .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
  
      node.append("circle")
          .attr("r", function(d) { return d.r; })
          .attr("class", function(d) { return "q" + color(d.Profit) + "-9"; });
  
      node.filter(function(d) { return !d.children; })
          .append("text")
          .attr("dy", ".3em")
          .style("text-anchor", "middle")
          .text(function(d) { return d.Company.substring(0, d.r / 3); });
  });
  </code></pre>
  
  <p>The JSON data looks like this:</p>
  
  <pre><code>{
      "children":[
      {
          "Year" : "2009",
          "Rank" : "1",
          "Revenue" : "442",
          "Profit" : "851.00",
          "Company" : "Exxon Mobil"
      },
      ....
  }
  </code></pre>
  
  <p>I want to remove the parent node. I am trying to use a filter function like described <a href="https://github.com/mbostock/d3/wiki/Selections#wiki-filter" rel="nofollow noreferrer">here</a>. </p>
  
  <pre><code>.filter(function(d) { return !d.children; })
  </code></pre>
  
  <p>But if i add my filter function where I initialize the <code>node</code> selection, either nothing happens or I get an error.</p>
  
  <p>(The filter works when I apply it before appending text)</p>
  
  <p>How do I solve this?</p>
  
  <p><strong>UPDATE:</strong> Here is a JSFIDDLE <a href="http://jsfiddle.net/B9w4N/8/" rel="nofollow noreferrer">http://jsfiddle.net/B9w4N/8/</a> showing my problem.</p>
  
  <p><img src="https://i.stack.imgur.com/UjgWX.png" alt="enter image description here"></p>