mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-20 18:20:19 +01:00
TAChart: Add Margins instead of built-in fixed margin (issue #13830)
* Based on patch by Andrei Kupreitchik * Used Margins in a demo git-svn-id: trunk@20224 -
This commit is contained in:
parent
ae52501a97
commit
f3dd9d641d
@ -18,6 +18,10 @@ object Form1: TForm1
|
||||
Foot.Font.Color = clBlue
|
||||
LeftAxis.Grid.Style = psDot
|
||||
LeftAxis.Title.Angle = 90
|
||||
Margins.Left = 8
|
||||
Margins.Top = 8
|
||||
Margins.Right = 8
|
||||
Margins.Bottom = 0
|
||||
Title.Brush.Color = clBtnFace
|
||||
Title.Font.Color = clBlue
|
||||
Title.Text.Strings = (
|
||||
|
||||
@ -7,22 +7,24 @@ LazarusResources.Add('TForm1','FORMDATA',[
|
||||
+#6'Chart1'#4'Left'#2#0#6'Height'#3#18#1#3'Top'#2#26#5'Width'#3'['#1#21'Botto'
|
||||
+'mAxis.Grid.Style'#7#5'psDot'#16'Foot.Brush.Color'#7#9'clBtnFace'#15'Foot.Fo'
|
||||
+'nt.Color'#7#6'clBlue'#19'LeftAxis.Grid.Style'#7#5'psDot'#20'LeftAxis.Title.'
|
||||
+'Angle'#2'Z'#17'Title.Brush.Color'#7#9'clBtnFace'#16'Title.Font.Color'#7#6'c'
|
||||
+'lBlue'#18'Title.Text.Strings'#1#6#7'TAChart'#0#5'Align'#7#8'alClient'#11'Pa'
|
||||
+'rentColor'#8#0#11'TLineSeries'#17'Chart1LineSeries1'#9'ZPosition'#2#1#13'Li'
|
||||
+'nePen.Color'#7#6'clTeal'#13'LinePen.Width'#2#3#11'SeriesColor'#7#6'clTeal'#6
|
||||
+'Source'#7#14'DbChartSource1'#0#0#10'TBarSeries'#16'Chart1BarSeries1'#14'Bar'
|
||||
+'Brush.Color'#7#5'clRed'#11'SeriesColor'#7#5'clRed'#0#0#0#7'TDBGrid'#7'DBGri'
|
||||
+'d1'#4'Left'#3'['#1#6'Height'#3#18#1#3'Top'#2#26#5'Width'#3#200#0#5'Align'#7
|
||||
+#7'alRight'#10'DataSource'#7#11'Datasource1'#10'Scrollbars'#7#10'ssAutoBoth'
|
||||
+#8'TabOrder'#2#1#0#0#8'TToolBar'#8'ToolBar1'#4'Left'#2#0#6'Height'#2#26#3'To'
|
||||
+'p'#2#0#5'Width'#3'#'#2#7'Caption'#6#8'ToolBar1'#12'ShowCaptions'#9#8'TabOrd'
|
||||
+'er'#2#2#0#11'TToolButton'#6'tbCopy'#4'Left'#2#1#3'Top'#2#2#7'Caption'#6#15
|
||||
+'Copy db to list'#7'OnClick'#7#11'tbCopyClick'#0#0#0#11'TMemDataset'#11'MemD'
|
||||
+'ataset1'#6'Active'#9#9'FieldDefs'#14#1#4'Name'#6#1'X'#8'DataType'#7#7'ftFlo'
|
||||
+'at'#9'Precision'#2#0#4'Size'#2#0#0#1#4'Name'#6#1'Y'#8'DataType'#7#7'ftFloat'
|
||||
+#9'Precision'#2#0#4'Size'#2#0#0#0#4'left'#3#15#1#3'top'#2'<'#0#0#11'TDatasou'
|
||||
+'rce'#11'Datasource1'#7'DataSet'#7#11'MemDataset1'#4'left'#3#15#1#3'top'#2'l'
|
||||
+#0#0#14'TDbChartSource'#14'DbChartSource1'#10'DataSource'#7#11'Datasource1'#6
|
||||
+'FieldX'#6#1'X'#6'FieldY'#6#1'Y'#4'left'#3#15#1#3'top'#3#156#0#0#0#0
|
||||
+'Angle'#2'Z'#12'Margins.Left'#2#8#11'Margins.Top'#2#8#13'Margins.Right'#2#8
|
||||
+#14'Margins.Bottom'#2#0#17'Title.Brush.Color'#7#9'clBtnFace'#16'Title.Font.C'
|
||||
+'olor'#7#6'clBlue'#18'Title.Text.Strings'#1#6#7'TAChart'#0#5'Align'#7#8'alCl'
|
||||
+'ient'#11'ParentColor'#8#0#11'TLineSeries'#17'Chart1LineSeries1'#9'ZPosition'
|
||||
+#2#1#13'LinePen.Color'#7#6'clTeal'#13'LinePen.Width'#2#3#11'SeriesColor'#7#6
|
||||
+'clTeal'#6'Source'#7#14'DbChartSource1'#0#0#10'TBarSeries'#16'Chart1BarSerie'
|
||||
+'s1'#14'BarBrush.Color'#7#5'clRed'#11'SeriesColor'#7#5'clRed'#0#0#0#7'TDBGri'
|
||||
+'d'#7'DBGrid1'#4'Left'#3'['#1#6'Height'#3#18#1#3'Top'#2#26#5'Width'#3#200#0#5
|
||||
+'Align'#7#7'alRight'#10'DataSource'#7#11'Datasource1'#10'Scrollbars'#7#10'ss'
|
||||
+'AutoBoth'#8'TabOrder'#2#1#0#0#8'TToolBar'#8'ToolBar1'#4'Left'#2#0#6'Height'
|
||||
+#2#26#3'Top'#2#0#5'Width'#3'#'#2#7'Caption'#6#8'ToolBar1'#12'ShowCaptions'#9
|
||||
+#8'TabOrder'#2#2#0#11'TToolButton'#6'tbCopy'#4'Left'#2#1#3'Top'#2#2#7'Captio'
|
||||
+'n'#6#15'Copy db to list'#7'OnClick'#7#11'tbCopyClick'#0#0#0#11'TMemDataset'
|
||||
+#11'MemDataset1'#6'Active'#9#9'FieldDefs'#14#1#4'Name'#6#1'X'#8'DataType'#7#7
|
||||
+'ftFloat'#9'Precision'#2#0#4'Size'#2#0#0#1#4'Name'#6#1'Y'#8'DataType'#7#7'ft'
|
||||
+'Float'#9'Precision'#2#0#4'Size'#2#0#0#0#4'left'#3#15#1#3'top'#2'<'#0#0#11'T'
|
||||
+'Datasource'#11'Datasource1'#7'DataSet'#7#11'MemDataset1'#4'left'#3#15#1#3't'
|
||||
+'op'#2'l'#0#0#14'TDbChartSource'#14'DbChartSource1'#10'DataSource'#7#11'Data'
|
||||
+'source1'#6'FieldX'#6#1'X'#6'FieldY'#6#1'Y'#4'left'#3#15#1#3'top'#3#156#0#0#0
|
||||
+#0
|
||||
]);
|
||||
|
||||
@ -138,6 +138,7 @@ type
|
||||
FGraphBrush: TBrush;
|
||||
FLeftAxis: TChartAxis;
|
||||
FLegend: TChartLegend;
|
||||
FMargins: TChartMargins;
|
||||
FMirrorX: Boolean; // From right to left ?
|
||||
FOnDrawReticule: TDrawReticuleEvent;
|
||||
FSeries: TChartSeriesList;
|
||||
@ -175,6 +176,7 @@ type
|
||||
procedure SetGraphBrush(Value: TBrush);
|
||||
procedure SetLeftAxis(Value: TChartAxis);
|
||||
procedure SetLegend(Value: TChartLegend);
|
||||
procedure SetMargins(AValue: TChartMargins);
|
||||
procedure SetMirrorX(AValue: Boolean);
|
||||
procedure SetReticuleMode(const AValue: TReticuleMode);
|
||||
procedure SetTitle(Value: TChartTitle);
|
||||
@ -258,6 +260,7 @@ type
|
||||
property GraphBrush: TBrush read FGraphBrush write SetGraphBrush;
|
||||
property LeftAxis: TChartAxis read FLeftAxis write SetLeftAxis;
|
||||
property Legend: TChartLegend read FLegend write SetLegend;
|
||||
property Margins: TChartMargins read FMargins write SetMargins;
|
||||
property MirrorX: Boolean read FMirrorX write SetMirrorX default false;
|
||||
property ReticuleMode: TReticuleMode
|
||||
read FReticuleMode write SetReticuleMode default rmNone;
|
||||
@ -375,6 +378,7 @@ begin
|
||||
FFrame.OnChange := @StyleChanged;
|
||||
|
||||
FExtent := TChartExtent.Create(Self);
|
||||
FMargins := TChartMargins.Create(Self);
|
||||
end;
|
||||
|
||||
destructor TChart.Destroy;
|
||||
@ -389,6 +393,7 @@ begin
|
||||
FBottomAxis.Free;
|
||||
FFrame.Free;
|
||||
FExtent.Free;
|
||||
FMargins.Free;
|
||||
|
||||
inherited Destroy;
|
||||
end;
|
||||
@ -876,12 +881,10 @@ begin
|
||||
end;
|
||||
|
||||
function TChart.GetMargins(ACanvas: TCanvas): TRect;
|
||||
const
|
||||
DEF_MARGIN = 4;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
Result := Rect(DEF_MARGIN, DEF_MARGIN, DEF_MARGIN, DEF_MARGIN);
|
||||
Result := FMargins.Data;
|
||||
for i := 0 to SeriesCount - 1 do
|
||||
if Series[i].Active then
|
||||
Series[i].UpdateMargins(ACanvas, Result);
|
||||
@ -1241,6 +1244,12 @@ begin
|
||||
Invalidate;
|
||||
end;
|
||||
|
||||
procedure TChart.SetMargins(AValue: TChartMargins);
|
||||
begin
|
||||
FMargins.Assign(AValue);
|
||||
Invalidate;
|
||||
end;
|
||||
|
||||
procedure TChart.SetChildOrder(Child: TComponent; Order: Integer);
|
||||
var
|
||||
i: Integer;
|
||||
|
||||
@ -31,6 +31,11 @@ uses
|
||||
Classes, SysUtils, Graphics, Controls, FPCanvas,
|
||||
TAChartUtils;
|
||||
|
||||
const
|
||||
MARKS_MARGIN_X = 4;
|
||||
MARKS_MARGIN_Y = 2;
|
||||
DEF_MARGIN = 4;
|
||||
|
||||
type
|
||||
TCustomChart = class(TCustomControl);
|
||||
|
||||
@ -272,9 +277,30 @@ type
|
||||
property UseYMax: Boolean index 4 read GetUseBounds write SetUseBounds default false;
|
||||
end;
|
||||
|
||||
const
|
||||
MARKS_MARGIN_X = 4;
|
||||
MARKS_MARGIN_Y = 2;
|
||||
TChartMargin = 0..MaxInt;
|
||||
|
||||
{ TChartMargins }
|
||||
|
||||
TChartMargins = class (TChartElement)
|
||||
private
|
||||
FData: record
|
||||
case Integer of
|
||||
0: (FRect: TRect;);
|
||||
1: (FCoords: array [1..4] of Integer;);
|
||||
end;
|
||||
function GetValue(AIndex: Integer): integer;
|
||||
procedure SetValue(AIndex: integer; AValue: TChartMargin);
|
||||
public
|
||||
constructor Create(AOwner: TCustomChart);
|
||||
public
|
||||
procedure Assign(Source: TPersistent); override;
|
||||
property Data: TRect read FData.FRect;
|
||||
published
|
||||
property Left: TChartMargin index 1 read GetValue write SetValue default DEF_MARGIN;
|
||||
property Top: TChartMargin index 2 read GetValue write SetValue default DEF_MARGIN;
|
||||
property Right: TChartMargin index 3 read GetValue write SetValue default DEF_MARGIN;
|
||||
property Bottom: TChartMargin index 4 read GetValue write SetValue default DEF_MARGIN;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
@ -829,6 +855,32 @@ begin
|
||||
StyleChanged(Self);
|
||||
end;
|
||||
|
||||
{ TChartMargins }
|
||||
|
||||
procedure TChartMargins.Assign(Source: TPersistent);
|
||||
begin
|
||||
if Source is TChartMargins then
|
||||
TChartMargins(Source).FData.FRect := Data;
|
||||
inherited Assign(Source);
|
||||
end;
|
||||
|
||||
constructor TChartMargins.Create(AOwner: TCustomChart);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FData.FRect := Rect(DEF_MARGIN, DEF_MARGIN, DEF_MARGIN, DEF_MARGIN);
|
||||
end;
|
||||
|
||||
function TChartMargins.GetValue(AIndex: Integer): integer;
|
||||
begin
|
||||
Result := FData.FCoords[AIndex];
|
||||
end;
|
||||
|
||||
procedure TChartMargins.SetValue(AIndex: integer; AValue: TChartMargin);
|
||||
begin
|
||||
if FData.FCoords[AIndex] = AValue then exit;
|
||||
FData.FCoords[AIndex] := AValue;
|
||||
StyleChanged(Self);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user