As we have seen previously, a builder models user input and represents it by building a RTView. Visualizations produced by builders may be composed with other visualizations. This is particularly useful when two visualizations may be "glued" together to form a complex one.
In essence, the composition of several builders is achieved by sharing a unique view among these builders and properly ordering elements added by each view. The class RTComposer specifically fulfills that purpose.
The variable data contains four numbers and represents the input of the script. Two visualizations are composed, using RTGrapher and RTPieBuilder. The variable c represents a composer. The two visualizations are composed of:
Sharing the view to both builders. This is carried out with g view: c view and b view: c view
After invoking build on a builder, the composer needs to snapshot the elements and give a name. The expression c group: #graph gives the name #graph to the elements added by RTGrapher. Similarly, elements added by RTMondrian are named #mondrian.
Adequately positioning elements produced by the builders. The expression c move: #graph onTheLeftOf: #mondrian performs this operation.
2. Propagating events
Events may be propagated from one builder to another. The method propagateHighlight defined on the class RTComposer serves this purpose. Consider a slightly different version of the previous script.
In total, four bars and four squares are represented. Each group contains the model given by the variable data. Using propagateHighlightToAll highlights elements in the view that have the same model. This is useful when elements have to be globally highlighted.
3. Titled visualization
It often happens that visualizations have to be given a title to make the overall picture meaningful. The class RTComposer offers the method nameGroup:as: to set a title to element groups. Consider the extension of the previous script (Figure 3.1):
4. World population Example
The following example gives two representation of the World population. Using a geographical map and a bar chart (Figure 4.1):