TAChart: Fix horizontal position of series labels for a bar series having multiple, non-stacked y values (issue #34862)

git-svn-id: trunk@60073 -
This commit is contained in:
wp 2019-01-13 15:56:22 +00:00
parent 554039e183
commit ed08eac4e4
2 changed files with 13 additions and 7 deletions

View File

@ -291,7 +291,7 @@ type
function GetErrorBars(APointIndex: Integer; IsXError: Boolean;
out AGraphPointPos, AGraphPointNeg: Double): Boolean;
}
function GetLabelDataPoint(AIndex: Integer): TDoublePoint; virtual;
function GetLabelDataPoint(AIndex, AYIndex: Integer): TDoublePoint; virtual;
procedure GetLegendItemsRect(AItems: TChartLegendItems; ABrush: TBrush);
function GetXRange(AX: Double; AIndex: Integer): Double;
function GetZeroLevel: Double; virtual;
@ -1263,7 +1263,6 @@ begin
y := Source[i]^.Y;
ysum := y;
prev := GetZeroLevel;
g := GetLabelDataPoint(i);
ld := GetLabelDirection(i);
for si := 0 to Source.YCount - 1 do begin
if Styles <> nil then begin
@ -1273,6 +1272,7 @@ begin
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;
@ -1390,7 +1390,7 @@ begin
Result := FErrorBars[AIndex];
end;
function TBasicPointSeries.GetLabelDataPoint(AIndex: Integer): TDoublePoint;
function TBasicPointSeries.GetLabelDataPoint(AIndex, AYIndex: Integer): TDoublePoint;
begin
Result := GetGraphPoint(AIndex);
end;

View File

@ -63,7 +63,7 @@ type
procedure SetSeriesColor(AValue: TColor);
procedure SetZeroLevel(AValue: Double);
strict protected
function GetLabelDataPoint(AIndex: Integer): TDoublePoint; override;
function GetLabelDataPoint(AIndex, AYIndex: Integer): TDoublePoint; override;
function ToolTargetDistance(const AParams: TNearestPointParams;
AGraphPt: TDoublePoint; APointIdx, AXIdx, AYIdx: Integer): Integer; override;
protected
@ -1245,13 +1245,19 @@ begin
Result := Abs(f(2 * w) - f(0));
end;
function TBarSeries.GetLabelDataPoint(AIndex: Integer): TDoublePoint;
function TBarSeries.GetLabelDataPoint(AIndex, AYIndex: Integer): TDoublePoint;
var
ofs, w: Double;
ofs, w, wbar: Double;
begin
Result := inherited GetLabelDataPoint(AIndex);
Result := inherited GetLabelDataPoint(AIndex, AYIndex);
BarOffsetWidth(TDoublePointBoolArr(Result)[IsRotated], AIndex, ofs, w);
TDoublePointBoolArr(Result)[IsRotated] += ofs;
// Find x centers of bars in non-stacked bar series with multiple y values.
if (not FStacked) and (Source.YCount > 1) then begin
wbar := 2 * w / Source.YCount;
TDoublePointboolArr(Result)[IsRotated] += (wbar * (AYIndex + 0.5) - w);
end;
end;
procedure TBarSeries.GetLegendItems(AItems: TChartLegendItems);