mySelection.sort( comparator ) in D3.js

Sort the order of elements in the selection (and DOM) according to custom criteria.

Arguments

nametypedescription
comparator Function This function is passed two data elements a and b to compare, and must return either a negative number, positive number, or zero. If negative, then a should be before b; if positive, then a should be after b; if zero, a and b are considered equal and the order is arbitrary.
Return Type
Selection

Description

For more details see https://github.com/mbostock/d3/wiki/Selections#wiki-sort.

See Also