Codebase list node-d3-shape / a9a2b52
Fix #126 stackOrderInsideOut. Mike Bostock 5 years ago
3 changed file(s) with 18 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
11141114
11151115 <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")
11161116
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.
11181118
11191119 <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")
11201120
0 import none from "./none";
0 import appearance from "./appearance";
11 import {sum} from "./ascending";
22
33 export default function(series) {
55 i,
66 j,
77 sums = series.map(sum),
8 order = none(series).sort(function(a, b) { return sums[b] - sums[a]; }),
8 order = appearance(series),
99 top = 0,
1010 bottom = 0,
1111 tops = [],
00 var tape = require("tape"),
11 shape = require("../../");
22
3 tape("stackOrderInsideOut(series) returns an order by sum", function(test) {
3 tape("stackOrderInsideOut(series) returns an order by appearance", function(test) {
44 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]]
1212 ]), [2, 3, 6, 5, 4, 1, 0]);
1313 test.end();
1414 });
1515
1616 tape("stackOrderInsideOut(series) treats NaN values as zero", function(test) {
1717 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]]
2525 ]), [2, 3, 6, 5, 4, 1, 0]);
2626 test.end();
2727 });