Published
Edited
Oct 3, 2022
1 fork
Importers
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
explodeObjects = function (d) {
const enhanced = { ...d };

return Object.entries(enhanced).reduce((acc, [k, v]) => {
if (_.isObject(v) && !(v instanceof Date)) {
delete acc[k];
let sum = 0;
for (const [subkey, subvalue] of Object.entries(v).filter(
([id]) => id !== "__total"
)) {
sum += subvalue;
acc[`${k}.${subkey}`] = subvalue;
}
acc[`${k}.sum`] = sum;
acc[`${k}.raw`] = JSON.stringify(v);
} else {
acc[k] = v;
}

return acc;
}, enhanced);
}
Insert cell
parsed.map(formatRecord)
Insert cell
// if you see any columns with "[object Object]", coerce them into text with this function
stringifyObjs = function (d) {
const enhanced = { ...d };

return Object.entries(enhanced).reduce((acc, [k, v]) => {
if (_.isObject(v) && !(v instanceof Date)) {
acc[k] = JSON.stringify(v);
acc[`${k}.sum`] = Object.entries({ ...v })
.filter(([id]) => id !== "__total")
.reduce((acc, [k, v]) => acc + v, 0);
} else {
acc[k] = v;
}

return acc;
}, enhanced);
}
Insert cell
Insert cell
Insert cell
_ = require("underscore")
Insert cell
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