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

View File

@ -63,7 +63,7 @@ type
procedure SetSeriesColor(AValue: TColor); procedure SetSeriesColor(AValue: TColor);
procedure SetZeroLevel(AValue: Double); procedure SetZeroLevel(AValue: Double);
strict protected strict protected
function GetLabelDataPoint(AIndex: Integer): TDoublePoint; override; function GetLabelDataPoint(AIndex, AYIndex: Integer): TDoublePoint; override;
function ToolTargetDistance(const AParams: TNearestPointParams; function ToolTargetDistance(const AParams: TNearestPointParams;
AGraphPt: TDoublePoint; APointIdx, AXIdx, AYIdx: Integer): Integer; override; AGraphPt: TDoublePoint; APointIdx, AXIdx, AYIdx: Integer): Integer; override;
protected protected
@ -1245,13 +1245,19 @@ begin
Result := Abs(f(2 * w) - f(0)); Result := Abs(f(2 * w) - f(0));
end; end;
function TBarSeries.GetLabelDataPoint(AIndex: Integer): TDoublePoint; function TBarSeries.GetLabelDataPoint(AIndex, AYIndex: Integer): TDoublePoint;
var var
ofs, w: Double; ofs, w, wbar: Double;
begin begin
Result := inherited GetLabelDataPoint(AIndex); Result := inherited GetLabelDataPoint(AIndex, AYIndex);
BarOffsetWidth(TDoublePointBoolArr(Result)[IsRotated], AIndex, ofs, w); BarOffsetWidth(TDoublePointBoolArr(Result)[IsRotated], AIndex, ofs, w);
TDoublePointBoolArr(Result)[IsRotated] += ofs; 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; end;
procedure TBarSeries.GetLegendItems(AItems: TChartLegendItems); procedure TBarSeries.GetLegendItems(AItems: TChartLegendItems);