makeHierarchy = config => {
const defaultConfig = {
childrenAccessorFn: ([key, value]) => value.size && Array.from(value),
sumFn: ([key, value]) => value
};
const { data, reduceFn, groupByFns, childrenAccessorFn, sumFn, sortFn } = {
...defaultConfig,
...config
};
const rollupData = d3.rollup(data, reduceFn, ...groupByFns);
const hierarchyData = d3
.hierarchy([null, rollupData], childrenAccessorFn)
.sum(sumFn)
.sort(sortFn);
return hierarchyData;
}