Building a Compound Display
You’ve seen that the SRGCompoundDisplay class allows the piecemeal construction of charts from sub-components. The most important thing to remember is that there are four similar axes and that those axes may have any of six component items added, removed, or modified at any time.
There are generally two methods for adding or registering a component to an axis (technically, an SRGAxisManager). The first uses a black-box function in the SRGCompoundDisplay to obtain a pointer to the relevant axis and then call the correct registration function. The second is to perform the operation explicitly. Both methods are equally correct. For example, in the CChart example discussed in “CChart Example”, the command
may be interchanged freely with
The axes are placed as follows. There are two x-axes and two y-axes. The x-axis that corresponds to the bottom of the chart rectangle is XAxisA. The opposite x-axis, for the top of the rectangle, is XAxisB. Similarly, the left most y-axis is YAxisA and the right most y-axis is YAxisB. Pointers to these axes may be obtained by using the appropriate function, for example, SRGCompoundDisplay::GetXAxisA().
Each axis manager has a set of registration functions that allow tick marks, grid lines, display, scale labels, title label, and data watcher to be added to the axis. There is also a corresponding set of functions (demonstrated below) that un-register the component. The unregistered component can be destroyed or a pointer to it can be returned so that it can be recycled and destroyed at a later time.
To add a title label to an axis:
SRGraphLabel *pL=new SRGraphLabel;
pL->SetAnnotation("This is a Title");
To remove the title and automatically delete it:
To adjust some aspect of the title, such as the font size:
SRGraphLabel *pL=pCD->GetXAxisA()->GetTitle();
NOTE >> The validity of the pointer should always be tested. If an attempt is made to retrieve a pointer to an item that has not yet been registered, a null pointer is returned.
Because the SRGCompoundDisplay and its sub-component SRGAxisManager use lists of items based upon certain Objective Chart components, it is possible to use derived components in their places. For example, any display class derived from SRGraphDisplay may be used in a compound display simply by registering it in the manner described above. Likewise, a special SRGDecimalScale-derived class can be used to provide custom axis labels.
The sub-components of a compound display are drawn in order of placement on the sub-component list. The axis managers are drawn in Ya Xa Yb Xb order. This implies that a display class attached to the Ya axis may be overwritten by the grid lines of the Xa axis manager. For this reason the DeferredDraw property has been added to the component architecture. This allows all items that should be on top to have their final pass-two draw deferred until all other items have been drawn. If a display should be shown on top, then call the SetDeferDraw(TRUE) method for the display. If the grid lines should overprint the displays, then call SetDeferDraw(TRUE) for the grid-line objects instead.