Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept iterables. #153

Merged
merged 18 commits into from
Aug 19, 2020
Prev Previous commit
Next Next commit
Accept iterable for stack.
  • Loading branch information
mbostock committed Nov 19, 2019
commit 5a4e7929c4ea8865e4d7591274a16cdd2416008d
20 changes: 11 additions & 9 deletions src/stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ function stackValue(d, key) {
return d[key];
}

function stackSeries(key) {
const series = [];
series.key = key;
return series;
}

export default function() {
var keys = constant([]),
order = orderNone,
Expand All @@ -14,18 +20,14 @@ export default function() {

function stack(data) {
var kz = keys.apply(this, arguments),
i,
m = data.length,
n = kz.length,
sz = new Array(n),
sz = kz.map(stackSeries),
i, n = sz.length, m = -1,
oz;

for (i = 0; i < n; ++i) {
for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
si[j] = sij = [0, +value(data[j], ki, j, data)];
sij.data = data[j];
for (const d of data) {
for (i = 0, ++m; i < n; ++i) {
(sz[i][m] = [0, +value(d, kz[i], m, data)]).data = d;
}
si.key = ki;
}

for (i = 0, oz = order(sz); i < n; ++i) {
Expand Down