弦
¥Chords
弦布局计算角度以生成 弦图。
¥The chord layout computes angles to generate a chord diagram.
chord()
源代码 · 使用默认设置构造一个新的和弦布局。
¥Source · Constructs a new chord layout with the default settings.
const chord = d3.chord();
chord(matrix) {#_chord}
源代码 · 计算指定大小为 n×n 的方阵的弦布局,其中矩阵表示 n 个节点的网络(完全有向图)中的有向流。
¥Source · Computes the chord layout for the specified square matrix of size n×n, where the matrix represents the directed flow amongst a network (a complete digraph) of n nodes.
chord(matrix) 的返回值是一个弦数组,其中每个弦表示两个节点 i 和 j(其中 i 可能等于 j)之间的双向流组合,并且是一个具有以下属性的对象:
¥The return value of chord(matrix) is an array of chords, where each chord represents the combined bidirectional flow between two nodes i and j (where i may be equal to j) and is an object with the following properties:
source
- 源子组¥
source
- the source subgrouptarget
- 目标子组¥
target
- the target subgroup
每个源子组和目标子组也是一个具有以下属性的对象:
¥Each source and target subgroup is also an object with the following properties:
startAngle
- 起始角度(弧度)¥
startAngle
- the start angle in radiansendAngle
- 以弧度为单位的结束角度¥
endAngle
- the end angle in radiansvalue
- 流值矩阵 [i][j]¥
value
- the flow value matrix[i][j]index
- 节点索引 i¥
index
- the node index i
弦通常传递给 ribbon 以显示网络关系。
¥The chords are typically passed to ribbon to display the network relationships.
返回的数组仅包含 matrix[i][j] 或 matrix[j][i] 值非零的弦对象。此外,返回的数组仅包含唯一的和弦:给定的弦 ij 表示从 i 到 j 以及从 j 到 i 的双向流,并且不包含重复的弦 ji;i 和 j 的选择方式应使弦的源始终代表 matrix[i][j] 和 matrix[j][i] 中较大的一个。
¥The returned array includes only chord objects for which the value matrix[i][j] or matrix[j][i] is non-zero. Furthermore, the returned array only contains unique chords: a given chord ij represents the bidirectional flow from i to j and from j to i, and does not contain a duplicate chord ji; i and j are chosen such that the chord’s source always represents the larger of matrix[i][j] and matrix[j][i].
弦数组还定义了一个长度为 n 的辅助数组 chords.groups,其中每个组代表节点 i 的组合流出,对应于元素 matrix[i][0 … n - 1],并且是一个具有以下属性的对象:
¥The chords array also defines a secondary array of length n, chords.groups, where each group represents the combined outflow for node i, corresponding to the elements matrix[i][0 … n - 1], and is an object with the following properties:
startAngle
- 起始角度(弧度)¥
startAngle
- the start angle in radiansendAngle
- 以弧度为单位的结束角度¥
endAngle
- the end angle in radiansvalue
- 节点 i 的总输出流量值¥
value
- the total outgoing flow value for node iindex
- 节点索引 i¥
index
- the node index i
这些组通常传递给 arc,以围绕弦布局的圆周生成一个圆环图。
¥The groups are typically passed to arc to produce a donut chart around the circumference of the chord layout.
chord.padAngle(angle) {#chord_padAngle}
源代码 · 如果指定了角度,则将相邻组之间的衬垫角度设置为指定的弧度数并返回此弦布局。如果未指定角度,则返回当前填充角度,默认为零。
¥Source · If angle is specified, sets the pad angle between adjacent groups to the specified number in radians and returns this chord layout. If angle is not specified, returns the current pad angle, which defaults to zero.
chord.sortGroups(compare) {#chord_sortGroups}
源代码 · 如果指定了 compare,则将组比较器设置为指定的函数或 null,并返回此弦布局。如果未指定 compare,则返回当前的组比较器,默认为 null。如果组比较器非空,则它将用于按组的总流出量对组进行排序。另请参阅 ascending 和 descending。
¥Source · If compare is specified, sets the group comparator to the specified function or null and returns this chord layout. If compare is not specified, returns the current group comparator, which defaults to null. If the group comparator is non-null, it is used to sort the groups by their total outflow. See also ascending and descending.
chord.sortSubgroups(compare) {#chord_sortSubgroups}
源代码 · 如果指定了 compare,则将子组比较器设置为指定函数或 null,并返回此和弦布局。如果未指定 compare,则返回当前子组比较器,默认为 null。如果子组比较器非空,则用于对与 matrix[i][0 … n 对应的子组进行排序。 - 1] 对于给定组 i,按其总流出量进行比较。另请参阅 ascending 和 descending。
¥Source · If compare is specified, sets the subgroup comparator to the specified function or null and returns this chord layout. If compare is not specified, returns the current subgroup comparator, which defaults to null. If the subgroup comparator is non-null, it is used to sort the subgroups corresponding to matrix[i][0 … n - 1] for a given group i by their total outflow. See also ascending and descending.
chord.sortChords(compare) {#chord_sortChords}
源代码 · 如果指定了 compare,则将弦比较器设置为指定的函数或 null,并返回此弦布局。如果未指定 compare,则返回当前的 chord 比较器,默认为 null。如果 chord 比较器非空,则使用它按组合流对 chords 进行排序;这只会影响弦的 z 轴顺序。另请参阅 ascending 和 descending。
¥Source · If compare is specified, sets the chord comparator to the specified function or null and returns this chord layout. If compare is not specified, returns the current chord comparator, which defaults to null. If the chord comparator is non-null, it is used to sort the chords by their combined flow; this only affects the z-order of the chords. See also ascending and descending.
chordDirected()
示例 · 源代码 · 用于单向流的弦布局。从 i 到 j 的弦仅根据 matrix[i][j] 中的值生成。
¥Examples · Source · A chord layout for unidirectional flows. The chord from i to j is generated from the value in matrix[i][j] only.
chordTranspose()
源代码 · 转置弦布局。Useful to highlight outgoing (rather than incoming) flows.
¥Source · A transposed chord layout. Useful to highlight outgoing (rather than incoming) flows.