Skip to content

Commit

Permalink
Fix #126 stackOrderInsideOut.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Jan 24, 2019
1 parent 31f282b commit a9a2b52
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ Returns a series order such that the largest series (according to the sum of val

<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")

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.
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.

<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")

Expand Down
4 changes: 2 additions & 2 deletions src/order/insideOut.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import none from "./none";
import appearance from "./appearance";
import {sum} from "./ascending";

export default function(series) {
var n = series.length,
i,
j,
sums = series.map(sum),
order = none(series).sort(function(a, b) { return sums[b] - sums[a]; }),
order = appearance(series),
top = 0,
bottom = 0,
tops = [],
Expand Down
30 changes: 15 additions & 15 deletions test/order/insideOut-test.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
var tape = require("tape"),
shape = require("../../");

tape("stackOrderInsideOut(series) returns an order by sum", function(test) {
tape("stackOrderInsideOut(series) returns an order by appearance", function(test) {
test.deepEqual(shape.stackOrderInsideOut([
[[0, 0]],
[[0, 1]],
[[0, 2]],
[[0, 3]],
[[0, 4]],
[[0, 5]],
[[0, 6]]
[[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 1]],
[[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 2], [0, 0]],
[[0, 0], [0, 0], [0, 0], [0, 0], [0, 3], [0, 0], [0, 0]],
[[0, 0], [0, 0], [0, 0], [0, 4], [0, 0], [0, 0], [0, 0]],
[[0, 0], [0, 0], [0, 5], [0, 0], [0, 0], [0, 0], [0, 0]],
[[0, 0], [0, 6], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]],
[[0, 7], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]
]), [2, 3, 6, 5, 4, 1, 0]);
test.end();
});

tape("stackOrderInsideOut(series) treats NaN values as zero", function(test) {
test.deepEqual(shape.stackOrderInsideOut([
[[0, 0], [0, NaN]],
[[0, 1], [0, NaN]],
[[0, 2], [0, NaN]],
[[0, 3], [0, NaN]],
[[0, 4], [0, NaN]],
[[0, 5], [0, NaN]],
[[0, 6], [0, NaN]]
[[0, 0], [0, NaN], [0, 0], [0, 0], [0, 0], [0, 0], [0, 1]],
[[0, 0], [0, 0], [0, NaN], [0, 0], [0, 0], [0, 2], [0, 0]],
[[0, 0], [0, 0], [0, 0], [0, 0], [0, 3], [0, 0], [0, 0]],
[[0, 0], [0, 0], [0, 0], [0, 4], [0, NaN], [0, 0], [0, 0]],
[[0, 0], [0, 0], [0, 5], [0, 0], [0, 0], [0, NaN], [0, 0]],
[[0, NaN], [0, 6], [0, 0], [0, NaN], [0, 0], [0, 0], [0, 0]],
[[0, 7], [0, NaN], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]
]), [2, 3, 6, 5, 4, 1, 0]);
test.end();
});

0 comments on commit a9a2b52

Please sign in to comment.