1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
unit main;
{$mode objfpc}{$H+}
interface
uses
ExtCtrls, Spin, StdCtrls, Forms, TAGraph, TASeries, TASources, TATools,
TATypes;
type
{ TForm1 }
TForm1 = class(TForm)
btnPrevExtent: TButton;
cgUseBounds: TCheckGroup;
Chart1: TChart;
ChartToolset1: TChartToolset;
ChartToolset1PanDragTool1: TPanDragTool;
ChartToolset1ZoomDragTool1: TZoomDragTool;
clRight: TConstantLine;
clLeft: TConstantLine;
clTop: TConstantLine;
clBottom: TConstantLine;
Chart1LineSeries: TLineSeries;
fseBounds: TFloatSpinEdit;
lblHistory: TLabel;
lblBoundValue: TLabel;
Panel1: TPanel;
RandomChartSource1: TRandomChartSource;
procedure btnPrevExtentClick(Sender: TObject);
procedure cgUseBoundsItemClick(Sender: TObject; AIndex: integer);
procedure Chart1ExtentChanged(ASender: TChart);
procedure FormCreate(Sender: TObject);
procedure fseBoundsChange(Sender: TObject);
private
FHistory: TChartExtentHistory;
FIsRemembering: Boolean;
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
uses
SysUtils, TAChartUtils;
{ TForm1 }
procedure TForm1.btnPrevExtentClick(Sender: TObject);
begin
FIsRemembering := FHistory.Count > 0;
if FIsRemembering then
Chart1.LogicalExtent := FHistory.Pop;
end;
procedure TForm1.cgUseBoundsItemClick(Sender: TObject; AIndex: integer);
begin
Unused(AIndex);
with Chart1.Extent do begin
UseXMin := cgUseBounds.Checked[0];
UseXMax := cgUseBounds.Checked[1];
UseYMin := cgUseBounds.Checked[2];
UseYMax := cgUseBounds.Checked[3];
end;
end;
procedure TForm1.Chart1ExtentChanged(ASender: TChart);
begin
Unused(ASender);
if not FIsRemembering then
FHistory.Add(Chart1.PrevLogicalExtent);
FIsRemembering := false;
btnPrevExtent.Enabled := FHistory.Count > 0;
lblHistory.Caption := Format(
'History: %d of %d', [FHistory.Count, FHistory.Capacity]);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
fseBoundsChange(nil);
FHistory := TChartExtentHistory.Create;
FHistory.Capacity := 8;
FIsRemembering := true;
end;
procedure TForm1.fseBoundsChange(Sender: TObject);
begin
clRight.Position := fseBounds.Value;
clLeft.Position := -fseBounds.Value;
clTop.Position := fseBounds.Value;
clBottom.Position := -fseBounds.Value;
with Chart1.Extent do begin
XMin := -fseBounds.Value;
XMax := fseBounds.Value;
YMin := -fseBounds.Value;
YMax := fseBounds.Value;
end;
end;
end.
|