mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 06:56:10 +02:00
TAChart: Add "Derivative" page to the source demo. Based on code by Werner Pamler
git-svn-id: trunk@32333 -
This commit is contained in:
parent
478be019bc
commit
f188c49a1a
@ -1,15 +1,16 @@
|
|||||||
object Form1: TForm1
|
object Form1: TForm1
|
||||||
Left = 342
|
Left = 342
|
||||||
Height = 415
|
Height = 438
|
||||||
Top = 199
|
Top = 199
|
||||||
Width = 595
|
Width = 637
|
||||||
Caption = 'Form1'
|
Caption = 'Form1'
|
||||||
ClientHeight = 415
|
ClientHeight = 438
|
||||||
ClientWidth = 595
|
ClientWidth = 637
|
||||||
|
OnCreate = FormCreate
|
||||||
LCLVersion = '0.9.31'
|
LCLVersion = '0.9.31'
|
||||||
object Splitter1: TSplitter
|
object Splitter1: TSplitter
|
||||||
Left = 590
|
Left = 632
|
||||||
Height = 415
|
Height = 438
|
||||||
Top = 0
|
Top = 0
|
||||||
Width = 5
|
Width = 5
|
||||||
Align = alRight
|
Align = alRight
|
||||||
@ -18,22 +19,22 @@ object Form1: TForm1
|
|||||||
end
|
end
|
||||||
object PageControl1: TPageControl
|
object PageControl1: TPageControl
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 415
|
Height = 438
|
||||||
Top = 0
|
Top = 0
|
||||||
Width = 590
|
Width = 632
|
||||||
ActivePage = tsBasic
|
ActivePage = tsBasic
|
||||||
Align = alClient
|
Align = alClient
|
||||||
TabIndex = 0
|
TabIndex = 0
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
object tsBasic: TTabSheet
|
object tsBasic: TTabSheet
|
||||||
Caption = 'Basic'
|
Caption = 'Basic'
|
||||||
ClientHeight = 389
|
ClientHeight = 412
|
||||||
ClientWidth = 582
|
ClientWidth = 624
|
||||||
object Memo1: TMemo
|
object Memo1: TMemo
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 34
|
Height = 34
|
||||||
Top = 0
|
Top = 0
|
||||||
Width = 582
|
Width = 624
|
||||||
Align = alTop
|
Align = alTop
|
||||||
Lines.Strings = (
|
Lines.Strings = (
|
||||||
'Modify sources at design-time.'
|
'Modify sources at design-time.'
|
||||||
@ -43,9 +44,9 @@ object Form1: TForm1
|
|||||||
end
|
end
|
||||||
object Chart2: TChart
|
object Chart2: TChart
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 355
|
Height = 378
|
||||||
Top = 34
|
Top = 34
|
||||||
Width = 291
|
Width = 333
|
||||||
AxisList = <
|
AxisList = <
|
||||||
item
|
item
|
||||||
Minors = <>
|
Minors = <>
|
||||||
@ -77,8 +78,8 @@ object Form1: TForm1
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
object Chart1: TChart
|
object Chart1: TChart
|
||||||
Left = 291
|
Left = 333
|
||||||
Height = 355
|
Height = 378
|
||||||
Top = 34
|
Top = 34
|
||||||
Width = 291
|
Width = 291
|
||||||
AxisList = <
|
AxisList = <
|
||||||
@ -114,13 +115,13 @@ object Form1: TForm1
|
|||||||
end
|
end
|
||||||
object tsStatistics: TTabSheet
|
object tsStatistics: TTabSheet
|
||||||
Caption = 'Statistics'
|
Caption = 'Statistics'
|
||||||
ClientHeight = 389
|
ClientHeight = 412
|
||||||
ClientWidth = 582
|
ClientWidth = 624
|
||||||
object chCalc: TChart
|
object chCalc: TChart
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 355
|
Height = 378
|
||||||
Top = 0
|
Top = 0
|
||||||
Width = 582
|
Width = 624
|
||||||
AxisList = <
|
AxisList = <
|
||||||
item
|
item
|
||||||
Minors = <>
|
Minors = <>
|
||||||
@ -167,11 +168,11 @@ object Form1: TForm1
|
|||||||
object Panel2: TPanel
|
object Panel2: TPanel
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 34
|
Height = 34
|
||||||
Top = 355
|
Top = 378
|
||||||
Width = 582
|
Width = 624
|
||||||
Align = alBottom
|
Align = alBottom
|
||||||
ClientHeight = 34
|
ClientHeight = 34
|
||||||
ClientWidth = 582
|
ClientWidth = 624
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
object cbCumulative: TCheckBox
|
object cbCumulative: TCheckBox
|
||||||
Left = 8
|
Left = 8
|
||||||
@ -186,6 +187,115 @@ object Form1: TForm1
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
object tsDerivative: TTabSheet
|
||||||
|
Caption = 'Derivative'
|
||||||
|
ClientHeight = 412
|
||||||
|
ClientWidth = 624
|
||||||
|
object chDerivative: TChart
|
||||||
|
Left = 0
|
||||||
|
Height = 327
|
||||||
|
Top = 0
|
||||||
|
Width = 624
|
||||||
|
AxisList = <
|
||||||
|
item
|
||||||
|
Grid.Color = clSilver
|
||||||
|
Minors = <>
|
||||||
|
Title.LabelFont.Orientation = 900
|
||||||
|
Title.Visible = True
|
||||||
|
Title.Caption = 'y, dy/dx'
|
||||||
|
end
|
||||||
|
item
|
||||||
|
Grid.Color = clSilver
|
||||||
|
Alignment = calBottom
|
||||||
|
Minors = <>
|
||||||
|
Title.Visible = True
|
||||||
|
Title.Caption = 'x'
|
||||||
|
end>
|
||||||
|
BackColor = clWhite
|
||||||
|
Foot.Brush.Color = clBtnFace
|
||||||
|
Foot.Font.Color = clBlue
|
||||||
|
Legend.Alignment = laTopCenter
|
||||||
|
Legend.ColumnCount = 2
|
||||||
|
Legend.Visible = True
|
||||||
|
Title.Brush.Color = clBtnFace
|
||||||
|
Title.Font.Color = clBlue
|
||||||
|
Title.Text.Strings = (
|
||||||
|
'TAChart'
|
||||||
|
)
|
||||||
|
Align = alClient
|
||||||
|
ParentColor = False
|
||||||
|
object chDerivativeLineOrig: TLineSeries
|
||||||
|
Title = 'y'
|
||||||
|
Source = lcsDerivative
|
||||||
|
end
|
||||||
|
object chDerivativeLineDeriv: TLineSeries
|
||||||
|
Title = 'dy/dx'
|
||||||
|
LinePen.Color = clRed
|
||||||
|
Source = ccsDerivative
|
||||||
|
end
|
||||||
|
end
|
||||||
|
object rgDataShape: TRadioGroup
|
||||||
|
Left = 0
|
||||||
|
Height = 54
|
||||||
|
Top = 327
|
||||||
|
Width = 624
|
||||||
|
Align = alBottom
|
||||||
|
AutoFill = True
|
||||||
|
Caption = 'Functions'
|
||||||
|
ChildSizing.LeftRightSpacing = 6
|
||||||
|
ChildSizing.TopBottomSpacing = 6
|
||||||
|
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
|
||||||
|
ChildSizing.EnlargeVertical = crsHomogenousChildResize
|
||||||
|
ChildSizing.ShrinkHorizontal = crsScaleChilds
|
||||||
|
ChildSizing.ShrinkVertical = crsScaleChilds
|
||||||
|
ChildSizing.Layout = cclLeftToRightThenTopToBottom
|
||||||
|
ChildSizing.ControlsPerLine = 7
|
||||||
|
ClientHeight = 36
|
||||||
|
ClientWidth = 620
|
||||||
|
Columns = 7
|
||||||
|
ItemIndex = 0
|
||||||
|
Items.Strings = (
|
||||||
|
'y = x'
|
||||||
|
'y = sin(x)'
|
||||||
|
'y = sin(x) / x'
|
||||||
|
'y = exp(-x/3)'
|
||||||
|
'Gaussian'
|
||||||
|
'Noisy Gaussian'
|
||||||
|
'Data from table'
|
||||||
|
)
|
||||||
|
OnClick = rgDataShapeClick
|
||||||
|
ParentFont = False
|
||||||
|
TabOrder = 1
|
||||||
|
end
|
||||||
|
object Panel1: TPanel
|
||||||
|
Left = 0
|
||||||
|
Height = 31
|
||||||
|
Top = 381
|
||||||
|
Width = 624
|
||||||
|
Align = alBottom
|
||||||
|
BevelOuter = bvNone
|
||||||
|
ClientHeight = 31
|
||||||
|
ClientWidth = 624
|
||||||
|
TabOrder = 2
|
||||||
|
object lblAccumulationRange: TLabel
|
||||||
|
Left = 8
|
||||||
|
Height = 14
|
||||||
|
Top = 9
|
||||||
|
Width = 95
|
||||||
|
Caption = 'AccumulationRange'
|
||||||
|
ParentColor = False
|
||||||
|
end
|
||||||
|
object seAccumulationRange: TSpinEdit
|
||||||
|
Left = 116
|
||||||
|
Height = 21
|
||||||
|
Top = 4
|
||||||
|
Width = 82
|
||||||
|
OnChange = seAccumulationRangeChange
|
||||||
|
TabOrder = 0
|
||||||
|
Value = 2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
object RandomChartSource1: TRandomChartSource
|
object RandomChartSource1: TRandomChartSource
|
||||||
PointsNumber = 8
|
PointsNumber = 8
|
||||||
@ -232,4 +342,14 @@ object Form1: TForm1
|
|||||||
left = 504
|
left = 504
|
||||||
top = 268
|
top = 268
|
||||||
end
|
end
|
||||||
|
object lcsDerivative: TListChartSource
|
||||||
|
left = 156
|
||||||
|
top = 84
|
||||||
|
end
|
||||||
|
object ccsDerivative: TCalculatedChartSource
|
||||||
|
AccumulationMethod = camDerivative
|
||||||
|
Origin = lcsDerivative
|
||||||
|
left = 156
|
||||||
|
top = 140
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,36 +5,53 @@ unit Main;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
ComCtrls, ExtCtrls, StdCtrls, Forms, TAGraph, TASeries, TASources, Classes;
|
ComCtrls, ExtCtrls, Spin, StdCtrls, Forms, TAGraph, TASeries, TASources,
|
||||||
|
Classes;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
{ TForm1 }
|
{ TForm1 }
|
||||||
|
|
||||||
TForm1 = class(TForm)
|
TForm1 = class(TForm)
|
||||||
|
ccsDerivative: TCalculatedChartSource;
|
||||||
cbCumulative: TCheckBox;
|
cbCumulative: TCheckBox;
|
||||||
ccsAvg: TCalculatedChartSource;
|
ccsAvg: TCalculatedChartSource;
|
||||||
ccsSum: TCalculatedChartSource;
|
ccsSum: TCalculatedChartSource;
|
||||||
Chart1: TChart;
|
Chart1: TChart;
|
||||||
Chart1BarSeries1: TBarSeries;
|
Chart1BarSeries1: TBarSeries;
|
||||||
Chart1LineSeries1: TLineSeries;
|
Chart1LineSeries1: TLineSeries;
|
||||||
|
chDerivativeLineOrig: TLineSeries;
|
||||||
|
chDerivativeLineDeriv: TLineSeries;
|
||||||
|
Chart1LineSeries4: TLineSeries;
|
||||||
|
Chart1LineSeries5: TLineSeries;
|
||||||
Chart2: TChart;
|
Chart2: TChart;
|
||||||
Chart2AreaSeries1: TAreaSeries;
|
Chart2AreaSeries1: TAreaSeries;
|
||||||
Chart2LineSeries1: TLineSeries;
|
Chart2LineSeries1: TLineSeries;
|
||||||
|
chDerivative: TChart;
|
||||||
chCalc: TChart;
|
chCalc: TChart;
|
||||||
chCalcLineSeries1: TLineSeries;
|
chCalcLineSeries1: TLineSeries;
|
||||||
chCalcLineSeriesAvg: TLineSeries;
|
chCalcLineSeriesAvg: TLineSeries;
|
||||||
chCalcLineSeriesSum: TLineSeries;
|
chCalcLineSeriesSum: TLineSeries;
|
||||||
|
seAccumulationRange: TSpinEdit;
|
||||||
|
lblAccumulationRange: TLabel;
|
||||||
ListChartSource1: TListChartSource;
|
ListChartSource1: TListChartSource;
|
||||||
|
lcsDerivative: TListChartSource;
|
||||||
Memo1: TMemo;
|
Memo1: TMemo;
|
||||||
PageControl1: TPageControl;
|
PageControl1: TPageControl;
|
||||||
|
Panel1: TPanel;
|
||||||
Panel2: TPanel;
|
Panel2: TPanel;
|
||||||
|
rgDataShape: TRadioGroup;
|
||||||
RandomChartSource1: TRandomChartSource;
|
RandomChartSource1: TRandomChartSource;
|
||||||
RandomChartSource2: TRandomChartSource;
|
RandomChartSource2: TRandomChartSource;
|
||||||
Splitter1: TSplitter;
|
Splitter1: TSplitter;
|
||||||
|
tsDerivative: TTabSheet;
|
||||||
tsStatistics: TTabSheet;
|
tsStatistics: TTabSheet;
|
||||||
tsBasic: TTabSheet;
|
tsBasic: TTabSheet;
|
||||||
procedure cbCumulativeChange(Sender: TObject);
|
procedure cbCumulativeChange(Sender: TObject);
|
||||||
|
procedure CreateData;
|
||||||
|
procedure seAccumulationRangeChange(Sender: TObject);
|
||||||
|
procedure FormCreate(Sender: TObject);
|
||||||
|
procedure rgDataShapeClick(Sender: TObject);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
@ -44,6 +61,9 @@ implementation
|
|||||||
|
|
||||||
{$R *.lfm}
|
{$R *.lfm}
|
||||||
|
|
||||||
|
uses
|
||||||
|
Math;
|
||||||
|
|
||||||
{ TForm1 }
|
{ TForm1 }
|
||||||
|
|
||||||
procedure TForm1.cbCumulativeChange(Sender: TObject);
|
procedure TForm1.cbCumulativeChange(Sender: TObject);
|
||||||
@ -51,5 +71,51 @@ begin
|
|||||||
chCalcLineSeriesSum.Active := cbCumulative.Checked;
|
chCalcLineSeriesSum.Active := cbCumulative.Checked;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.CreateData;
|
||||||
|
const
|
||||||
|
N = 100;
|
||||||
|
MIN_X = -10;
|
||||||
|
MAX_X = 10;
|
||||||
|
EPS = 1e-6;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
x, y: Double;
|
||||||
|
begin
|
||||||
|
lcsDerivative.Clear;
|
||||||
|
if rgDataShape.ItemIndex = 6 then
|
||||||
|
for i := 0 to 9 do
|
||||||
|
lcsDerivative.Add(i - IfThen(i > 6, 1, 0), i)
|
||||||
|
else
|
||||||
|
for i := 0 to N - 1 do begin
|
||||||
|
x := MIN_X + (MAX_X - MIN_X) / (N - 1) * i;
|
||||||
|
if SameValue(x, 0.0, EPS) then x := 0;
|
||||||
|
case rgDataShape.ItemIndex of
|
||||||
|
0: y := x;
|
||||||
|
1: y := Sin(x);
|
||||||
|
2: if (x = 0) then y := 1 else y := Sin(x) / x;
|
||||||
|
3: y := Exp(-x / 3);
|
||||||
|
4: y := Exp(-Sqr((x - 2.5) / 2.5));
|
||||||
|
5: y := Exp(-Sqr((x - 2.5) / 2.5)) + 0.05 * (Random - 0.5);
|
||||||
|
end;
|
||||||
|
lcsDerivative.Add(x, y);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.FormCreate(Sender: TObject);
|
||||||
|
begin
|
||||||
|
Randomize;
|
||||||
|
CreateData;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.rgDataShapeClick(Sender: TObject);
|
||||||
|
begin
|
||||||
|
CreateData;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.seAccumulationRangeChange(Sender: TObject);
|
||||||
|
begin
|
||||||
|
ccsDerivative.AccumulationRange := seAccumulationRange.Value;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user