Skip to content

Instantly share code, notes, and snippets.

@weibeld
Last active October 31, 2017 22:27
Show Gist options
  • Save weibeld/1b8d88256c4f204c1a11fcdf4c5e5286 to your computer and use it in GitHub Desktop.
Save weibeld/1b8d88256c4f204c1a11fcdf4c5e5286 to your computer and use it in GitHub Desktop.
A small Graphviz "Hello World" program
// A small Graphviz "Hello World" program
//
// Usage:
//
// dot -Tpdf graphviz.dot >out.pdf
//
// See all supported output formats with:
//
// dot -Txxx
//
// Alternative layout algorithms: neato, fdp, twopi, circo (instead of dot)
//
// Daniel Weibel <danielmweibel@gmail.com> 14 March 2014
//----------------------------------------------------------------------------//
// A small finite state machine (FSM)
digraph fsm {
// Graph attributes
rankdir=LR;
// Node attributes
start [shape=plaintext];
1 [shape=doublecircle];
0 [label="¬p\n¬q"];
node [shape=circle];
// Edges and edge attributes
start -> 0;
0 -> 0 [label = "a,b"];
0 -> 1 [label = "b"];
1 -> 1 [label = "b"];
1 -> 2 [label = "a"];
2 -> 2 [label = "a,b"];
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.38.0 (20140413.2041)
-->
<!-- Title: fsm Pages: 1 -->
<svg width="318pt" height="91pt"
viewBox="0.00 0.00 318.21 90.91" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 86.9117)">
<title>fsm</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-86.9117 314.214,-86.9117 314.214,4 -4,4"/>
<!-- start -->
<g id="node1" class="node"><title>start</title>
<text text-anchor="middle" x="27" y="-21.2558" font-family="Times,serif" font-size="14.00">start</text>
</g>
<!-- 0 -->
<g id="node3" class="node"><title>0</title>
<ellipse fill="none" stroke="black" cx="118" cy="-25.4558" rx="27" ry="25.4118"/>
<text text-anchor="middle" x="118" y="-28.2558" font-family="Times,serif" font-size="14.00">¬p</text>
<text text-anchor="middle" x="118" y="-14.2558" font-family="Times,serif" font-size="14.00">¬q</text>
</g>
<!-- start&#45;&gt;0 -->
<g id="edge1" class="edge"><title>start&#45;&gt;0</title>
<path fill="none" stroke="black" d="M54.2216,-25.4558C62.5505,-25.4558 71.9135,-25.4558 80.8161,-25.4558"/>
<polygon fill="black" stroke="black" points="80.9659,-28.9559 90.9659,-25.4558 80.9658,-21.9559 80.9659,-28.9559"/>
</g>
<!-- 1 -->
<g id="node2" class="node"><title>1</title>
<ellipse fill="none" stroke="black" cx="210" cy="-25.4558" rx="18" ry="18"/>
<ellipse fill="none" stroke="black" cx="210" cy="-25.4558" rx="22" ry="22"/>
<text text-anchor="middle" x="210" y="-21.2558" font-family="Times,serif" font-size="14.00">1</text>
</g>
<!-- 1&#45;&gt;1 -->
<g id="edge4" class="edge"><title>1&#45;&gt;1</title>
<path fill="none" stroke="black" d="M202.317,-46.4466C201.369,-56.5431 203.93,-65.4558 210,-65.4558 213.889,-65.4558 216.337,-61.798 217.346,-56.5145"/>
<polygon fill="black" stroke="black" points="220.846,-56.5582 217.683,-46.4466 213.85,-56.3238 220.846,-56.5582"/>
<text text-anchor="middle" x="210" y="-68.2558" font-family="Times,serif" font-size="14.00">b</text>
</g>
<!-- 2 -->
<g id="node4" class="node"><title>2</title>
<ellipse fill="none" stroke="black" cx="292.214" cy="-25.4558" rx="18" ry="18"/>
<text text-anchor="middle" x="292.214" y="-21.2558" font-family="Times,serif" font-size="14.00">2</text>
</g>
<!-- 1&#45;&gt;2 -->
<g id="edge5" class="edge"><title>1&#45;&gt;2</title>
<path fill="none" stroke="black" d="M232.075,-25.4558C241.79,-25.4558 253.445,-25.4558 263.83,-25.4558"/>
<polygon fill="black" stroke="black" points="264.058,-28.9559 274.058,-25.4558 264.058,-21.9559 264.058,-28.9559"/>
<text text-anchor="middle" x="253.107" y="-28.2558" font-family="Times,serif" font-size="14.00">a</text>
</g>
<!-- 0&#45;&gt;1 -->
<g id="edge3" class="edge"><title>0&#45;&gt;1</title>
<path fill="none" stroke="black" d="M145.032,-25.4558C155.233,-25.4558 167.026,-25.4558 177.687,-25.4558"/>
<polygon fill="black" stroke="black" points="177.869,-28.9559 187.869,-25.4558 177.869,-21.9559 177.869,-28.9559"/>
<text text-anchor="middle" x="166.5" y="-28.2558" font-family="Times,serif" font-size="14.00">b</text>
</g>
<!-- 0&#45;&gt;0 -->
<g id="edge2" class="edge"><title>0&#45;&gt;0</title>
<path fill="none" stroke="black" d="M109.823,-50.0262C109.259,-60.2474 111.984,-68.9117 118,-68.9117 121.854,-68.9117 124.357,-65.3559 125.511,-60.1128"/>
<polygon fill="black" stroke="black" points="129.01,-60.2353 126.177,-50.0262 122.026,-59.7736 129.01,-60.2353"/>
<text text-anchor="middle" x="118" y="-71.7117" font-family="Times,serif" font-size="14.00">a,b</text>
</g>
<!-- 2&#45;&gt;2 -->
<g id="edge6" class="edge"><title>2&#45;&gt;2</title>
<path fill="none" stroke="black" d="M285.48,-42.4931C284.106,-52.3138 286.351,-61.4558 292.214,-61.4558 295.878,-61.4558 298.129,-57.8847 298.967,-52.8088"/>
<polygon fill="black" stroke="black" points="302.466,-52.4865 298.947,-42.4931 295.466,-52.4997 302.466,-52.4865"/>
<text text-anchor="middle" x="292.214" y="-64.2558" font-family="Times,serif" font-size="14.00">a,b</text>
</g>
</g>
</svg>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment