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

  1. {**********************************************}
  2. {   TCumulative Function Component             }
  3. {   Copyright (c) 1997-98 by David Berneda     }
  4. {**********************************************}
  5. {$I teedefs.inc}
  6. unit teeCumu;
  7.  
  8. interface
  9.  
  10. { The TCumulative function sums the Series values
  11.   starting from the first point.
  12.  
  13.   Example:
  14.  
  15.   Given these values               :      1 2 3
  16.  
  17.   The TCumulative function returns :      1 3 6
  18.  
  19.                                      ( 1=1, 1+2=3 and 1+2+3=6 )
  20. }
  21.  
  22. uses
  23.   WinTypes,WinProcs, Messages, SysUtils, Classes, Graphics, TeEngine, Chart;
  24.  
  25. type
  26.   TCumulative = class(TTeeFunction)
  27.   public
  28.     { Public declarations }
  29.     Constructor Create(AOwner: TComponent); override;
  30.     Function Calculate(Series:TChartSeries; First,Last:Longint):Double; override;
  31.     Function CalculateMany(SeriesList:TList; ValueIndex:Longint):Double;  override;
  32.   published
  33.     { Published declarations }
  34.     property Period;
  35.   end;
  36.  
  37. implementation
  38.  
  39. Uses TeeProco,TeeConst;  { <-- needed only for the "Functions" constant }
  40.  
  41. Constructor TCumulative.Create(AOwner: TComponent);
  42. Begin
  43.   inherited Create(AOwner);
  44.   InternalSetPeriod(1);
  45. end;
  46.  
  47. Function TCumulative.Calculate(Series:TChartSeries; First,Last:Longint):Double;
  48. begin
  49.   if First>0 then result:=ParentSeries.MandatoryValueList.Last
  50.              else result:=0;
  51.   if First>=0 then
  52.      result:=result+ValueList(Series).Value[First];
  53. end;
  54.  
  55. { Returns the sum( ) of the current ValueIndex point of all Series PLUS the
  56.   accumulated calculation of the previous ValueIndex point.
  57. }
  58. Function TCumulative.CalculateMany(SeriesList:TList; ValueIndex:Longint):Double;
  59. var t:Longint;
  60.     tmpList:TChartValueList;
  61. begin
  62.   if ValueIndex=0 then result:=0
  63.                   else result:=ParentSeries.MandatoryValueList[ValueIndex-1];
  64.   for t:=0 to SeriesList.Count-1 do
  65.   begin
  66.     tmpList:=ValueList(TChartSeries(SeriesList[t]));
  67.     if tmpList.Count>ValueIndex then result:=result+tmpList[ValueIndex];
  68.   end;
  69. end;
  70.  
  71. { Series/Functions Registration }
  72. Procedure TeeCumuExitProc; far;
  73. begin
  74.   UnRegisterTeeFunctions([TCumulative]);
  75. end;
  76.  
  77. initialization
  78.   RegisterTeeFunction( TCumulative, TeeMsg_FunctionCumulative, TeeMsg_GalleryFunctions, 2 );
  79. {$IFDEF D1}
  80.   AddExitProc(TeeCumuExitProc);
  81. {$ELSE}
  82. finalization
  83.   TeeCumuExitProc;
  84. {$ENDIF}
  85. end.
  86.