mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 10:39:09 +02:00
TAChart: Add property AlignSides to TChartExtentLink.
git-svn-id: trunk@61691 -
This commit is contained in:
parent
57dd9caaa1
commit
6cedfbf9a3
@ -5,7 +5,7 @@ unit TAChartExtentLink;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, TAChartUtils, TAGraph;
|
Classes, TAChartUtils, TAChartAxisUtils, TAGraph;
|
||||||
|
|
||||||
type
|
type
|
||||||
TLinkedChart = class(TCollectionItem)
|
TLinkedChart = class(TCollectionItem)
|
||||||
@ -34,12 +34,17 @@ type
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
TChartExtendLinkMode = (elmXY, elmOnlyX, elmOnlyY);
|
TChartExtendLinkMode = (elmXY, elmOnlyX, elmOnlyY);
|
||||||
|
TChartSides = set of TChartAxisAlignment;
|
||||||
|
|
||||||
TChartExtentLink = class(TComponent)
|
TChartExtentLink = class(TComponent)
|
||||||
strict private
|
strict private
|
||||||
FEnabled: Boolean;
|
FEnabled: Boolean;
|
||||||
FLinkedCharts: TLinkedCharts;
|
FLinkedCharts: TLinkedCharts;
|
||||||
FMode: TChartExtendLinkMode;
|
FMode: TChartExtendLinkMode;
|
||||||
|
FAlignSides: TChartSides;
|
||||||
|
procedure SetAlignSides(AValue: TChartSides);
|
||||||
|
protected
|
||||||
|
procedure DoAlignSides;
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -47,6 +52,7 @@ type
|
|||||||
procedure AddChart(AChart: TChart);
|
procedure AddChart(AChart: TChart);
|
||||||
procedure SyncWith(AChart: TChart);
|
procedure SyncWith(AChart: TChart);
|
||||||
published
|
published
|
||||||
|
property AlignSides: TChartSides read FAlignSides write SetAlignSides default [];
|
||||||
property Enabled: Boolean read FEnabled write FEnabled default true;
|
property Enabled: Boolean read FEnabled write FEnabled default true;
|
||||||
property LinkedCharts: TLinkedCharts read FLinkedCharts write FLinkedCharts;
|
property LinkedCharts: TLinkedCharts read FLinkedCharts write FLinkedCharts;
|
||||||
property Mode: TChartExtendLinkMode read FMode write FMode default elmXY;
|
property Mode: TChartExtendLinkMode read FMode write FMode default elmXY;
|
||||||
@ -57,7 +63,7 @@ procedure Register;
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
SysUtils, TAGeometry;
|
SysUtils, Math, TAGeometry, TAChartAxis;
|
||||||
|
|
||||||
procedure Register;
|
procedure Register;
|
||||||
begin
|
begin
|
||||||
@ -143,6 +149,52 @@ begin
|
|||||||
inherited;
|
inherited;
|
||||||
end;
|
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);
|
procedure TChartExtentLink.SyncWith(AChart: TChart);
|
||||||
|
|
||||||
function CombineXY(const AX, AY: TDoubleRect): TDoubleRect;
|
function CombineXY(const AX, AY: TDoubleRect): TDoubleRect;
|
||||||
|
Loading…
Reference in New Issue
Block a user