Stupid Dot tricks

Experimenting with stylized diagrams, I created a gvpr program that would post process an enhanced dot program, adding row, column, and cellAdjust (the last tweaks the position within the cell).
I use dot to establish all the standard attributes, then my gvpr program to reposition all the nodes, based on the new attributes, then neato -n to route edges and produce the output.
Dot rowcol1

digraph rc {
  graph[nodesep=.5]

  node [style=filled fillcolor=white]
  {
    node [row=1]
    a1 [col=1]
    a2 [col=2]
    a3 [col=3]
    a5 [col=5 fillcolor=orange]
    a6 [col=6 fillcolor=red]
  }
  {
    node [row=2]
    b1 [col=1]
    b4 [col=4]
    b5 [col=5]   
  }
  {
    node [row=3]
    c1 [col=1]
    c2 [col=2]
  }
  {
    node [row=4]
    d4 [col=4 fillcolor=yellow]
    d5 [col=5]   
  }
}

digraph circles {
  graph[nodesep=.5]

  {
    node [row=2 shape=circle style=filled]
    // sequence matters
    large  [col=2 label="" width=1.5  fillcolor=red]
    medium [col=2 label="" width=1    fillcolor=green]
    small  [col=2 label="ok" width=.5   fillcolor=blue fontcolor=white]

    x1 [row=4 col=4 fillcolor=orange]
    x2 [row=4 col=7 fillcolor=lightblue]
    x3 [row=3 col=1 fillcolor=purple]
  } 

large->x1
medium->x2
small->x3
}

digraph circles {
  graph[nodesep=.5]

    node [row=3 shape=circle style=filled]
    // sequence matters
    large  [col=3 label="" width=1.5  fillcolor=red]
    medium [col=3 label="" width=1    fillcolor=green]
    small  [col=3 label="" width=.5   fillcolor=blue]
    t1     [col=3 label="" width=.3    fillcolor=orange cellAdjust=n]
    t2     [col=3 label="" width=.3    fillcolor=purple cellAdjust=e]
    t3     [col=3 label="" width=.3    fillcolor=pink   cellAdjust=sw]
    t4     [col=3 label="" width=.3    fillcolor=yellow cellAdjust=se]

    node [row=3 shape=square style=filled]
    // sequence matters
    large2  [col=5 label="" width=1.5  fillcolor=red]
    node [row=3 shape=star style=filled]
    medium2 [col=5 label="" width=1    fillcolor=green]
    node [row=3 shape=circle style=filled]
    small2  [col=5 label="" width=.5   fillcolor=blue]
    t12     [col=5 label="" width=.3    fillcolor=orange cellAdjust=n]
    t22     [col=5 label="" width=.3    fillcolor=purple cellAdjust=e]
    t32     [col=5 label="" width=.3    fillcolor=pink   cellAdjust=sw]
    t42     [col=5 label="" width=.3    fillcolor=yellow cellAdjust=se]

    node [row=3 shape=square style=filled]
    // sequence matters
    large3  [col=7 label="" width=1.5  fillcolor=red]
    node [row=3 shape=star style=filled]
    medium3 [col=7 label="" width=1    fillcolor=green]
    node [row=3 shape=circle style=filled]
    small3  [col=7 label="" width=.5   fillcolor=blue]
    t13     [col=7 label="" width=.3    fillcolor=orange cellAdjust=n]
    node [row=3 shape=circle style=filled]
    t23     [col=7 label="" width=.3    fillcolor=purple cellAdjust=e]
    node [row=3 shape=triangle style=filled]
    t33     [col=7 label="" width=.3    fillcolor=pink   cellAdjust=sw]
    node [row=3 shape=octagon style=filled]
    t43     [col=7 label="" width=.3    fillcolor=yellow cellAdjust=se]
}
1 Like

Thanks for the contribution @steveroush and welcome to the forum :smiley:.

I haven’t used gvpr myself. What does the gvpr program that creates this look like?

That program is a work-in-progress (currently broken) (feature creep).
If you are interested in gvpr programs in general, you can find them here (maybe) in a Linux install: /usr/share/graphviz/gvpr/ or here if you built your own from git: …/cmd/gvpr/lib/
Here is a little program that counts nodes, edges and the number of characters in the node and edge labels:

BEGIN {
  int nodeCnt=0, edgeCnt=0, nodeLabelCharCnt=0, edgeLabelCharCnt=0;
}
N {
  nodeCnt++;
  nodeLabelCharCnt+=length($.label);
}
E {
  edgeCnt++;
  edgeLabelCharCnt+=length($.label);
}
//////////////////////////////////////////////////////////
END_G{
   print ("Total nodes: ", nodeCnt);
   print ("Total edges: ", edgeCnt);
   print ("Total node label character count: ", nodeLabelCharCnt);
   print ("Total edge label character count: ", edgeLabelCharCnt);
}
1 Like