Logo

15.3.5 Specifying shapes

A Shape represents the specification of how a GraphElement should be drawn. There are several types of Shapes available, both for Nodes and for Edges.

The visual appearance of Shapes can be parameterized using blocks that take the entity behind the GraphElement as parameter. For example, if we have a class entity, we can specify the height: of a RectangleShape by:

MORectangleShape new height: [ :class |
class numberOfMethods ].

As a convenience, if the computation is provided by a simple message to be sent to the entity, we can use a abbreviated form:

MORectangleShape new height: #numberOfMethods.

Furthermore, if we deal with a constant, we can directly pass the value:

MORectangleShape new height: 10.

Typically, shapes are created via the scripting interface provided by ShapeSelector. For example, to create a RectangleShape with width and height, we can write:

view shape rectangle 
height: #numberOfMethods;
width: [ :class | class numberOfAttributes ].

To attach this shape to a GraphElement, we simply have to define it before a nodes: or edges:from:to: instructions (or the variations of these). So, to specify shapes for nodes and edges, we can write:

view shape rectangle 
height: #numberOfMethods;
width: [ :class | class numberOfAttributes ].
view nodes: (MooseModel root allModels allModelClasses reject: #isInterface).

view shape verticalOrthogonalLine color: Color veryVeryLightGray.
view edgesFrom: [ :class | class superclass ].

If no shape is specified, the default shape is chosen: for nodes the default shape is a square, and for edges the default shape is a line. Furthermore, once a nodes: or edges:from:to: instruction is executed, the shape is reset to the default shape. Thus, in the following example, only the first set of nodes (the interfaces) is represented with text labels, the second (the actual classes) being shown using the default rectangle:

"the interfaces are displayed with a label"
view shape label text: [ :class | class name ].
view nodes: (MooseModel root allModels allModelClasses select: #isInterface).

"the non interfaces are displayed with the default square shape"
view nodes: (MooseModel root allModels allModelClasses reject: #isInterface)

For building complex shapes, Mondrian offers the FormsBuilder, a small engine inspired from the Java implementation with the same name that offers a Form Layout (see http://www.jgoodies.com/articles/forms.pdf).

An example of a complex shape is a UML package diagram.

script

User Contributed Notes

norbert (3 April 2013, 9:48 pm)

The link to JGoodies pdf s broken

tudor (8 January 2013, 11:31 pm)

Thanks LukeDunstan81. I adopted the suggested corrections.

LukeDunstan81 (8 January 2013, 2:26 pm)

Corrections:

 

RecangleShape -> RectangleShape

reseted -> reset

a text labels -> text labels

tudor (24 July 2011, 11:59 am)

They are not :) . The first is select, the second is reject. In any case, I now marked it more explicitly with comments.

damien.cassou (24 July 2011, 9:54 am)

In the last example, the two sets of nodes are identical:

 

view nodes: (MooseModel root allModels allModelClasses select: #isInterface).

view nodes: (MooseModel root allModels allModelClasses reject: #isInterface).

Add a Note