Skip to content

Instantly share code, notes, and snippets.

@rodw
Created January 3, 2014 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodw/8242144 to your computer and use it in GitHub Desktop.
Save rodw/8242144 to your computer and use it in GitHub Desktop.
somewhat brute force solution to the question raised in this tweet: https://twitter.com/silentbicycle/status/418760644066676736 output from `dot -Tpng figure2.gv` at http://ow.ly/i/4bZ8B
digraph fig2 {
splines=line # makes edges straight rather than curved
ranksep=0.2 # controls distance between rows
# create a record-type node representing the row of numbers
# (the `<x>` bit declares a port we can point edges to)
n [shape=record label="{<a>58}|{<b>82}|{<c>16}|{<d>85}|{<e>65}|{<f>5}|{<g>67}|{<h>26}"]
# create some dummy rows, each with one false node per element in n
node [shape=point height=0 style=invis];
{ rank=same; fa1;fb1;fc1;fd1;fe1;ff1;fg1;fh1; }
{ rank=same; fa2;fb2;fc2;fd2;fe2;ff2;fg2;fh2; }
{ rank=same; fa3;fb3;fc3;fd3;fe3;ff3;fg3;fh3; }
edge [style=invis]
n:a -> fa1 -> fa2 -> fa3
n:b -> fb1 -> fb2 -> fb3
n:c -> fc1 -> fc2 -> fc3
n:d -> fd1 -> fd2 -> fd3
n:e -> fe1 -> fe2 -> fe3
n:f -> ff1 -> ff2 -> ff3
n:g -> fg1 -> fg2 -> fg3
n:h -> fh1 -> fh2 -> fh3
# create the subsequence edges
edge [dir=none style=bold constraint=false] # no arrows, fat lines, don't change node placement
edge [color=black] # first subsequence
fa1 -> n:a # vertical lines
fd1 -> n:d
fg1 -> n:g
fa1 -> fd1 -> fg1 # horizontal line
edge [color=blue] # second subsequence
fb2 -> n:b # vertical lines
fe2 -> n:e
fh2 -> n:h
fb2 -> fe2 -> fh2 # horizontal line
edge [color=red] # third subsequence
fc3 -> n:c # vertical lines
ff3 -> n:f
fc3 -> ff3 # horizontal line
# create a legend
subgraph clusterLegend {
pencolor=transparent # hide the line around the cluster
# create "head" nodes to contain the label text
node [shape=plaintext style="" width=2 fontsize=12 fontname=Helvetica]
l1h [label="first subsequence\l" fontcolor=black]
l2h [label="second subsequence\l" fontcolor=blue]
l3h [label="third subsequence\l" fontcolor=red]
# create the corresponding "tail" nodes and edges
node [shape="point" width=0 style=invis]
edge [dir=none style=bold constraint=false minlen=1]
l1t -> l1h [color=black]
l2t -> l2h [color=blue]
l3t -> l3h [color=red]
# ensure that the labels are stacked top-to-bottom
edge [style=invis constraint=true minlen=""]
l1t -> l2t -> l3t
l1h -> l2h -> l3h
}
# create a dummy edge to ensure the legend is placed below the figure
fb3 -> l1t [style=invis constraint=true minlen=2]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment