mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-12 12:19:57 +02:00
TAChart: Fix stacked bar series containing missing values (NaN).
git-svn-id: trunk@60355 -
This commit is contained in:
parent
0a38c2bc83
commit
7ea6dda14a
@ -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;
|
||||
|
@ -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]);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user