D3.layout.chord () analysis

Source: Internet
Author: User

Source:

var τ= 2 * MATH.PI;
D3.layout.chord =function() {    varChord = {}, chords, groups, Matrix, n, padding = 0, Sortgroups, sortsubgroups, sortchords; functionrelayout () {varsubgroups = {}, groupsums = [], Groupindex = D3.range (n), Subgroupindex =[], K, X, x0, I, J; Chords= []; Groups= []; K= 0, i =-1;  while(++i <N) {x= 0, J =-1;  while(++j <N) {x+=Matrix[i][j];        } groupsums.push (x);        Subgroupindex.push (D3.range (n)); K+=x; }      if(sortgroups) {Groupindex.sort (function(A, b) {returnsortgroups (Groupsums[a], groupsums[b]);      }); }      if(sortsubgroups) {Subgroupindex.foreach (function(d, i) {D.sort (function(A, b) {returnsortsubgroups (Matrix[i][a], matrix[i][b]);        });      }); }
The and of all values of the matrix before the K operation, and the angle value of 1 digits after the operation K= (τ-padding * n)/K; X= 0, i =-1; while(++i <N) {x0= x, j =-1; while(++j <N) {varDI = Groupindex[i], DJ = Subgroupindex[di][j], v = matrix[di][dj], a0 = x, a1 = x + = v *K; Subgroups[di+ "-" + dj) ={index:di, SUBINDEX:DJ, startangle:a0, ENDANGLE:A1, value : v}; } Groups[di]={index:di, startangle:x0, endangle:x, Value: (x-x0)/k}; X+=padding; } I=-1; while(++i <N) {j= I-1; while(++j <N) {varSource = subgroups[i + "-" + j], target = subgroups[j + "-" +i]; if(Source.value | |target.value) {Chords.push (Source.value< Target.value?{source:target, target:source}: {Source:source, Target:target}); } } } if(Sortchords) resort (); } functionResort () {Chords.sort (function(A, b) {returnSortchords ((A.source.value + a.target.value)/2, (B.source.value + b.target.value)/2); }); } Chord.matrix=function(x) {if(!arguments.length)returnMatrix; N= (Matrix = x) &&matrix.length; Chords= Groups =NULL; returnchord; }; Chord.padding=function(x) {if(!arguments.length)returnpadding; Padding=x; Chords= Groups =NULL; returnchord; }; Chord.sortgroups=function(x) {if(!arguments.length)returnsortgroups; Sortgroups=x; Chords= Groups =NULL; returnchord; }; Chord.sortsubgroups=function(x) {if(!arguments.length)returnsortsubgroups; Sortsubgroups=x; Chords=NULL; returnchord; }; Chord.sortchords=function(x) {if(!arguments.length)returnsortchords; Sortchords=x; if(Chords) resort (); returnchord; }; Chord.chords=function() { if(!chords) relayout (); returnchords; }; Chord.groups=function() { if(!groups) Relayout (); returngroups; }; returnchord; };
D3.layout.chord ()

Build a new chord layout. By default, the input data is not categorized and is not populated between groups. Unlike other layouts, the chord layout is not a function applied to the data; instead, the data is specified by setting the correlation matrix, which is retrieved through the chords and groups accessors.

Chord.matrix ([matrix])

After you specify the matrix, set the input data matrix to use for that layout. If no matrix is specified, the current data matrix is returned, which is undefined by default. The number of the input matrix must be "square matrix": [[11975,5871,8916,2868], [1951,10048,2060,6171], [8010,16145,8090,8045], [1013,990,940,6907]]

Each row of the matrix corresponds to a specific grouping, such as one of the hair colors described above. Each column I in the matrix corresponds to the line I, and each cell IJ represents the relationship between group I and group J.

Chord.padding ([padding])

If padding is specified, sets the angular padding between groups to the specified value Inradians. If padding is not specified, returns the current padding and which defaults to zero. wish to compute the padding as a function of the number of groups (the number of rows or columns in the associated Matrix). After the fill is specified, an angle fill is set between different groups for the specified value (in radians). If no padding is specified, the current fill is returned, and the default value is 0. You might want to calculate that the padding is a function of the number of groupings (the number of rows and columns in the associated matrix).

Chord.sortgroups ([Comparator])

If you have specified comparator, use the specified comparator function to set the order of grouping (rows) for the layout. The comparator function is called for each of the two rows, and the passed in parameter is the sum of the row I and Line J. Typically, you need to specify comparator according to D3.ascending or d3.descending. If comparator is not specified, the current grouping order is returned, and the default value is empty.

Chord.sortsubgroups ([Comparator])

If you have specified comparator, use the specified comparator function to set the order of grouping (columns within rows) for the layout. For each pair of elements, use the comparator function, which is the value of each cell. In general, you need to specify comparator in ascending or descending order. If comparator is not specified, the current sub-group is arranged in the order that the default value is empty.

Chord.sortchords ([Comparator])

If you have specified comparator, use the specified comparator function to set the order of the chord (Z-order) for the chord layout. Call the comparator function for each of the two strings, with the entry parameter being the minimum value of the source cell and the target cell. Typically, you specify comparator in ascending or descending order. If comparator is not specified, the current chord order is returned, and the default value is empty.

Chord.chords ()

Returns the computed chord object for the current configuration and associated matrix of the given layout. If the chord object has been computed, this method returns the cached value. If there are any changes to the layout properties, the chord before calculation is emptied. At this point, if the method is called next time, the layout needs to be recalculated. The returned object has the following properties:? Source-Describes the Origin object. Target-describes the destination object. These two objects describe the following entities:? Index-row indexes, I.? Subindex index-column index, J.? startangle-the starting angle of the arc, within the radians.? endangle-the ending angle of the arc, within the radians.? Value-the value of the associated cell IJ. It is important to note that these objects are easy for the chord generator to match the default accessors, but you can still override the accessors or modify the returned object to make the layout fine-tuned.

Chord.groups ()

Returns the computed grouping object for the current configuration and associated matrix of the given layout. This method returns the cached value if the grouped object has been computed. If there are any changes to the layout properties, the previously calculated groupings are emptied. At this point, if the method is called next time, the layout needs to be recalculated. The returned object has the following properties:? Index-row indexes, I.? StartAngle-The starting angle of the arc, within the radians. Endangle-the ending angle of the arc, within the radians. Value-The sum of the values of the related row I. It is important to note that these objects have a good degree of consistency with the default accessors of the Radian generator, but you can still override the accessors or modify the returned object to make the layout fine-tuned.

D3.layout.chord () analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.