title: Dynamic legend based on data
body: <p>I've set up a legend within my D3 visualization and the legend currently includes all possible 'vehicles' and their color designation.</p>
  
  <p>I set the colors like so:</p>
  
  <pre><code>var color = d3.scale.ordinal()
    .domain(['bike', 'motorcycle', 'car', 'van', 'truck'])
    .range(['#00986F', '#41A5D1', '#695998', '#E2595B', '#AA595B']);
  </code></pre>
  
  <p>...and I use this scale like so:</p>
  
  <pre><code>var vehiclesLegend = vehiclesLegendWrapper.selectAll('.vehiclesLegendSquare')
    .data(color.range())
    .enter().append('g')
    .attr('class', 'vehiclesLegendSquare')...
  </code></pre>
  
  <p>The problem is that not all of my datasets contain all of the possible vehicles so my legend will still show 'truck', for example, even when there are no trucks in the data.</p>
  
  <p>Is there a simple way to exclude certain vehicle/color combos from legend based on the dataset?</p>