mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-27 20:00:47 +02:00
TAChart: Add TChartExtentLink component
git-svn-id: trunk@32087 -
This commit is contained in:
parent
d4f841d515
commit
069dd88df5
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -2483,6 +2483,7 @@ components/tachart/tachartaxis.pas svneol=native#text/pascal
|
||||
components/tachart/tachartaxisutils.pas svneol=native#text/pascal
|
||||
components/tachart/tachartbgra.lpk svneol=native#text/pascal
|
||||
components/tachart/tachartbgra.pas svneol=native#text/pascal
|
||||
components/tachart/tachartextentlink.pas svneol=native#text/pascal
|
||||
components/tachart/tachartfpvectorial.lpk svneol=native#text/plain
|
||||
components/tachart/tachartfpvectorial.pas svneol=native#text/pascal
|
||||
components/tachart/tachartlazaruspkg.lpk svneol=native#text/plain
|
||||
|
148
components/tachart/tachartextentlink.pas
Normal file
148
components/tachart/tachartextentlink.pas
Normal file
@ -0,0 +1,148 @@
|
||||
unit TAChartExtentLink;
|
||||
|
||||
{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, TAChartUtils, TAGraph;
|
||||
|
||||
type
|
||||
TLinkedChart = class(TCollectionItem)
|
||||
strict private
|
||||
FChart: TChart;
|
||||
FListener: TListener;
|
||||
procedure OnExtentChanged(ASender: TObject);
|
||||
procedure SetChart(AValue: TChart);
|
||||
public
|
||||
constructor Create(ACollection: TCollection); override;
|
||||
destructor Destroy; override;
|
||||
published
|
||||
property Chart: TChart read FChart write SetChart;
|
||||
end;
|
||||
|
||||
TLinkedCharts = class(TCollection)
|
||||
strict private
|
||||
FOwner: TComponent;
|
||||
protected
|
||||
function GetOwner: TPersistent; override;
|
||||
public
|
||||
constructor Create(AOwner: TComponent);
|
||||
end;
|
||||
|
||||
TChartExtendLinkMode = (elmXY, elmOnlyX, elmOnlyY);
|
||||
|
||||
TChartExtentLink = class(TComponent)
|
||||
strict private
|
||||
FLinkedCharts: TLinkedCharts;
|
||||
FMode: TChartExtendLinkMode;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
|
||||
procedure SyncWith(AChart: TChart);
|
||||
published
|
||||
property LinkedCharts: TLinkedCharts read FLinkedCharts write FLinkedCharts;
|
||||
property Mode: TChartExtendLinkMode read FMode write FMode default elmXY;
|
||||
end;
|
||||
|
||||
procedure Register;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
SysUtils, TAGeometry;
|
||||
|
||||
procedure Register;
|
||||
begin
|
||||
RegisterComponents(CHART_COMPONENT_IDE_PAGE, [TChartExtentLink]);
|
||||
end;
|
||||
|
||||
{ TLinkedCharts }
|
||||
|
||||
constructor TLinkedCharts.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(TLinkedChart);
|
||||
FOwner := AOwner;
|
||||
end;
|
||||
|
||||
function TLinkedCharts.GetOwner: TPersistent;
|
||||
begin
|
||||
Result := FOwner;
|
||||
end;
|
||||
|
||||
{ TLinkedChart }
|
||||
|
||||
constructor TLinkedChart.Create(ACollection: TCollection);
|
||||
begin
|
||||
inherited Create(ACollection);
|
||||
FListener := TListener.Create(@FListener, @OnExtentChanged);
|
||||
end;
|
||||
|
||||
destructor TLinkedChart.Destroy;
|
||||
begin
|
||||
FreeAndNil(FListener);
|
||||
inherited;
|
||||
end;
|
||||
|
||||
procedure TLinkedChart.OnExtentChanged(ASender: TObject);
|
||||
begin
|
||||
Unused(ASender);
|
||||
(Collection.Owner as TChartExtentLink).SyncWith(Chart);
|
||||
end;
|
||||
|
||||
procedure TLinkedChart.SetChart(AValue: TChart);
|
||||
begin
|
||||
if FChart = AValue then exit;
|
||||
if Chart <> nil then
|
||||
Chart.ExtentBroadcaster.Unsubscribe(FListener);
|
||||
FChart := AValue;
|
||||
if Chart <> nil then
|
||||
Chart.ExtentBroadcaster.Subscribe(FListener);
|
||||
end;
|
||||
|
||||
{ TChartExtentLink }
|
||||
|
||||
constructor TChartExtentLink.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FLinkedCharts := TLinkedCharts.Create(Self);
|
||||
end;
|
||||
|
||||
destructor TChartExtentLink.Destroy;
|
||||
begin
|
||||
FreeAndNil(FLinkedCharts);
|
||||
inherited;
|
||||
end;
|
||||
|
||||
procedure TChartExtentLink.SyncWith(AChart: TChart);
|
||||
|
||||
function CombineXY(const AX, AY: TDoubleRect): TDoubleRect;
|
||||
begin
|
||||
Result.a := DoublePoint(AX.a.X, AY.a.Y);
|
||||
Result.b := DoublePoint(AX.b.X, AY.b.Y);
|
||||
end;
|
||||
|
||||
var
|
||||
c: TCollectionItem;
|
||||
begin
|
||||
if AChart = nil then exit;
|
||||
for c in LinkedCharts do
|
||||
with TLinkedChart(c).Chart do begin
|
||||
// Do not sync if the chart was never drawn yet.
|
||||
if LogicalExtent = EmptyExtent then continue;
|
||||
// An event loop will be broken since setting LogicalExtent to
|
||||
// the same value does not initiale the extent broadcast.
|
||||
case Mode of
|
||||
elmXY:
|
||||
LogicalExtent := AChart.LogicalExtent;
|
||||
elmOnlyX:
|
||||
LogicalExtent := CombineXY(AChart.LogicalExtent, LogicalExtent);
|
||||
elmOnlyY:
|
||||
LogicalExtent := CombineXY(LogicalExtent, AChart.LogicalExtent);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -30,7 +30,7 @@
|
||||
for details about the copyright.
|
||||
"/>
|
||||
<Version Major="1"/>
|
||||
<Files Count="31">
|
||||
<Files Count="32">
|
||||
<Item1>
|
||||
<Filename Value="tagraph.pas"/>
|
||||
<HasRegisterProc Value="True"/>
|
||||
@ -169,6 +169,11 @@
|
||||
<HasRegisterProc Value="True"/>
|
||||
<UnitName Value="TADataPointsEditor"/>
|
||||
</Item31>
|
||||
<Item32>
|
||||
<Filename Value="tachartextentlink.pas"/>
|
||||
<HasRegisterProc Value="True"/>
|
||||
<UnitName Value="TAChartExtentLink"/>
|
||||
</Item32>
|
||||
</Files>
|
||||
<LazDoc Paths="$(LazarusDir)\components\tachart\fpdoc"/>
|
||||
<Type Value="RunAndDesignTime"/>
|
||||
|
@ -12,7 +12,8 @@ uses
|
||||
TATypes, TADrawUtils, TAMultiSeries, TALegend, TAStyles, TAFuncSeries,
|
||||
TALegendPanel, TARadialSeries, TACustomSource, TAGeometry, TANavigation,
|
||||
TADrawerCanvas, TADrawerSVG, TAIntervalSources, TAChartAxisUtils,
|
||||
TAChartListbox, TAEnumerators, TADataPointsEditor, LazarusPackageIntf;
|
||||
TAChartListbox, TAEnumerators, TADataPointsEditor, TAChartExtentLink,
|
||||
LazarusPackageIntf;
|
||||
|
||||
implementation
|
||||
|
||||
@ -30,6 +31,7 @@ begin
|
||||
RegisterUnit('TAIntervalSources', @TAIntervalSources.Register);
|
||||
RegisterUnit('TAChartListbox', @TAChartListbox.Register);
|
||||
RegisterUnit('TADataPointsEditor', @TADataPointsEditor.Register);
|
||||
RegisterUnit('TAChartExtentLink', @TAChartExtentLink.Register);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
@ -604,6 +604,7 @@ begin
|
||||
FBuiltinToolset := OnInitBuiltinTools(Self);
|
||||
FActiveToolIndex := -1;
|
||||
|
||||
FLogicalExtent := EmptyExtent;
|
||||
FPrevLogicalExtent := EmptyExtent;
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user