Use maximum, not first, value.
Mike Bostock
5 years ago
1102 | 1102 |
|
1103 | 1103 |
<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")
|
1104 | 1104 |
|
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.
|
1106 | 1106 |
|
1107 | 1107 |
<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")
|
1108 | 1108 |
|
0 | 0 |
import none from "./none";
|
1 | 1 |
|
2 | 2 |
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]; });
|
5 | 5 |
}
|
6 | 6 |
|
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;
|
11 | 11 |
}
|