title: {d3.js} migration v3 to v4: code work on v3 (d3.layout.stack()) error v4 (d3.stack())
body: <p>I'm trying to migrate D3 from v3 to v4: </p>
  
  <p>Read:
  <a href="https://github.com/d3/d3/blob/master/CHANGES.md#shapes-d3-shape" rel="noreferrer">https://github.com/d3/d3/blob/master/CHANGES.md#shapes-d3-shape</a></p>
  
  <p>See:
  <code>d3.layout.stack</code> ↦ <code>d3.stack</code></p>
  
  <p>I changed my working code:</p>
  
  <p>Code working on v3: <code>(d3.layout.stack())</code> </p>
  
  <p>Code producing error in v4: <code>(d3.stack())</code></p>
  
  <p>V4:</p>
  
  <pre><code>var dvstack = d3.stack(); 
  var layers = dvstack(d3.range(nLocal).map(function(d,i) { ...
  console.log(dvstack);
  
  function stack(data) {
  
   var kz = keys.apply(this, arguments),
       i,
       m = data.length,
       n = kz.length,
       sz = new Array(n),
       oz;
  
   for (i = 0; i &lt; n; ++i) {
     for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j &lt; m;++j) {
       si[j] = sij = [0, +value(data[j], ki, j, data)];
       sij.data = data[j];
     }
     si.key = ki;
   }
  
   for (i = 0, oz = order(sz); i &lt; n; ++i) {
     sz[oz[i]].index = i;
   }
  
   offset(sz, oz);
   return sz;    }
  
  layers[c].dvnum = c;
  </code></pre>
  
  <blockquote>
    <p>Error: 
    SCRIPT5007: Unable to set property 'dvnum' of undefined or null reference</p>
  </blockquote>
  
  <p>V3:</p>
  
  <pre><code>var stack = d3.layout.stack(); 
  var layers = stack(d3.range(nLocal).map(function(d,i) { ...
  console.log(stack);
  
  function stack(data, index) {
  
   if (!(n = data.length)) return data;
   var series = data.map(function(d, i) {
     return values.call(stack, d, i);
   });
   var points = series.map(function(d) {
     return d.map(function(v, i) {
       return [ x.call(stack, v, i), y.call(stack, v, i) ];
     });
   });
   var orders = order.call(stack, points, index);
   series = d3.permute(series, orders);
   points = d3.permute(points, orders);
   var offsets = offset.call(stack, points, index);
   var m = series[0].length, n, i, j, o;
   for (j = 0; j &lt; m; ++j) {
     out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
     for (i = 1; i &lt; n; ++i) {
       out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
     }
   }
   return data;    }
  
  layers[c].dvnum = c;
  </code></pre>
  
  <p>Screenshot of the working code in v3:
  <img src="https://i.stack.imgur.com/ne4oj.png" alt="screenshot working code (D3 v3)"></p>
  
  <p>Screenshot of the working code (D3 v3) console.log(layers)
  <img src="https://i.stack.imgur.com/iFqup.png" alt="screenshot console.log(layers) working code (D3 v3)"></p>
  
  <p>Screenshot of the (D3 v4) console.log(layers)
  <img src="https://i.stack.imgur.com/EfZDZ.png" alt="screenshot console.log(layers)  (D3 v4)"></p>