Login required
Download

Class diagram plugin

(10)
Author(s): Trygve Amundsen
Current Release: 0.5.1
Grails Version: 1.2.0 > *
Tags development domain modelling uml visualization

Install the plugin

grails install-plugin class-diagram [-global]
Use the -global flag if you want the class diagram to be available globally, ie. for all your grails projects.
Hey, wait: the -global flag is currently broken, don't use it! (or see http://jira.codehaus.org/browse/GRAILS-5608)

Install graphviz dot utility

This plugin is dependent on the excellent graphviz library. Download and put its bin folder on your path (or set the path to the graphviz dot utility in Config.groovy: graphviz.dot.executable property=/full/path/to/dot-executable).

The dot utility is a tool to generate nice-looking diagrams with a minimum of effort. It is part of Graphviz and should be part of any programmers toolkit :) .

The ClassDiagram plugin

The ClassDiagram plugin provides an UML-like diagram of your grails domain classes.

Usage

After installation (see the installation tab), a class diagram of our domain classes should be available under http://localhost:8080/yourApp/classDiagram:

Changing diagram preferences

You can change your diagram preferences in the preferences dialog. Most items provide a tooltip for details.

New for version 0.5 is the class filtering edit box. Check the tooltip for samples!

Legend

The following relations are recognized:

Configuration file

Below follows a copy of the plugins configuration. It is easy to override: just pick one or more of the properties you want to change and add it to your Config.groovy.

Yo can change diagram appearance (such as colors and node/edge shapes), and you may create your own skins. You also can change most graphviz attributes.

If you don't want to clutter your Config.groovy file, you can also change the plugin configuration. If, for instance, the plugin is installed globally you will find the config file under something like ~/.grails/1.2.0/global-plugins/grails-class-diagram-0.5.1/conf/ClassDiagramConfig.groovy.

/**
 * Default properties. May be overridden in Config.properties for each project
 */
graphviz {
    dot.executable = "dot" // include full file path if not on path
}

classDiagram { preferences { defaults { // Defaults used in preferences form. skin = "regular" outputFormat = "png" // Should be an image format from http://www.graphviz.org/doc/info/output.html showProperties = true showMethods = true showAssociationNames = true showMethodReturnType = true showMethodSignature = false showPropertyType = true showEmbeddedAsProperty = false showPackages = false autoUpdate = true classSelection = "<all>" classSelectionIsRegexp = false graphOrientation = "TB" // See http://www.graphviz.org/doc/info/attrs.html#k:rankdir for valid values fontsize = 9 } } associations { arrows { // See http://www.graphviz.org/doc/info/arrows.html for available arrowheads and their visual appearance references = "open" belongsTo = "odiamond" embedded = "diamond" inherits = "onormal" none = "none" } decorators { // plain text to be shown on edge ends hasOne = "1" hasMany = "*" none = "" } } skins { // See http://graphviz.org/doc/info/attrs.html for available properties on graph, node and edge. // You may use any property except the 'shape' property (it is set internally to [shape:'record']). // Also, if you use the fontsize property, the gui size slider will not be able to override it. classic { name = "Classic" graphStyle = [bgcolor:"white"] nodeStyle = [style:"rounded,filled", color:"blue", fillcolor:"azure2", fontname:"Verdana"] edgeStyle = [color:"gray40", fontname:"Verdana"] packageStyle = [style:"rounded,filled", color:"gray95", fontname:"Verdana"] } classicSpaced { name = "Classic Spaced" graphStyle = [bgcolor:"white", mclimit:100, nodesep:'0.75 equally', ranksep:'0.75 equally'] nodeStyle = [style:"rounded,filled", color:"blue", fillcolor:"azure2", fontname:"Verdana", fontsize:18] edgeStyle = [color:"gray40", fontname:"Verdana", fontsize:18, labelfontsize:20, labeldistance:3.5] packageStyle = [style:"rounded,filled", color:"gray95"] } regular { name = "Regular" graphStyle = [bgcolor:"white"] nodeStyle = [style:"filled", color:"lightyellow3", fillcolor:"lightyellow", fontname:"Verdana"] edgeStyle = [color:"gray40", fontname:"Verdana"] packageStyle = [style:"filled", color:"gray95", fontname:"Verdana"] } white { name = "White on Gray" graphStyle = [bgcolor:"gray90"] nodeStyle = [style:"filled", color:"gray40", fillcolor:"white", fontname:"Verdana"] edgeStyle = [color:"gray40", fontname:"Verdana"] packageStyle = [style:"", color:"gray40", fontname:"Verdana"] } gray { name = "Gray" graphStyle = [bgcolor:"white"] nodeStyle = [style:"filled", color:"gray40", fillcolor:"gray90", fontname:"Verdana"] edgeStyle = [color:"gray40", fontname:"Verdana"] packageStyle = [style:"filled", color:"gray95", fontname:"Verdana"] } } legend { style { graphStyle = [bgcolor:"gray94", margin:"0,0", size:"7,7"] nodeStyle = [style:"filled", color:"gray50", fillcolor:"white", margin:"0,0", fontsize:15, fontname:"Verdana"] edgeStyle = [color:"gray50", fontsize:15, fontname:"Verdana"] packageStyle = [style:"filled", color:"gray94", fontname:"Verdana"] } } }

Credits

Thanks to Merlyn Albery-Speyer's blogs on the subject. The DotBuilder was based on his idea. Also thanks to Frank Schoep for his blog on UML diagrams using graphviz. And of course thanks to the people behind the fantastic graphviz utility.

Release notes

0.5.1 Fix

  • GRAILSPLUGINS-1931 - Associations now shows up as properties
0.5 Fixes & features
  • GRAILSPLUGINS-1587 - Enum classes appears outside all package (when using package view)
  • GRAILSPLUGINS-1618 - In One-to-Many relationships the belongsTo diamond is not always shown by class-diagram.
  • GRAILSPLUGINS-1926 - css files in show.gsp are not correctly referenced
  • GRAILSPLUGINS-1740 - Too many inheritance associations
  • GRAILSPLUGINS-1589 - User should be able to select domain class subset
0.4.1 Fixes
  • GRAILSPLUGINS-1607: java.lang.StringIndexOutOfBoundsException for 1-char-long property names.
  • GRAILSPLUGINS-1583: Show association name from both directions
0.4 Fixes & Features.
  • GRAILSPLUGINS-1559: WAR-packaged application fails to start if deployed with Class diagram plugin
  • Default preferences configurable.
  • Classes can now be shown grouped in packages
  • Graphviz 2.24 fix: translates bgcolor:none to black, while prior versions translate to white! Fixed
  • Default outputFormat is now png
  • Properties page now initially invisible
  • Non-image outputFormats like svg and pdf now works, even from form
  • New skin, classicSpaced, that use graphviz options to get more 'space' around nodes. Contributed by Gavin Kromhout.
  • Preferences defaults can now be configured
  • Legend: not loaded before required, and brushed up
  • GUI form state fixes: Hiding menu now conservers preferences; enter-key now synonymous with pushing 'Update'.
  • DotBuilder now supports subgraphs
  • Added property for graph orientation: top to bottom or left to right
  • (cleaned up CSS a bit)
  • (reformatted code to 4 spaces indentation, not tabs)
0.3 Brush-up. Added support for embedded objects, provided a GUI for changing properties, re-ordering

0.2 Bugfix. Removed domain classes in sub-packages when packaging plugin.

0.1 Initial release

Backlog

See JIRA for the official backlog and doc/NOTES.txt for details and future ideas.
  • Which output formats has been tested and is known to work?
    • A: image formats: png, jpg, gif, bmp; Other: pdf, eps, svg, dot
  • I am running IE 7 and the preferences dialog looks awful.
    • A: Find a CSS guru and contribute, or move to another browser. I just cannot make it work :) The plugin is known to work on Firefox 3.5.7, Safari 4.0.4 and Chrome 4.0.249.49.
  • Image is blurry (when the menu is visible).
    • A: This is probably because the browser has zoom on. Workaround: Either reset the zoom in the browser, or click the image
  • The image doesnt size when I move the size slider.
    • A: This may occur if your skin has hardcoded fontsize. Use another skin or create your own.
  • IE does not know what to do with non image formats.
    • A: IE uses the file name extension and may not recognise the mime type.
    • A: Save the file and give it the appropriate extension e.g. model.pdf