TAChart: fixed diminishing size of bar charts

patch by: Alexander Klenin
fixes issue (13130)

git-svn-id: trunk@18649 -
This commit is contained in:
vincents 2009-02-12 14:51:34 +00:00
parent 6285c8757d
commit 9335ffdf78
2 changed files with 25 additions and 19 deletions

View File

@ -236,8 +236,6 @@ type
FAxisVisible: Boolean; FAxisVisible: Boolean;
FNumBarSeries: Integer;
procedure SetAutoUpdateXMin(Value: Boolean); procedure SetAutoUpdateXMin(Value: Boolean);
procedure SetAutoUpdateXMax(Value: Boolean); procedure SetAutoUpdateXMax(Value: Boolean);
procedure SetAutoUpdateYMin(Value: Boolean); procedure SetAutoUpdateYMin(Value: Boolean);
@ -328,7 +326,6 @@ type
property Canvas; property Canvas;
property SeriesCount: Integer read GetSeriesCount; property SeriesCount: Integer read GetSeriesCount;
property NumBarSeries: Integer read FNumBarSeries;
property ChartHeight: Integer read GetChartHeight; property ChartHeight: Integer read GetChartHeight;
property ChartWidth: Integer read GetChartWidth; property ChartWidth: Integer read GetChartWidth;
property Series: TFPList read FSeries write FSeries; property Series: TFPList read FSeries write FSeries;
@ -730,8 +727,6 @@ begin
FFrame := TChartPen.Create; FFrame := TChartPen.Create;
FFrame.Visible := true; FFrame.Visible := true;
FFrame.OnChange := StyleChanged; FFrame.OnChange := StyleChanged;
FNumBarSeries := 0;
end; end;
destructor TChart.Destroy; destructor TChart.Destroy;
@ -1250,11 +1245,7 @@ begin
end; end;
Series.Add(Serie); Series.Add(Serie);
TBasicChartSeries(Serie).ParentChart := Self; TBasicChartSeries(Serie).ParentChart := Self;
if Serie is TBarSeries then begin
(Serie as TBarSeries).SeriesNumber := FNumBarSeries;
Inc(FNumBarSeries); //FIXME: this is never decremented when series is deleted
end;
end; end;
procedure TChart.DeleteSerie(Serie: TComponent); procedure TChart.DeleteSerie(Serie: TComponent);

View File

@ -159,11 +159,11 @@ type
FBarBrush: TBrush; FBarBrush: TBrush;
FBarPen: TPen; FBarPen: TPen;
FBarWidthPercent: Integer; FBarWidthPercent: Integer;
FSeriesNumber: Integer;
procedure SetBarWidthPercent(Value: Integer); procedure SetBarWidthPercent(Value: Integer);
procedure SetBarBrush(Value: TBrush); procedure SetBarBrush(Value: TBrush);
procedure SetBarPen(Value: TPen); procedure SetBarPen(Value: TPen);
procedure ExamineAllBarSeries(out ATotalNumber, AMyPos: Integer);
protected protected
procedure StyleChanged(Sender: TObject); procedure StyleChanged(Sender: TObject);
procedure DrawLegend(ACanvas: TCanvas; const ARect: TRect); override; procedure DrawLegend(ACanvas: TCanvas; const ARect: TRect); override;
@ -175,12 +175,12 @@ type
procedure Draw(ACanvas: TCanvas); override; procedure Draw(ACanvas: TCanvas); override;
function AddXY(X, Y: Double; XLabel: String; Color: TColor): Longint; override; function AddXY(X, Y: Double; XLabel: String; Color: TColor): Longint; override;
published published
property BarWidthPercent:Integer read FBarWidthPercent write SetBarWidthPercent default 70; property BarWidthPercent: Integer
read FBarWidthPercent write SetBarWidthPercent default 70;
property BarBrush: TBrush read FBarBrush write SetBarBrush; property BarBrush: TBrush read FBarBrush write SetBarBrush;
property BarPen: TPen read FBarPen write SetBarPen; property BarPen: TPen read FBarPen write SetBarPen;
property Title; property Title;
property Active; property Active;
property SeriesNumber: Integer read FSeriesNumber write FSeriesNumber;
end; end;
{ TPieSeries } { TPieSeries }
@ -1128,7 +1128,7 @@ var
graphCoordTop: ChartCoord; graphCoordTop: ChartCoord;
graphCoordBottom: ChartCoord; graphCoordBottom: ChartCoord;
topX, topY, bottomY: Integer; topX, topY, bottomY: Integer;
barWidth, TotalbarWidth: Integer; barWidth, totalbarWidth, totalBarSeries, myPos: Integer;
bx1, by1, bx2, by2: Integer; bx1, by1, bx2, by2: Integer;
function BarInViewPort(cTop, cBottom: ChartCoord): Boolean; function BarInViewPort(cTop, cBottom: ChartCoord): Boolean;
@ -1156,10 +1156,10 @@ begin
ACanvas.Brush.Assign(FBarBrush); ACanvas.Brush.Assign(FBarBrush);
//calc the single bar width //calc the single bar width
TotalbarWidth := totalbarWidth :=
Round((FBarWidthPercent * 0.01) * ParentChart.ChartWidth / FCoordList.Count); Round((FBarWidthPercent * 0.01) * ParentChart.ChartWidth / FCoordList.Count);
//to use with multibar -- with is on by default ExamineAllBarSeries(totalBarSeries, myPos);
barWidth := TotalbarWidth div ParentChart.NumBarSeries; barWidth := totalbarWidth div totalBarSeries;
for i := 0 to FCoordList.Count - 1 do begin for i := 0 to FCoordList.Count - 1 do begin
//get the top and bottom points //get the top and bottom points
@ -1188,9 +1188,9 @@ begin
bx2 := topX+(barWidth div 2); bx2 := topX+(barWidth div 2);
by2 := bottomY; by2 := bottomY;
} }
bx1 := topX - (TotalbarWidth div 2) + SeriesNumber * barWidth; bx1 := topX - (TotalbarWidth div 2) + myPos * barWidth;
by1 := topY; by1 := topY;
bx2 := topX - (TotalbarWidth div 2) + SeriesNumber * barWidth + barWidth; bx2 := topX - (TotalbarWidth div 2) + myPos * barWidth + barWidth;
by2 := bottomY; by2 := bottomY;
//FIXME only draw if bar inside image coord (get a better way of doing this) //FIXME only draw if bar inside image coord (get a better way of doing this)
@ -1214,6 +1214,21 @@ begin
ACanvas.Rectangle(ARect); ACanvas.Rectangle(ARect);
end; end;
procedure TBarSeries.ExamineAllBarSeries(out ATotalNumber, AMyPos: Integer);
var
i: Integer;
begin
ATotalNumber := 0;
AMyPos := -1;
for i := 0 to ParentChart.SeriesCount - 1 do begin
if ParentChart.Series[i] = Self then
AMyPos := ATotalNumber;
if TBasicChartSeries(ParentChart.Series[i]) is TBarSeries then
Inc(ATotalNumber);
end;
Assert(AMyPos >= 0);
end;
constructor TPieSeries.Create(AOwner: TComponent); constructor TPieSeries.Create(AOwner: TComponent);
begin begin
inherited Create(AOwner); inherited Create(AOwner);