1
d3.layout.chord = function() {
15
groupIndex = d3.range(n),
27
k = 0, i = -1; while (++i < n) {
28
x = 0, j = -1; while (++j < n) {
32
subgroupIndex.push(d3.range(n));
38
groupIndex.sort(function(a, b) {
39
return sortGroups(groupSums[a], groupSums[b]);
45
subgroupIndex.forEach(function(d, i) {
46
d.sort(function(a, b) {
47
return sortSubgroups(matrix[i][a], matrix[i][b]);
52
// Convert the sum to scaling factor for [0, 2pi].
53
// TODO Allow start and end angle to be specified.
54
// TODO Allow padding to be specified as percentage?
55
k = (2 * Math.PI - padding * n) / k;
57
// Compute the start and end angle for each group and subgroup.
58
// Note: Opera has a bug reordering object literal properties!
59
x = 0, i = -1; while (++i < n) {
60
x0 = x, j = -1; while (++j < n) {
61
var di = groupIndex[i],
62
dj = subgroupIndex[di][j],
66
subgroups[di + "-" + dj] = {
83
// Generate chords for each (non-empty) subgroup-subgroup link.
84
i = -1; while (++i < n) {
85
j = i - 1; while (++j < n) {
86
var source = subgroups[i + "-" + j],
87
target = subgroups[j + "-" + i];
88
if (source.value || target.value) {
89
chords.push(source.value < target.value
90
? {source: target, target: source}
91
: {source: source, target: target});
96
if (sortChords) resort();
100
chords.sort(function(a, b) {
102
(a.source.value + a.target.value) / 2,
103
(b.source.value + b.target.value) / 2);
107
chord.matrix = function(x) {
108
if (!arguments.length) return matrix;
109
n = (matrix = x) && matrix.length;
110
chords = groups = null;
114
chord.padding = function(x) {
115
if (!arguments.length) return padding;
117
chords = groups = null;
121
chord.sortGroups = function(x) {
122
if (!arguments.length) return sortGroups;
124
chords = groups = null;
128
chord.sortSubgroups = function(x) {
129
if (!arguments.length) return sortSubgroups;
135
chord.sortChords = function(x) {
136
if (!arguments.length) return sortChords;
138
if (chords) resort();
142
chord.chords = function() {
143
if (!chords) relayout();
147
chord.groups = function() {
148
if (!groups) relayout();