From a9a2b5294450df678a44f06097d23b299c96ee08 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Wed, 23 Jan 2019 17:03:02 -0800 Subject: [PATCH] Fix #126 stackOrderInsideOut. --- README.md | 2 +- src/order/insideOut.js | 4 ++-- test/order/insideOut-test.js | 30 +++++++++++++++--------------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 605290b..ca0b8ff 100644 --- a/README.md +++ b/README.md @@ -1115,7 +1115,7 @@ Returns a series order such that the largest series (according to the sum of val # d3.stackOrderInsideOut(series) [<>](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. # d3.stackOrderNone(series) [<>](https://github.com/d3/d3-shape/blob/master/src/order/none.js "Source") diff --git a/src/order/insideOut.js b/src/order/insideOut.js index 459d21c..7b8d1b9 100644 --- a/src/order/insideOut.js +++ b/src/order/insideOut.js @@ -1,4 +1,4 @@ -import none from "./none"; +import appearance from "./appearance"; import {sum} from "./ascending"; export default function(series) { @@ -6,7 +6,7 @@ export default function(series) { 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 = [], diff --git a/test/order/insideOut-test.js b/test/order/insideOut-test.js index cbd4010..9af8c65 100644 --- a/test/order/insideOut-test.js +++ b/test/order/insideOut-test.js @@ -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(); });