TAChart: Use binary search to speed up extent detection for sorted series

+ Fix a typo in TCustomChartSeries.AxisToGraph

git-svn-id: trunk@25923 -
This commit is contained in:
ask 2010-06-05 16:04:50 +00:00
parent a31323c48b
commit e8d4380072
2 changed files with 38 additions and 7 deletions

View File

@ -155,7 +155,7 @@ uses
function TCustomChartSeries.AxisToGraph(
const APoint: TDoublePoint): TDoublePoint;
begin
Result := DoublePoint(AxisToGraphX(APoint.X), AxisToGraphX(APoint.Y));
Result := DoublePoint(AxisToGraphX(APoint.X), AxisToGraphY(APoint.Y));
if IsRotated then
Exchange(Result.X, Result.Y);
end;

View File

@ -309,14 +309,45 @@ end;
procedure TCustomChartSource.FindBounds(
AXMin, AXMax: Double; out ALB, AUB: Integer);
function FindLB(X: Double; L, R: Integer): Integer;
begin
while L <= R do begin
Result := (R - L) div 2 + L;
if Item[Result]^.X < X then
L := Result + 1
else
R := Result - 1;
end;
Result := L;
end;
function FindUB(X: Double; L, R: Integer): Integer;
begin
while L <= R do begin
Result := (R - L) div 2 + L;
if Item[Result]^.X <= X then
L := Result + 1
else
R := Result - 1;
end;
Result := R;
end;
begin
EnsureOrder(AXMin, AXMax);
ALB := 0;
while (ALB < Count) and (Item[ALB]^.X < AXMin) do
Inc(ALB);
AUB := Count - 1;
while (AUB > 0) and (Item[AUB]^.X < AXMax) do
Inc(AUB);
if IsSorted then begin
ALB := FindLB(AXMin, 0, Count - 1);
AUB := FindUB(AXMax, 0, Count - 1);
end
else begin
ALB := 0;
while (ALB < Count) and (Item[ALB]^.X < AXMin) do
Inc(ALB);
AUB := Count - 1;
while (AUB > 0) and (Item[AUB]^.X < AXMax) do
Dec(AUB);
end;
end;
function TCustomChartSource.FormatItem(