TAChart: Fixes incorrect axis title alignment in TChartExtentLink when one title is empty or when Axis.Title.Attachment = maCenter.

This commit is contained in:
wp_xyz 2024-04-30 22:48:40 +02:00
parent 720fc1261d
commit 7ec978ec60
2 changed files with 16 additions and 3 deletions

View File

@ -1028,10 +1028,16 @@ end;
function TChartAxis.MeasureTitleSize(ADrawer: IChartDrawer): Integer;
var
ttl: String;
sz: TSize;
begin
sz := Title.MeasureLabel(ADrawer, GetRealTitle);
Result := IfThen(IsVertical, sz.CX, sz.CY);
ttl := GetRealTitle;
if Title.Visible and (ttl <> '') then
begin
sz := Title.MeasureLabel(ADrawer, GetRealTitle);
Result := IfThen(IsVertical, sz.CX, sz.CY);
end else
Result := 0;
end;
function TChartAxis.PositionIsStored: Boolean;

View File

@ -201,6 +201,7 @@ var
ch: TChart;
maxLabelSize: array[TChartAxisAlignment] of Integer = (0, 0, 0, 0);
maxTitleSize: array[TChartAxisAlignment] of Integer = (0, 0, 0, 0);
maxTitleDistance: array[TChartAxisAlignment] of Integer = (0, 0, 0, 0);
titleSize: Integer;
al: TChartAxisAlignment;
axis: TChartAxis;
@ -231,8 +232,12 @@ begin
axis := ch.AxisList.GetAxisByAlign(al);
if axis <> nil then
begin
titleSize := axis.MeasureTitleSize(ch.Drawer);
if axis.Title.DistanceToCenter then
titleSize := titleSize div 2;
maxTitleSize[al] := Max(maxTitleSize[al], axis.MeasureTitleSize(ch.Drawer));
maxLabelSize[al] := Max(maxLabelSize[al], axis.MeasureLabelSize(ch.Drawer));
maxTitleDistance[al] := Max(maxTitleDistance[al], axis.Title.Distance);
end;
end;
end;
@ -246,9 +251,11 @@ begin
if axis <> nil then
begin
titleSize := axis.MeasureTitleSize(ch.Drawer);
if axis.Title.DistanceToCenter then
titleSize := titleSize div 2;
if (maxTitleSize[al] <> 0) and (not axis.Title.Visible or (axis.Title.Caption = '')) then
dec(titleSize, axis.Title.Distance);
axis.LabelSize := maxTitleSize[al] + maxLabelSize[al] - titleSize;
axis.LabelSize := maxTitleSize[al] + maxTitleDistance[al] + maxLabelSize[al] - titleSize;
end;
end;
end;