Skip to content

Commit

Permalink
d3.layout.pie: return arcs in original data order.
Browse files Browse the repository at this point in the history
Fixes d3#406.
  • Loading branch information
jasondavies committed Dec 13, 2011
1 parent 05d871b commit c603af8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
6 changes: 4 additions & 2 deletions d3.layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,9 +638,11 @@ d3.layout.pie = function() {
});

// Return the arcs in the original data's order.
return data.map(function(d, i) {
return arcs[index[i]];
data = [];
arcs.forEach(function(arc, i) {
data[index[i]] = arc;
});
return data;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion d3.layout.min.js

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions src/layout/pie.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ d3.layout.pie = function() {
});

// Return the arcs in the original data's order.
return data.map(function(d, i) {
return arcs[index[i]];
data = [];
arcs.forEach(function(arc, i) {
data[index[i]] = arc;
});
return data;
}

/**
Expand Down
26 changes: 26 additions & 0 deletions test/layout/pie-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require("../env");
require("../../d3");
require("../../d3.layout");

var vows = require("vows"),
assert = require("assert");

var suite = vows.describe("d3.layout.pie");

suite.addBatch({
"pie": {
topic: d3.layout.pie,
"arcs are in same order as original data": function(pie) {
assert.deepEqual(pie([5, 30, 15]).map(function(d) { return d.data; }), [
5, 30, 15
]);
assert.deepEqual(pie([
84, 90, 48, 61, 58, 8, 6, 31, 45, 18
]).map(function(d) { return d.data; }), [
84, 90, 48, 61, 58, 8, 6, 31, 45, 18
]);
}
}
});

suite.export(module);

0 comments on commit c603af8

Please sign in to comment.