Codebase list node-d3-shape / 992fd6f
Use maximum, not first, value. Mike Bostock 5 years ago
2 changed file(s) with 7 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
11021102
11031103 <a name="stackOrderAppearance" href="#stackOrderAppearance">#</a> d3.<b>stackOrderAppearance</b>(<i>series</i>) [<>](https://github.com/d3/d3-shape/blob/master/src/order/appearance.js "Source")
11041104
1105 Returns a series order such that the earliest series (according to the first non-zero value) is at the bottom.
1105 Returns a series order such that the earliest series (according to the maximum value) is at the bottom.
11061106
11071107 <a name="stackOrderAscending" href="#stackOrderAscending">#</a> d3.<b>stackOrderAscending</b>(<i>series</i>) [<>](https://github.com/d3/d3-shape/blob/master/src/order/ascending.js "Source")
11081108
00 import none from "./none";
11
22 export default function(series) {
3 var starts = series.map(start);
4 return none(series).sort(function(a, b) { return starts[a] - starts[b]; });
3 var peaks = series.map(peak);
4 return none(series).sort(function(a, b) { return peaks[a] - peaks[b]; });
55 }
66
7 function start(series) {
8 var i = -1, n = series.length;
9 while (++i < n && !+series[i][1]);
10 return i;
7 function peak(series) {
8 var i = -1, j = 0, n = series.length, vi, vj = -Infinity;
9 while (++i < n) if ((vi = +series[i][1]) > vj) vj = vi, j = i;
10 return j;
1111 }