The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....


Unit: SDL_rchart
Class: TContourPlot
Declaration: OnScalesRendered: TRenderEvent;
{ TRenderEvent = procedure (Sender: TObject; canvas: TCanvas; Top, Left: integer) of object; }

The events OnBeforeRenderData, OnDataRendered and OnScalesRendered  provide hooks for adding user defined graphics to the contour plot. Internally, a chart is constructed in three phases before the result is copied to the screen: in the first phase the scales are drawn, then the data is drawn and finally the crosshairs are rendered. The OnScalesRendered event is triggered after the scales are drawn giving access to the non-data areas of the contour plot (i.e. the areas where the scales and captions are drawn). The events OnBeforeRenderData and OnDataRendered are triggered before and after drawing the chart. Note that the latter two events give access to the chart canvas (the area where the chart elements are is drawn).

The event OnScalesRendered occurs after the scales of the chart has been drawn and before the data is drawn. The variable parameter Canvas provides access to the canvas of the data area. Please note that the state of the canvas (e.g. the color of its pen, or the fill mode of the brush) depends on the graphics elements drawn before. The parameters Top and Left are always zero.

Hint 1: Graphic elements outside the scales area (i.e. the area which is defined by the properties MarginLeft, MarginTop, MarginRight, and MarginBottom) are cut automatically.

Hint 2: In order modify individual ticks of the scales you should use the event OnScaleTickDrawn.

Hint 3: Please note that drawing graphic elements in the OnScalesRendered event does not create an entry in the data container. Thus you are at your own as far as the management of these drawing elements is concerned.

Hint 4: In order to avoid unwanted size effects regarding characters displayed on canvases of different resolution (i.e. the screen and a printer) you should never directly assign the font size within the event. Use SetCanvasFontSizeScaled instead. So, for example, the statement Canvas.Font.Size := 12; should be replaced by SetCanvasFontSizeScaled (Canvas, 12);

Example: Following is an example on how to implement user defined graphics on top of the contour plot. It displays the text HALLO twice, one text is positioned at absolute coordinates (120,120), the other text is drawn relative to the world-coordinates at position [20.0, 1.0]. Note that the method R2M returns coordinates relative to the chart window (and not relative to the data area); you have therefore subtract Top and Left before positioning the graphics.

procedure TForm2.CPlot1ScalesRendered (Sender: TObject;
             var Canvas: TCanvas;  Top, Left: integer);

  xout,yout: longint;

canvas.Font.Color := clBlue;
Canvas.TextOut (120,120,'HALLO');
CPlot1.R2M (20.0, 1.0, xout,yout);
Canvas.TextOut (xout-Left, yout-Top,'HALLO');

Last Update: 2023-Dec-13