{**********************************************}
{   TCountTeeFunction Component                }
{   Copyright (c) 1996-2020 by Steema Software }
{**********************************************}
unit TeeCount;
{$I TeeDefs.inc}

interface

Uses Classes,

     {$IFDEF FMX}
     FMX.Types,
     {$ELSE}
     Graphics,
     {$ENDIF}

     {$IFDEF FMX}
     FMXTee.Engine, FMXTee.Chart, FMXTee.Series
     {$ELSE}
     TeEngine, Chart, Series
     {$ENDIF}
     ;

Type
  TCountTeeFunction=class(TTeeFunction)
  protected
    procedure PrepareForGallery(const Chart:TCustomAxisPanel); override;
  public
    Function Calculate(const Series:TChartSeries; First,Last:Integer):Double; override;
    Function CalculateMany(const SeriesList:TDataSourcesList; ValueIndex:Integer):Double;  override;
  end;

implementation

Uses SysUtils,
     {$IFDEF FMX}
     FMXTee.ProConstants
     {$ELSE}
     TeeProCo
     {$ENDIF};

Function TCountTeeFunction.Calculate(const Series:TChartSeries; First,Last:Integer):Double;
begin
  if First=TeeAllValues then result:=ValueList(Series).Count
                        else result:=Last-First+1;
end;

Function TCountTeeFunction.CalculateMany(const SeriesList:TDataSourcesList; ValueIndex:Integer):Double;
var t : Integer;
begin
  result:=0;

  for t:=0 to SeriesList.Count-1 do
      if ValueList(TChartSeries(SeriesList[t])).Count>ValueIndex then
         result:=result+1;
end;

procedure TCountTeeFunction.PrepareForGallery(const Chart:TCustomAxisPanel);
begin
  inherited;
  Chart[1].VertAxis:=aRightAxis;
end;

initialization
  RegisterTeeBasicFunction(TCountTeeFunction, @TeeMsg_FunctionCount);
finalization
  UnRegisterTeeFunctions([TCountTeeFunction]);
end.
