简体   繁体   English

graphviz / dot:两个节点之间的距离可以单独设置吗?

[英]graphviz/dot: can the distance between two nodes be set individually?

I'm trying to use dot (version 2.28.0) in order to make a flow chart of my source code. 我正在尝试使用dot(版本2.28.0)来制作我的源代码的流程图。 For that, I would like the graph to consist of subgraphs where each of these subgraphs represents a source file in the code base. 为此,我希望图形由子图组成,其中每个子图表示代码库中的源文件。 At the top of each subgraph, there should be the file name as a node in a visually easily distinguishable fashion (ie bold, white text on dark blue background). 在每个子图的顶部,应该有文件名作为节点,以视觉上容易区分的方式(即深蓝色背景上的粗体,白色文本)。 Below the file name node should be the nodes representing the flow of routines in that file in the order they are being called. 文件名节点下面应该是按照调用顺序表示该文件中的例程流的节点。

My problem now is that I would like the distance between "filename nodes" and "routine nodes" to be smaller than the distance between individual "routine nodes", plus, there should be no arrow between. 我现在的问题是我希望“文件名节点”和“例程节点”之间的距离小于各个“例程节点”之间的距离,而且,之间不应该有箭头。

I tried to use the minlen attribute for the edge connecting the "filename node" to the first "routine node", but when I set that to a value below 1.0, the two nodes come out next to each other rather than stacked. 我尝试将minlen属性用于将“文件名节点”连接到第一个“例程节点”的边缘,但是当我将其设置为低于1.0的值时,这两个节点彼此相邻而不是堆叠。

Is there any way to make the first two nodes be closer to each other than the other two, yet top/bottom oriented? 有没有办法让前两个节点比另外两个节点更接近,但是顶部/底部是否定向?

digraph "prog.c"
{
    edge [fontname="FreeSans",fontsize="12",labelfontname="FreeSans",labelfontsize="10"];
    node [fontname="FreeSans",fontsize="14",shape=record,height=0.2];
    compound=true;

    subgraph cluster_main {
        Node1_0 [label="main.c", shape=folder, fontcolor="white", style=filled, fillcolor="#00008b"];
        Node1_1 [label="routine1()"];
        Node1_2 [label="routine2()"];
        edge [color="transparent", minlen="0.5"]; // stacking not ok
        // edge [color="transparent", minlen="1.0"]; // stacking ok
        Node1_0 -> Node1_1 ;
        edge [color="black", minlen="1.0"];
        Node1_1 -> Node1_2 ;
    }
}

Edit: I should have commented out the line which lead to the undesired result rather than the one leading to the desired result (I had planned to attach two pngs for clarification, but I'm not allowed to do so as a newbie); 编辑:我应该注释掉导致不良结果的线而不是导致所需结果的线(我原本计划附加两个png用于澄清,但我不允许这样做作为新手); so here is the code I would actually want to modify in a way that the first two nodes have a different (smaller) distance to each than the last two. 所以这里是我实际想要修改的代码,前两个节点的距离与最后两个节点的距离不同(较小)。

digraph "prog.c"
{
    edge [fontname="FreeSans",fontsize="12",labelfontname="FreeSans",labelfontsize="10"];
    node [fontname="FreeSans",fontsize="14",shape=record,height=0.2];
    compound=true;

    subgraph cluster_main {
        Node1_0 [label="main.c", shape=folder, fontcolor="white", style=filled, fillcolor="#00008b"];
        Node1_1 [label="routine1()"];
        Node1_2 [label="routine2()"];
        //edge [color="transparent", minlen="0.5"]; // stacking not ok
        edge [color="transparent", minlen="1.0"]; // stacking ok
        Node1_0 -> Node1_1 ;
        edge [color="black", minlen="1.0"];
        Node1_1 -> Node1_2 ;
    }
}

There are a couple of "graph" properties that can control what you need. 有一些“图形”属性可以控制您的需求。 pad, ranksep, nodesep pad,ranksep,nodesep

Also, I increased your node size, but only for my own ease of use... 另外,我增加了你的节点大小,但仅限于我自己的易用性......

digraph "prog.c"
{
    graph [pad=".75", ranksep="0.25", nodesep="0.25"];
    node [fontname="FreeSans",fontsize="14",shape=record,width=2, height=.5];
    edge [fontname="FreeSans",fontsize="12",labelfontname="FreeSans",labelfontsize="10"];

    compound=true;

    subgraph cluster_main {
        Node1_0 [label="main.c", shape=folder, fontcolor="white", style=filled, fillcolor="#00008b"];
        Node1_1 [label="routine1()"];
        Node1_2 [label="routine2()"];
        edge [color="transparent", minlen="0.5"]; // stacking not ok
        // edge [color="transparent", minlen="1.0"]; // stacking ok
        Node1_0 -> Node1_1 ;
        edge [color="black", minlen="1.0"];
        Node1_1 -> Node1_2 ;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM