From 7ea6dda14aaf3ebcea554d59586a00cdd7ece0f8 Mon Sep 17 00:00:00 2001 From: wp Date: Thu, 7 Feb 2019 15:38:55 +0000 Subject: [PATCH] TAChart: Fix stacked bar series containing missing values (NaN). git-svn-id: trunk@60355 - --- components/tachart/tacustomseries.pas | 36 +++++++++++++++------------ components/tachart/taseries.pas | 5 ++-- components/tachart/tasources.pas | 18 +++++++++++--- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/components/tachart/tacustomseries.pas b/components/tachart/tacustomseries.pas index 4262369c04..21947e7688 100644 --- a/components/tachart/tacustomseries.pas +++ b/components/tachart/tacustomseries.pas @@ -1265,6 +1265,7 @@ var lfont: TFont; curr, prev: Double; ext: TDoubleRect; + yIsNaN: Boolean; begin if not Marks.IsMarkLabelsVisible then exit; @@ -1275,29 +1276,24 @@ begin ext := Extent; for i := FLoBound to FUpBound do begin - if IsNan(Source[i]^.Point) then + if IsNan(Source[i]^.X) then continue; - y := Source[i]^.Y; - ysum := y; if FSupportsZeroLevel then prev := GetZeroLevel else prev := TDoublePointBoolArr(ext.a)[not IsRotated]; + y := Source[i]^.Y; + yIsNaN := IsNaN(y); + ysum := IfThen(yIsNaN, prev, y); ld := GetLabelDirection(i); for si := 0 to Source.YCount - 1 do begin - if Styles <> nil then begin - style := Styles.StyleByIndex(si); - if style.UseFont then - Marks.LabelFont.Assign(style.Font) - else - Marks.LabelFont.Assign(lfont); - end; g := GetLabelDataPoint(i, si); if si > 0 then begin - y := NumberOr(Source[i]^.YList[si-1], 0); - if IsNaN(y) then Continue; + y := Source[i]^.YList[si-1]; + yIsNaN := IsNaN(y); + if yIsNaN then y := 0.0; if Stacked then begin - if IsNaN(ysum) then ysum := y else ysum += y; + ysum += y; y := ysum; end; end; @@ -1319,9 +1315,17 @@ begin with ParentChart do if ((Marks.YIndex = MARKS_YINDEX_ALL) or (Marks.YIndex = si)) and - IsPointInViewPort(g) - then + IsPointInViewPort(g) and (not yIsNaN) + then begin + if Styles <> nil then begin + style := Styles.StyleByIndex(si); + if style.UseFont then + Marks.LabelFont.Assign(style.Font) + else + Marks.LabelFont.Assign(lfont); + end; DrawLabel(FormattedMark(i, '', si), GraphToImage(g), ld); + end; end; end; @@ -1413,7 +1417,7 @@ end; function TBasicPointSeries.GetLabelDataPoint(AIndex, AYIndex: Integer): TDoublePoint; begin - Result := GetGraphPoint(AIndex); + Result := GetGraphPoint(AIndex, 0, AYIndex); end; function TBasicPointSeries.GetLabelDirection(AIndex: Integer): TLabelDirection; diff --git a/components/tachart/taseries.pas b/components/tachart/taseries.pas index cf3f8c8f25..196fb04c5d 100644 --- a/components/tachart/taseries.pas +++ b/components/tachart/taseries.pas @@ -1190,9 +1190,8 @@ begin if FStacked then begin heights[1] := NumberOr(p.Y, zero); for stackIndex := 1 to Source.YCount - 1 do begin - y := Source[pointIndex]^.YList[stackIndex - 1]; - if not IsNan(y) then - heights[stackIndex + 1] := heights[stackIndex] + y; + y := NumberOr(Source[pointIndex]^.YList[stackIndex - 1], 0); + heights[stackIndex + 1] := heights[stackIndex] + y; end; for stackIndex := 0 to High(heights) do heights[stackindex] := AxisToGraphY(heights[stackindex]); diff --git a/components/tachart/tasources.pas b/components/tachart/tasources.pas index c79e9b1408..d9de974206 100644 --- a/components/tachart/tasources.pas +++ b/components/tachart/tasources.pas @@ -688,6 +688,18 @@ begin Notify; end; +function CompareFloat(x1, x2: Double): Integer; +begin + if IsNaN(x1) and IsNaN(x2) then + Result := 0 + else if IsNaN(x1) then + Result := +1 + else if IsNaN(x2) then + Result := -1 + else + Result := CompareValue(x1, x2); +end; + function CompareDataItemX(AItem1, AItem2: Pointer): Integer; var i: Integer; @@ -695,13 +707,11 @@ var begin item1 := PChartDataItem(AItem1); item2 := PChartDataItem(AItem2); - Result := Sign(item1^.X - item2^.X); // wp: why "sign" ??? - -// Result := Sign(PChartDataItem(AItem1)^.X - PChartDataItem(AItem2)^.X); + Result := CompareFloat(item1^.X, item2^.X); if Result = 0 then for i := 0 to Min(High(item1^.XList), High(item2^.XList)) do begin - Result := Sign(item1^.XList[i] - item2^.XList[i]); + Result := CompareFloat(item1^.XList[i], item2^.XList[i]); if Result <> 0 then exit; end;