$ dot -Tplain input.dot $ dot -Tplain-ext input.dot
纯文本
简单、基于行的语言
plain和plain-ext格式使用一种简单的基于行的语言生成输出。后一种格式的不同之处在于,在边上适用时会提供头尾节点的端口名称。
一个简单图的示例输出,包含两个通过一条边连接的节点:
-Tplain
$ echo 'digraph { a->b }' | dot -Tplain
graph 1 0.75 1.5
node a 0.375 1.25 0.75 0.5 a solid ellipse black lightgrey
node b 0.375 0.25 0.75 0.5 b solid ellipse black lightgrey
edge a b 4 0.375 0.99579 0.375 0.88865 0.375 0.7599 0.375 0.64045 solid black
stop
-Tplain-ext
$ echo 'digraph { a->b }' | dot -Tplain-ext
graph 1 0.75 1.5
node a 0.375 1.25 0.75 0.5 a solid ellipse black lightgrey
node b 0.375 0.25 0.75 0.5 b solid ellipse black lightgrey
edge a b 4 0.375 0.99579 0.375 0.88865 0.375 0.7599 0.375 0.64045 solid black
stop
共有四种类型的语句。
graph scale width height node name x y width height label style shape color fillcolor edge tail head n x₁ y₁ .. xₙ yₙ [label xl yl] style color stop
- graph
- The width and height values give the width and height of the drawing. The lower left corner of the drawing is at the origin. The scale value indicates how the drawing should be scaled if a 大小 attribute was given and the drawing needs to be scaled to conform to that size. If no scaling is necessary, it will be set to 1.0. Note that all graph, node and edge coordinates and lengths are given unscaled.
- node
- The name value is the name of the node, and x and y give the node's position. The width and height are the width and height of the node. The label, style, shape, color and fillcolor give the node's label, 样式, shape, 颜色 and fillcolor, respectively, using attribute default values where necessary. If the node does not have a style attribute, "solid" is used.
- edge
- The tail and head values give the names of the head and
tail nodes. In plain-ext format, the head or tail name will be appended
with a colon and a portname if the edge connects to the node at a port.
n is the number of control points defining the
B-spline forming the edge. This is followed by 2*n numbers giving
the x and y coordinates of the control points in order from tail to head.
If the edge has a label, this comes next
followed by the x and y coordinates of the label's position.
The edge description is completed by the edge's
样式 and 颜色.
As with nodes, if a style is not defined, "solid" is used.
注意: 边语句中给出的控制点定义了边的实体部分。具体来说,如果边在头节点或尾节点处有箭头,则最后一个或第一个控制点与关联节点边界之间会存在间隙。至少有3种可能的方式来处理这个间隙:
- 确保输入图中的所有边都使用
dir=none、arrowhead=none或arrowtail=none参数。在这种情况下,终止控制点将始终与节点接触。 - 考虑连接控制点和节点中心的线段,并确定该线段与节点边界的交点。然后使用控制点和交点作为箭头的主轴。这种方法的问题在于,如果边有端口,边将不会指向节点的中心。在这种情况下,可以使用控制点及其切线,而不是控制点和中心点。
- 调整输入图使用
headclip=false或tailclip=false。在这种情况下,边将终止于 节点的中心而非边界。如果使用了箭头, 仍会存在间隙,但通常这会发生在节点内部。 应用程序仍需将样条曲线裁剪至节点边界。 此外,与上一条相同,如果边指向 节点端口,此技术将失效。
- 确保输入图中的所有边都使用
输出包含一行graph信息,一系列node行(每个节点一行),一系列edge行(每条边一行),以及最后一行stop信息。所有单位均为英寸,用浮点数表示。
请注意,纯文本格式提供的信息非常有限,实际上仅包含节点位置和大小,以及边的样条控制点。这些格式通常最适合只需要这些几何信息、并愿意自行填充所有图形细节的应用程序。这些格式唯一的真正优势在于其简洁性和易于解析。一般来说,dot和xdot在提供的信息量方面更为可取。