mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-05 06:39:34 +01:00
TAChart: Refactor TCalculatedChartSource.ExtractItem/GetOriginItem
git-svn-id: trunk@32398 -
This commit is contained in:
parent
0ed375aea1
commit
3b18b3adee
@ -182,7 +182,7 @@ type
|
|||||||
procedure CalcPercentage;
|
procedure CalcPercentage;
|
||||||
procedure Changed(ASender: TObject);
|
procedure Changed(ASender: TObject);
|
||||||
function EffectiveAccumulationRange: Cardinal;
|
function EffectiveAccumulationRange: Cardinal;
|
||||||
procedure ExtractItem(out AItem: TChartDataItem; AIndex: Integer);
|
procedure ExtractItem(AIndex: Integer);
|
||||||
procedure RangeAround(AIndex: Integer; out ALeft, ARight: Integer);
|
procedure RangeAround(AIndex: Integer; out ALeft, ARight: Integer);
|
||||||
procedure SetAccumulationDirection(AValue: TChartAccumulationDirection);
|
procedure SetAccumulationDirection(AValue: TChartAccumulationDirection);
|
||||||
procedure SetAccumulationMethod(AValue: TChartAccumulationMethod);
|
procedure SetAccumulationMethod(AValue: TChartAccumulationMethod);
|
||||||
@ -864,6 +864,17 @@ end;
|
|||||||
{ TCalculatedChartSource }
|
{ TCalculatedChartSource }
|
||||||
|
|
||||||
procedure TCalculatedChartSource.CalcAccumulation(AIndex: Integer);
|
procedure TCalculatedChartSource.CalcAccumulation(AIndex: Integer);
|
||||||
|
var
|
||||||
|
lastItemIndex: Integer = -1;
|
||||||
|
|
||||||
|
function GetOriginItem(AItemIndex: Integer): PChartDataItem;
|
||||||
|
begin
|
||||||
|
Result := @FItem;
|
||||||
|
if lastItemIndex = AItemIndex then exit;
|
||||||
|
ExtractItem(AItemIndex);
|
||||||
|
lastItemIndex := AItemIndex;
|
||||||
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
i, oldLeft, oldRight, newLeft, newRight: Integer;
|
i, oldLeft, oldRight, newLeft, newRight: Integer;
|
||||||
begin
|
begin
|
||||||
@ -878,39 +889,28 @@ begin
|
|||||||
(Abs(oldRight - newRight) > 1)
|
(Abs(oldRight - newRight) > 1)
|
||||||
then begin
|
then begin
|
||||||
FHistory.Clear;
|
FHistory.Clear;
|
||||||
for i := newLeft to newRight do begin
|
for i := newLeft to newRight do
|
||||||
ExtractItem(FItem, i);
|
FHistory.AddLast(GetOriginItem(i)^);
|
||||||
FHistory.AddLast(FItem);
|
|
||||||
end;
|
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
if FHistory.Capacity = 0 then
|
if FHistory.Capacity = 0 then
|
||||||
for i := oldLeft to newLeft - 1 do begin
|
for i := oldLeft to newLeft - 1 do
|
||||||
ExtractItem(FItem, i);
|
FHistory.RemoveValue(GetOriginItem(i)^)
|
||||||
FHistory.RemoveValue(FItem);
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
for i := oldLeft to newLeft - 1 do
|
for i := oldLeft to newLeft - 1 do
|
||||||
FHistory.RemoveFirst;
|
FHistory.RemoveFirst;
|
||||||
if FHistory.Capacity = 0 then
|
if FHistory.Capacity = 0 then
|
||||||
for i := oldRight downto newRight + 1 do begin
|
for i := oldRight downto newRight + 1 do
|
||||||
ExtractItem(FItem, i);
|
FHistory.RemoveValue(GetOriginItem(i)^)
|
||||||
FHistory.RemoveValue(FItem);
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
for i := oldRight downto newRight + 1 do
|
for i := oldRight downto newRight + 1 do
|
||||||
FHistory.RemoveLast;
|
FHistory.RemoveLast;
|
||||||
for i := oldLeft - 1 downto newLeft do begin
|
for i := oldLeft - 1 downto newLeft do
|
||||||
ExtractItem(FItem, i);
|
FHistory.AddFirst(GetOriginItem(i)^);
|
||||||
FHistory.AddFirst(FItem);
|
for i := oldRight + 1 to newRight do
|
||||||
end;
|
FHistory.AddLast(GetOriginItem(i)^);
|
||||||
for i := oldRight + 1 to newRight do begin
|
|
||||||
ExtractItem(FItem, i);
|
|
||||||
FHistory.AddLast(FItem);
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
if (AIndex <> newLeft) and (AIndex <> newRight) then
|
GetOriginItem(AIndex);
|
||||||
ExtractItem(FItem, AIndex);
|
|
||||||
case AccumulationMethod of
|
case AccumulationMethod of
|
||||||
camSum:
|
camSum:
|
||||||
FHistory.GetSum(FItem);
|
FHistory.GetSum(FItem);
|
||||||
@ -1010,17 +1010,16 @@ begin
|
|||||||
Result := AccumulationRange;
|
Result := AccumulationRange;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCalculatedChartSource.ExtractItem(
|
procedure TCalculatedChartSource.ExtractItem(AIndex: Integer);
|
||||||
out AItem: TChartDataItem; AIndex: Integer);
|
|
||||||
var
|
var
|
||||||
t: TDoubleDynArray;
|
t: TDoubleDynArray;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
AItem := Origin[AIndex]^;
|
FItem := Origin[AIndex]^;
|
||||||
SetLength(t, Length(FYOrder));
|
SetLength(t, Length(FYOrder));
|
||||||
for i := 0 to High(FYOrder) do
|
for i := 0 to High(FYOrder) do
|
||||||
t[i] := AItem.YList[FYOrder[i]];
|
t[i] := FItem.YList[FYOrder[i]];
|
||||||
AItem.YList := t;
|
FItem.YList := t;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCalculatedChartSource.GetCount: Integer;
|
function TCalculatedChartSource.GetCount: Integer;
|
||||||
@ -1037,7 +1036,7 @@ begin
|
|||||||
Result := @FItem;
|
Result := @FItem;
|
||||||
if FIndex = AIndex then exit;
|
if FIndex = AIndex then exit;
|
||||||
if (AccumulationMethod = camNone) or (AccumulationRange = 1) then
|
if (AccumulationMethod = camNone) or (AccumulationRange = 1) then
|
||||||
ExtractItem(FItem, AIndex)
|
ExtractItem(AIndex)
|
||||||
else
|
else
|
||||||
CalcAccumulation(AIndex);
|
CalcAccumulation(AIndex);
|
||||||
CalcPercentage;
|
CalcPercentage;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user