English 中文(简体)
graphviz: minor tweaks to make the graph look nicer
原标题:
  • 时间:2010-01-19 15:03:16
  •  标签:
  • graphviz

I have a test graph here that I would like to tweak to make it look nicer.

alt text

Here is the graphviz (dot) source, test6.dot:

digraph G {
    ranksep=0.3; size="6.0,6.0";
    node [fontsize=11];
  
    subgraph clusterA {
        X2 [shape=box];

      node [style=filled];
        1 -> 2 -> 3 -> X2 -> 5;
        6;
        7;
      label = "A";
      color=blue
    }
    X1 [shape=box];
    subgraph clusterB {
      node [style=filled];
        8;
        9;
        10 -> 11 -> 12;
        12 -> 9;
        12 -> 8 -> 13;
        13 -> 14;
      label = "B";
      color=blue
    }
    subgraph clusterC {
      label = "C";
      {
        node [style="invis"];
        gap;
      }
      node [shape=box];
      
      edge [style="invis"];
      X3 -> gap -> X4;           
    }
  
    14 -> X4 -> 3;
    6 -> X1 -> 10;
    { edge [dir="both"];
      8 -> X3 -> 7;
    }
    
    9 -> X3
  }

Questions / changes I would like to make:

  • I want the flow of nodes 10 -> 11 -> 12 -> 8 -> 13 -> 14 to be in a vertical line (swap 8 and 9 horizontally). How can I do this? (same with 1 -> 2 -> 3 -> X2 -> 5; swap 6 and 1)
  • I want X1 to be at the same vertical position as 10, and the same horizontal position as 6. How can I do this?
  • I want 8 and X3 and 7 to be at the same vertical position, also with 14 and X4 and 3. How can I do this?
  • The ranksep=0.3; statement works great except note that 8 -> 13 -> 14 has a larger gap, as does X3 -> gap -> X4. Why doesn t it obey the ranksep=0.3 rule, and how do I fix this?
最佳回答

Below is the best I can do: phantom nodes and edges help. But I can t seem to encourage a particular ordering in the transverse direction (the other direction from rankdir).

alt text

 digraph G {
    ranksep=0.3; size="6.0,6.0";
    rankdir=TB;

    node [fontsize=11];

    subgraph clusterA {
      X2 [shape=box];
      label = "A";
      color=blue;

      node [style=filled];
        /* force 1, 6, and 7 to be at the top together,
           add enough phantoms to keep things in nice columns */
        {
          node [style="invis", label=""]; 
          phantom3;
          phantom4;
          phantom5;
          phantom6;
        }


          rank = same;
          1 -> 2 -> 3 -> X2 -> 5;        

          edge [style="invis"];
          6 -> phantom3 -> phantom5;
          7 -> phantom4 -> phantom6;

    }
    subgraph clusterB {
      node [style=filled];
      label = "B";
      color=blue;
      /* create an invisible phantom node 
           to take up space */
      {
        node [style="invis",label=""];
        phantom1;
        phantom1b;
      }

      { rank=same; 11;
        phantom1;
      }

      10 -> 11 -> 12 -> 8 -> 13 -> 14;
      12 -> 9;
      phantom1 -> 9 -> phantom1b [style="invis"];

    }


    /* force X1 to be at the same vertical pos as 10
       (this yields a warning though) */
    { rank = same; 
      X1 [shape=box];
      10;
    }

    6 -> X1;
    X1 -> 10 [weight=0.5];

    subgraph clusterC {
      label = "C";

      phantom2 [style="invis", label=""];

      node [shape=box];

      edge [style="invis"];
      X3 -> phantom2 -> X4;           
    }

    9 -> X3 [weight=0.5];

    { 
      edge [weight=20];
      14 -> X4 -> 3;
      3 -> X4 -> 14 [style="invis"];
      /* add a reverse path so graphviz doesn t force 14 above X4 above 3 */
    }
    { 
      edge [dir="both", weight=20];
      8 -> X3 -> 7;
      7 -> X3 -> 8 [style="invis"];
      edge [style="invis"];
      X4 -> phantom6;
      1 -> phantom2;
      8 -> phantom2;
    }

  }
问题回答

暂无回答




相关问题
graphviz: minor tweaks to make the graph look nicer

I have a test graph here that I would like to tweak to make it look nicer. Here is the graphviz (dot) source, test6.dot: digraph G { ranksep=0.3; size="6.0,6.0"; node [fontsize=11]; ...

GraphViz - How to connect subgraphs?

In the DOT language for GraphViz, I m trying to represent a dependency diagram. I need to be able to have nodes inside a container and to be able to make nodes and/or containers dependent on other ...

QuickGraph GraphvizRecord doesn t display in vertices

I m trying to build a Graphviz graph containing record vertices using QuickGraph. So far, I have this: var algo = new GraphvizAlgorithm<Entity, EntityEdge>(this); algo.CommonVertexFormat.Shape =...

Specified edge lengths on networkx/igraph (Python)

I wanted to visualize a network with the data I have and would like to graph them with specific edge lengths. I use Python, and I ve tried networkx and igraph to plot but all seem to assign fixed edge ...

Graphical interface for Graphiz for Mac OS?

I installed the Graphviz GUI from pizelmap.com, but it appears to only be a viewer for .dot Graphviz files. I am looking for a graphical editor, where I can create diagrams by pointing and clicking--...

How to add edge labels in Graphviz?

I am trying to draw a graph using Graphviz, but I need to add labels on the edges. There does not seem to be any way to that in Graphviz. Are there a way out?

Tips on Using Bison --graph=[file] on Linux

Recently (about a month ago) I was trying to introduce new constructs to my company s in-house extension language, and struggling with a couple of reduce-reduce errors. While I eventually solved this ...

How to change arrowhead type?

I want to simulate non-directional graphs with .dot. To that end, I want the arrowhead type to be "none". How do I set this? "f" -> "t" [label=2],[arrowhead=none] "m" -> "d" [label=0],[...

热门标签