Published unlisted
Edited
Feb 5, 2021
Importers
Insert cell
Insert cell
fcumsum([1, 1e-14, -1])
Insert cell
function fcumsum(values, valueof) {
const adder = new d3.Adder();
let index = -1;
return Float64Array.from(values, valueof === undefined
? v => adder.add(+v || 0)
: v => adder.add(+valueof(v, ++index, values) || 0)
);
}
Insert cell
fcumsum([1, 2, 3])
Insert cell
fcumsum(data, d => d.value)
Insert cell
d3.cumsum(data, d => d.value)
Insert cell
Insert cell
fcumsum(["1", null, 0.1, "0.1", 0.1, "a", undefined, "5e-1"]) // 1…1.8
Insert cell
d3.cumsum(["1", null, 0.1, "0.1", 0.1, "a", undefined, "5e-1"])
Insert cell
data = [
{ value: 18.7 },
{ value: 14.3 },
{ value: 16.4 },
{ value: 17.3 },
{ value: 15.2 },
{ value: 10.4 },
{ value: 10.4 },
{ value: 14.7 },
{ value: 15.5 },
{ value: 15.2 },
{ value: 13.3 },
{ value: 19.2 }
]
Insert cell
// d3.fcumsum was introduced in d3-array@2.x
d3 = require("d3-array@2") // ^next
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more