May 2019
Beginner to intermediate
650 pages
14h 50m
English
You can sort the objects (the leaves) inside each group using sortValues(). For example, this code will sort the movies by year (see Collections/6-nesting-sort.html):
const groupByDirector = d3.nest() .key(d => d.director) .sortValues((a,b) => d3.ascending(a.year, b.year)) .entries(movies);
You can also sort by keys using sortKeys():
const groupByDirector = d3.nest() .key(d => d.director) .sortKeys((a,b) => d3.ascending(a, b)) .sortValues((a,b) => d3.ascending(a.year, b.year)) .entries(movies);
Multiple key() methods can be called in order with different keys for multi-level nesting (see Collections/5-nesting-entries.html).
Read now
Unlock full access