mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-07 16:49:25 +01:00
TAChart: Support NaNs in area series. Update demo
git-svn-id: trunk@32448 -
This commit is contained in:
parent
5416195ef5
commit
1176e4faca
@ -41,6 +41,10 @@ object Form1: TForm1
|
||||
BarBrush.Color = clRed
|
||||
Source = lcs1
|
||||
end
|
||||
object Chart1AreaSeries1: TAreaSeries
|
||||
Active = False
|
||||
Source = lcs1
|
||||
end
|
||||
object Chart1PieSeries1: TPieSeries
|
||||
Active = False
|
||||
Source = lcs1
|
||||
@ -79,6 +83,7 @@ object Form1: TForm1
|
||||
Items.Strings = (
|
||||
'Line'
|
||||
'Bar'
|
||||
'Area'
|
||||
'Pie'
|
||||
)
|
||||
OnClick = rgSeriesTypeClick
|
||||
|
||||
@ -11,6 +11,7 @@ uses
|
||||
type
|
||||
TForm1 = class(TForm)
|
||||
Chart1: TChart;
|
||||
Chart1AreaSeries1: TAreaSeries;
|
||||
Chart1BarSeries1: TBarSeries;
|
||||
Chart1LineSeries1: TLineSeries;
|
||||
Chart1PieSeries1: TPieSeries;
|
||||
|
||||
@ -64,6 +64,8 @@
|
||||
</SearchPaths>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<GenerateDebugInfo Value="True"/>
|
||||
<DebugInfoType Value="dsAuto"/>
|
||||
<UseExternalDbgSyms Value="True"/>
|
||||
</Debugging>
|
||||
<Options>
|
||||
|
||||
@ -212,6 +212,9 @@ type
|
||||
FUpBound: Integer;
|
||||
FUseReticule: Boolean;
|
||||
|
||||
strict protected
|
||||
procedure UpdateGraphPoints(AIndex: Integer); overload; inline;
|
||||
procedure UpdateGraphPoints(AIndex, ALo, AUp: Integer); overload;
|
||||
protected
|
||||
procedure AfterAdd; override;
|
||||
procedure AfterDrawPointer(
|
||||
@ -224,7 +227,6 @@ type
|
||||
function GetZeroLevel: Double; virtual;
|
||||
procedure PrepareGraphPoints(
|
||||
const AExtent: TDoubleRect; AFilterByExtent: Boolean);
|
||||
procedure UpdateGraphPoints(AIndex: Integer);
|
||||
procedure UpdateMargins(ADrawer: IChartDrawer; var AMargins: TRect); override;
|
||||
procedure UpdateMinXRange;
|
||||
|
||||
@ -1025,16 +1027,21 @@ begin
|
||||
UpdateParentChart;
|
||||
end;
|
||||
|
||||
procedure TBasicPointSeries.UpdateGraphPoints(AIndex: Integer);
|
||||
procedure TBasicPointSeries.UpdateGraphPoints(AIndex, ALo, AUp: Integer);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
if IsRotated then
|
||||
for i := FLoBound to FUpBound do
|
||||
FGraphPoints[i - FLoBound].X += AxisToGraphY(Source[i]^.YList[AIndex])
|
||||
for i := ALo to AUp do
|
||||
FGraphPoints[i - ALo].X += AxisToGraphY(Source[i]^.YList[AIndex])
|
||||
else
|
||||
for i := FLoBound to FUpBound do
|
||||
FGraphPoints[i - FLoBound].Y += AxisToGraphY(Source[i]^.YList[AIndex]);
|
||||
for i := ALo to AUp do
|
||||
FGraphPoints[i - ALo].Y += AxisToGraphY(Source[i]^.YList[AIndex]);
|
||||
end;
|
||||
|
||||
procedure TBasicPointSeries.UpdateGraphPoints(AIndex: Integer);
|
||||
begin
|
||||
UpdateGraphPoints(AIndex, FLoBound, FUpBound);
|
||||
end;
|
||||
|
||||
procedure TBasicPointSeries.UpdateMargins(
|
||||
|
||||
@ -1068,24 +1068,16 @@ var
|
||||
end;
|
||||
|
||||
var
|
||||
ext, ext2: TDoubleRect;
|
||||
prevPts: TPointArray;
|
||||
|
||||
procedure DrawSegment(AStart, AEnd: Integer);
|
||||
var
|
||||
i, j, n2, numPrevPts: Integer;
|
||||
a, b: TDoublePoint;
|
||||
ext, ext2: TDoubleRect;
|
||||
z, z1, z2: Double;
|
||||
prevPts: TPointArray;
|
||||
begin
|
||||
if IsEmpty then exit;
|
||||
|
||||
ext := ParentChart.CurrentExtent;
|
||||
ext2 := ext;
|
||||
ExpandRange(ext2.a.X, ext2.b.X, 0.1);
|
||||
ExpandRange(ext2.a.Y, ext2.b.Y, 0.1);
|
||||
|
||||
PrepareGraphPoints(ext, true);
|
||||
if Length(FGraphPoints) = 0 then exit;
|
||||
|
||||
SetLength(pts, Length(FGraphPoints) * 4 + 4);
|
||||
SetLength(prevPts, Length(pts));
|
||||
begin
|
||||
numPts := 0;
|
||||
numPrevPts := 0;
|
||||
|
||||
if UseZeroLevel then
|
||||
@ -1097,12 +1089,12 @@ begin
|
||||
|
||||
for j := 0 to Source.YCount - 1 do begin
|
||||
if j > 0 then
|
||||
UpdateGraphPoints(j - 1);
|
||||
UpdateGraphPoints(j - 1, AStart, AEnd);
|
||||
numPts := 0;
|
||||
a := ProjToRect(FGraphPoints[0], ext2);
|
||||
a := ProjToRect(FGraphPoints[AStart], ext2);
|
||||
PushPoint(ProjToLine(a, z1));
|
||||
z1 := IfThen(IsRotated, a.X, a.Y);
|
||||
for i := 0 to High(FGraphPoints) - 1 do begin
|
||||
for i := AStart to AEnd - 1 do begin
|
||||
a := FGraphPoints[i];
|
||||
b := FGraphPoints[i + 1];
|
||||
case ConnectType of
|
||||
@ -1128,7 +1120,7 @@ begin
|
||||
PushPoint(ProjToRect(b, ext2));
|
||||
end;
|
||||
end;
|
||||
a := ProjToRect(FGraphPoints[High(FGraphPoints)], ext2);
|
||||
a := ProjToRect(FGraphPoints[AEnd], ext2);
|
||||
PushPoint(ProjToLine(a, z2));
|
||||
z2 := IfThen(IsRotated, a.X, a.Y);
|
||||
n2 := numPts;
|
||||
@ -1151,12 +1143,40 @@ begin
|
||||
end;
|
||||
if AreaLinesPen.Style <> psClear then begin
|
||||
ADrawer.Pen := AreaLinesPen;
|
||||
for i := 1 to High(FGraphPoints) - 1 do begin
|
||||
for i := AStart + 1 to AEnd - 1 do begin
|
||||
a := ProjToRect(FGraphPoints[i], ext2);
|
||||
b := ProjToLine(a, z);
|
||||
ADrawer.Line(ParentChart.GraphToImage(a), ParentChart.GraphToImage(b));
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
var
|
||||
i, j: Integer;
|
||||
begin
|
||||
if IsEmpty then exit;
|
||||
|
||||
ext := ParentChart.CurrentExtent;
|
||||
ext2 := ext;
|
||||
ExpandRange(ext2.a.X, ext2.b.X, 0.1);
|
||||
ExpandRange(ext2.a.Y, ext2.b.Y, 0.1);
|
||||
|
||||
PrepareGraphPoints(ext, true);
|
||||
if Length(FGraphPoints) = 0 then exit;
|
||||
|
||||
SetLength(pts, Length(FGraphPoints) * 4 + 4);
|
||||
SetLength(prevPts, Length(pts));
|
||||
j := -1;
|
||||
for i := 0 to High(FGraphPoints) do
|
||||
if IsNan(FGraphPoints[i]) = (j >= 0) then
|
||||
if j >= 0 then begin
|
||||
DrawSegment(j, i - 1);
|
||||
j := -1;
|
||||
end
|
||||
else
|
||||
j := i;
|
||||
if j >= 0 then
|
||||
DrawSegment(j, High(FGraphPoints));
|
||||
DrawLabels(ADrawer);
|
||||
end;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user