mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-30 12:12:47 +02:00
TChart.LabelPosition from Salvatore Coppola
git-svn-id: trunk@6991 -
This commit is contained in:
parent
2221cce016
commit
c7bee00dd9
43
lcl/chart.pp
43
lcl/chart.pp
@ -29,9 +29,13 @@ unit Chart;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
SysUtils, Classes, LCLProc, Controls, ExtCtrls, Graphics, Dialogs;
|
SysUtils, Classes, LCLProc, LCLIntf, LCLType, Controls, ExtCtrls, Graphics,
|
||||||
|
Dialogs;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
|
TPosLabel=(plLeft, plCenter, plRight);
|
||||||
|
|
||||||
{ TCustomBarChart }
|
{ TCustomBarChart }
|
||||||
|
|
||||||
TBar = class(TCollectionItem)
|
TBar = class(TCollectionItem)
|
||||||
@ -47,6 +51,7 @@ type
|
|||||||
FUpdateCount: Integer;
|
FUpdateCount: Integer;
|
||||||
FBars: TCollection;
|
FBars: TCollection;
|
||||||
FDepth: byte;
|
FDepth: byte;
|
||||||
|
FLabelPosition:TPosLabel;
|
||||||
function NormalizeScaleUnits(OldScale: Integer): Integer;
|
function NormalizeScaleUnits(OldScale: Integer): Integer;
|
||||||
protected
|
protected
|
||||||
procedure Paint; override;
|
procedure Paint; override;
|
||||||
@ -59,8 +64,9 @@ type
|
|||||||
function BarCount: Integer;
|
function BarCount: Integer;
|
||||||
procedure BeginUpdate;
|
procedure BeginUpdate;
|
||||||
procedure EndUpdate;
|
procedure EndUpdate;
|
||||||
public
|
published
|
||||||
property Depth: byte read FDepth write FDepth;
|
property Depth: byte read FDepth write FDepth;
|
||||||
|
property LabelPosition: TPosLabel read FLabelPosition write FLabelPosition;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -83,7 +89,6 @@ type
|
|||||||
property ClientWidth;
|
property ClientWidth;
|
||||||
property Color;
|
property Color;
|
||||||
property Constraints;
|
property Constraints;
|
||||||
property Depth: byte;
|
|
||||||
property DragMode;
|
property DragMode;
|
||||||
property Enabled;
|
property Enabled;
|
||||||
property Font;
|
property Font;
|
||||||
@ -125,6 +130,7 @@ begin
|
|||||||
inherited Create(AOwner);
|
inherited Create(AOwner);
|
||||||
FBars:=TCollection.Create(TBar);
|
FBars:=TCollection.Create(TBar);
|
||||||
FDepth:=5;
|
FDepth:=5;
|
||||||
|
FLabelPosition:=plLeft;
|
||||||
SetInitialBounds(0,0,150,120);
|
SetInitialBounds(0,0,150,120);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -181,7 +187,7 @@ procedure TCustomBarChart.Paint;
|
|||||||
|
|
||||||
var
|
var
|
||||||
i,k,j,h,w,h1,HMax,VMax: integer;
|
i,k,j,h,w,h1,HMax,VMax: integer;
|
||||||
|
bx,by:integer;
|
||||||
NScaleLines : Integer;
|
NScaleLines : Integer;
|
||||||
ScaleUnits : Integer;
|
ScaleUnits : Integer;
|
||||||
PixelPerUnit: Double;
|
PixelPerUnit: Double;
|
||||||
@ -205,6 +211,8 @@ var
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
inherited Paint;
|
inherited Paint;
|
||||||
|
bx:=GetSystemMetrics(SM_CXEDGE);
|
||||||
|
by:=GetSystemMetrics(SM_CYEDGE);
|
||||||
hmax:=10;
|
hmax:=10;
|
||||||
vmax:=0;
|
vmax:=0;
|
||||||
for i:=0 to FBars.Count-1 do
|
for i:=0 to FBars.Count-1 do
|
||||||
@ -234,7 +242,7 @@ begin
|
|||||||
Canvas.MoveTo(hmax,h1+FDepth);
|
Canvas.MoveTo(hmax,h1+FDepth);
|
||||||
Canvas.LineTo(hmax,h1+FDepth+h);
|
Canvas.LineTo(hmax,h1+FDepth+h);
|
||||||
Canvas.LineTo(hmax+w,h1+FDepth+h);
|
Canvas.LineTo(hmax+w,h1+FDepth+h);
|
||||||
Canvas.TextOut(0,0,Caption);
|
Canvas.TextOut(bx,by,Caption);
|
||||||
j:=Canvas.TextWidth(IntTostr(VMax));
|
j:=Canvas.TextWidth(IntTostr(VMax));
|
||||||
if VMax=0 then
|
if VMax=0 then
|
||||||
begin
|
begin
|
||||||
@ -286,21 +294,24 @@ begin
|
|||||||
s:=IntToStr(m);
|
s:=IntToStr(m);
|
||||||
w:=z+(RBC-FDepth) div 2;
|
w:=z+(RBC-FDepth) div 2;
|
||||||
Canvas.MoveTo(Hmax+BL+Fdepth div 2,w);
|
Canvas.MoveTo(Hmax+BL+Fdepth div 2,w);
|
||||||
Canvas.LineTo(Hmax+BL+Fdepth+5,w);
|
Canvas.LineTo(Hmax+BL+Fdepth+5-bx,w);
|
||||||
Canvas.Brush.Color:=clYellow;
|
Canvas.Brush.Color:=clYellow;
|
||||||
with rc do
|
with rc do
|
||||||
begin
|
begin
|
||||||
left:=hmax+BL+FDepth+5;
|
left:=hmax+BL+FDepth+5-bx;
|
||||||
right:=left+Canvas.TextWidth(s)+6;
|
right:=left+Canvas.TextWidth(s)+2*bx;
|
||||||
top:=Canvas.TextHeight(s) div 2+3;
|
top:=w-Canvas.TextHeight(s) div 2-by;
|
||||||
bottom:=w+top;
|
bottom:=w+Canvas.TextHeight(s) div 2+by;
|
||||||
top:=bottom-2*top;
|
|
||||||
end;
|
end;
|
||||||
Canvas.Rectangle(rc);
|
Canvas.Rectangle(rc);
|
||||||
//debugln('TCustomBarChart.Paint A ',dbgs(rc),' s="',s,'"');
|
//debugln('TCustomBarChart.Paint A ',dbgs(rc),' s="',s,'"');
|
||||||
Canvas.TextRect(rc,rc.Left,rc.Top,s);
|
Canvas.TextOut(rc.Left+bx,rc.Top+by,s);
|
||||||
Canvas.Font.Color:=Font.Color;
|
Canvas.Font.Color:=Font.Color;
|
||||||
Canvas.TextRect(Rect(0,z,hmax-5,z+RBC),0,z,ts.FSName);
|
case FLabelPosition of
|
||||||
|
plLeft: Canvas.TextOut(bx,z,ts.FSName);
|
||||||
|
plCenter: Canvas.TextOut(HMax+((BL-Canvas.TextWidth(ts.FSName)) div 2),z,ts.FSName);
|
||||||
|
plRight: Canvas.TextOut(HMax+BL-Canvas.TextWidth(ts.FSName)-bx,z,ts.FSName);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
Canvas.Pen.Style:=psSolid;
|
Canvas.Pen.Style:=psSolid;
|
||||||
end;
|
end;
|
||||||
@ -312,6 +323,10 @@ end;
|
|||||||
|
|
||||||
procedure TCustomBarChart.BeginUpdate;
|
procedure TCustomBarChart.BeginUpdate;
|
||||||
begin
|
begin
|
||||||
|
if FUpdateCount=0 then begin
|
||||||
|
Canvas.Brush.Color:=Color;
|
||||||
|
Canvas.FillRect(GetClientRect);
|
||||||
|
end;
|
||||||
Inc(FUpdateCount);
|
Inc(FUpdateCount);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -321,7 +336,7 @@ begin
|
|||||||
raise Exception.Create('TCustomBarChart.EndUpdate');
|
raise Exception.Create('TCustomBarChart.EndUpdate');
|
||||||
Dec(FUpdateCount);
|
Dec(FUpdateCount);
|
||||||
If FUpdateCount=0 then
|
If FUpdateCount=0 then
|
||||||
Repaint;
|
Invalidate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomBarChart.BarCount: Integer;
|
function TCustomBarChart.BarCount: Integer;
|
||||||
|
Loading…
Reference in New Issue
Block a user