Logo

15.3.7 Conventions for Mondrian scripts

The variable holding the instance of a ViewRenderer is typically named view.

When implementing a visualization, it is advisable to create two methods: one that specifies the visualization for a view received as parameter, and one that actually instantiates the view and calls the first method.

For example, a simple class hierarchy visualization would be implemented in the FAMIXClassGroup class as in the following two methods:

FAMIXClassGroup>>viewSimpleHierarchyOn: view
view shape label text: #name.
view nodes: self.
view edgesFrom: #superclass.
view treeLayout
FAMIXClassGroup>>viewSimpleHierarchy
| view |
view := MOViewRenderer new.
self viewHierarchyOn: view.
view open

The second method instantiates the ViewRenderer , it delegates to the first method for the actual specification of the visualization, and it finally opens the visualization.

At first sight, the second method is the useful one as it allows us to open conveniently the visualization when we have a class group. Furthermore, having this script available in a unary method (i.e., without parameters), also allows us to register it as a menu item by adding a Pragma

FAMIXClassGroup>>viewSimpleHierarchy
<menuItem: 'Simple hierarchy' category: 'Visualize'>
| view |
view := MOViewRenderer new.
self viewHierarchyOn: view.
view open

However, the first method is also particularly useful when we want to reuse the logic of the visualization in other contexts. For example, suppose that in a visualization showing the hierarchy of namespaces we want to show the hierarchy of classes when we hover over a namespace:

FAMIXNamespaceGroup>>viewSimpleHierarchyOn: view
view interaction popupView: [ :eachNamespace :popupView |
eachNamespace classes viewSimpleHierarchyOn: popupView ].
view nodes: self.
view edgesFrom: #parentScope.
view treeLayout

Add a Note