TAChart: Initial commit of TChartLiveView

git-svn-id: trunk@63737 -
This commit is contained in:
wp 2020-08-14 21:27:39 +00:00
parent d578ab9494
commit 0d14011057
4 changed files with 113 additions and 2 deletions

1
.gitattributes vendored
View File

@ -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

View File

@ -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"/>

View File

@ -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

View 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.