TAChart: 3D look for bar series.

* Add Series.Depth property
* Publish and impement it in TBarSeries
* Update demo

git-svn-id: trunk@19628 -
This commit is contained in:
ask 2009-04-26 07:11:58 +00:00
parent 4f29817505
commit 7277e0b12c
5 changed files with 83 additions and 25 deletions

View File

@ -120,6 +120,9 @@ procedure CalculateIntervals(
function DoublePoint(const ACoord: TChartCoord): TDoublePoint; inline;
function DoubleRect(AX1, AY1, AX2, AY2: Double): TDoubleRect; inline;
procedure DrawLineDepth(ACanvas: TCanvas; AX1, AY1, AX2, AY2, ADepth: Integer);
procedure DrawLineDepth(ACanvas: TCanvas; const AP1, AP2: TPoint; ADepth: Integer);
procedure Exchange(var A, B: Integer); overload;
procedure Exchange(var A, B: Double); overload;
procedure Exchange(var A, B: TDoublePoint); overload;
@ -228,6 +231,20 @@ begin
Result.b.Y := AY2;
end;
procedure DrawLineDepth(ACanvas: TCanvas; AX1, AY1, AX2, AY2, ADepth: Integer);
begin
DrawLineDepth(ACanvas, Point(AX1, AY1), Point(AX2, AY2), ADepth);
end;
procedure DrawLineDepth(
ACanvas: TCanvas; const AP1, AP2: TPoint; ADepth: Integer);
var
d: TSize;
begin
d := Size(ADepth, -ADepth);
ACanvas.Polygon([AP1, AP1 + d, AP2 + d, AP2]);
end;
procedure Exchange(var A, B: Integer); overload;
var
t: Integer;

View File

@ -53,6 +53,7 @@ type
protected
FActive: Boolean;
FChart: TChart;
FDepth: TChartZPosition;
FShowInLegend: Boolean;
FTitle: String;
FZPosition: TChartZPosition;
@ -67,6 +68,7 @@ type
virtual;
function GetSeriesColor: TColor; virtual; abstract;
procedure SetActive(AValue: Boolean); virtual; abstract;
procedure SetDepth(AValue: TChartZPosition); virtual; abstract;
procedure SetSeriesColor(const AValue: TColor); virtual; abstract;
procedure SetShowInLegend(AValue: Boolean); virtual; abstract;
procedure SetZPosition(AValue: TChartZPosition); virtual; abstract;
@ -88,6 +90,7 @@ type
function IsEmpty: Boolean; virtual; abstract;
property Active: Boolean read FActive write SetActive;
property Depth: TChartZPosition read FDepth write SetDepth default 0;
property ParentChart: TChart read FChart;
property SeriesColor: TColor
read GetSeriesColor write SetSeriesColor default clTAColor;
@ -1032,6 +1035,16 @@ begin
end;
procedure TChart.DisplaySeries(ACanvas: TCanvas);
procedure OffsetDrawArea(AZPos, ADepth: Integer);
begin
FOffset.X -= AZPos;
FOffset.Y += AZPos;
OffsetRect(FClipRect, -AZPos, AZPos);
FClipRect.Right += ADepth;
FClipRect.Top -= ADepth;
end;
var
i: Integer;
seriesInZOrder: TFPList;
@ -1043,18 +1056,14 @@ begin
for i := 0 to SeriesCount - 1 do
with TBasicChartSeries(seriesInZOrder[i]) do begin
if not Active then continue;
FOffset.X -= ZPosition;
FOffset.Y += ZPosition;
OffsetRect(FClipRect, -ZPosition, ZPosition);
OffsetDrawArea(ZPosition, Depth);
// Set clipping region so we don't draw outside.
// TODO: Replace by Canvas.ClipRect after fixing issue 13418.
IntersectClipRect(
ACanvas.Handle,
FClipRect.Left, FClipRect.Top, FClipRect.Right, FClipRect.Bottom);
Draw(ACanvas);
FOffset.X += ZPosition;
FOffset.Y -= ZPosition;
OffsetRect(FClipRect, ZPosition, -ZPosition);
OffsetDrawArea(-ZPosition, -Depth);
// Now disable clipping.
SelectClipRgn(ACanvas.Handle, 0);
end;

View File

@ -58,6 +58,7 @@ type
function GetLegendWidth(ACanvas: TCanvas): Integer; override;
function GetValuesTotal: Double;
procedure SetActive(AValue: Boolean); override;
procedure SetDepth(AValue: TChartZPosition); override;
procedure SetShowInLegend(AValue: Boolean); override;
procedure SetZPosition(AValue: TChartZPosition); override;
procedure StyleChanged(Sender: TObject);
@ -135,6 +136,7 @@ type
property BarPen: TPen read FBarPen write SetBarPen;
property BarWidthPercent: Integer
read FBarWidthPercent write SetBarWidthPercent default 70;
property Depth;
property SeriesColor;
end;
@ -319,6 +321,7 @@ type
function GetLegendWidth(ACanvas: TCanvas): Integer; override;
function GetSeriesColor: TColor; override;
procedure SetActive(AValue: Boolean); override;
procedure SetDepth(AValue: TChartZPosition); override;
procedure SetSeriesColor(const AValue: TColor); override;
procedure SetShowInLegend(AValue: Boolean); override;
procedure SetZPosition(AValue: TChartZPosition); override;
@ -524,6 +527,13 @@ begin
UpdateParentChart;
end;
procedure TChartSeries.SetDepth(AValue: TChartZPosition);
begin
if FDepth = AValue then exit;
FDepth := AValue;
UpdateParentChart;
end;
procedure TChartSeries.SetMarks(const AValue: TChartMarks);
begin
if FMarks = AValue then exit;
@ -1187,6 +1197,11 @@ begin
end;
ACanvas.Rectangle(r);
if Depth > 0 then begin
DrawLineDepth(ACanvas, r.Left, r.Top, r.Right - 1, r.Top, Depth);
DrawLineDepth(
ACanvas, r.Right - 1, r.Top, r.Right - 1, r.Bottom - 1, Depth);
end;
end;
if not Marks.IsMarkLabelsVisible then exit;
@ -1646,6 +1661,13 @@ begin
UpdateParentChart;
end;
procedure TFuncSeries.SetDepth(AValue: TChartZPosition);
begin
if FDepth = AValue then exit;
FDepth := AValue;
UpdateParentChart;
end;
procedure TFuncSeries.SetExtent(const AValue: TChartExtent);
begin
if FExtent = AValue then exit;

View File

@ -2,18 +2,19 @@ object Form1: TForm1
Left = 318
Height = 300
Top = 150
Width = 400
Width = 560
Caption = 'Form1'
ClientHeight = 300
ClientWidth = 400
ClientWidth = 560
OnCreate = FormCreate
Position = poScreenCenter
LCLVersion = '0.9.27'
object Chart1: TChart
Height = 300
Width = 400
Width = 560
BottomAxis.Grid.Style = psDot
BottomAxis.Grid.Visible = True
Depth = 40
Depth = 50
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
Frame.Visible = True
@ -28,17 +29,24 @@ object Form1: TForm1
Align = alClient
ParentColor = False
object Chart1BarSeries1: TBarSeries
ZPosition = 10
BarBrush.Color = clTeal
BarWidthPercent = 50
Depth = 10
SeriesColor = clTeal
end
object Chart1BarSeries2: TBarSeries
ZPosition = 20
ZPosition = 30
BarBrush.Color = clMaroon
BarWidthPercent = 50
Depth = 10
SeriesColor = clMaroon
end
object Chart1BarSeries3: TBarSeries
ZPosition = 40
ZPosition = 50
BarBrush.Color = clBlue
BarWidthPercent = 50
Depth = 10
SeriesColor = clBlue
end
end

View File

@ -2,17 +2,19 @@
LazarusResources.Add('TForm1','FORMDATA',[
'TPF0'#6'TForm1'#5'Form1'#4'Left'#3'>'#1#6'Height'#3','#1#3'Top'#3#150#0#5'Wi'
+'dth'#3#144#1#7'Caption'#6#5'Form1'#12'ClientHeight'#3','#1#11'ClientWidth'#3
+#144#1#8'OnCreate'#7#10'FormCreate'#10'LCLVersion'#6#6'0.9.27'#0#6'TChart'#6
+'Chart1'#6'Height'#3','#1#5'Width'#3#144#1#21'BottomAxis.Grid.Style'#7#5'psD'
+'ot'#23'BottomAxis.Grid.Visible'#9#5'Depth'#2'('#16'Foot.Brush.Color'#7#9'cl'
+'BtnFace'#15'Foot.Font.Color'#7#6'clBlue'#13'Frame.Visible'#9#19'LeftAxis.Gr'
+'id.Style'#7#5'psDot'#21'LeftAxis.Grid.Visible'#9#20'LeftAxis.Title.Angle'#2
+'Z'#17'Title.Brush.Color'#7#9'clBtnFace'#16'Title.Font.Color'#7#6'clBlue'#18
+'Title.Text.Strings'#1#6#7'TAChart'#0#5'Align'#7#8'alClient'#11'ParentColor'
+#8#0#10'TBarSeries'#16'Chart1BarSeries1'#14'BarBrush.Color'#7#6'clTeal'#11'S'
+'eriesColor'#7#6'clTeal'#0#0#10'TBarSeries'#16'Chart1BarSeries2'#9'ZPosition'
+#2#20#14'BarBrush.Color'#7#8'clMaroon'#11'SeriesColor'#7#8'clMaroon'#0#0#10
+'TBarSeries'#16'Chart1BarSeries3'#9'ZPosition'#2'('#14'BarBrush.Color'#7#6'c'
+'lBlue'#11'SeriesColor'#7#6'clBlue'#0#0#0#0
+'dth'#3'0'#2#7'Caption'#6#5'Form1'#12'ClientHeight'#3','#1#11'ClientWidth'#3
+'0'#2#8'OnCreate'#7#10'FormCreate'#8'Position'#7#14'poScreenCenter'#10'LCLVe'
+'rsion'#6#6'0.9.27'#0#6'TChart'#6'Chart1'#6'Height'#3','#1#5'Width'#3'0'#2#21
+'BottomAxis.Grid.Style'#7#5'psDot'#23'BottomAxis.Grid.Visible'#9#5'Depth'#2
+'2'#16'Foot.Brush.Color'#7#9'clBtnFace'#15'Foot.Font.Color'#7#6'clBlue'#13'F'
+'rame.Visible'#9#19'LeftAxis.Grid.Style'#7#5'psDot'#21'LeftAxis.Grid.Visible'
+#9#20'LeftAxis.Title.Angle'#2'Z'#17'Title.Brush.Color'#7#9'clBtnFace'#16'Tit'
+'le.Font.Color'#7#6'clBlue'#18'Title.Text.Strings'#1#6#7'TAChart'#0#5'Align'
+#7#8'alClient'#11'ParentColor'#8#0#10'TBarSeries'#16'Chart1BarSeries1'#9'ZPo'
+'sition'#2#10#14'BarBrush.Color'#7#6'clTeal'#15'BarWidthPercent'#2'2'#5'Dept'
+'h'#2#10#11'SeriesColor'#7#6'clTeal'#0#0#10'TBarSeries'#16'Chart1BarSeries2'
+#9'ZPosition'#2#30#14'BarBrush.Color'#7#8'clMaroon'#15'BarWidthPercent'#2'2'
+#5'Depth'#2#10#11'SeriesColor'#7#8'clMaroon'#0#0#10'TBarSeries'#16'Chart1Bar'
+'Series3'#9'ZPosition'#2'2'#14'BarBrush.Color'#7#6'clBlue'#15'BarWidthPercen'
+'t'#2'2'#5'Depth'#2#10#11'SeriesColor'#7#6'clBlue'#0#0#0#0
]);