Skip to content

¥Cluster

/Chaos/Chaos/Eros/Chaos/Erebus/Chaos/Tartarus/Chaos/Gaia/Chaos/Gaia/Mountains/Chaos/Gaia/Pontus/Chaos/Gaia/UranusEros/Chaos/ErosErebus/Chaos/ErebusTartarus/Chaos/TartarusMountains/Chaos/Gaia/MountainsPontus/Chaos/Gaia/PontusUranus/Chaos/Gaia/UranusChaos/ChaosGaia/Chaos/Gaia

示例 · 簇布局生成 dendrograms:将树的叶节点置于相同深度的节点链接图。树状图通常不如 整洁树 紧凑,但当所有叶子节点应该位于同一级别时很有用,例如对于层次聚类或 系统发育树图

¥Examples · The cluster layout produces dendrograms: node-link diagrams that place leaf nodes of the tree at the same depth. Dendrograms are typically less compact than tidy trees, but are useful when all the leaves should be at the same level, such as for hierarchical clustering or phylogenetic tree diagrams.

cluster()

源代码 · 使用默认设置创建一个新的集群布局。

¥Source · Creates a new cluster layout with default settings.

cluster(root) {#_cluster}

源代码 · 布局指定的根 hierarchy,并在根及其后代上分配以下属性:

¥Source · Lays out the specified root hierarchy, assigning the following properties on root and its descendants:

  • node.x - 节点的 x 坐标

    ¥node.x - the x-coordinate of the node

  • node.y - 节点的 y 坐标

    ¥node.y - the y coordinate of the node

坐标 x 和 y 表示任意坐标系;例如,你可以将 x 视为角度,y 视为半径,以生成 径向布局。你可能需要在将层次结构传递给集群布局之前调用 root.sort

¥The coordinates x and y represent an arbitrary coordinate system; for example, you can treat x as an angle and y as a radius to produce a radial layout. You may want to call root.sort before passing the hierarchy to the cluster layout.

cluster.size(size) {#cluster_size}

源代码 · 如果指定了 size,则将此包布局的大小设置为指定的 [width, height] 双元素数组并返回此包布局。如果未指定大小,则返回当前布局大小,默认为 [1, 1]。布局大小为 null 表示将改用 节点大小。坐标 x 和 y 表示任意坐标系;例如,要生成 径向布局,大小 [360, radius] 对应的宽度为 360°,深度为半径。

¥Source · If size is specified, sets this cluster layout’s size to the specified two-element array of numbers [width, height] and returns this cluster layout. If size is not specified, returns the current layout size, which defaults to [1, 1]. A layout size of null indicates that a node size will be used instead. The coordinates x and y represent an arbitrary coordinate system; for example, to produce a radial layout, a size of [360, radius] corresponds to a breadth of 360° and a depth of radius.

cluster.nodeSize(size) {#cluster_nodeSize}

源代码 · 如果指定了 size,则将此簇布局的大小设置为指定的 [width, height] 双元素数组并返回此簇布局。如果未指定大小,则返回当前节点大小,默认为 null。节点大小为 null 表示将改用 布局大小。指定节点大小后,根节点始终位于 ⟨0, 0⟩。

¥Source · If size is specified, sets this cluster layout’s node size to the specified two-element array of numbers [width, height] and returns this cluster layout. If size is not specified, returns the current node size, which defaults to null. A node size of null indicates that a layout size will be used instead. When a node size is specified, the root node is always positioned at ⟨0, 0⟩.

cluster.separation(separation) {#cluster_separation}

源代码 · 如果指定了 separation,则将 separation 访问器设置为指定的函数并返回此树形布局。如果未指定分隔符,则返回当前分隔符访问器,默认为:

¥Source · If separation is specified, sets the separation accessor to the specified function and returns this cluster layout. If separation is not specified, returns the current separation accessor, which defaults to:

js
function separation(a, b) {
  return a.parent == b.parent ? 1 : 2;
}

分离访问器用于分离相邻的叶子节点。分离函数接收两个叶子节点 a 和 b,并返回所需的分离值。这些节点通常是同级节点,但如果布局决定将这些节点相邻放置,则它们之间的关系可能更远。

¥The separation accessor is used to separate neighboring leaves. The separation function is passed two leaves a and b, and must return the desired separation. The nodes are typically siblings, though the nodes may be more distantly related if the layout decides to place such nodes adjacent.