Skip to content

Commit

Permalink
Fix two sorting bugs in chord layout.
Browse files Browse the repository at this point in the history
We still weren't sorting subgroups correctly. Also, we now sort chords by their
average value, rather than the source value, which works well with one-sided
chords (where either the source or target value is zero).
  • Loading branch information
mbostock committed Oct 24, 2011
1 parent 2f6d2fa commit c0e5b96
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion d3.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ try {
d3_style_setProperty.call(this, name, value + "", priority);
};
}
d3 = {version: "2.4.5"}; // semver
d3 = {version: "2.4.6"}; // semver
var d3_array = d3_arraySlice; // conversion for NodeLists

function d3_arrayCopy(pseudoarray) {
Expand Down
6 changes: 4 additions & 2 deletions d3.layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ d3.layout.chord = function() {
x = 0, i = -1; while (++i < n) {
x0 = x, j = -1; while (++j < n) {
var di = groupIndex[i],
dj = subgroupIndex[i][j],
dj = subgroupIndex[di][j],
v = matrix[di][dj];
subgroups[di + "-" + dj] = {
index: di,
Expand Down Expand Up @@ -153,7 +153,9 @@ d3.layout.chord = function() {

function resort() {
chords.sort(function(a, b) {
return sortChords(a.target.value, b.target.value);
return sortChords(
(a.source.value + a.target.value) / 2,
(b.source.value + b.target.value) / 2);
});
}

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

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion d3.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d3",
"version": "2.4.5",
"version": "2.4.6",
"description": "A small, free JavaScript library for manipulating documents based on data.",
"keywords": [
"dom",
Expand Down
2 changes: 1 addition & 1 deletion src/core/core.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d3 = {version: "2.4.5"}; // semver
d3 = {version: "2.4.6"}; // semver
6 changes: 4 additions & 2 deletions src/layout/chord.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ d3.layout.chord = function() {
x = 0, i = -1; while (++i < n) {
x0 = x, j = -1; while (++j < n) {
var di = groupIndex[i],
dj = subgroupIndex[i][j],
dj = subgroupIndex[di][j],
v = matrix[di][dj];
subgroups[di + "-" + dj] = {
index: di,
Expand Down Expand Up @@ -95,7 +95,9 @@ d3.layout.chord = function() {

function resort() {
chords.sort(function(a, b) {
return sortChords(a.target.value, b.target.value);
return sortChords(
(a.source.value + a.target.value) / 2,
(b.source.value + b.target.value) / 2);
});
}

Expand Down

0 comments on commit c0e5b96

Please sign in to comment.