From 5c796207d7b54d96ef2cb6032d0af872eabecece Mon Sep 17 00:00:00 2001 From: ask Date: Fri, 10 Apr 2009 08:42:18 +0000 Subject: [PATCH] TAChart: Rename Auto{X/Y}{Max/Min} to Use{X/Y}{Max/Min} and make it work. git-svn-id: trunk@19297 - --- components/tachart/funcdemo/main.lfm | 4 +++ components/tachart/funcdemo/main.lrs | 11 ++++---- components/tachart/taseries.pas | 31 ++++++++++++++------- components/tachart/tatypes.pas | 40 ++++++++++++++-------------- 4 files changed, 51 insertions(+), 35 deletions(-) diff --git a/components/tachart/funcdemo/main.lfm b/components/tachart/funcdemo/main.lfm index c41746c69e..e66ffd10a0 100644 --- a/components/tachart/funcdemo/main.lfm +++ b/components/tachart/funcdemo/main.lfm @@ -36,6 +36,10 @@ object Form1: TForm1 Extent.YMin = -1 Extent.XMax = 6.28 Extent.YMax = 1 + Extent.UseXMin = True + Extent.UseYMin = True + Extent.UseXMax = True + Extent.UseYMax = True Pen.Color = clOlive Pen.Width = 2 Title = 'Sin(x)' diff --git a/components/tachart/funcdemo/main.lrs b/components/tachart/funcdemo/main.lrs index 67db1d2656..114559bb41 100644 --- a/components/tachart/funcdemo/main.lrs +++ b/components/tachart/funcdemo/main.lrs @@ -14,9 +14,10 @@ LazarusResources.Add('TForm1','FORMDATA',[ +'alClient'#5'Color'#7#9'clBtnFace'#11'ParentColor'#8#0#11'TFuncSeries'#17'Ch' +'art1FuncSeries1'#11'Extent.XMin'#5#0#248'(\'#143#194#245#200#1#192#11'Exten' +'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'?'#9'Pen.Color'#7#7'clOliv' - +'e'#9'Pen.Width'#2#2#5'Title'#6#6'Sin(x)'#0#0#5'TLine'#11'Chart1XAxis'#12'Sh' - +'owInLegend'#8#11'SeriesColor'#7#7'clBlack'#0#0#5'TLine'#11'Chart1YAxis'#12 - +'ShowInLegend'#8#9'LineStyle'#7#10'lsVertical'#11'SeriesColor'#7#7'clBlack'#0 - +#0#0#0 + +#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 + +'clOlive'#9'Pen.Width'#2#2#5'Title'#6#6'Sin(x)'#0#0#5'TLine'#11'Chart1XAxis' + +#12'ShowInLegend'#8#11'SeriesColor'#7#7'clBlack'#0#0#5'TLine'#11'Chart1YAxis' + +#12'ShowInLegend'#8#9'LineStyle'#7#10'lsVertical'#11'SeriesColor'#7#7'clBlac' + +'k'#0#0#0#0 ]); diff --git a/components/tachart/taseries.pas b/components/tachart/taseries.pas index 73d50a1f7f..1681963020 100644 --- a/components/tachart/taseries.pas +++ b/components/tachart/taseries.pas @@ -1555,19 +1555,28 @@ procedure TFuncSeries.Draw(ACanvas: TCanvas); begin FChart.XImageToGraph(AX, xg); OnCalculate(xg, yg); - yg := EnsureRange(yg, Extent.YMin, Extent.YMax); + if Extent.UseYMin and (yg < Extent.YMin) then + yg := Extent.YMin; + if Extent.UseYMax and (yg > Extent.YMax) then + yg := Extent.YMax; FChart.YGraphToImage(yg, Result); end; var - x, xmax: Integer; + x, xmax, t: Integer; begin if not Assigned(OnCalculate) then exit; - FChart.XGraphToImage(Extent.XMin, x); - x := Max(x, FChart.ClipRect.Left); - FChart.XGraphToImage(Extent.XMax, xmax); - xmax := Min(xmax, FChart.ClipRect.Right); + x := FChart.ClipRect.Left; + if Extent.UseXMin then begin + FChart.XGraphToImage(Extent.XMin, t); + x := Max(x, t); + end; + xmax := FChart.ClipRect.Right; + if Extent.UseXMax then begin + FChart.XGraphToImage(Extent.XMax, t); + x := Min(x, t); + end; ACanvas.Pen.Assign(Pen); @@ -1657,10 +1666,12 @@ end; procedure TFuncSeries.UpdateBounds(var AXMin, AYMin, AXMax, AYMax: Double); begin - if Extent.XMin < AXMin then AXMin := Extent.XMin; - if Extent.YMin < AYMin then AYMin := Extent.YMin; - if Extent.XMax > AXMax then AXMax := Extent.XMax; - if Extent.YMax > AYMax then AYMax := Extent.YMax; + with Extent do begin + if UseXMin and (XMin < AXMin) then AXMin := XMin; + if UseYMin and (YMin < AYMin) then AYMin := YMin; + if UseXMax and (XMax > AXMax) then AXMax := XMax; + if UseYMax and (YMax > AYMax) then AYMax := YMax; + end; end; procedure TFuncSeries.UpdateParentChart; diff --git a/components/tachart/tatypes.pas b/components/tachart/tatypes.pas index 727a2b60b8..37e39480bb 100644 --- a/components/tachart/tatypes.pas +++ b/components/tachart/tatypes.pas @@ -243,23 +243,23 @@ type TChartExtent = class (TChartElement) private FExtent: TDoubleRect; - FAuto: array [1..4] of Boolean; + FUseBounds: array [1..4] of Boolean; - function GetAuto(AIndex: integer): Boolean; - function GetBorder(AIndex: Integer): Double; - procedure SetAuto(AIndex: Integer; AValue: Boolean); - procedure SetBorder(AIndex: Integer; const AValue: Double); + function GetBounds(AIndex: Integer): Double; + function GetUseBounds(AIndex: integer): Boolean; + procedure SetBounds(AIndex: Integer; const AValue: Double); + procedure SetUseBounds(AIndex: Integer; AValue: Boolean); public property Extent: TDoubleRect read FExtent; published - property XMin: Double index 1 read GetBorder write SetBorder; - property YMin: Double index 2 read GetBorder write SetBorder; - property XMax: Double index 3 read GetBorder write SetBorder; - property YMax: Double index 4 read GetBorder write SetBorder; - property AutoXMin: Boolean index 1 read GetAuto write SetAuto; - property AutoYMin: Boolean index 2 read GetAuto write SetAuto; - property AutoXMax: Boolean index 3 read GetAuto write SetAuto; - property AutoYMax: Boolean index 4 read GetAuto write SetAuto; + property XMin: Double index 1 read GetBounds write SetBounds; + property YMin: Double index 2 read GetBounds write SetBounds; + property XMax: Double index 3 read GetBounds write SetBounds; + property YMax: Double index 4 read GetBounds write SetBounds; + property UseXMin: Boolean index 1 read GetUseBounds write SetUseBounds; + property UseYMin: Boolean index 2 read GetUseBounds write SetUseBounds; + property UseXMax: Boolean index 3 read GetUseBounds write SetUseBounds; + property UseYMax: Boolean index 4 read GetUseBounds write SetUseBounds; end; const @@ -770,23 +770,23 @@ end; { TChartExtent } -function TChartExtent.GetAuto(AIndex: Integer): Boolean; +function TChartExtent.GetUseBounds(AIndex: Integer): Boolean; begin - Result := FAuto[AIndex]; + Result := FUseBounds[AIndex]; end; -function TChartExtent.GetBorder(AIndex: Integer): Double; +function TChartExtent.GetBounds(AIndex: Integer): Double; begin - Result := Extent.coords[AIndex]; + Result := FExtent.coords[AIndex]; end; -procedure TChartExtent.SetAuto(AIndex: Integer; AValue: Boolean); +procedure TChartExtent.SetUseBounds(AIndex: Integer; AValue: Boolean); begin - FAuto[AIndex] := AValue; + FUseBounds[AIndex] := AValue; StyleChanged(Self); end; -procedure TChartExtent.SetBorder(AIndex: Integer; const AValue: Double); +procedure TChartExtent.SetBounds(AIndex: Integer; const AValue: Double); begin FExtent.coords[AIndex] := AValue; StyleChanged(Self);