Component Placement
Every component has a placement rectangle stored in an SRGraphRect object. The definition of an SRGraphRect rectangle is similar to that of a CRect object with left, top, right, and bottom extents. The four positions are defined in a floating-point format so that a component can be accurately placed when using device independent coordinates. Thus, SRGraphRect can position a component according to one of four measurement modes. These are: Pixel, Metric (millimeters), Imperial (inches), and Percentage.
*Pixel placement positions the rectangle to an absolute point on screen or in print. Therefore, if your screen has 72 pixels per inch and your printer has 600 pixels per inch, then the printed image will be considerably smaller than the on-screen one.
*Metric and Imperial placement using inches and millimeters produce images that are the same size on screen and printer.
*The Percentage mode automatically repositions the component rectangle so that it always occupies the same fraction of the available drawing area. This mode is particularly useful if the display window can be resized by the end user.
The functions SRGraphComponent::SetRect() and SetMeasurement() set the position rectangle coordinates and the measurement mode.
The parameter to SetMeasurement() can be one of:
SetMeasurement() calls SetSizeDefaults() to set default margins, tick sizes, and legend key sizes to values appropriate for the selected measurement mode.
SetRect() can specify rectangles that automatically expand to fill the available space in one or more directions. If you use a –1 value when setting a rectangle’s right side, then that side locks to the right most position in the window in which the component is displayed. Setting –1 in all four parameters makes the component cover all of the available space.
The Objective Chart functions GetFinalRect() and CalcFinalRect() facilitate repositioning of resizeable components by users.
The two functions return the same information, but CalcFinalRect() can be used during chart setup while GetFinalRect() only works after the chart has been drawn.
For standard (nonresizeable) components both functions return the rectangle specified by SetRect().
The resizeable components — SRGraphTitleResizeable, SRGraphLegend, SRGTextPanel— store the final, resized rectangle, m_FinalRect, during the draw process and override CalcFinalRect() to estimate the final rectangle before it is drawn.
The code below demonstrates how CalcFinalRect() can be used in OnInitialUpdate() to position other components around a resizeable component.
SRGraphTitleResizeable* pTitle = new SRGraphTitleResizeable;
[ ... ] // other initialization omitted for brevity
m_Graph.AddComponent((SRGraphComponent *)pTitle);
SRGraphRect rectTitle = pTitle->CalcFinalRect(pDC, this);
SRGraphDisplay *pDisplay = new SRGraphDisplay;
pDisplay->SetRect(-1, rectTitle.bottom+1,-1,-1);
[ ... ]