A legend is essential as soon as non-trivial data is visualized. Unless a visualization is frequently used or highly intuitive, a legend is necessary to guide the user with all the different visual cues.
RTLegendBuilder is the main class to build legends. It offers facilities that are both easy to use and flexible enough to accomodate most of the need.
A legend is created with the following steps:
buildhas to be sent to the builder
As a first example, consider the following code snippet that simply visualizes some classes. The visualization uses a color to indicate a particular threshold on the color of each class. The size of a class reflects the number of methods of the class, and if the number of lines of code of the class is below 1,000 then the class is green, otherwise it is red (Figure 1.1):
The first code given above creates a small visualization and adds a legend to it.
The legend is available on-demand, meaning that the user has to locate the mouse cursor above the
? character, located on the top-left corner of the visualization. The view, referenced by the variable
v, has to be passed to the legend builder. The legend then has to be configured. The message
addText: provides a descriptive text of the legend and
addColor:text: is used to give a meaning to a color. The message
build adds the legend in the view
RTLegendBuilder offers many utility methods to build expressive legends. In particular:
addText:adds a text to the legend
addColor: aColor text: aTextprovides a textual description of a color
addColorFadingFrom: startColor to: endColor text: textualDescriptionuseful for describing a color fading ranging from
addColorFadingUsing: colors text: textualDescriptiondescribes a fading based on the provided set of colors.
addLineColor: aColor text: aTextassociates a text to a colored line
addRectanglePolymetricWidth: widthDescription height: heightDescription box: boxDescriptionassociates a description to the height, width, and the color of a box
Clearly indicating the meaning of the different visual dimensions is highly important to make the visualization accessible. The following example adds a legend to a simple visualization of some classes (Figure 3.1):
A description of each metric is provided using the message