home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Src Code / TEEFUNCI.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-24  |  6.7 KB  |  246 lines

  1. {*************************************}
  2. {    TeeChart Functions               }
  3. { Copyright (c) 1996 by David Berneda }
  4. {    All Rights Reserved              }
  5. {*************************************}
  6. {$I teedefs.inc}
  7. unit TeeFunci;
  8.  
  9. interface
  10.  
  11. Uses Classes,TeEngine;
  12.  
  13. Type TBasicTeeFunction=class(TTeeFunction)
  14.      end;
  15.  
  16.      TAddTeeFunction=class(TTeeFunction)
  17.      public
  18.        Function Calculate(SourceSeries:TChartSeries; FirstIndex,LastIndex:Longint):Double; override;
  19.        Function CalculateMany(SourceSeriesList:TList; ValueIndex:Longint):Double;  override;
  20.      end;
  21.  
  22.      TManySeriesTeeFunction=class(TTeeFunction)
  23.      protected
  24.        Function CalculateValue(Const AResult,AValue:Double):Double; virtual; abstract;
  25.      public
  26.        Function CalculateMany(SourceSeriesList:TList; ValueIndex:Longint):Double;  override;
  27.      end;
  28.  
  29.      TSubtractTeeFunction=class(TManySeriesTeeFunction)
  30.      protected
  31.        Function CalculateValue(Const AResult,AValue:Double):Double; override;
  32.      end;
  33.  
  34.      TMultiplyTeeFunction=class(TManySeriesTeeFunction)
  35.      protected
  36.        Function CalculateValue(Const AResult,AValue:Double):Double; override;
  37.      end;
  38.  
  39.      TDivideTeeFunction=class(TManySeriesTeeFunction)
  40.      protected
  41.        Function CalculateValue(Const AResult,AValue:Double):Double; override;
  42.      end;
  43.  
  44.      THighTeeFunction=class(TTeeFunction)
  45.      public
  46.        Function Calculate(SourceSeries:TChartSeries; FirstIndex,LastIndex:Longint):Double; override;
  47.        Function CalculateMany(SourceSeriesList:TList; ValueIndex:Longint):Double;  override;
  48.      end;
  49.  
  50.      TLowTeeFunction=class(TTeeFunction)
  51.      public
  52.        Function Calculate(SourceSeries:TChartSeries; FirstIndex,LastIndex:Longint):Double; override;
  53.        Function CalculateMany(SourceSeriesList:TList; ValueIndex:Longint):Double;  override;
  54.      end;
  55.  
  56.      TAverageTeeFunction=class(TTeeFunction)
  57.      public
  58.        Function Calculate(SourceSeries:TChartSeries; FirstIndex,LastIndex:Longint):Double; override;
  59.        Function CalculateMany(SourceSeriesList:TList; ValueIndex:Longint):Double;  override;
  60.      end;
  61.  
  62. implementation
  63.  
  64. Uses SysUtils,TeeProcs,TeeConst;
  65.  
  66. { Add }
  67. Function TAddTeeFunction.Calculate(SourceSeries:TChartSeries; FirstIndex,LastIndex:Longint):Double;
  68. var t:Longint;
  69. begin
  70.   With ValueList(SourceSeries) do
  71.   if FirstIndex=TeeAllValues then result:=Total
  72.   else
  73.   begin
  74.     result:=0;
  75.     for t:=FirstIndex to LastIndex do result:=result+Value[t];
  76.   end;
  77. end;
  78.  
  79. Function TAddTeeFunction.CalculateMany(SourceSeriesList:TList; ValueIndex:Longint):Double;
  80. var t:Longint;
  81.     tmpList:TChartValueList;
  82. begin
  83.   result:=0;
  84.   for t:=0 to SourceSeriesList.Count-1 do
  85.   begin
  86.     tmpList:=ValueList(TChartSeries(SourceSeriesList[t]));
  87.     if tmpList.Count>ValueIndex then result:=result+tmpList[ValueIndex];
  88.   end;
  89. end;
  90.  
  91. { ManySeriesFunction }
  92. Function TManySeriesTeeFunction.CalculateMany(SourceSeriesList:TList; ValueIndex:Longint):Double;
  93. var tmpList  : TChartValueList;
  94.     tmpFirst : Boolean;
  95.     t        : Longint;
  96. begin
  97.   tmpFirst:=True;
  98.   result:=0;
  99.   for t:=0 to SourceSeriesList.Count-1 do
  100.   begin
  101.     tmpList:=ValueList(TChartSeries(SourceSeriesList[t]));
  102.     if tmpList.Count>ValueIndex then
  103.     begin
  104.       if tmpFirst then
  105.       begin
  106.         result:=tmpList[ValueIndex];
  107.         tmpFirst:=False;
  108.       end
  109.       else result:=CalculateValue(result,tmpList[ValueIndex]);
  110.     end
  111.   end
  112. end;
  113.  
  114. { Subtract }
  115. Function TSubtractTeeFunction.CalculateValue(Const AResult,AValue:Double):Double;
  116. begin
  117.   result:=AResult-AValue;
  118. end;
  119.  
  120. { Multiply }
  121. Function TMultiplyTeeFunction.CalculateValue(Const AResult,AValue:Double):Double;
  122. begin
  123.   result:=AResult*AValue;
  124. end;
  125.  
  126. { Divide }
  127. Function TDivideTeeFunction.CalculateValue(Const AResult,AValue:Double):Double;
  128. begin
  129.   if AValue=0 then result:=AResult
  130.               else result:=AResult/AValue;
  131. end;
  132.  
  133. { High }
  134. Function THighTeeFunction.Calculate(SourceSeries:TChartSeries; FirstIndex,LastIndex:Longint):Double;
  135. var t:Longint;
  136.     tmp:Double;
  137. begin
  138.   With ValueList(SourceSeries) do
  139.   if FirstIndex=TeeAllValues then result:=MaxValue
  140.   else
  141.   begin
  142.     result:=0;
  143.     for t:=FirstIndex to LastIndex do
  144.     begin
  145.       tmp:=Value[t];
  146.       if t=FirstIndex then result:=tmp else
  147.       if tmp>result then result:=tmp;
  148.     end;
  149.   end;
  150. end;
  151.  
  152. Function THighTeeFunction.CalculateMany(SourceSeriesList:TList; ValueIndex:Longint):Double;
  153. var t:Longint;
  154.     tmp:Double;
  155.     tmpList:TChartValueList;
  156. begin
  157.   result:=0;
  158.   for t:=0 to SourceSeriesList.Count-1 do
  159.   begin
  160.     tmpList:=ValueList(TChartSeries(SourceSeriesList[t]));
  161.     if tmpList.Count>ValueIndex then
  162.     begin
  163.       tmp:=tmpList[ValueIndex];
  164.       if (t=0) or (tmp>result) then result:=tmp;
  165.     end;
  166.   end;
  167. end;
  168.  
  169. { Low }
  170. Function TLowTeeFunction.Calculate(SourceSeries:TChartSeries; FirstIndex,LastIndex:Longint):Double;
  171. var t:Longint;
  172.     tmp:Double;
  173. begin
  174.   With ValueList(SourceSeries) do
  175.   if FirstIndex=TeeAllValues then result:=MinValue
  176.   else
  177.   begin
  178.     result:=0;
  179.     for t:=FirstIndex to LastIndex do
  180.     begin
  181.       tmp:=Value[t];
  182.       if t=FirstIndex then result:=tmp else
  183.       if tmp<result then result:=tmp;
  184.     end;
  185.   end;
  186. end;
  187.  
  188. Function TLowTeeFunction.CalculateMany(SourceSeriesList:TList; ValueIndex:Longint):Double;
  189. var t:Longint;
  190.     tmp:Double;
  191.     tmpList:TChartValueList;
  192. begin
  193.   result:=0;
  194.   for t:=0 to SourceSeriesList.Count-1 do
  195.   begin
  196.     tmpList:=ValueList(TChartSeries(SourceSeriesList[t]));
  197.     if tmpList.Count>ValueIndex then
  198.     begin
  199.       tmp:=tmpList[ValueIndex];
  200.       if (t=0) or (tmp<result) then result:=tmp;
  201.     end;
  202.   end;
  203. end;
  204.  
  205. { Average }
  206. Function TAverageTeeFunction.Calculate(SourceSeries:TChartSeries; FirstIndex,LastIndex:Longint):Double;
  207. var t:Longint;
  208. begin
  209.   if FirstIndex=TeeAllValues then
  210.   With SourceSeries do
  211.   begin
  212.     if Count>0 then result:=ValueList(SourceSeries).Total/Count
  213.                else result:=0;
  214.   end
  215.   else
  216.   begin
  217.     result:=0;
  218.     With ValueList(SourceSeries) do
  219.     for t:=FirstIndex to LastIndex do result:=result+Value[t];
  220.     result:=result/(LastIndex-FirstIndex+1);
  221.   end;
  222. end;
  223.  
  224. Function TAverageTeeFunction.CalculateMany(SourceSeriesList:TList; ValueIndex:Longint):Double;
  225. var t,Counter:Longint;
  226.     tmpList:TChartValueList;
  227. begin
  228.   result:=0;
  229.   if SourceSeriesList.Count>0 then
  230.   begin
  231.     Counter:=0;
  232.     for t:=0 to SourceSeriesList.Count-1 do
  233.     begin
  234.       tmpList:=ValueList(TChartSeries(SourceSeriesList[t]));
  235.       if tmpList.Count>ValueIndex then
  236.       begin
  237.         Inc(Counter);
  238.         result:=result+tmpList[ValueIndex];
  239.       end;
  240.     end;
  241.     if Counter>0 then result:=result/Counter;
  242.   end;
  243. end;
  244.  
  245. end.
  246.