diff --git a/components/tachart/tacustomsource.pas b/components/tachart/tacustomsource.pas index a9bb612a52..7f6942d097 100644 --- a/components/tachart/tacustomsource.pas +++ b/components/tachart/tacustomsource.pas @@ -655,6 +655,9 @@ begin UpdateMinMax(YList[j], Result.a.Y, Result.b.Y); end; +// ALB -> leftmost item where X >= AXMin, or Count if no such item +// ALB -> rightmost item where X <= AXMax, or -1 if no such item +// If the source is sorted, performs binary search. Otherwise, skips NaNs. procedure TCustomChartSource.FindBounds( AXMin, AXMax: Double; out ALB, AUB: Integer); @@ -690,10 +693,10 @@ begin end else begin ALB := 0; - while (ALB < Count) and (IsNan(Item[ALB]^.X) or (Item[ALB]^.X < AXMin)) do + while (ALB < Count) and (NumberOr(Item[ALB]^.X, AXMin - 1) < AXMin) do Inc(ALB); AUB := Count - 1; - while (AUB >= 0) and (IsNan(Item[AUB]^.X) or (Item[AUB]^.X > AXMax)) do + while (AUB >= 0) and (NumberOr(Item[AUB]^.X, AXMax + 1) > AXMax) do Dec(AUB); end; end; @@ -904,8 +907,7 @@ begin FValuesTotal := 0; for i := 0 to Count - 1 do with Item[i]^ do - if not IsNan(Y) then - FValuesTotal += Y; + FValuesTotal += NumberOr(Y); FValuesTotalIsValid := true; Result := FValuesTotal; end;