Skip to content

Instantly share code, notes, and snippets.

@nking
Created June 18, 2014 00:12
Show Gist options
  • Save nking/e1c91d1c7305dee5ec7d to your computer and use it in GitHub Desktop.
Save nking/e1c91d1c7305dee5ec7d to your computer and use it in GitHub Desktop.
UML Class Diagrams can be made with graphviz.
(1) download graphviz
http://www.graphviz.org/Download.php
(2) write your dot file.
Note that in your dot file, you may want to exclude most dependencies
because the dot layout algorithm will weigh them equally with
the inheritance edges and you probably want a preference for better
display of the inheritance and composition relationships.
Here's the contents of example_graphviz.dat showing how to draw
inheritance, composition, aggregation, and dependencies.
digraph G {
rankdir = "TB"
fontname = "Bitstream Vera Sans"
fontsize = 8
node [
fontname = "Bitstream Vera Sans"
fontsize = 8
shape = "box"
]
edge [
fontname = "Bitstream Vera Sans"
fontsize = 8
]
edge [
arrowhead = "empty"
]
//inheritance: superclass -> subclass
Animal -> Dog [dir = "back" arrowtail = "empty"]
Animal -> Cat [dir = "back" arrowtail = "empty"]
//composition: class -> member variable
Dog -> DogBark [dir = "back" arrowtail = "diamond"]
// aggregation: class -> member variable w/ root reference created elsewhere,
edge [
arrowhead = "none"
headlabel = "0..*"
taillabel = "0..*"
]
Cat -> Dog
// "uses", i.e. dependency
edge [
arrowhead = "vee"
style = "dotted"
taillabel = "uses"
headlabel = ""
]
Bird -> BirdFood
}
(3) dot -T png -o classes.png example_graphviz.dat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment