module documentation

igraph中默认图形绘制器的辅助类。

此模块包含复杂的元类魔法。如果你不理解这些类背后的逻辑,可能你也不需要它们。

igraph的默认图形绘制器使用各种数据源来确定顶点和边的视觉外观。这些数据源如下(按优先级顺序):

  • The keyword arguments passed to the igraph.plot() function (or to igraph.Graph.__plot__() as a matter of fact, since igraph.plot() just passes these attributes on). For instance, a keyword argument named vertex_label can be used to set the labels of vertices.
  • The attributes of the vertices/edges being drawn. For instance, a vertex that has a label attribute will use that label when drawn by the default graph drawer.
  • The global configuration of igraph. For instance, if the global igraph.config.Configuration instance has a key called plotting.vertex_color, that will be used as a default color for the vertices.
  • If all else fails, there is a built-in default; for instance, the default vertex color is "red". This is hard-wired in the source code.

上述逻辑不仅适用于默认的图形绘制器,也可以在其他图形绘制器中使用,因此它被重构到本模块中的类中。不同的图形绘制器可能会检查不同的顶点或边属性,因此从各种数据源收集属性的类是在运行时使用一个名为AttributeCollectorMeta的元类生成的。你不需要直接使用AttributeCollectorMeta,只需实现AttributeCollectorBase的子类,它将确保使用适当的元类。通过AttributeCollectorBase,你可以使用简单的声明性语法来指定你感兴趣的属性。例如:

    class VisualEdgeBuilder(AttributeCollectorBase):
        arrow_size = 1.0
        arrow_width = 1.0
        color = ("black", palette.get)
        width = 1.0

    for edge in VisualEdgeBuilder(graph.es):
        print edge.color

上述类是一个视觉边缘构建器——一个在构建时指定图形边缘视觉属性的类。它指定了我们感兴趣的属性是arrow_sizearrow_widthcolorwidth;同时也给出了默认值。对于color,我们还指定了一个名为{palette.get}的方法应该在每个属性值上调用,以将颜色名称转换为RGB值。对于其他三个属性,float将隐式地在所有属性值上调用,这是从默认值本身的类型推断出来的。

另请参阅
属性收集器元数据, 属性收集器基础
AttributeCollectorBase 属性收集器子类的基础类。继承此类的类可以使用声明性语法来指定它们打算收集的顶点或边属性。参见 AttributeCollectorMeta...
AttributeCollectorMeta 属性收集器类的元类
AttributeSpecification 描述如何检索给定属性值的类。