Skip to content

打包

¥Pack

示例 · 封闭图使用包含(嵌套)来表示层次结构。叶子圆圈的大小编码了数据的量化维度。封闭圆显示每个子树的近似累积大小,但由于空间浪费,可能会出现一些失真;只有叶节点可以准确比较。虽然 圆形填充 的空间利用效率不如 treemap,但“浪费”的空间更能凸显层次结构。

¥Examples · Enclosure diagrams use containment (nesting) to represent a hierarchy. The size of the leaf circles encodes a quantitative dimension of the data. The enclosing circles show the approximate cumulative size of each subtree, but due to wasted space there is some distortion; only the leaf nodes can be compared accurately. Although circle packing does not use space as efficiently as a treemap, the “wasted” space more prominently reveals the hierarchical structure.

pack()

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

¥Source · Creates a new pack layout with the default settings.

pack(root) {#_pack}

源代码 · 布局指定的根 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 circle’s center

  • node.y - 圆心的 y 坐标

    ¥node.y - the y coordinate of the circle’s center

  • node.r - 圆的半径

    ¥node.r - the radius of the circle

你必须在将层次结构传递给包布局之前调用 root.sum。你可能还需要在计算布局之前调用 root.sort 来对层次结构进行排序。

¥You must call root.sum before passing the hierarchy to the pack layout. You probably also want to call root.sort to order the hierarchy before computing the layout.

pack.radius(radius) {#pack_radius}

源代码 · 如果指定了半径,则将包布局的半径访问器设置为指定的函数,并返回此包布局。如果未指定半径,则返回当前半径访问器,默认为 null。如果半径访问器为空,则每个叶子圆的半径由叶节点的值(由 node.sum 计算)得出;然后按比例缩放半径以适应 布局大小。如果半径访问器不为空,则每个叶子圆的半径由该函数精确指定。

¥Source · If radius is specified, sets the pack layout’s radius accessor to the specified function and returns this pack layout. If radius is not specified, returns the current radius accessor, which defaults to null. If the radius accessor is null, the radius of each leaf circle is derived from the leaf node.value (computed by node.sum); the radii are then scaled proportionally to fit the layout size. If the radius accessor is not null, the radius of each leaf circle is specified exactly by the function.

pack.size(size) {#pack_size}

源代码 · 如果指定了 size,则将此分区布局的大小设置为指定的 [width, height] 双元素数组,并返回此分区布局。如果未指定 size,则返回当前大小,默认为 [1, 1]。

¥Source · If size is specified, sets this pack layout’s size to the specified two-element array of numbers [width, height] and returns this pack layout. If size is not specified, returns the current size, which defaults to [1, 1].

pack.padding(padding) {#pack_padding}

源代码 · 如果指定了 padding,则将此包布局的 padding 访问器设置为指定的数字或函数,并返回此包布局。如果未指定 padding,则返回当前 padding 访问器,默认为常量零。当兄弟元素被打包时,相切兄弟元素之间的间隔将大致等于指定的填充;封闭的父圆也将与其子圆之间以大约指定的填充分隔。如果未指定 显式半径,则填充是近似的,因为需要两遍算法才能拟合 布局大小:圆圈首先被填充,没有填充;计算缩放因子并将其应用于指定的填充;最后,圆圈会用填充重新填充。

¥Source · If padding is specified, sets this pack layout’s padding accessor to the specified number or function and returns this pack layout. If padding is not specified, returns the current padding accessor, which defaults to the constant zero. When siblings are packed, tangent siblings will be separated by approximately the specified padding; the enclosing parent circle will also be separated from its children by approximately the specified padding. If an explicit radius is not specified, the padding is approximate because a two-pass algorithm is needed to fit within the layout size: the circles are first packed without padding; a scaling factor is computed and applied to the specified padding; and lastly the circles are re-packed with padding.

packSiblings(circles)

源代码 · 打包指定的圆数组,每个圆必须包含一个 circle.r 属性,用于指定圆的半径。为每个圆分配以下属性:

¥Source · Packs the specified array of circles, each of which must have a circle.r property specifying the circle’s radius. Assigns the following properties to each circle:

  • circle.x - 圆心的 x 坐标

    ¥circle.x - the x-coordinate of the circle’s center

  • circle.y - 圆心的 y 坐标

    ¥circle.y - the y coordinate of the circle’s center

这些圆按照 Wang 等人 的前链填充算法进行定位。

¥The circles are positioned according to the front-chain packing algorithm by Wang et al.

packEnclose(circles)

示例 · 源代码 · 计算包含指定圆数组的 最小圆 值。每个圆必须包含一个 circle.r 属性,用于指定圆的半径,以及 circle.x 和 circle.y 属性,用于指定圆心。封闭圆使用 Matoušek-Sharir-Welzl 算法 计算。(另请参阅 阿波罗尼乌斯问题。)

¥Examples · Source · Computes the smallest circle that encloses the specified array of circles, each of which must have a circle.r property specifying the circle’s radius, and circle.x and circle.y properties specifying the circle’s center. The enclosing circle is computed using the Matoušek-Sharir-Welzl algorithm. (See also Apollonius’ Problem.)