home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 25: Programming / pc_actual_25.iso / Delphi / TeeChartPro / TeeChart5Delphi5Eval.exe / %MAINDIR% / Examples / Features / CurveFitting_Dynamic.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-09-10  |  3.7 KB  |  144 lines

  1. unit CurveFitting_Dynamic;
  2.  
  3. interface
  4.  
  5. uses
  6.   WinTypes,WinProcs, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, Buttons, TeEngine, CurvFitt, Series, ExtCtrls, TeeProcs, Chart,
  8.   TeeFunci, TeeComma, TeeTools;
  9.  
  10. type
  11.   TDynamicTrend = class(TForm)
  12.     Chart1: TChart;
  13.     Series1: TFastLineSeries;
  14.     Timer1: TTimer;
  15.     Series2: TAreaSeries;
  16.     Series3: TLineSeries;
  17.     TeeFunction2: TCurveFittingFunction;
  18.     Panel2: TPanel;
  19.     GroupBox1: TGroupBox;
  20.     Label1: TLabel;
  21.     Label2: TLabel;
  22.     ScrollBar3: TScrollBar;
  23.     ScrollBar4: TScrollBar;
  24.     GroupBox2: TGroupBox;
  25.     Label3: TLabel;
  26.     Label4: TLabel;
  27.     ScrollBar1: TScrollBar;
  28.     ScrollBar2: TScrollBar;
  29.     TeeFunction1: TCurveFittingFunction;
  30.     TeeCommander1: TTeeCommander;
  31.     ChartTool1: TRotateTool;
  32.     procedure ScrollBar2Change(Sender: TObject);
  33.     procedure ScrollBar1Change(Sender: TObject);
  34.     procedure Timer1Timer(Sender: TObject);
  35.     procedure ScrollBar3Change(Sender: TObject);
  36.     procedure ScrollBar4Change(Sender: TObject);
  37.     procedure FormCreate(Sender: TObject);
  38.   private
  39.     { Private declarations }
  40.     Procedure ResizeFunction(AFunction:TCustomFittingFunction; APos:Longint);
  41.     Procedure Movefunction(AFunction:TCustomFittingFunction; APos:Longint);
  42.   public
  43.     { Public declarations }
  44.   end;
  45.  
  46. implementation
  47.  
  48. {$R *.DFM}
  49.  
  50. Procedure TDynamicTrend.ResizeFunction(AFunction:TCustomFittingFunction; APos:Longint);
  51. begin
  52.   With AFunction do
  53.   begin
  54.     if (FirstPoint+APos)<((ParentSeries.DataSource) as TChartSeries).Count then
  55.     begin
  56.       BeginUpdate;
  57.       LastPoint:=FirstPoint+APos;
  58.       FirstCalcPoint:=FirstPoint;
  59.       LastCalcPoint:=LastPoint;
  60.       EndUpdate;
  61.       ScrollBar1.Max:=Series1.Count-APos;
  62.     end;
  63.   end;
  64. end;
  65.  
  66. Procedure TDynamicTrend.MoveFunction(AFunction:TCustomFittingFunction; APos:Longint);
  67. var tmp:Longint;
  68. begin
  69.   with AFunction do
  70.   begin
  71.     tmp:=LastPoint-FirstPoint;
  72.     if APos+tmp<(ParentSeries.DataSource as TChartSeries).Count then
  73.     begin
  74.       BeginUpdate;
  75.       FirstPoint:=APos;
  76.       LastPoint:=FirstPoint+tmp;
  77.       FirstCalcPoint:=FirstPoint;
  78.       LastCalcPoint:=LastPoint;
  79.       EndUpdate;
  80.     end;
  81.   end;
  82. end;
  83.  
  84. procedure TDynamicTrend.ScrollBar2Change(Sender: TObject);
  85. begin
  86.   ResizeFunction(TeeFunction2,ScrollBar2.Position);
  87. end;
  88.  
  89. procedure TDynamicTrend.ScrollBar1Change(Sender: TObject);
  90. begin
  91.   MoveFunction(TeeFunction2,ScrollBar1.Position);
  92. end;
  93.  
  94. procedure TDynamicTrend.Timer1Timer(Sender: TObject);
  95. begin
  96.   With ScrollBar1 do
  97.   begin
  98.     if Position<Max-1 then Position:=Position+1
  99.                       else Position:=Min
  100.   end;
  101.   With ScrollBar3 do
  102.   begin
  103.     if Position<Max-1 then Position:=Position+1
  104.                       else Position:=Min
  105.   end;
  106. end;
  107.  
  108.  
  109. procedure TDynamicTrend.ScrollBar3Change(Sender: TObject);
  110. begin
  111.   MoveFunction(TeeFunction1,ScrollBar3.Position);
  112. end;
  113.  
  114. procedure TDynamicTrend.ScrollBar4Change(Sender: TObject);
  115. begin
  116.   ResizeFunction(TeeFunction1,ScrollBar4.Position);
  117. end;
  118.  
  119. procedure TDynamicTrend.FormCreate(Sender: TObject);
  120. begin
  121.   { set function first and last points }
  122.   TeeFunction1.FirstPoint:=10;
  123.   TeeFunction1.LastPoint:=40;
  124.   TeeFunction1.FirstCalcPoint:=10;
  125.   TeeFunction1.LastCalcPoint:=40;
  126.   TeeFunction2.FirstPoint:=40;
  127.   TeeFunction2.LastPoint:=70;
  128.   TeeFunction2.FirstCalcPoint:=40;
  129.   TeeFunction2.LastCalcPoint:=70;
  130.  
  131.   { add sample random values to red line }
  132.   Series1.FillSampleValues(280);
  133.   ScrollBar1.Max:=Series1.Count;
  134.   ScrollBar3.Max:=Series1.Count;
  135.  
  136.   { default size in number of points }
  137.   ScrollBar2.Position:=30;
  138.   ScrollBar4.Position:=30;
  139. end;
  140.  
  141. initialization
  142.   RegisterClass(TDynamicTrend);
  143. end.
  144.