b } This g" /> b } This g" /> b } This g"/>

Border around graph

147 Views Asked by At

I would like to create an border around the graph which is getting generated with nop2 engine.

digraph {
  a[pos="0,0!"]
  b[pos="100,0!"]
  a -> b
}

This gets translated into this :

enter image description here

which does not have an border around it. How can we generate an thick border around the whole graph?

I tried using clusters but they are not supported in neato. So, no help.

2

There are 2 best solutions below

1
sroush On BEST ANSWER

Here is a gvpr (https://www.graphviz.org/pdf/gvpr.1.pdf) program that will add a periphery to a (root) graph. It does so by adding a rectangular node that is the size of the bounding box (the bb attribute), and then expanding the bb value.
Her is a command line:
dot -Knop2 myfile.gv |gvpr -cf addP.gvpr | dot -Knop2 -Tpng >myfile.png

Save this as addP.gvpr

/*
  add a periphery around a graph, by way of a large node (bb-sized)
*/
BEG_G {
  double   llx, lly, urx, ury, dx, dy, Margin;
  string   BB;
  graph_t  aG;
  node_t   aN;
  Margin=8;
  BB=$G.bb;
  sscanf ($G.bb, "%lf,%lf,%lf,%lf", &llx, &lly, &urx, &ury);
  llx-=Margin;
  lly-=Margin;
  urx+=Margin;
  ury+=Margin;
  $G.bb=(string)llx + "," + (string)lly + " " + (string)urx + "," + (string)ury;

  aN=node($G,"_____surround");
  aN.pos=(string)(llx+((urx-llx)/2)) + "," + (string)(lly+((ury-lly)/2));
  aN.width=(urx-llx)/72;
  aN.height=(ury-lly)/72;
  aN.shape="rect";
  aN.label="";
  aN.penwidth=4;
  aN.style="solid"  // not filled
}
9
sroush On

neato will honor any clusters that have been (correctly) positioned by others, but fails to position clusters if left to its own.

If you can use the fdp engine instead of nop2/neato,
use this command line: fdp -s myfile.gv -Tpng >myfile.png and the following alteration to your input:

digraph {
  splines=true  // added for splined edges
  subgraph clusterX{
    graph[penwidth=4] 
    a[pos="0,0!"]
    b[pos="100,0!"]
    c[pos="200,0!"]  // for splined edge
    a -> b
    a -> c
  }
}

Giving:
enter image description here