mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-06 04:57:12 +01:00
TAChart: Add TBarSeries.BarOffsetPercent property
git-svn-id: trunk@27570 -
This commit is contained in:
parent
ea59a61dee
commit
e7ce0b0dac
@ -32,8 +32,8 @@ type
|
|||||||
|
|
||||||
TLegendItem = class
|
TLegendItem = class
|
||||||
private
|
private
|
||||||
FText: String;
|
|
||||||
FColor: TColor;
|
FColor: TColor;
|
||||||
|
FText: String;
|
||||||
public
|
public
|
||||||
constructor Create(const AText: String; AColor: TColor = clTAColor);
|
constructor Create(const AText: String; AColor: TColor = clTAColor);
|
||||||
procedure Draw(ACanvas: TCanvas; const ARect: TRect); virtual;
|
procedure Draw(ACanvas: TCanvas; const ARect: TRect); virtual;
|
||||||
|
|||||||
@ -43,13 +43,16 @@ type
|
|||||||
TBarSeries = class(TBasicPointSeries)
|
TBarSeries = class(TBasicPointSeries)
|
||||||
private
|
private
|
||||||
FBarBrush: TBrush;
|
FBarBrush: TBrush;
|
||||||
|
FBarOffsetPercent: Integer;
|
||||||
FBarPen: TPen;
|
FBarPen: TPen;
|
||||||
FBarWidthPercent: Integer;
|
FBarWidthPercent: Integer;
|
||||||
FZeroLevel: Double;
|
FZeroLevel: Double;
|
||||||
|
|
||||||
function CalcBarWidth(AX: Double; AIndex: Integer): Double;
|
procedure BarOffsetWidth(
|
||||||
|
AX: Double; AIndex: Integer; out AOffset, AWidth: Double);
|
||||||
function IsZeroLevelStored: boolean;
|
function IsZeroLevelStored: boolean;
|
||||||
procedure SetBarBrush(Value: TBrush);
|
procedure SetBarBrush(Value: TBrush);
|
||||||
|
procedure SetBarOffsetPercent(const AValue: Integer);
|
||||||
procedure SetBarPen(Value: TPen);
|
procedure SetBarPen(Value: TPen);
|
||||||
procedure SetBarWidthPercent(Value: Integer);
|
procedure SetBarWidthPercent(Value: Integer);
|
||||||
procedure SetSeriesColor(AValue: TColor);
|
procedure SetSeriesColor(AValue: TColor);
|
||||||
@ -67,6 +70,8 @@ type
|
|||||||
property AxisIndexX;
|
property AxisIndexX;
|
||||||
property AxisIndexY;
|
property AxisIndexY;
|
||||||
property BarBrush: TBrush read FBarBrush write SetBarBrush;
|
property BarBrush: TBrush read FBarBrush write SetBarBrush;
|
||||||
|
property BarOffsetPercent: Integer
|
||||||
|
read FBarOffsetPercent write SetBarOffsetPercent default 0;
|
||||||
property BarPen: TPen read FBarPen write SetBarPen;
|
property BarPen: TPen read FBarPen write SetBarPen;
|
||||||
property BarWidthPercent: Integer
|
property BarWidthPercent: Integer
|
||||||
read FBarWidthPercent write SetBarWidthPercent default DEF_BAR_WIDTH_PERCENT;
|
read FBarWidthPercent write SetBarWidthPercent default DEF_BAR_WIDTH_PERCENT;
|
||||||
@ -694,9 +699,14 @@ end;
|
|||||||
|
|
||||||
{ TBarSeries }
|
{ TBarSeries }
|
||||||
|
|
||||||
function TBarSeries.CalcBarWidth(AX: Double; AIndex: Integer): Double;
|
procedure TBarSeries.BarOffsetWidth(
|
||||||
|
AX: Double; AIndex: Integer; out AOffset, AWidth: Double);
|
||||||
|
var
|
||||||
|
r: Double;
|
||||||
begin
|
begin
|
||||||
Result := GetXRange(AX, AIndex) * FBarWidthPercent * PERCENT / 2;
|
r := GetXRange(AX, AIndex) * PERCENT;
|
||||||
|
AOffset := r * BarOffsetPercent;
|
||||||
|
AWidth := r * BarWidthPercent / 2;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TBarSeries.Create(AOwner: TComponent);
|
constructor TBarSeries.Create(AOwner: TComponent);
|
||||||
@ -776,7 +786,7 @@ var
|
|||||||
|
|
||||||
var
|
var
|
||||||
i, j: Integer;
|
i, j: Integer;
|
||||||
z: Double;
|
z, ofs: Double;
|
||||||
begin
|
begin
|
||||||
if IsEmpty then exit;
|
if IsEmpty then exit;
|
||||||
|
|
||||||
@ -788,11 +798,15 @@ begin
|
|||||||
ACanvas.Brush.Assign(BarBrush);
|
ACanvas.Brush.Assign(BarBrush);
|
||||||
for i := FLoBound to FUpBound do begin
|
for i := FLoBound to FUpBound do begin
|
||||||
p := FGraphPoints[i - FLoBound];
|
p := FGraphPoints[i - FLoBound];
|
||||||
w := CalcBarWidth(GetGraphPointX(i), i);
|
BarOffsetWidth(GetGraphPointX(i), i, ofs, w);
|
||||||
if IsRotated then
|
if IsRotated then begin
|
||||||
z := AxisToGraphX(ZeroLevel)
|
z := AxisToGraphX(ZeroLevel);
|
||||||
else
|
p.Y += ofs;
|
||||||
|
end
|
||||||
|
else begin
|
||||||
z := AxisToGraphY(ZeroLevel);
|
z := AxisToGraphY(ZeroLevel);
|
||||||
|
p.X += ofs;
|
||||||
|
end;
|
||||||
cumulHeight := z;
|
cumulHeight := z;
|
||||||
ACanvas.Brush.Color := GetColor(i);
|
ACanvas.Brush.Color := GetColor(i);
|
||||||
BuildBar(p.Y - z, 0);
|
BuildBar(p.Y - z, 0);
|
||||||
@ -805,16 +819,18 @@ end;
|
|||||||
|
|
||||||
function TBarSeries.Extent: TDoubleRect;
|
function TBarSeries.Extent: TDoubleRect;
|
||||||
var
|
var
|
||||||
x: Double;
|
x, ofs, w: Double;
|
||||||
begin
|
begin
|
||||||
Result := inherited Extent;
|
Result := inherited Extent;
|
||||||
if IsEmpty then exit;
|
if IsEmpty then exit;
|
||||||
UpdateMinMax(ZeroLevel, Result.a.Y, Result.b.Y);
|
UpdateMinMax(ZeroLevel, Result.a.Y, Result.b.Y);
|
||||||
// Show first and last bars fully.
|
// Show first and last bars fully.
|
||||||
x := GetGraphPointX(0);
|
x := GetGraphPointX(0);
|
||||||
Result.a.X := Min(Result.a.X, x - CalcBarWidth(x, 0));
|
BarOffsetWidth(x, 0, ofs, w);
|
||||||
|
Result.a.X := Min(Result.a.X, x + ofs - w);
|
||||||
x := GetGraphPointX(Count - 1);
|
x := GetGraphPointX(Count - 1);
|
||||||
Result.b.X := Max(Result.b.X, x + CalcBarWidth(x, Count - 1));
|
BarOffsetWidth(x, Count - 1, ofs, w);
|
||||||
|
Result.b.X := Max(Result.b.X, x + ofs + w);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TBarSeries.GetLegendItems(AItems: TChartLegendItems);
|
procedure TBarSeries.GetLegendItems(AItems: TChartLegendItems);
|
||||||
@ -837,6 +853,13 @@ begin
|
|||||||
FBarBrush.Assign(Value);
|
FBarBrush.Assign(Value);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TBarSeries.SetBarOffsetPercent(const AValue: Integer);
|
||||||
|
begin
|
||||||
|
if FBarOffsetPercent = AValue then exit;
|
||||||
|
FBarOffsetPercent := AValue;
|
||||||
|
UpdateParentChart;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TBarSeries.SetBarPen(Value:TPen);
|
procedure TBarSeries.SetBarPen(Value:TPen);
|
||||||
begin
|
begin
|
||||||
FBarPen.Assign(Value);
|
FBarPen.Assign(Value);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user