Help with making subgraph smaller

I am working on a graph where I have a key/legend. The problem I am having is that the key subgraph is always too wide, and I would like it to be a small key/legend looking portion of the graph.
digraph G {
fontname="Helvetica";
labelloc=t;
rankdir=LR;
label="Course Graph";

node[style=filled, fontname="Helvetica", colorscheme=greens3, color=1];

subgraph cluster_key {
rank=min;
label="Key";
rankdir=LR;
nodesep=0.02;

k1[shape=plaintext, style=solid, label="Required Course"]
k2[shape=plaintext, style=solid, label="Course 1 is a prerequisite for Course 2"]
k3[shape=plaintext, style=solid, label="Course 1 and Course 2 are corequisite"]
k4[shape=plaintext, style=solid, label="You must take either Course 1 OR Course 2\nbefore taking Course 3"]

kc1[label="Course", peripheries=2, color=2];
prereq[label="Course 1"];
kc2[label="Course 2"];
coreq1[label="Course 1"];
coreq2[label="Course 2"];

or[style="dashed", color="black", shape="diamond", label="OR"];
or1[label="Course 1"];
or1 -> or[style="dashed", dir="none"];
or2[label="Course 2"];
or2 -> or[style="dashed", dir="none"];
kc3[label="Course 3"]
or->kc3;
{ rank=min;k1 k2 k3 k4 }
{
rank=same;
kc1 prereq coreq1 or1 or2
}
{
rank=same;
kc2 coreq2 kc3
}

prereq->kc2
coreq1->coreq2[dir=both]

k1->kc1[style=invis, minlen=0.25, len=0.25];
k2->prereq[style=invis];
k3->coreq1[style=invis];
}

c3[color=3, peripheries=2];
c4[color=3, peripheries=2];

c1->c2[dir=both];
c2->c3;

c4_reqs[style="dashed", color="black", shape="diamond", label="OR"];
c4_reqs->c4;
c2->c4_reqs[style="dashed", dir="none"];
c5->c4_reqs[style="dashed", dir="none"];

}

<code>

digraph G {
//      size="11, 8.5";
//      compound=true;
      fontname="Helvetica";
      labelloc=t;
      label="Web Development Specialist  (6138)";
      rankdir=LR;

      node[style=filled, fontname="Helvetica", colorscheme=greens3, color=1];

    subgraph cluster_key {
    rank=min;
    label="Key";
    rankdir=LR;
    nodesep=0.02;

    k1[shape=plaintext, style=solid, label="Required Course"]
    k2[shape=plaintext, style=solid, label="Course 1 is a prerequisite for Course 2"]
    k3[shape=plaintext, style=solid, label="Course 1 and Course 2 are corequisite"]
    k4[shape=plaintext, style=solid, label="You must take either Course 1 OR Course 2
before taking Course 3"]

    kc1[label="Course", peripheries=2, color=2];
    prereq[label="Course 1"];
    kc2[label="Course 2"];
    coreq1[label="Course 1"];
    coreq2[label="Course 2"];

    or[style="dashed", color="black", shape="diamond", label="OR"];
    or1[label="Course 1"];
    or1 -> or[style="dashed", dir="none"];
    or2[label="Course 2"];
    or2 -> or[style="dashed", dir="none"];
    kc3[label="Course 3"]
    or->kc3;
    { rank=min;k1 k2 k3 k4 }
    {
        rank=same;
        kc1 prereq coreq1 or1 or2
    }
    {
        rank=same;
        kc2 coreq2 kc3
    }

    prereq->kc2
    coreq1->coreq2[dir=both]

    k1->kc1[style=invis, minlen=0.25, len=0.25];
    k2->prereq[style=invis];
    k3->coreq1[style=invis];
    }

CGS1800[label="CGS1800: Introduction to Web Site Development", peripheries=2, color=2, url="http://www.palmbeachstate.edu/IE_CourseOutlines/IE_ShowOutline.asp?show=Y&CourseID=CGS1800"];
CGS2801[label="CGS2801: Advanced Web Page Media", peripheries=2, color=2, url="http://www.palmbeachstate.edu/IE_CourseOutlines/IE_ShowOutline.asp?show=Y&CourseID=CGS2801"];
ART1300C[label="ART1300C: Drawing 1", url="http://www.palmbeachstate.edu/IE_CourseOutlines/IE_ShowOutline.asp?show=Y&CourseID=ART1300C"];
CGS1100[label="CGS1100: Microcomputer Applications", peripheries=2, color=2, url="http://www.palmbeachstate.edu/IE_CourseOutlines/IE_ShowOutline.asp?show=Y&CourseID=CGS1100"];
COP1220[label="COP1220: Introduction to Programming in C", url="http://www.palmbeachstate.edu/IE_CourseOutlines/IE_ShowOutline.asp?show=Y&CourseID=COP1220"];
COP1000[label="COP1000: Introduction to Programming Logic", peripheries=2, color=2, url="http://www.palmbeachstate.edu/IE_CourseOutlines/IE_ShowOutline.asp?show=Y&CourseID=COP1000"];
CGS2555[label="CGS2555: Introduction to the Internet", peripheries=2, color=2, url="http://www.palmbeachstate.edu/IE_CourseOutlines/IE_ShowOutline.asp?show=Y&CourseID=CGS2555"];
CGS1561[label="CGS1561: Inside the PC", peripheries=2, color=2, url="http://www.palmbeachstate.edu/IE_CourseOutlines/IE_ShowOutline.asp?show=Y&CourseID=CGS1561"];
COP2822[label="COP2822: Web Site Design", peripheries=2, color=2, url="http://www.palmbeachstate.edu/IE_CourseOutlines/IE_ShowOutline.asp?show=Y&CourseID=COP2822"];
CNT2402[label="CNT2402: Implementing and Administering Network Security", peripheries=2, color=2, url="http://www.palmbeachstate.edu/IE_CourseOutlines/IE_ShowOutline.asp?show=Y&CourseID=CNT2402"];
COP2840[label="COP2840: Server-side Programming", peripheries=2, color=2, url="http://www.palmbeachstate.edu/IE_CourseOutlines/IE_ShowOutline.asp?show=Y&CourseID=COP2840"];
ART1201C[label="ART1201C: Design Fundamentals", url="http://www.palmbeachstate.edu/IE_CourseOutlines/IE_ShowOutline.asp?show=Y&CourseID=ART1201C"];
COP2334[label="COP2334: Programming in C++", url="http://www.palmbeachstate.edu/IE_CourseOutlines/IE_ShowOutline.asp?show=Y&CourseID=COP2334"];
ART1205C[label="ART1205C: Color Design", url="http://www.palmbeachstate.edu/IE_CourseOutlines/IE_ShowOutline.asp?show=Y&CourseID=ART1205C"];
GRA2131C[label="GRA2131C: Multimedia Graphics", url="http://www.palmbeachstate.edu/IE_CourseOutlines/IE_ShowOutline.asp?show=Y&CourseID=GRA2131C"];
COP2800[label="COP2800: Programming in Java", url="http://www.palmbeachstate.edu/IE_CourseOutlines/IE_ShowOutline.asp?show=Y&CourseID=COP2800"];
OST1831[label="OST1831: Microsoft Windows", peripheries=2, color=2, url="http://www.palmbeachstate.edu/IE_CourseOutlines/IE_ShowOutline.asp?show=Y&CourseID=OST1831"];
CGS2802[label="CGS2802: Web Site Administration", peripheries=2, color=2, url="http://www.palmbeachstate.edu/IE_CourseOutlines/IE_ShowOutline.asp?show=Y&CourseID=CGS2802"];
COP1332[label="COP1332: Visual Basic Programming", url="http://www.palmbeachstate.edu/IE_CourseOutlines/IE_ShowOutline.asp?show=Y&CourseID=COP1332"];
COP2831[label="COP2831: Advanced Web Page Applications (XML and JavaScript)", peripheries=2, color=2, url="http://www.palmbeachstate.edu/IE_CourseOutlines/IE_ShowOutline.asp?show=Y&CourseID=COP2831"];
GRA2100C[label="GRA2100C: Introduction to Macintosh Graphics", url="http://www.palmbeachstate.edu/IE_CourseOutlines/IE_ShowOutline.asp?show=Y&CourseID=GRA2100C"];
CNT2000[label="CNT2000: Network Technologies", peripheries=2, color=2, url="http://www.palmbeachstate.edu/IE_CourseOutlines/IE_ShowOutline.asp?show=Y&CourseID=CNT2000"];
CGS1100->CGS1800 [dir="both"];
CGS1800->CGS2801;
COP1000->COP1220;
CGS1100->COP1000 [dir="both"];
CGS1100->CGS2555 [dir="both"];
COP2822->COP2831_REQS[style="dashed", dir="none"];
COP1220->COP2831_REQS[style="dashed", dir="none"];
ART1201C->GRA2100C [dir="both"]
ART1300C->GRA2100C [dir="both"];
CGS1100->CNT2000 [dir="both"];
COP2822_REQS[style="dashed", shape="diamond", color="black", label="OR"];
COP2822_REQS->COP2822;
CGS2555->COP2822_REQS[style="dashed", dir="none"];
COP2822_REQS1[style="plaintext, dashed", color="black", label="AND"];
COP2822_REQS1->COP2822_REQS;
ART1201C->COP2822_REQS1;
ART1300C->COP2822_REQS1;
ART1205C->COP2822_REQS1;
COP2822_REQSO2[style="dashed", shape="diamond", color="black", label="OR"];
COP2822_REQSO2->COP2822_REQS1;
GRA2100C->COP2822_REQSO2[style="dashed", dir="none"];
GRA2131C->COP2822_REQSO2[style="dashed", dir="none"];
CGS1100->CNT2402;
COP1000->COP2840;
COP2840_REQS[style="dashed", color="black", shape="diamond", label="OR"];
COP2840_REQS->COP2840;
COP1220->COP2840_REQS[style="dashed", dir="none"];
COP1332->COP2840_REQS[style="dashed", dir="none"];
COP2334->COP2840_REQS[style="dashed", dir="none"];
COP2800->COP2840_REQS[style="dashed", dir="none"];
COP2831->COP2840_REQS[style="dashed", dir="none"];
COP1000->COP2334;
ART1201C->ART1205C;
ART1300C->ART1205C;
ART1201C->GRA2131C;
ART1300C->GRA2131C;
COP2800_REQS[style="dashed", color="black", shape="diamond", label="OR"];
COP2800_REQS->COP2800;
COP1220->COP2800_REQS[style="dashed", dir="none"];
COP2334->COP2800_REQS[style="dashed", dir="none"];
CGS1100->CGS2802;
COP1000->COP1332;
COP2831_REQS[style="dashed", color="black", shape="diamond", label="OR"];
COP2831_REQS->COP2831;
COP2822->COP2831_REQS[style="dashed", dir="none"];
COP1220->COP2831_REQS[style="dashed", dir="none"];
ART1201C->GRA2100C [dir="both"];
ART1300C->GRA2100C [dir="both"];
CGS1100->CNT2000 [dir="both"];
}

</code>

AttachmentSize
key.png58.82 KB
web_dev.png384.74 KB

If you run dot on a single

If you run dot on a single graph, the global parameters such as ranksep and nodesep are the same everywhere, so the nodes in the key will be as far apart as the nodes in the main graph. The only way around this is to process your main graph and the key graph separately, and then combine them. Assuming you have pulled out the key graph into key.gv, to make its layout smaller, reduce nodesep and ranksep, and change the default node attributes to

node[margin="0.06,0,025" width=0.5 height=0.25 style=filled, fontsize=6, fontname="Helvetica", colorscheme=greens3, color=1];

Of course, you can play with the values to get what you want.

Next you have to combine the layouts. One way is to run dot on each separately, producing two png files. Then use some png utility to combine them. Another approach is to use the gvpack command. Assume your main graph is in main.gv. You would then run

  dot main.gv > main1.gv

  dot key.gv > key1.gv

  gvpack -array_li1 main1.gv key1.gv | neato -n2 -Tpng > out.png

That being said, your graph exposed a couple of bugs. These have been fixed. So, for this to work properly, you will need to upgrade to tomorrow's working version. If this isn't feasible, let me know as I can describe a workaround using the current version.

Here is an what you get with the approach I suggested.

 

Recent comments