source: node_modules/d3-selection/src/selection/sort.js

Last change on this file was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Prototype 1.1

  • Property mode set to 100644
File size: 684 bytes
RevLine 
[e4c61dd]1import {Selection} from "./index.js";
2
3export default function(compare) {
4 if (!compare) compare = ascending;
5
6 function compareNode(a, b) {
7 return a && b ? compare(a.__data__, b.__data__) : !a - !b;
8 }
9
10 for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
11 for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
12 if (node = group[i]) {
13 sortgroup[i] = node;
14 }
15 }
16 sortgroup.sort(compareNode);
17 }
18
19 return new Selection(sortgroups, this._parents).order();
20}
21
22function ascending(a, b) {
23 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
24}
Note: See TracBrowser for help on using the repository browser.