mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-14 15:19:40 +02:00
TAChart: Initial commit of TChartLiveView
git-svn-id: trunk@63737 -
This commit is contained in:
parent
d578ab9494
commit
0d14011057
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -5456,6 +5456,7 @@ components/tachart/tachartimagelist.pas svneol=native#text/pascal
|
||||
components/tachart/tachartlazaruspkg.lpk svneol=native#text/plain
|
||||
components/tachart/tachartlazaruspkg.pas svneol=native#text/plain
|
||||
components/tachart/tachartlistbox.pas svneol=native#text/pascal
|
||||
components/tachart/tachartliveview.pas svneol=native#text/pascal
|
||||
components/tachart/tachartstrconsts.pas svneol=native#text/plain
|
||||
components/tachart/tachartteechart.pas svneol=native#text/pascal
|
||||
components/tachart/tachartutils.pas svneol=native#text/plain
|
||||
|
@ -30,7 +30,7 @@
|
||||
for details about the copyright.
|
||||
"/>
|
||||
<Version Major="1"/>
|
||||
<Files Count="53">
|
||||
<Files Count="54">
|
||||
<Item1>
|
||||
<Filename Value="tagraph.pas"/>
|
||||
<HasRegisterProc Value="True"/>
|
||||
@ -261,6 +261,10 @@
|
||||
<Filename Value="tadatapointseditor.pas"/>
|
||||
<UnitName Value="TADataPointsEditor"/>
|
||||
</Item53>
|
||||
<Item54>
|
||||
<Filename Value="tachartliveview.pas"/>
|
||||
<UnitName Value="TAChartLiveView"/>
|
||||
</Item54>
|
||||
</Files>
|
||||
<CompatibilityMode Value="True"/>
|
||||
<LazDoc Paths="$(LazarusDir)\components\tachart\fpdoc"/>
|
||||
|
@ -18,7 +18,8 @@ uses
|
||||
TATextElements, TAAxisSource, TASeriesPropEditors, TACustomFuncSeries,
|
||||
TAFitUtils, TAGUIConnector, TADiagram, TADiagramDrawing, TADiagramLayout,
|
||||
TAChartStrConsts, TAChartCombos, TAHtml, TAFonts, TAExpressionSeries,
|
||||
TAFitLib, TASourcePropEditors, TADataPointsEditor, LazarusPackageIntf;
|
||||
TAFitLib, TASourcePropEditors, TADataPointsEditor, TAChartLiveView,
|
||||
LazarusPackageIntf;
|
||||
|
||||
implementation
|
||||
|
||||
|
105
components/tachart/tachartliveview.pas
Normal file
105
components/tachart/tachartliveview.pas
Normal file
@ -0,0 +1,105 @@
|
||||
unit TAChartLiveView;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, TAGraph, TAChartUtils;
|
||||
|
||||
type
|
||||
TChartLiveView = class(TComponent)
|
||||
private
|
||||
FActive: Boolean;
|
||||
FChart: TChart;
|
||||
FListener: TListener;
|
||||
FViewportSize: Double;
|
||||
procedure FullExtentChanged(Sender: TObject);
|
||||
procedure SetActive(const AValue: Boolean);
|
||||
procedure SetChart(const AValue: TChart);
|
||||
procedure SetViewportSize(const AValue: Double);
|
||||
procedure UpdateViewport;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
published
|
||||
property Active: Boolean read FActive write SetActive default false;
|
||||
property Chart: TChart read FChart write SetChart default nil;
|
||||
property ViewportSize: double read FViewportSize write SetViewportSize;
|
||||
end;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
constructor TChartLiveView.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited;
|
||||
FListener := TListener.Create(@FChart, @FullExtentChanged);
|
||||
end;
|
||||
|
||||
destructor TChartLiveView.Destroy;
|
||||
begin
|
||||
FreeAndNil(FListener);
|
||||
inherited;
|
||||
end;
|
||||
|
||||
procedure TChartLiveView.FullExtentChanged(Sender: TObject);
|
||||
begin
|
||||
if (not FActive) or (FChart = nil) then
|
||||
exit;
|
||||
UpdateViewport;
|
||||
end;
|
||||
|
||||
procedure TChartLiveView.SetActive(const AValue: Boolean);
|
||||
begin
|
||||
if FActive = AValue then exit;
|
||||
|
||||
FActive := AValue;
|
||||
FullExtentChanged(nil);
|
||||
end;
|
||||
|
||||
procedure TChartLiveView.SetChart(const AValue: TChart);
|
||||
begin
|
||||
if FChart = AValue then exit;
|
||||
|
||||
if FListener.IsListening then
|
||||
FChart.FullExtentBroadcaster.Unsubscribe(FListener);
|
||||
FChart := AValue;
|
||||
if FChart <> nil then
|
||||
FChart.FullExtentBroadcaster.Subscribe(FListener);
|
||||
FullExtentChanged(Self);
|
||||
end;
|
||||
|
||||
procedure TChartLiveView.SetViewportSize(const AValue: Double);
|
||||
begin
|
||||
if FViewportSize = AValue then exit;
|
||||
|
||||
FViewportSize := AValue;
|
||||
FullExtentChanged(nil);
|
||||
end;
|
||||
|
||||
procedure TChartLiveView.UpdateViewport;
|
||||
var
|
||||
fext, lext: TDoubleRect;
|
||||
w: double;
|
||||
begin
|
||||
fext := FChart.GetFullExtent();
|
||||
lext := FChart.LogicalExtent;
|
||||
w := lext.b.x - lext.a.x;
|
||||
if FViewportSize = 0 then
|
||||
w := lext.b.x - lext.a.x
|
||||
else
|
||||
w := FViewportSize;
|
||||
lext.b.x := fext.b.x;
|
||||
lext.a.x := lext.b.X - w;
|
||||
if lext.a.x < fext.a.x then begin
|
||||
lext.a.x := fext.a.x;
|
||||
lext.b.x := lext.a.x + w;
|
||||
end;
|
||||
lext.a.y := fext.a.y;
|
||||
lext.b.y := fext.b.y;
|
||||
FChart.LogicalExtent := lext;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user