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....



OnScaleTickDrawn


Unit:SDL_scale
Class: TScale
Declaration: OnScaleTickDrawn: TScaleTickDrawnEvent;
{ TScaleTickDrawnEvent = procedure (Sender: TObject; Canvas: TCanvas; ScaleType: TScaleType; CurrentTickPos: double; ChartX, ChartY: integer) of object; }

The OnScaleTickDrawn event provides a hook for adding or modifying individual scale ticks. The event OnScaleTickDrawn occurs whenever a tick mark on a scale has been 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 parameter ScaleType specifies to which type of scale the tick mark belongs to. The parameter CurrentTickPos holds the numeric value which corresponds to the tick mark, and the parameters ChartX and ChartY contain the position of the tick mark on the canvas.

Hint 1: The declaration of this event has been changed with the introduction of release 10.1 of the SDL Suite. Please see the corresponding type declaration and the section How to Deal with a Canvas Reference Change for details.

Hint 2: Graphic elements outside the scales area are cut automatically.

Hint 3: 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 draw user defined labels on the left y-axis. The left y-axis is labeled by hexadecimal numbers instead of the standard decimal numbers. Please note that the property LabelType has to be set to ftNoFigs in order to prevent the standard labels from being displayed. The function hex is part of unit math1.

procedure TForm2.Scale1ScaleTickDrawn (Sender: TObject; Canvas: TCanvas;
                               ScaleType: TScaleType; CurrentTickPos: double;
                               ChartX, ChartY: integer);

var
  astr   : string;
  tw, th : integer;

begin
if ScaleType = sctYL then
  begin
  astr := hex(round(CurrentTickPos),8);
  tw := canvas.TextWidth(astr);
  th := canvas.TextHeight(astr);
  Canvas.TextOut (ChartX-tw-8, ChartY-(th div 2), astr);
  end;
end;


Last Update: 2023-Dec-13