TAChart: Add "Derivative" page to the source demo. Based on code by Werner Pamler

git-svn-id: trunk@32333 -
This commit is contained in:
ask 2011-09-14 11:44:38 +00:00
parent 478be019bc
commit f188c49a1a
2 changed files with 209 additions and 23 deletions

View File

@ -1,15 +1,16 @@
object Form1: TForm1
Left = 342
Height = 415
Height = 438
Top = 199
Width = 595
Width = 637
Caption = 'Form1'
ClientHeight = 415
ClientWidth = 595
ClientHeight = 438
ClientWidth = 637
OnCreate = FormCreate
LCLVersion = '0.9.31'
object Splitter1: TSplitter
Left = 590
Height = 415
Left = 632
Height = 438
Top = 0
Width = 5
Align = alRight
@ -18,22 +19,22 @@ object Form1: TForm1
end
object PageControl1: TPageControl
Left = 0
Height = 415
Height = 438
Top = 0
Width = 590
Width = 632
ActivePage = tsBasic
Align = alClient
TabIndex = 0
TabOrder = 1
object tsBasic: TTabSheet
Caption = 'Basic'
ClientHeight = 389
ClientWidth = 582
ClientHeight = 412
ClientWidth = 624
object Memo1: TMemo
Left = 0
Height = 34
Top = 0
Width = 582
Width = 624
Align = alTop
Lines.Strings = (
'Modify sources at design-time.'
@ -43,9 +44,9 @@ object Form1: TForm1
end
object Chart2: TChart
Left = 0
Height = 355
Height = 378
Top = 34
Width = 291
Width = 333
AxisList = <
item
Minors = <>
@ -77,8 +78,8 @@ object Form1: TForm1
end
end
object Chart1: TChart
Left = 291
Height = 355
Left = 333
Height = 378
Top = 34
Width = 291
AxisList = <
@ -114,13 +115,13 @@ object Form1: TForm1
end
object tsStatistics: TTabSheet
Caption = 'Statistics'
ClientHeight = 389
ClientWidth = 582
ClientHeight = 412
ClientWidth = 624
object chCalc: TChart
Left = 0
Height = 355
Height = 378
Top = 0
Width = 582
Width = 624
AxisList = <
item
Minors = <>
@ -167,11 +168,11 @@ object Form1: TForm1
object Panel2: TPanel
Left = 0
Height = 34
Top = 355
Width = 582
Top = 378
Width = 624
Align = alBottom
ClientHeight = 34
ClientWidth = 582
ClientWidth = 624
TabOrder = 1
object cbCumulative: TCheckBox
Left = 8
@ -186,6 +187,115 @@ object Form1: TForm1
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
object RandomChartSource1: TRandomChartSource
PointsNumber = 8
@ -232,4 +342,14 @@ object Form1: TForm1
left = 504
top = 268
end
object lcsDerivative: TListChartSource
left = 156
top = 84
end
object ccsDerivative: TCalculatedChartSource
AccumulationMethod = camDerivative
Origin = lcsDerivative
left = 156
top = 140
end
end

View File

@ -5,36 +5,53 @@ unit Main;
interface
uses
ComCtrls, ExtCtrls, StdCtrls, Forms, TAGraph, TASeries, TASources, Classes;
ComCtrls, ExtCtrls, Spin, StdCtrls, Forms, TAGraph, TASeries, TASources,
Classes;
type
{ TForm1 }
TForm1 = class(TForm)
ccsDerivative: TCalculatedChartSource;
cbCumulative: TCheckBox;
ccsAvg: TCalculatedChartSource;
ccsSum: TCalculatedChartSource;
Chart1: TChart;
Chart1BarSeries1: TBarSeries;
Chart1LineSeries1: TLineSeries;
chDerivativeLineOrig: TLineSeries;
chDerivativeLineDeriv: TLineSeries;
Chart1LineSeries4: TLineSeries;
Chart1LineSeries5: TLineSeries;
Chart2: TChart;
Chart2AreaSeries1: TAreaSeries;
Chart2LineSeries1: TLineSeries;
chDerivative: TChart;
chCalc: TChart;
chCalcLineSeries1: TLineSeries;
chCalcLineSeriesAvg: TLineSeries;
chCalcLineSeriesSum: TLineSeries;
seAccumulationRange: TSpinEdit;
lblAccumulationRange: TLabel;
ListChartSource1: TListChartSource;
lcsDerivative: TListChartSource;
Memo1: TMemo;
PageControl1: TPageControl;
Panel1: TPanel;
Panel2: TPanel;
rgDataShape: TRadioGroup;
RandomChartSource1: TRandomChartSource;
RandomChartSource2: TRandomChartSource;
Splitter1: TSplitter;
tsDerivative: TTabSheet;
tsStatistics: TTabSheet;
tsBasic: TTabSheet;
procedure cbCumulativeChange(Sender: TObject);
procedure CreateData;
procedure seAccumulationRangeChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure rgDataShapeClick(Sender: TObject);
end;
var
@ -44,6 +61,9 @@ implementation
{$R *.lfm}
uses
Math;
{ TForm1 }
procedure TForm1.cbCumulativeChange(Sender: TObject);
@ -51,5 +71,51 @@ begin
chCalcLineSeriesSum.Active := cbCumulative.Checked;
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.