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:
RTLegendBuilder
addText:
, addColor:text:
)below
, above
, onDemand
). build
has to be sent to the builderAs 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 v
.
The class RTLegendBuilder
offers many utility methods to build expressive legends. In particular:
addText:
adds a text to the legendaddColor: aColor text: aText
provides a textual description of a coloraddColorFadingFrom: startColor to: endColor text: textualDescription
useful for describing a color fading ranging from startColor
to endColor
addColorFadingUsing: colors text: textualDescription
describes a fading based on the provided set of colors.addLineColor: aColor text: aText
associates a text to a colored lineaddRectanglePolymetricWidth: widthDescription height: heightDescription box: boxDescription
associates a description to the height, width, and the color of a boxClearly 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 addRectanglePolymetricWidth:height:box:
.