module documentation

igraph库中与布局相关的代码。

这个包包含了Layout对象的实现。

Layout 表示图的布局。
函数 _3d_version_for 为给定布局算法的3D版本创建别名。
函数 _layout 根据布局算法返回图的布局。
函数 _layout_auto 根据图的简单拓扑属性选择并运行合适的布局函数。
函数 _layout_method_wrapper 包装现有的布局方法,以确保它返回一个布局而不是列表的列表。
函数 _layout_sugiyama 使用分层的Sugiyama布局放置顶点。
变量 _layout_mapping 未记录
def _3d_version_for(func): (source)

为给定布局算法的3D版本创建别名。

此函数是一个装饰器,它创建一个方法,在将dim=3附加到关键字参数列表后调用func

参数
func必须是Graph对象的一个方法。
返回
一种新方法
def _layout(graph, layout=None, *args, **kwds): (source)

根据布局算法返回图的布局。

未在此处指定的参数和关键字参数直接传递给布局算法。有关这些参数的说明,请参阅布局算法的文档。

此方法理解的已注册布局名称有:

参数
graph未记录
layout要使用的布局。这可以是已注册的布局名称之一,也可以是一个可调用对象,该对象返回一个Layout对象或包含坐标的列表的列表。如果None,则使用plotting.layout配置键的值。
*args未记录
**kwds未记录
返回
一个 Layout 对象。
def _layout_auto(graph, *args, **kwds): (source)

根据图的简单拓扑属性选择并运行合适的布局函数。

此函数尝试使用以下规则为图形选择合适的布局函数:

  1. If the graph has an attribute called layout, it will be used. It may either be a Layout instance, a list of coordinate pairs, the name of a layout function, or a callable function which generates the layout when called with the graph as a parameter.
  2. Otherwise, if the graph has vertex attributes called x and y, these will be used as coordinates in the layout. When a 3D layout is requested (by setting dim to 3), a vertex attribute named z will also be needed.
  3. Otherwise, if the graph is connected and has at most 100 vertices, the Kamada-Kawai layout will be used (see GraphBase.layout_kamada_kawai()).
  4. Otherwise, if the graph has at most 1000 vertices, the Fruchterman-Reingold layout will be used (see GraphBase.layout_fruchterman_reingold()).
  5. If everything else above failed, the DrL layout algorithm will be used (see GraphBase.layout_drl()).

除了dim之外,此函数的所有参数都传递给所选的布局函数(以防我们需要调用某些布局函数)。

参数
graph未记录
*args未记录
dim指定我们是否希望获得2D或3D布局。
返回
一个 Layout 对象。
def _layout_method_wrapper(func): (source)

包装现有的布局方法,以确保它返回一个布局而不是列表的列表。

参数
func要包装的方法。必须是Graph对象的方法。
返回
一种新方法
def _layout_sugiyama(graph, layers=None, weights=None, hgap=1, vgap=1, maxiter=100, return_extended_graph=False): (source)

使用分层的Sugiyama布局放置顶点。

这是一个分层布局,最适合用于有向无环图,尽管它也可以用于无向图或循环图。

每个顶点被分配到一个层,并且每一层被放置在一个水平线上。然后使用重心启发式算法对同一层内的顶点进行排列,以尽量减少边的交叉。

在跨越多个层的边上将添加虚拟顶点。因此,返回的布局包含比原始图中节点数量更多的行;这些额外的行对应于虚拟顶点。

参考文献:

  • K Sugiyama, S Tagawa, M Toda: Methods for visual understanding of hierarchical system structures. IEEE Systems, Man and Cybernetics 11(2):109-125, 1981.
  • P Eades, X Lin and WF Smyth: A fast effective heuristic for the feedback arc set problem. Information Processing Letters 47:319-323, 1993.
参数
graph未记录
layers一个向量,指定每个顶点的非负整数层索引,或包含层索引的数值顶点属性的名称。如果为None,将自动确定分层。对于无向图,将提取一个生成树,并使用从度数最大的节点开始的广度优先搜索将顶点分配到层。对于有向图,通过使用Eades、Lin和Smyth的启发式方法反转近似反馈弧集中的边来打破循环,然后使用最长路径分层将顶点放置在层中。
weights要使用的边权重。可以是序列、可迭代对象,甚至是边属性名称。
hgap同一层顶点之间的最小水平间距。
vgap层之间的垂直间隙。层索引将乘以vgap以获得Y坐标。
maxiter在交叉减少步骤中执行的最大迭代次数。如果您觉得得到的边交叉过多,请增加此值。
return_extended_graph指定是否还应返回添加了虚拟顶点的扩展图。当此参数为True时,结果将是一个包含布局和扩展图的元组。扩展图的前|V|个节点将对应于原始图的节点,其余的是虚拟节点。使用返回的布局和隐藏的虚拟节点绘制扩展图将产生一个与原始图相似的布局,但增加了边弯曲。扩展图还包含一个名为_original_eid的边属性,该属性指定了扩展图中边的原始图中边的ID。
返回
计算出的布局,可能(通常也会)比顶点的数量有更多的行;剩余的行对应于分层步骤中引入的虚拟节点。当return_extended_graphTrue时,它还将包含扩展图。
_layout_mapping: dict[str, str] = (source)

未记录