TAChart: Add property UseZeroLevel to TBarSeries in order to make it behave like TAreaSeries on linear and logarithmic axes Issue #34863

git-svn-id: branches/fixes_2_0@60386 -
This commit is contained in:
mattias 2019-02-09 08:48:01 +00:00
parent 8caa81b321
commit 7b22ce1935

View File

@ -51,6 +51,7 @@ type
FBarWidthPercent: Integer; FBarWidthPercent: Integer;
FBarWidthStyle: TBarWidthStyle; FBarWidthStyle: TBarWidthStyle;
FOnBeforeDrawBar: TBeforeDrawBarEvent; FOnBeforeDrawBar: TBeforeDrawBarEvent;
FUseZeroLevel: Boolean;
FZeroLevel: Double; FZeroLevel: Double;
function IsZeroLevelStored: boolean; function IsZeroLevelStored: boolean;
@ -61,6 +62,7 @@ type
procedure SetBarWidthStyle(AValue: TBarWidthStyle); procedure SetBarWidthStyle(AValue: TBarWidthStyle);
procedure SetOnBeforeDrawBar(AValue: TBeforeDrawBarEvent); procedure SetOnBeforeDrawBar(AValue: TBeforeDrawBarEvent);
procedure SetSeriesColor(AValue: TColor); procedure SetSeriesColor(AValue: TColor);
procedure SetUseZeroLevel(AValue: Boolean);
procedure SetZeroLevel(AValue: Double); procedure SetZeroLevel(AValue: Double);
strict protected strict protected
function GetLabelDataPoint(AIndex, AYIndex: Integer): TDoublePoint; override; function GetLabelDataPoint(AIndex, AYIndex: Integer): TDoublePoint; override;
@ -103,6 +105,8 @@ type
property Styles; property Styles;
property ToolTargets default [nptPoint, nptYList, nptCustom]; property ToolTargets default [nptPoint, nptYList, nptCustom];
property UseReticule; deprecated 'Use DatapointCrosshairTool instead'; property UseReticule; deprecated 'Use DatapointCrosshairTool instead';
property UseZeroLevel: Boolean
read FUseZeroLevel write SetUseZeroLevel default true;
property ZeroLevel: Double property ZeroLevel: Double
read FZeroLevel write SetZeroLevel stored IsZeroLevelStored; read FZeroLevel write SetZeroLevel stored IsZeroLevelStored;
published published
@ -1037,6 +1041,7 @@ begin
Self.FBarWidthPercent := FBarWidthPercent; Self.FBarWidthPercent := FBarWidthPercent;
Self.FBarWidthStyle := FBarWidthStyle; Self.FBarWidthStyle := FBarWidthStyle;
Self.FOnBeforeDrawBar := FOnBeforeDrawBar; Self.FOnBeforeDrawBar := FOnBeforeDrawBar;
Self.FUseZeroLevel := FUseZeroLevel;
Self.FZeroLevel := FZeroLevel; Self.FZeroLevel := FZeroLevel;
end; end;
inherited Assign(ASource); inherited Assign(ASource);
@ -1075,6 +1080,7 @@ begin
FStacked := true; FStacked := true;
FOptimizeX := false; FOptimizeX := false;
FSupportsZeroLevel := true; FSupportsZeroLevel := true;
FUseZeroLevel := true;
end; end;
destructor TBarSeries.Destroy; destructor TBarSeries.Destroy;
@ -1156,6 +1162,7 @@ var
var var
ofs, y: Double; ofs, y: Double;
zero: Double;
begin begin
if IsEmpty then exit; if IsEmpty then exit;
@ -1166,6 +1173,10 @@ begin
ExpandRange(ext2.a.Y, ext2.b.Y, 1.0); ExpandRange(ext2.a.Y, ext2.b.Y, 1.0);
scaled_depth := ADrawer.Scale(Depth); scaled_depth := ADrawer.Scale(Depth);
if UseZeroLevel then
zero := ZeroLevel
else
zero := IfThen(IsRotated, ext2.a.X, ext2.a.Y);
PrepareGraphPoints(ext2, true); PrepareGraphPoints(ext2, true);
SetLength(heights, Source.YCount + 1); SetLength(heights, Source.YCount + 1);
@ -1175,9 +1186,9 @@ begin
p.X := AxisToGraphX(p.X); p.X := AxisToGraphX(p.X);
BarOffsetWidth(p.X, pointIndex, ofs, w); BarOffsetWidth(p.X, pointIndex, ofs, w);
p.X += ofs; p.X += ofs;
heights[0] := ZeroLevel; heights[0] := zero;
if FStacked then begin if FStacked then begin
heights[1] := NumberOr(p.Y, ZeroLevel); heights[1] := NumberOr(p.Y, zero);
for stackIndex := 1 to Source.YCount - 1 do begin for stackIndex := 1 to Source.YCount - 1 do begin
y := Source[pointIndex]^.YList[stackIndex - 1]; y := Source[pointIndex]^.YList[stackIndex - 1];
if not IsNan(y) then if not IsNan(y) then
@ -1193,7 +1204,7 @@ begin
if not IsNaN(y) then if not IsNaN(y) then
heights[stackIndex + 1] := AxisToGraphY(y) heights[stackIndex + 1] := AxisToGraphY(y)
else else
heights[stackIndex + 1] := ZeroLevel; heights[stackIndex + 1] := zero;
end; end;
p.X -= w; p.X -= w;
w := w / High(heights); w := w / High(heights);
@ -1217,6 +1228,7 @@ begin
if IsEmpty then exit; if IsEmpty then exit;
if BarWidthStyle = bwPercentMin then if BarWidthStyle = bwPercentMin then
UpdateMinXRange; UpdateMinXRange;
if not IsEmpty and UseZeroLevel then
UpdateMinMax(GraphToAxisY(ZeroLevel), Result.a.Y, Result.b.Y); UpdateMinMax(GraphToAxisY(ZeroLevel), Result.a.Y, Result.b.Y);
// Show first and last bars fully. // Show first and last bars fully.
@ -1346,7 +1358,7 @@ end;
function TBarSeries.GetZeroLevel: Double; function TBarSeries.GetZeroLevel: Double;
begin begin
Result := ZeroLevel; Result := IfThen(UseZeroLevel, ZeroLevel, 0.0);
end; end;
function TBarSeries.IsZeroLevelStored: boolean; function TBarSeries.IsZeroLevelStored: boolean;
@ -1398,6 +1410,14 @@ begin
FBarBrush.Color := AValue; FBarBrush.Color := AValue;
end; end;
procedure TBarSeries.SetUseZeroLevel(AValue: Boolean);
begin
if FUseZeroLevel = AValue then exit;
FUseZeroLevel := AValue;
// FSupportsZeroLevel := FUseZeroLevel;
UpdateParentChart;
end;
procedure TBarSeries.SetZeroLevel(AValue: Double); procedure TBarSeries.SetZeroLevel(AValue: Double);
begin begin
if FZeroLevel = AValue then exit; if FZeroLevel = AValue then exit;
@ -1473,7 +1493,7 @@ begin
FAreaLinesPen := TPen.Create; FAreaLinesPen := TPen.Create;
FAreaLinesPen.OnChange := @StyleChanged; FAreaLinesPen.OnChange := @StyleChanged;
FStacked := true; FStacked := true;
FSupportsZeroLevel := FUseZeroLevel; FSupportsZeroLevel := true; //FUseZeroLevel;
end; end;
destructor TAreaSeries.Destroy; destructor TAreaSeries.Destroy;
@ -1698,7 +1718,7 @@ function TAreaSeries.Extent: TDoubleRect;
begin begin
Result := inherited Extent; Result := inherited Extent;
if not IsEmpty and UseZeroLevel then if not IsEmpty and UseZeroLevel then
UpdateMinMax(ZeroLevel, Result.a.Y, Result.b.Y); UpdateMinMax(GraphToAxisY(ZeroLevel), Result.a.Y, Result.b.Y);
end; end;
procedure TAreaSeries.GetLegendItems(AItems: TChartLegendItems); procedure TAreaSeries.GetLegendItems(AItems: TChartLegendItems);
@ -1762,7 +1782,7 @@ procedure TAreaSeries.SetUseZeroLevel(AValue: Boolean);
begin begin
if FUseZeroLevel = AValue then exit; if FUseZeroLevel = AValue then exit;
FUseZeroLevel := AValue; FUseZeroLevel := AValue;
FSupportsZeroLevel := FUseZeroLevel; // FSupportsZeroLevel := FUseZeroLevel;
UpdateParentChart; UpdateParentChart;
end; end;