Fix #126 stackOrderInsideOut.
Mike Bostock
5 years ago
1114 | 1114 | |
1115 | 1115 | <a name="stackOrderInsideOut" href="#stackOrderInsideOut">#</a> d3.<b>stackOrderInsideOut</b>(<i>series</i>) [<>](https://github.com/d3/d3-shape/blob/master/src/order/insideOut.js "Source") |
1116 | 1116 | |
1117 | Returns a series order such that the larger series (according to the sum of values) are on the inside and the smaller series are on the outside. This order is recommended for streamgraphs in conjunction with the [wiggle offset](#stackOffsetWiggle). See [Stacked Graphs—Geometry & Aesthetics](http://leebyron.com/streamgraph/) by Byron & Wattenberg for more information. | |
1117 | Returns a series order such that the earliest series (according to the maximum value) are on the inside and the later series are on the outside. This order is recommended for streamgraphs in conjunction with the [wiggle offset](#stackOffsetWiggle). See [Stacked Graphs—Geometry & Aesthetics](http://leebyron.com/streamgraph/) by Byron & Wattenberg for more information. | |
1118 | 1118 | |
1119 | 1119 | <a name="stackOrderNone" href="#stackOrderNone">#</a> d3.<b>stackOrderNone</b>(<i>series</i>) [<>](https://github.com/d3/d3-shape/blob/master/src/order/none.js "Source") |
1120 | 1120 |
0 | import none from "./none"; | |
0 | import appearance from "./appearance"; | |
1 | 1 | import {sum} from "./ascending"; |
2 | 2 | |
3 | 3 | export default function(series) { |
5 | 5 | i, |
6 | 6 | j, |
7 | 7 | sums = series.map(sum), |
8 | order = none(series).sort(function(a, b) { return sums[b] - sums[a]; }), | |
8 | order = appearance(series), | |
9 | 9 | top = 0, |
10 | 10 | bottom = 0, |
11 | 11 | tops = [], |
0 | 0 | var tape = require("tape"), |
1 | 1 | shape = require("../../"); |
2 | 2 | |
3 | tape("stackOrderInsideOut(series) returns an order by sum", function(test) { | |
3 | tape("stackOrderInsideOut(series) returns an order by appearance", function(test) { | |
4 | 4 | test.deepEqual(shape.stackOrderInsideOut([ |
5 | [[0, 0]], | |
6 | [[0, 1]], | |
7 | [[0, 2]], | |
8 | [[0, 3]], | |
9 | [[0, 4]], | |
10 | [[0, 5]], | |
11 | [[0, 6]] | |
5 | [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 1]], | |
6 | [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 2], [0, 0]], | |
7 | [[0, 0], [0, 0], [0, 0], [0, 0], [0, 3], [0, 0], [0, 0]], | |
8 | [[0, 0], [0, 0], [0, 0], [0, 4], [0, 0], [0, 0], [0, 0]], | |
9 | [[0, 0], [0, 0], [0, 5], [0, 0], [0, 0], [0, 0], [0, 0]], | |
10 | [[0, 0], [0, 6], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]], | |
11 | [[0, 7], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]] | |
12 | 12 | ]), [2, 3, 6, 5, 4, 1, 0]); |
13 | 13 | test.end(); |
14 | 14 | }); |
15 | 15 | |
16 | 16 | tape("stackOrderInsideOut(series) treats NaN values as zero", function(test) { |
17 | 17 | test.deepEqual(shape.stackOrderInsideOut([ |
18 | [[0, 0], [0, NaN]], | |
19 | [[0, 1], [0, NaN]], | |
20 | [[0, 2], [0, NaN]], | |
21 | [[0, 3], [0, NaN]], | |
22 | [[0, 4], [0, NaN]], | |
23 | [[0, 5], [0, NaN]], | |
24 | [[0, 6], [0, NaN]] | |
18 | [[0, 0], [0, NaN], [0, 0], [0, 0], [0, 0], [0, 0], [0, 1]], | |
19 | [[0, 0], [0, 0], [0, NaN], [0, 0], [0, 0], [0, 2], [0, 0]], | |
20 | [[0, 0], [0, 0], [0, 0], [0, 0], [0, 3], [0, 0], [0, 0]], | |
21 | [[0, 0], [0, 0], [0, 0], [0, 4], [0, NaN], [0, 0], [0, 0]], | |
22 | [[0, 0], [0, 0], [0, 5], [0, 0], [0, 0], [0, NaN], [0, 0]], | |
23 | [[0, NaN], [0, 6], [0, 0], [0, NaN], [0, 0], [0, 0], [0, 0]], | |
24 | [[0, 7], [0, NaN], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]] | |
25 | 25 | ]), [2, 3, 6, 5, 4, 1, 0]); |
26 | 26 | test.end(); |
27 | 27 | }); |