TAChart: Add property AlignSides to TChartExtentLink.

git-svn-id: trunk@61691 -
This commit is contained in:
wp 2019-08-13 22:19:55 +00:00
parent 57dd9caaa1
commit 6cedfbf9a3

View File

@ -5,7 +5,7 @@ unit TAChartExtentLink;
interface
uses
Classes, TAChartUtils, TAGraph;
Classes, TAChartUtils, TAChartAxisUtils, TAGraph;
type
TLinkedChart = class(TCollectionItem)
@ -34,12 +34,17 @@ type
end;
TChartExtendLinkMode = (elmXY, elmOnlyX, elmOnlyY);
TChartSides = set of TChartAxisAlignment;
TChartExtentLink = class(TComponent)
strict private
FEnabled: Boolean;
FLinkedCharts: TLinkedCharts;
FMode: TChartExtendLinkMode;
FAlignSides: TChartSides;
procedure SetAlignSides(AValue: TChartSides);
protected
procedure DoAlignSides;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
@ -47,6 +52,7 @@ type
procedure AddChart(AChart: TChart);
procedure SyncWith(AChart: TChart);
published
property AlignSides: TChartSides read FAlignSides write SetAlignSides default [];
property Enabled: Boolean read FEnabled write FEnabled default true;
property LinkedCharts: TLinkedCharts read FLinkedCharts write FLinkedCharts;
property Mode: TChartExtendLinkMode read FMode write FMode default elmXY;
@ -57,7 +63,7 @@ procedure Register;
implementation
uses
SysUtils, TAGeometry;
SysUtils, Math, TAGeometry, TAChartAxis;
procedure Register;
begin
@ -143,6 +149,52 @@ begin
inherited;
end;
// Note: ignores several axes on the same chart side
procedure TChartExtentLink.DoAlignSides;
var
c: TCollectionItem;
ch: TChart;
labelSize: array[TChartAxisAlignment] of Integer = (0, 0, 0, 0);
sideUsed: array[TChartAxisAlignment] of boolean = (false, false, false, false);
al: TChartAxisAlignment;
axis: TChartAxis;
begin
for c in LinkedCharts do begin
ch := TLinkedChart(c).Chart;
FillChar(sideUsed, SizeOf(sideUsed), 0);
for al in TChartAxisAlignment do
if (al in FAlignsides) and not sideUsed[al] then begin
sideUsed[al] := true;
axis := ch.AxisList.GetAxisByAlign(al);
if axis <> nil then
labelsize[al] := Max(labelsize[al], axis.MeasureLabelSize(ch.Drawer));
end;
end;
for c in LinkedCharts do begin
ch := TLinkedChart(c).Chart;
FillChar(sideUsed, SizeOf(sideUsed), 0);
for al in TChartAxisAlignment do begin
axis := ch.AxisList.GetAxisByAlign(al);
if (axis <> nil) then begin
if (al in FAlignSides) and not sideUsed[al] then
sideUsed[al] := true;
if sideUsed[al] then
axis.labelSize := labelSize[al]
else
axis.LabelSize := 0;
end;
end;
end;
end;
procedure TChartExtentLink.SetAlignSides(AValue: TChartSides);
begin
if AValue = FAlignSides then exit;
FAlignSides := AValue;
DoAlignSides;
end;
procedure TChartExtentLink.SyncWith(AChart: TChart);
function CombineXY(const AX, AY: TDoubleRect): TDoubleRect;