TAChart: Refactor TLine series. Add static TLine series to the demo

issue #13214 part 5

git-svn-id: trunk@18777 -
This commit is contained in:
ask 2009-02-20 14:28:08 +00:00
parent f6a27a57d4
commit 604c32679f
4 changed files with 132 additions and 109 deletions

View File

@ -55,6 +55,19 @@ object Form1: TForm1
Align = alClient
Color = clBtnFace
ParentColor = False
object Chart1LineHor: TLine
ShowInLegend = False
Pen.Cosmetic = True
Pen.Style = psDot
SeriesColor = clBlack
end
object Chart1LineVert: TLine
ShowInLegend = False
LineStyle = lsVertical
Pen.Cosmetic = True
Pen.Style = psDot
SeriesColor = clBlack
end
end
object Panel1: TPanel
Height = 94

View File

@ -1,3 +1,5 @@
{ This is an automatically generated lazarus resource file }
LazarusResources.Add('TForm1','FORMDATA',[
'TPF0'#6'TForm1'#5'Form1'#4'Left'#3'U'#1#6'Height'#3#238#1#3'Top'#3#225#0#5'W'
+'idth'#3'I'#2#7'Caption'#6#5'Form1'#12'ClientHeight'#3#238#1#11'ClientWidth'
@ -20,58 +22,62 @@ LazarusResources.Add('TForm1','FORMDATA',[
+'omAxis.Grid.Cosmetic'#9#21'BottomAxis.Grid.Style'#7#5'psDot'#23'BottomAxis.'
+'Grid.Visible'#9#14'Frame.Cosmetic'#9#13'Frame.Visible'#9#9'BackColor'#7#9'c'
+'lBtnFace'#5'Align'#7#8'alClient'#5'Color'#7#9'clBtnFace'#11'ParentColor'#8#0
+#0#6'TPanel'#6'Panel1'#6'Height'#2'^'#3'Top'#3#144#1#5'Width'#3'I'#2#5'Align'
+#7#8'alBottom'#12'ClientHeight'#2'^'#11'ClientWidth'#3'I'#2#8'TabOrder'#2#0#0
+#6'TLabel'#6'lblAdd'#4'Left'#2#13#6'Height'#2#14#3'Top'#2#10#5'Width'#2#24#7
+'Caption'#6#4'Add:'#11'ParentColor'#8#0#0#6'TLabel'#8'lblClear'#4'Left'#2#13
+#6'Height'#2#14#3'Top'#2'('#5'Width'#2#30#7'Caption'#6#6'Clear:'#11'ParentCo'
+'lor'#8#0#0#6'TLabel'#11'lblAddCount'#4'Left'#3' '#1#6'Height'#2#14#3'Top'#2
+#16#5'Width'#2':'#7'Caption'#6#12'Multiple add'#11'ParentColor'#8#0#0#7'TBut'
+'ton'#9'btnAddPie'#4'Left'#2'0'#6'Height'#2#24#3'Top'#2#8#5'Width'#2'4'#25'B'
+'orderSpacing.InnerBorder'#2#4#7'Caption'#6#3'Pie'#7'OnClick'#7#14'btnAddPie'
+'Click'#8'TabOrder'#2#0#0#0#7'TButton'#10'btnAddLine'#4'Left'#3#216#0#6'Heig'
+'ht'#2#24#3'Top'#2#8#5'Width'#2'4'#25'BorderSpacing.InnerBorder'#2#4#7'Capti'
+'on'#6#4'Line'#7'OnClick'#7#15'btnAddLineClick'#8'TabOrder'#2#1#0#0#7'TButto'
+'n'#10'btnAddArea'#4'Left'#2'h'#6'Height'#2#24#3'Top'#2#8#5'Width'#2'4'#25'B'
+'orderSpacing.InnerBorder'#2#4#7'Caption'#6#4'Area'#7'OnClick'#7#15'btnAddAr'
+'eaClick'#8'TabOrder'#2#2#0#0#7'TButton'#9'btnAddBar'#4'Left'#3#160#0#6'Heig'
+'ht'#2#24#3'Top'#2#8#5'Width'#2'4'#25'BorderSpacing.InnerBorder'#2#4#7'Capti'
+'on'#6#3'Bar'#7'OnClick'#7#14'btnAddBarClick'#8'TabOrder'#2#3#0#0#9'TCheckBo'
+'x'#8'cbLegend'#4'Left'#3#128#1#6'Height'#2#17#3'Top'#2#8#5'Width'#2'8'#7'Ca'
+'ption'#6#6'Legend'#8'OnChange'#7#14'cbLegendChange'#8'TabOrder'#2#4#0#0#9'T'
+'CheckBox'#12'cbBottomAxis'#4'Left'#3#128#1#6'Height'#2#17#3'Top'#2#24#5'Wid'
+'th'#2'K'#7'Caption'#6#11'Bottom Axis'#7'Checked'#9#8'OnChange'#7#18'cbBotto'
+'mAxisChange'#5'State'#7#9'cbChecked'#8'TabOrder'#2#5#0#0#9'TCheckBox'#10'cb'
+'LeftAxis'#4'Left'#3#128#1#6'Height'#2#17#3'Top'#2'('#5'Width'#2'<'#7'Captio'
+'n'#6#9'Left Axis'#7'Checked'#9#8'OnChange'#7#16'cbLeftAxisChange'#5'State'#7
+#9'cbChecked'#8'TabOrder'#2#6#0#0#9'TCheckBox'#7'cbTitle'#4'Left'#3#240#1#6
+'Height'#2#17#3'Top'#2#8#5'Width'#2'('#7'Caption'#6#5'Title'#7'Checked'#9#8
+'OnChange'#7#13'cbTitleChange'#5'State'#7#9'cbChecked'#8'TabOrder'#2#7#0#0#9
+'TCheckBox'#8'cbFooter'#4'Left'#3#240#1#6'Height'#2#17#3'Top'#2#24#5'Width'#2
+'2'#7'Caption'#6#6'Footer'#8'OnChange'#7#14'cbFooterChange'#8'TabOrder'#2#8#0
+#0#9'TCheckBox'#10'cbInverted'#4'Left'#3#240#1#6'Height'#2#17#3'Top'#2'('#5
+'Width'#2';'#7'Caption'#6#8'Inverted'#8'OnChange'#7#16'cbInvertedChange'#8'T'
+'abOrder'#2#9#0#0#7'TButton'#11'btnClearBar'#4'Left'#3#160#0#6'Height'#2#24#3
+'Top'#2'&'#5'Width'#2'4'#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#3'Ba'
+'r'#7'OnClick'#7#16'btnClearBarClick'#8'TabOrder'#2#10#0#0#7'TButton'#12'btn'
+'ClearArea'#4'Left'#2'h'#6'Height'#2#24#3'Top'#2'&'#5'Width'#2'4'#25'BorderS'
+'pacing.InnerBorder'#2#4#7'Caption'#6#4'Area'#7'OnClick'#7#17'btnClearAreaCl'
+'ick'#8'TabOrder'#2#11#0#0#7'TButton'#12'btnClearLine'#4'Left'#3#216#0#6'Hei'
+'ght'#2#24#3'Top'#2'&'#5'Width'#2'4'#25'BorderSpacing.InnerBorder'#2#4#7'Cap'
+'tion'#6#4'Line'#7'OnClick'#7#17'btnClearLineClick'#8'TabOrder'#2#12#0#0#7'T'
+'Button'#11'btnClearPie'#4'Left'#2'0'#6'Height'#2#24#3'Top'#2'&'#5'Width'#2
+'4'#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#3'Pie'#7'OnClick'#7#16'bt'
+'nClearPieClick'#8'TabOrder'#2#13#0#0#9'TSpinEdit'#10'edAddCount'#4'Left'#3
+' '#1#6'Height'#2#21#3'Top'#2')'#5'Width'#2'Z'#8'MaxValue'#4'@B'#15#0#8'MinV'
,'alue'#2#1#8'TabOrder'#2#14#5'Value'#2#1#0#0#9'TCheckBox'#18'cbShowGridCheck'
+'Box'#4'Left'#3#128#1#6'Height'#2#17#3'Top'#2'8'#5'Width'#2'F'#7'Caption'#6
+#10'Show grid '#7'Checked'#9#8'OnChange'#7#24'cbShowGridCheckBoxChange'#5'St'
+'ate'#7#9'cbChecked'#8'TabOrder'#2#15#0#0#9'TCheckBox'#16'cbShowAxisTitles'#4
+'Left'#3#240#1#6'Height'#2#17#3'Top'#2'8'#5'Width'#2'?'#7'Caption'#6#11'Axis'
+' titles'#8'OnChange'#7#22'cbShowAxisTitlesChange'#8'TabOrder'#2#16#0#0#9'TC'
+'heckBox'#18'cbShowVertReticule'#4'Left'#3#128#1#6'Height'#2#17#3'Top'#2'H'#5
+'Width'#2'L'#7'Caption'#6#13'Vert reticule'#8'OnChange'#7#24'cbShowVertRetic'
+'uleChange'#8'TabOrder'#2#17#0#0#9'TCheckBox'#14'cbShowReticule'#4'Left'#3
+#240#1#6'Height'#2#17#3'Top'#2'H'#5'Width'#2';'#7'Caption'#6#8'Reticule'#8'O'
+'nChange'#7#20'cbShowReticuleChange'#8'TabOrder'#2#18#0#0#0#0
+#5'TLine'#13'Chart1LineHor'#12'ShowInLegend'#8#12'Pen.Cosmetic'#9#9'Pen.Styl'
+'e'#7#5'psDot'#11'SeriesColor'#7#7'clBlack'#0#0#5'TLine'#14'Chart1LineVert'
+#12'ShowInLegend'#8#9'LineStyle'#7#10'lsVertical'#12'Pen.Cosmetic'#9#9'Pen.S'
+'tyle'#7#5'psDot'#11'SeriesColor'#7#7'clBlack'#0#0#0#6'TPanel'#6'Panel1'#6'H'
+'eight'#2'^'#3'Top'#3#144#1#5'Width'#3'I'#2#5'Align'#7#8'alBottom'#12'Client'
+'Height'#2'^'#11'ClientWidth'#3'I'#2#8'TabOrder'#2#0#0#6'TLabel'#6'lblAdd'#4
+'Left'#2#13#6'Height'#2#14#3'Top'#2#10#5'Width'#2#24#7'Caption'#6#4'Add:'#11
+'ParentColor'#8#0#0#6'TLabel'#8'lblClear'#4'Left'#2#13#6'Height'#2#14#3'Top'
+#2'('#5'Width'#2#30#7'Caption'#6#6'Clear:'#11'ParentColor'#8#0#0#6'TLabel'#11
+'lblAddCount'#4'Left'#3' '#1#6'Height'#2#14#3'Top'#2#16#5'Width'#2':'#7'Capt'
+'ion'#6#12'Multiple add'#11'ParentColor'#8#0#0#7'TButton'#9'btnAddPie'#4'Lef'
+'t'#2'0'#6'Height'#2#24#3'Top'#2#8#5'Width'#2'4'#25'BorderSpacing.InnerBorde'
+'r'#2#4#7'Caption'#6#3'Pie'#7'OnClick'#7#14'btnAddPieClick'#8'TabOrder'#2#0#0
+#0#7'TButton'#10'btnAddLine'#4'Left'#3#216#0#6'Height'#2#24#3'Top'#2#8#5'Wid'
+'th'#2'4'#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#4'Line'#7'OnClick'#7
+#15'btnAddLineClick'#8'TabOrder'#2#1#0#0#7'TButton'#10'btnAddArea'#4'Left'#2
+'h'#6'Height'#2#24#3'Top'#2#8#5'Width'#2'4'#25'BorderSpacing.InnerBorder'#2#4
+#7'Caption'#6#4'Area'#7'OnClick'#7#15'btnAddAreaClick'#8'TabOrder'#2#2#0#0#7
+'TButton'#9'btnAddBar'#4'Left'#3#160#0#6'Height'#2#24#3'Top'#2#8#5'Width'#2
+'4'#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#3'Bar'#7'OnClick'#7#14'bt'
+'nAddBarClick'#8'TabOrder'#2#3#0#0#9'TCheckBox'#8'cbLegend'#4'Left'#3#128#1#6
+'Height'#2#17#3'Top'#2#8#5'Width'#2'8'#7'Caption'#6#6'Legend'#8'OnChange'#7
+#14'cbLegendChange'#8'TabOrder'#2#4#0#0#9'TCheckBox'#12'cbBottomAxis'#4'Left'
+#3#128#1#6'Height'#2#17#3'Top'#2#24#5'Width'#2'K'#7'Caption'#6#11'Bottom Axi'
+'s'#7'Checked'#9#8'OnChange'#7#18'cbBottomAxisChange'#5'State'#7#9'cbChecked'
+#8'TabOrder'#2#5#0#0#9'TCheckBox'#10'cbLeftAxis'#4'Left'#3#128#1#6'Height'#2
+#17#3'Top'#2'('#5'Width'#2'<'#7'Caption'#6#9'Left Axis'#7'Checked'#9#8'OnCha'
+'nge'#7#16'cbLeftAxisChange'#5'State'#7#9'cbChecked'#8'TabOrder'#2#6#0#0#9'T'
+'CheckBox'#7'cbTitle'#4'Left'#3#240#1#6'Height'#2#17#3'Top'#2#8#5'Width'#2'('
+#7'Caption'#6#5'Title'#7'Checked'#9#8'OnChange'#7#13'cbTitleChange'#5'State'
+#7#9'cbChecked'#8'TabOrder'#2#7#0#0#9'TCheckBox'#8'cbFooter'#4'Left'#3#240#1
+#6'Height'#2#17#3'Top'#2#24#5'Width'#2'2'#7'Caption'#6#6'Footer'#8'OnChange'
+#7#14'cbFooterChange'#8'TabOrder'#2#8#0#0#9'TCheckBox'#10'cbInverted'#4'Left'
+#3#240#1#6'Height'#2#17#3'Top'#2'('#5'Width'#2';'#7'Caption'#6#8'Inverted'#8
+'OnChange'#7#16'cbInvertedChange'#8'TabOrder'#2#9#0#0#7'TButton'#11'btnClear'
+'Bar'#4'Left'#3#160#0#6'Height'#2#24#3'Top'#2'&'#5'Width'#2'4'#25'BorderSpac'
+'ing.InnerBorder'#2#4#7'Caption'#6#3'Bar'#7'OnClick'#7#16'btnClearBarClick'#8
+'TabOrder'#2#10#0#0#7'TButton'#12'btnClearArea'#4'Left'#2'h'#6'Height'#2#24#3
+'Top'#2'&'#5'Width'#2'4'#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#4'Ar'
+'ea'#7'OnClick'#7#17'btnClearAreaClick'#8'TabOrder'#2#11#0#0#7'TButton'#12'b'
+'tnClearLine'#4'Left'#3#216#0#6'Height'#2#24#3'Top'#2'&'#5'Width'#2'4'#25'Bo'
+'rderSpacing.InnerBorder'#2#4#7'Caption'#6#4'Line'#7'OnClick'#7#17'btnClearL'
+'ineClick'#8'TabOrder'#2#12#0#0#7'TButton'#11'btnClearPie'#4'Left'#2'0'#6'He'
,'ight'#2#24#3'Top'#2'&'#5'Width'#2'4'#25'BorderSpacing.InnerBorder'#2#4#7'Ca'
+'ption'#6#3'Pie'#7'OnClick'#7#16'btnClearPieClick'#8'TabOrder'#2#13#0#0#9'TS'
+'pinEdit'#10'edAddCount'#4'Left'#3' '#1#6'Height'#2#21#3'Top'#2')'#5'Width'#2
+'Z'#8'MaxValue'#4'@B'#15#0#8'MinValue'#2#1#8'TabOrder'#2#14#5'Value'#2#1#0#0
+#9'TCheckBox'#18'cbShowGridCheckBox'#4'Left'#3#128#1#6'Height'#2#17#3'Top'#2
+'8'#5'Width'#2'F'#7'Caption'#6#10'Show grid '#7'Checked'#9#8'OnChange'#7#24
+'cbShowGridCheckBoxChange'#5'State'#7#9'cbChecked'#8'TabOrder'#2#15#0#0#9'TC'
+'heckBox'#16'cbShowAxisTitles'#4'Left'#3#240#1#6'Height'#2#17#3'Top'#2'8'#5
+'Width'#2'?'#7'Caption'#6#11'Axis titles'#8'OnChange'#7#22'cbShowAxisTitlesC'
+'hange'#8'TabOrder'#2#16#0#0#9'TCheckBox'#18'cbShowVertReticule'#4'Left'#3
+#128#1#6'Height'#2#17#3'Top'#2'H'#5'Width'#2'L'#7'Caption'#6#13'Vert reticul'
+'e'#8'OnChange'#7#24'cbShowVertReticuleChange'#8'TabOrder'#2#17#0#0#9'TCheck'
+'Box'#14'cbShowReticule'#4'Left'#3#240#1#6'Height'#2#17#3'Top'#2'H'#5'Width'
+#2';'#7'Caption'#6#8'Reticule'#8'OnChange'#7#20'cbShowReticuleChange'#8'TabO'
+'rder'#2#18#0#0#0#0
]);

View File

@ -31,6 +31,8 @@ type
cbLegend: TCheckBox;
cbShowGridCheckBox: TCheckBox;
cbShowVertReticule: TCheckBox;
Chart1LineHor: TLine;
Chart1LineVert: TLine;
lblAddCount: TLabel;
lblAdd: TLabel;
lblClear: TLabel;

View File

@ -306,16 +306,14 @@ type
TLine = class(TBasicLineSeries)
private
FPen: TPen;
FPosGraph: Double; // Graph coordinates of line
FStyle: TLineStyle;
PosImage: Integer; // Image coordinates of line
PosGraph: Double; // Graph coordinates of line
FPen: TPen;
procedure SetPos(Value: Double);
procedure SetPen(Value: TPen);
procedure SetStyle(Value: TLineStyle);
procedure SetPen(AValue: TPen);
procedure SetPos(AValue: Double);
procedure SetStyle(AValue: TLineStyle);
procedure Changed;
protected
function GetSeriesColor: TColor; override;
procedure SetSeriesColor(const AValue: TColor); override;
@ -328,7 +326,7 @@ type
published
property LineStyle: TLineStyle read FStyle write SetStyle default lsHorizontal;
property Pen: TPen read FPen write SetPen;
property Position: Double read PosGraph write SetPos;
property Position: Double read FPosGraph write SetPos;
property SeriesColor;
end;
@ -1002,41 +1000,10 @@ begin
UpdateParentChart;
end;
constructor TLine.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{ TLine }
FPen := TPen.Create;
FPen.OnChange := @StyleChanged;
LineStyle := lsHorizontal;
end;
destructor TLine.Destroy;
procedure TLine.Changed;
begin
inherited Destroy;
FPen.Free;
end;
procedure TLine.SetPen(Value: TPen);
begin
FPen.Assign(Value);
end;
procedure TLine.SetStyle(Value: TLineStyle);
begin
if FStyle <> Value then begin
FStyle := Value;
case LineStyle of
lsHorizontal: begin YGraphMin := PosGraph; YGraphMax := PosGraph; end;
lsVertical: begin XGraphMin := PosGraph; XGraphMax := PosGraph; end;
end;
UpdateParentChart;
end;
end;
procedure TLine.SetPos(Value: Double);
begin
PosGraph := Value;
//FIXME: not the best way of doing this
{if Visible then begin
NBPointsMax:=NBPointsMax+1;
@ -1055,13 +1022,46 @@ begin
end;
end;}
case LineStyle of
lsHorizontal: begin YGraphMin := PosGraph; YGraphMax := PosGraph; end;
lsVertical: begin XGraphMin := PosGraph; XGraphMax := PosGraph; end;
lsHorizontal: begin YGraphMin := FPosGraph; YGraphMax := FPosGraph; end;
lsVertical: begin XGraphMin := FPosGraph; XGraphMax := FPosGraph; end;
end;
UpdateParentChart;
end;
constructor TLine.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FPen := TPen.Create;
FPen.OnChange := @StyleChanged;
LineStyle := lsHorizontal;
end;
destructor TLine.Destroy;
begin
inherited Destroy;
FPen.Free;
end;
procedure TLine.SetPen(AValue: TPen);
begin
FPen.Assign(AValue);
end;
procedure TLine.SetStyle(AValue: TLineStyle);
begin
if FStyle = AValue then exit;
FStyle := AValue;
Changed;
end;
procedure TLine.SetPos(AValue: Double);
begin
if FPosGraph = AValue then exit;
FPosGraph := AValue;
Changed;
end;
procedure TLine.SetSeriesColor(const AValue: TColor);
begin
FPen.Color := AValue;
@ -1069,24 +1069,24 @@ end;
procedure TLine.Draw(ACanvas: TCanvas);
var
XMin, XMax, YMin, YMax: Integer;
xmin, xmax, ymin, ymax, posImage: Integer;
begin
InitBounds(XMin, YMin, XMax, YMax);
InitBounds(xmin, ymin, xmax, ymax);
ACanvas.Pen.Assign(FPen);
case LineStyle of
lsHorizontal:
if (PosGraph < ParentChart.XGraphMax) and (PosGraph > ParentChart.XGraphMin) then begin
ParentChart.YGraphToImage(PosGraph, PosImage);
ACanvas.MoveTo(XMin, PosImage);
ACanvas.LineTo(XMax, PosImage);
if InRange(FPosGraph, ParentChart.XGraphMin, ParentChart.XGraphMax) then begin
ParentChart.YGraphToImage(FPosGraph, posImage);
ACanvas.MoveTo(xmin, posImage);
ACanvas.LineTo(xmax, posImage);
end;
lsVertical:
if (PosGraph < ParentChart.YGraphMax) and (PosGraph > ParentChart.YGraphMin) then begin
ParentChart.XGraphToImage(PosGraph, PosImage);
ACanvas.MoveTo(PosImage, YMin);
ACanvas.LineTo(PosImage, YMax);
if InRange(FPosGraph, ParentChart.YGraphMin, ParentChart.YGraphMax) then begin
ParentChart.XGraphToImage(FPosGraph, posImage);
ACanvas.MoveTo(posImage, ymin);
ACanvas.LineTo(posImage, ymax);
end;
end;
end;
@ -1096,6 +1096,8 @@ begin
Result := FPen.Color;
end;
{ TBarSeries }
constructor TBarSeries.Create(AOwner: TComponent);
begin
inherited Create(AOwner);