mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-10 06:08:17 +02:00
TAChart: Fix axes for series having very long labels. Issue #34896. Based on patch by Marcin Wiazowski.
git-svn-id: trunk@60129 -
This commit is contained in:
parent
12278e7ef4
commit
3b38aad6ce
@ -250,8 +250,8 @@ type
|
||||
FMin, FMax: PDouble;
|
||||
function CalcOffset(AScale: Double): Double;
|
||||
function CalcScale(ASign: Integer): Double;
|
||||
constructor Init(
|
||||
AAxis: TChartAxis; AImageLo, AImageHi, AMarginLo, AMarginHi: Integer;
|
||||
constructor Init(AAxis: TChartAxis; AImageLo, AImageHi: Integer;
|
||||
AMarginLo, AMarginHi, ARequiredMarginLo, ARequiredMarginHi: Integer;
|
||||
AMin, AMax: PDouble);
|
||||
procedure UpdateMinMax(AConv: TAxisConvFunc);
|
||||
end;
|
||||
@ -1215,9 +1215,40 @@ end;
|
||||
|
||||
{ TAxisCoeffHelper }
|
||||
|
||||
constructor TAxisCoeffHelper.Init(
|
||||
AAxis: TChartAxis; AImageLo, AImageHi, AMarginLo, AMarginHi: Integer;
|
||||
procedure EnsureGuaranteedSpace(var AValue1, AValue2: Integer;
|
||||
AImage1, AImage2, AMargin1, AMargin2, AGuaranteed: Integer);
|
||||
var
|
||||
delta1, delta2: Integer;
|
||||
begin
|
||||
delta1 := AImage1 - AValue1;
|
||||
delta2 := AImage2 - AValue2;
|
||||
if (AValue2 = AImage2 - AMargin2) then begin
|
||||
AValue2 := AImage2 - AMargin2;
|
||||
AValue1 := AValue2 - AGuaranteed;
|
||||
end else
|
||||
if (AValue1 = AImage1 + AMargin1) then begin
|
||||
AValue1 := AImage1 + AMargin1;
|
||||
AValue2 := AValue1 + AGuaranteed;
|
||||
end else
|
||||
begin
|
||||
AValue1 := (AImage1 + AImage2 + AGuaranteed) div 2;
|
||||
AValue2 := AValue1 + AGuaranteed;
|
||||
if AValue1 + delta1 >= AImage1 then begin
|
||||
AValue1 := AImage1 - delta1;
|
||||
AValue2 := AValue1 + AGuaranteed;
|
||||
end else
|
||||
if AValue2 + delta2 <= AImage2 then begin
|
||||
AValue2 := AImage2 - delta2;
|
||||
AValue1 := AValue2 - AGuaranteed;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
constructor TAxisCoeffHelper.Init(AAxis: TChartAxis; AImageLo, AImageHi: Integer;
|
||||
AMarginLo, AMarginHi, ARequiredMarginLo, ARequiredMarginHi: Integer;
|
||||
AMin, AMax: PDouble);
|
||||
const
|
||||
GUARANTEED_SPACE = 10;
|
||||
begin
|
||||
FAxis := AAxis;
|
||||
FImageLo := AImageLo;
|
||||
@ -1226,14 +1257,26 @@ begin
|
||||
FMax := AMax;
|
||||
FLo := FImageLo + AMarginLo;
|
||||
FHi := FImageHi + AMarginHi;
|
||||
|
||||
if Assigned(AAxis) and AAxis.IsVertical then begin
|
||||
if (FHi + GUARANTEED_SPACE >= FLo) then
|
||||
EnsureGuaranteedSpace(FHi, FLo, FImageHi, FImageLo,
|
||||
ARequiredMarginHi, ARequiredMarginLo, GUARANTEED_SPACE);
|
||||
end else begin
|
||||
if (FLo + GUARANTEED_SPACE >= FHi) then
|
||||
EnsureGuaranteedSpace(FLo, FHi, FImageLo, FImageHi,
|
||||
ARequiredMarginLo, ARequiredMarginHi, GUARANTEED_SPACE);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TAxisCoeffHelper.CalcScale(ASign: Integer): Double;
|
||||
begin
|
||||
if (FMax^ = FMin^) or (Sign(FHi - FLo) <> ASign) then exit(1.0);
|
||||
if (FMax^ <= FMin^) or (Sign(FHi - FLo) <> ASign) then
|
||||
Result := ASign
|
||||
else
|
||||
Result := (FHi - FLo) / (FMax^ - FMin^);
|
||||
if (FAxis <> nil) and FAxis.IsFlipped then
|
||||
Exchange(FLo, FHi);
|
||||
Result := (FHi - FLo) / (FMax^ - FMin^);
|
||||
Result := -Result;
|
||||
end;
|
||||
|
||||
function TAxisCoeffHelper.CalcOffset(AScale: Double): Double;
|
||||
|
@ -1427,7 +1427,7 @@ begin
|
||||
lmpNegative: isNeg := true;
|
||||
lmpInside: isNeg := Source[AIndex]^.Y >= ref;
|
||||
end;
|
||||
if (isRotated and ParentChart.IsRightToLeft) xor GetAxisY.Inverted then
|
||||
if (IsRotated and ParentChart.IsRightToLeft) xor GetAxisY.Inverted then
|
||||
isNeg := not isNeg;
|
||||
Result := DIR[IsRotated, isNeg];
|
||||
end;
|
||||
|
@ -583,10 +583,10 @@ var
|
||||
begin
|
||||
rX.Init(
|
||||
BottomAxis, FClipRect.Left, FClipRect.Right, AMargin.Left, -AMargin.Right,
|
||||
@FCurrentExtent.a.X, @FCurrentExtent.b.X);
|
||||
FMargins.Left, FMargins.Right, @FCurrentExtent.a.X, @FCurrentExtent.b.X);
|
||||
rY.Init(
|
||||
LeftAxis, FClipRect.Bottom, FClipRect.Top, -AMargin.Bottom, AMargin.Top,
|
||||
@FCurrentExtent.a.Y, @FCurrentExtent.b.Y);
|
||||
FMargins.Bottom, FMargins.Top, @FCurrentExtent.a.Y, @FCurrentExtent.b.Y);
|
||||
FScale.X := rX.CalcScale(1);
|
||||
FScale.Y := rY.CalcScale(-1);
|
||||
if Proportional then begin
|
||||
|
Loading…
Reference in New Issue
Block a user