TAChart: Introduce TFuncSeries.Step to control drawing granularity.

git-svn-id: trunk@19298 -
This commit is contained in:
ask 2009-04-10 09:33:06 +00:00
parent 5c796207d7
commit 51f0ad8fc8
3 changed files with 19 additions and 5 deletions

View File

@ -42,6 +42,7 @@ object Form1: TForm1
Extent.UseYMax = True Extent.UseYMax = True
Pen.Color = clOlive Pen.Color = clOlive
Pen.Width = 2 Pen.Width = 2
Step = 4
Title = 'Sin(x)' Title = 'Sin(x)'
end end
object Chart1XAxis: TLine object Chart1XAxis: TLine

View File

@ -16,8 +16,8 @@ LazarusResources.Add('TForm1','FORMDATA',[
+'t.YMin'#5#0#0#0#0#0#0#0#128#255#191#11'Extent.XMax'#5#0#248'(\'#143#194#245 +'t.YMin'#5#0#0#0#0#0#0#0#128#255#191#11'Extent.XMax'#5#0#248'(\'#143#194#245
+#200#1'@'#11'Extent.YMax'#5#0#0#0#0#0#0#0#128#255'?'#14'Extent.UseXMin'#9#14 +#200#1'@'#11'Extent.YMax'#5#0#0#0#0#0#0#0#128#255'?'#14'Extent.UseXMin'#9#14
+'Extent.UseYMin'#9#14'Extent.UseXMax'#9#14'Extent.UseYMax'#9#9'Pen.Color'#7#7 +'Extent.UseYMin'#9#14'Extent.UseXMax'#9#14'Extent.UseYMax'#9#9'Pen.Color'#7#7
+'clOlive'#9'Pen.Width'#2#2#5'Title'#6#6'Sin(x)'#0#0#5'TLine'#11'Chart1XAxis' +'clOlive'#9'Pen.Width'#2#2#4'Step'#2#4#5'Title'#6#6'Sin(x)'#0#0#5'TLine'#11
+#12'ShowInLegend'#8#11'SeriesColor'#7#7'clBlack'#0#0#5'TLine'#11'Chart1YAxis' +'Chart1XAxis'#12'ShowInLegend'#8#11'SeriesColor'#7#7'clBlack'#0#0#5'TLine'#11
+#12'ShowInLegend'#8#9'LineStyle'#7#10'lsVertical'#11'SeriesColor'#7#7'clBlac' +'Chart1YAxis'#12'ShowInLegend'#8#9'LineStyle'#7#10'lsVertical'#11'SeriesColo'
+'k'#0#0#0#0 +'r'#7#7'clBlack'#0#0#0#0
]); ]);

View File

@ -291,6 +291,8 @@ type
TFuncCalculateEvent = procedure (const AX: Double; out AY: Double) of object; TFuncCalculateEvent = procedure (const AX: Double; out AY: Double) of object;
TFuncSeriesStep = 1..MaxInt;
{ TFuncSeries } { TFuncSeries }
TFuncSeries = class(TBasicChartSeries) TFuncSeries = class(TBasicChartSeries)
@ -298,10 +300,12 @@ type
FExtent: TChartExtent; FExtent: TChartExtent;
FOnCalculate: TFuncCalculateEvent; FOnCalculate: TFuncCalculateEvent;
FPen: TChartPen; FPen: TChartPen;
FStep: TFuncSeriesStep;
procedure SetExtent(const AValue: TChartExtent); procedure SetExtent(const AValue: TChartExtent);
procedure SetOnCalculate(const AValue: TFuncCalculateEvent); procedure SetOnCalculate(const AValue: TFuncCalculateEvent);
procedure SetPen(const AValue: TChartPen); procedure SetPen(const AValue: TChartPen);
procedure SetStep(AValue: TFuncSeriesStep);
protected protected
procedure DrawLegend(ACanvas: TCanvas; const ARect: TRect); override; procedure DrawLegend(ACanvas: TCanvas; const ARect: TRect); override;
function GetLegendCount: Integer; override; function GetLegendCount: Integer; override;
@ -327,6 +331,7 @@ type
property Pen: TChartPen read FPen write SetPen; property Pen: TChartPen read FPen write SetPen;
property OnCalculate: TFuncCalculateEvent read FOnCalculate write SetOnCalculate; property OnCalculate: TFuncCalculateEvent read FOnCalculate write SetOnCalculate;
property ShowInLegend; property ShowInLegend;
property Step: TFuncSeriesStep read FStep write SetStep default 2;
property Title; property Title;
end; end;
@ -1538,6 +1543,7 @@ begin
FShowInLegend := true; FShowInLegend := true;
FPen := TChartPen.Create; FPen := TChartPen.Create;
FPen.OnChange := @StyleChanged; FPen.OnChange := @StyleChanged;
FStep := 2;
end; end;
destructor TFuncSeries.Destroy; destructor TFuncSeries.Destroy;
@ -1582,7 +1588,7 @@ begin
ACanvas.MoveTo(x, CalcY(x)); ACanvas.MoveTo(x, CalcY(x));
while x < xmax do begin while x < xmax do begin
Inc(x, 2); Inc(x, FStep);
ACanvas.LineTo(x, CalcY(x)); ACanvas.LineTo(x, CalcY(x));
end; end;
end; end;
@ -1659,6 +1665,13 @@ begin
UpdateParentChart; UpdateParentChart;
end; end;
procedure TFuncSeries.SetStep(AValue: TFuncSeriesStep);
begin
if FStep = AValue then exit;
FStep := AValue;
UpdateParentChart;
end;
procedure TFuncSeries.StyleChanged(Sender: TObject); procedure TFuncSeries.StyleChanged(Sender: TObject);
begin begin
UpdateParentChart; UpdateParentChart;