title: dc.js - Remove empty bins from stacked bar chart upon filtering
body: <p>Here is the <a href="https://jsfiddle.net/JaelB/x1vL3ebj/58/" rel="nofollow noreferrer">fiddle</a> for a stacked bar chart. This chart filters another line chart.</p>
  
  <p>To remove empty bins, I tried <a href="https://github.com/dc-js/dc.js/wiki/FAQ" rel="nofollow noreferrer">dc.js FAQ</a>, <a href="https://github.com/dc-js/dc.js/blob/master/web/examples/filtering-removing.html" rel="nofollow noreferrer">this example</a> and <a href="https://stackoverflow.com/questions/44354064/remove-empty-bins-with-reduce-add-remove-function-not-working">this</a>. </p>
  
  <p>I saw <a href="https://stackoverflow.com/questions/30886088/dc-js-stacked-bar-chart-with-empty-bin-filter-displaying-in-strange-way">this</a> and <a href="https://stackoverflow.com/questions/42115001/elastic-x-axis-for-stacked-barchart-removing-the-empty-bins-dc-js">this</a> for a stacked bar chart scenario, but my grouping is different.
  I've tried different things but I'm not able to get it to work.</p>
  
  <p>Pretty sure I'm missing something simple. </p>
  
  <p>Kindly review my code. Am I doing something wrong? How do i get the remove_empty_bins() working?</p>
  
  <pre><code> var stack = dc.barChart('#stack');
  
   var XDimension = ndx.dimension(function (d) {return d.no;});
  
            var YDimension_before = XDimension.group().reduce(
              function(p, d) {
                p[d.sub_no] = (p[d.sub_no]|| 0) + +d.avg;
                return p;
              },
              function(p, d) {
                p[d.sub_no] = (p[d.sub_no]|| 0) - +d.avg;
                return p;
              },
              function() {
                return {};});
  
           var YDimension = remove_empty_bins(YDimension_before);
  
        stack.width(550)
            .height(400)
            .dimension(XDimension)
            .group(YDimension, '1', sel_stack(1))
            .transitionDuration(500)
            .xUnits(dc.units.ordinal)
            .x(d3.scaleBand())
            .margins({left: 80, top: 20, right: 80, bottom: 80})
            .brushOn(false)
            .clipPadding(20)
            .elasticX(true)
            .elasticY(true)
            .title(function(d) {
            return [ d.key + '[' + this.layer + '] ',
                    d.value[this.layer]].join('\n')
            });
   stack.stack(YDimension, '2', sel_stack(2))
                        .stack(YDimension, '3', sel_stack(3))
  
  function remove_empty_bins(source_group) {
            return {
                all:function () {
                    return source_group.all().filter(function(d) {
                       return d.value != 0;
  
                    });
                }
            };
        }
  </code></pre>