{
const deathsByCauseAndMonth = d3.rollups(
crimea,
(v) => d3.sum(v, (d) => d.deaths),
(d) => d.cause,
(d) => d3.utcMonth(d.date)
);
const thresholds = d3.utcMonths(
d3.utcMonth.every(4).floor(d3.min(crimea, (d) => d.date)),
d3.max(crimea, (d) => d.date),
4
);
return thresholds.flatMap((from, i) => {
const to =
i === thresholds.length - 1
? d3.utcMonth.offset(from, 4)
: thresholds[i + 1];
return deathsByCauseAndMonth.map(([cause, g]) => {
return {
cause,
from: from,
to: to,
deaths: d3.sum(
g.filter(([date, deaths]) => date >= from && date < to),
(d) => d[1]
)
};
});
});
}