diff --git a/components/tachart/tacustomsource.pas b/components/tachart/tacustomsource.pas index 95f0fa2e51..196ce85133 100644 --- a/components/tachart/tacustomsource.pas +++ b/components/tachart/tacustomsource.pas @@ -128,6 +128,21 @@ type function ToImage(AX: Double): Integer; inline; end; + TBasicChartSource = class(TComponent) + strict private + FBroadcaster: TBroadcaster; + FUpdateCount: Integer; + strict protected + procedure Notify; + public + constructor Create(AOwner: TComponent); override; + destructor Destroy; override; + procedure BeginUpdate; + procedure EndUpdate; virtual; + function IsUpdating: Boolean; inline; + property Broadcaster: TBroadcaster read FBroadcaster; + end; + TCustomChartSource = class; TCustomChartSourceEnumerator = class @@ -142,16 +157,14 @@ type property Current: PChartDataItem read GetCurrent; end; - TCustomChartSource = class(TComponent) + TCustomChartSource = class(TBasicChartSource) strict private - FBroadcaster: TBroadcaster; - FUpdateCount: Integer; - procedure SortValuesInRange( var AValues: TChartValueTextArray; AStart, AEnd: Integer); strict protected FExtent: TDoubleRect; FExtentIsValid: Boolean; + FUpdateCount: Integer; FValuesTotal: Double; FValuesTotalIsValid: Boolean; FYCount: Cardinal; @@ -161,17 +174,13 @@ type function GetLink(AIndex: Integer): PChartLinkItem; virtual; abstract; function GetLinkCount: Integer; virtual; abstract; procedure InvalidateCaches; - procedure Notify; procedure SetYCount(AValue: Cardinal); virtual; abstract; public constructor Create(AOwner: TComponent); override; - destructor Destroy; override; public procedure AfterDraw; virtual; procedure BeforeDraw; virtual; - procedure BeginUpdate; procedure EndUpdate; virtual; - function IsUpdating: Boolean; inline; public class procedure CheckFormat(const AFormat: String); function Extent: TDoubleRect; virtual; @@ -190,7 +199,6 @@ type function XOfMax: Double; function XOfMin: Double; - property Broadcaster: TBroadcaster read FBroadcaster; property Count: Integer read GetCount; property Item[AIndex: Integer]: PChartDataItem read GetItem; default; property Link[AIndex: Integer]: PChartLinkItem read GetLink; @@ -449,6 +457,44 @@ begin YList[AIndex - 1] := AValue; end; +{ TBaisChartSource } + +constructor TBasicChartSource.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + FBroadcaster := TBroadcaster.Create; +end; + +destructor TBasicChartSource.Destroy; +begin + FreeAndNil(FBroadcaster); + inherited Destroy; +end; + +procedure TBasicChartSource.BeginUpdate; +begin + Inc(FUpdateCount); +end; + +procedure TBasicChartSource.EndUpdate; +begin + Dec(FUpdateCount); + if FUpdateCount > 0 then exit; + Notify; +end; + +function TBasicChartSource.IsUpdating: Boolean; inline; +begin + Result := FUpdateCount > 0; +end; + +procedure TBasicChartSource.Notify; +begin + if not IsUpdating then + FBroadcaster.Broadcast(Self); +end; + + { TChartSourceBuffer } procedure TChartSourceBuffer.AddFirst(const AItem: TChartDataItem); @@ -596,11 +642,6 @@ begin // empty end; -procedure TCustomChartSource.BeginUpdate; -begin - Inc(FUpdateCount); -end; - class procedure TCustomChartSource.CheckFormat(const AFormat: String); begin Format(AFormat, [0.0, 0.0, '', 0.0, 0.0]); @@ -609,16 +650,9 @@ end; constructor TCustomChartSource.Create(AOwner: TComponent); begin inherited Create(AOwner); - FBroadcaster := TBroadcaster.Create; FYCount := 1; end; -destructor TCustomChartSource.Destroy; -begin - FreeAndNil(FBroadcaster); - inherited; -end; - procedure TCustomChartSource.EndUpdate; begin Dec(FUpdateCount); @@ -761,17 +795,6 @@ begin Result := false; end; -function TCustomChartSource.IsUpdating: Boolean; inline; -begin - Result := FUpdateCount > 0; -end; - -procedure TCustomChartSource.Notify; -begin - if not IsUpdating then - FBroadcaster.Broadcast(Self); -end; - procedure TCustomChartSource.SortValuesInRange( var AValues: TChartValueTextArray; AStart, AEnd: Integer); var