home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Delphi1_And_Delphi2 / EXAMPLES / EXTENDED / UISOAXIS.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-24  |  3.7 KB  |  144 lines

  1. unit UISOAxis;
  2.  
  3. interface
  4.  
  5. uses
  6.   WinTypes,WinProcs, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, Buttons, TeEngine, Series, ExtCtrls, TeeProcs, Chart;
  8.  
  9. { See below the MakeISOAxis routine.
  10.   This routine will change the axis scales to be isometric
  11.   with the screen size and video mode pixel size.
  12.  
  13.   So, both the Left and Bottom axis will have equivalent
  14.   distance on screen for the same Axis Increment.
  15.   This makes the grid lines to appear "squared".
  16. }
  17.  
  18. type
  19.   TIsoMetricAxisForm = class(TForm)
  20.     Chart1: TChart;
  21.     Series1: TFastLineSeries;
  22.     ScrollBar1: TScrollBar;
  23.     Label1: TLabel;
  24.     Label2: TLabel;
  25.     Button1: TButton;
  26.     Button2: TButton;
  27.     CheckBox1: TCheckBox;
  28.     procedure Chart1UndoZoom(Sender: TObject);
  29.     procedure ScrollBar1Change(Sender: TObject);
  30.     procedure FormCreate(Sender: TObject);
  31.     procedure Chart1Zoom(Sender: TObject);
  32.     procedure Button1Click(Sender: TObject);
  33.     procedure Button2Click(Sender: TObject);
  34.     procedure CheckBox1Click(Sender: TObject);
  35.   private
  36.     { Private declarations }
  37.   public
  38.     { Public declarations }
  39.   end;
  40.  
  41. var
  42.   IsoMetricAxisForm: TIsoMetricAxisForm;
  43.  
  44. implementation
  45.  
  46. {$R *.DFM}
  47.  
  48. { Call this function with a Chart or DBChart component
  49.   to adjust the axis scales isometrically:
  50.  
  51.     MakeISOAxis( Chart1 );
  52. }
  53. Procedure MakeIsoAxis(AChart:TCustomChart);
  54. var tmpX,tmpY,XRange,YRange,Offset,XYScreen:Double;
  55. begin
  56.   With AChart do
  57.   if (ChartHeight>0) and (ChartWidth>0) then
  58.   begin
  59.     With BottomAxis do XRange:=Maximum-Minimum;
  60.     With LeftAxis do   YRange:=Maximum-Minimum;
  61.  
  62.     XYScreen:=1.0*(GetDeviceCaps(Canvas.Handle,HORZSIZE)/Screen.Width)/
  63.                   (GetDeviceCaps(Canvas.Handle,VERTSIZE)/Screen.Height);
  64.  
  65.     tmpX:=(XRange/ChartWidth);
  66.     tmpY:=(YRange/ChartHeight)*XYScreen;
  67.  
  68.     if tmpX>tmpY then
  69.     begin
  70.       if tmpY<>0 then
  71.       begin
  72.         Offset:=((YRange*tmpX/tmpY)-YRange)/2.0;
  73.         With LeftAxis do SetMinMax(Minimum-Offset,Maximum+Offset);
  74.       end;
  75.     end
  76.     else
  77.     if tmpX<>0 then
  78.     begin
  79.       Offset:=((XRange*tmpY/tmpX)-XRange)/2.0;
  80.       With BottomAxis do SetMinMax(Minimum-Offset,Maximum+Offset);
  81.     end;
  82.   end;
  83. end;
  84.  
  85. { If user unzooms the Chart with left mouse button, repeat isoaxis: }
  86. procedure TIsoMetricAxisForm.Chart1UndoZoom(Sender: TObject);
  87. begin
  88.   MakeISOAxis(Chart1);
  89. end;
  90.  
  91. { This scrollbar is used in this example to change the axes increment... }
  92. procedure TIsoMetricAxisForm.ScrollBar1Change(Sender: TObject);
  93. begin
  94.   With Chart1 do
  95.   begin
  96.     LeftAxis.Increment  :=ScrollBar1.Position*10;
  97.     BottomAxis.Increment:=ScrollBar1.Position*10;
  98.     Label2.Caption:=FloatToStr(LeftAxis.Increment);
  99.   end;
  100. end;
  101.  
  102. { Add sample value and initialize the example controls... }
  103. procedure TIsoMetricAxisForm.FormCreate(Sender: TObject);
  104. begin
  105.   Series1.FillSampleValues(100);
  106.   ScrollBar1Change(Self);
  107.   CheckBox1Click(Self);
  108. end;
  109.  
  110. { After Zooming the Chart, remake ISO axis: }
  111. procedure TIsoMetricAxisForm.Chart1Zoom(Sender: TObject);
  112. begin
  113.   MakeISOAxis(Chart1);
  114. end;
  115.  
  116. procedure TIsoMetricAxisForm.Button1Click(Sender: TObject);
  117. begin
  118.   Close;
  119. end;
  120.  
  121. procedure TIsoMetricAxisForm.Button2Click(Sender: TObject);
  122. begin
  123.   MakeISOAxis(Chart1);
  124. end;
  125.  
  126. { When Axis.LabelsSeparation is zero, the axis will
  127.    display all labels without checking for anti-overlapping.
  128. }
  129. procedure TIsoMetricAxisForm.CheckBox1Click(Sender: TObject);
  130. begin
  131.   if CheckBox1.Checked then
  132.   begin
  133.     Chart1.LeftAxis.LabelsSeparation:=0;
  134.     Chart1.BottomAxis.LabelsSeparation:=0;
  135.   end
  136.   else
  137.   begin
  138.     Chart1.LeftAxis.LabelsSeparation:=10;
  139.     Chart1.BottomAxis.LabelsSeparation:=10;
  140.   end;
  141. end;
  142.  
  143. end.
  144.