diff --git a/.gitattributes b/.gitattributes
index 3782a7a0e8..065732fd76 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -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
diff --git a/components/tachart/tachartlazaruspkg.lpk b/components/tachart/tachartlazaruspkg.lpk
index a871668721..30c6f9eeb7 100644
--- a/components/tachart/tachartlazaruspkg.lpk
+++ b/components/tachart/tachartlazaruspkg.lpk
@@ -30,7 +30,7 @@
for details about the copyright.
"/>
-
+
@@ -261,6 +261,10 @@
+
+
+
+
diff --git a/components/tachart/tachartlazaruspkg.pas b/components/tachart/tachartlazaruspkg.pas
index 851ad47b7c..8ac3688206 100644
--- a/components/tachart/tachartlazaruspkg.pas
+++ b/components/tachart/tachartlazaruspkg.pas
@@ -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
diff --git a/components/tachart/tachartliveview.pas b/components/tachart/tachartliveview.pas
new file mode 100644
index 0000000000..c19dbbfdce
--- /dev/null
+++ b/components/tachart/tachartliveview.pas
@@ -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.
+