The d3-collection module contains the d3.nest() function, which is widely used for grouping. It can be replaced by the d3.group and d3.rollup() functions from the d3-array module, but, at the time of writing, it's not a ready-to-use replacement yet, for the following reasons:
- You still need to convert the resulting map or set into an array before using it, since the current version of selection.data() only supports arrays
- With one level of grouping, the spread operator or the Array.from() function can be used to obtain an array, but it's harder if you need to group and sort multiple levels
- Generator functions in other D3 modules and plugins that require nested structures frequently assume the nested object structure that's produced by d3.nest() as the default
Mike Bostock suggests creating reusable functions for nesting and rollup...