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

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