mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-19 10:39:30 +01:00
TAChart: Let user add points to ListSource without keeping X-order
git-svn-id: trunk@23240 -
This commit is contained in:
parent
fd45608001
commit
4f2de1c04c
@ -98,7 +98,9 @@ type
|
|||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
public
|
public
|
||||||
function Add(AX, AY: Double; const ALabel: String; AColor: TColor): Integer;
|
function Add(
|
||||||
|
AX, AY: Double; const ALabel: String; AColor: TColor;
|
||||||
|
AInOrder: Boolean = true): Integer;
|
||||||
procedure Clear;
|
procedure Clear;
|
||||||
procedure CopyForm(ASource: TCustomChartSource);
|
procedure CopyForm(ASource: TCustomChartSource);
|
||||||
procedure Delete(AIndex: Integer); inline;
|
procedure Delete(AIndex: Integer); inline;
|
||||||
@ -427,7 +429,8 @@ end;
|
|||||||
{ TListChartSource }
|
{ TListChartSource }
|
||||||
|
|
||||||
function TListChartSource.Add(
|
function TListChartSource.Add(
|
||||||
AX, AY: Double; const ALabel: String; AColor: TColor): Integer;
|
AX, AY: Double; const ALabel: String;
|
||||||
|
AColor: TColor; AInOrder: Boolean): Integer;
|
||||||
var
|
var
|
||||||
pcc: PChartDataItem;
|
pcc: PChartDataItem;
|
||||||
begin
|
begin
|
||||||
@ -438,14 +441,16 @@ begin
|
|||||||
pcc^.Text := ALabel;
|
pcc^.Text := ALabel;
|
||||||
UpdateCachesAfterAdd(AX, AY);
|
UpdateCachesAfterAdd(AX, AY);
|
||||||
|
|
||||||
// We keep data points ordered by X coordinate.
|
|
||||||
// Note that this leads to O(N^2) time except
|
|
||||||
// for the case of adding already ordered points.
|
|
||||||
// So, is the user wants to add many (>10000) points to a graph,
|
|
||||||
// he should pre-sort them to avoid performance penalty.
|
|
||||||
Result := FData.Count;
|
Result := FData.Count;
|
||||||
while (Result > 0) and (Item[Result - 1]^.X > AX) do
|
if AInOrder then begin
|
||||||
Dec(Result);
|
// Keep data points ordered by X coordinate.
|
||||||
|
// Note that this leads to O(N^2) time except
|
||||||
|
// for the case of adding already ordered points.
|
||||||
|
// So, is the user wants to add many (>10000) points to a graph,
|
||||||
|
// he should pre-sort them to avoid performance penalty.
|
||||||
|
while (Result > 0) and (Item[Result - 1]^.X > AX) do
|
||||||
|
Dec(Result);
|
||||||
|
end;
|
||||||
FData.Insert(Result, pcc);
|
FData.Insert(Result, pcc);
|
||||||
Notify;
|
Notify;
|
||||||
end;
|
end;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user