1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
|
unit ceMain;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics,
Dialogs, Menus, StdCtrls, ExtCtrls, Types,
TAGraph, TATools, TAChartAxis, TATextElements, TASeries, TASources,
TALegend, TAChartImageList,
ceAxisFrame;
type
{ TMainForm }
TMainForm = class(TForm)
Bevel1: TBevel;
Chart1: TChart;
Chart1AreaSeries1: TAreaSeries;
Chart1BarSeries1: TBarSeries;
Chart1LineSeries1: TLineSeries;
ChartToolset1: TChartToolset;
ChartToolset1AxisClickTool1: TAxisClickTool;
ChartToolset1DataPointClickTool1: TDataPointClickTool;
ChartToolset1LegendClickTool1: TLegendClickTool;
ChartToolset1TitleFootClickTool1: TTitleFootClickTool;
cbDoubleClick: TCheckBox;
cbUseAllInOneDialog: TCheckBox;
Label1: TLabel;
MainMenu: TMainMenu;
MenuItem1: TMenuItem;
mnuSeries: TMenuItem;
mnuChartLegend: TMenuItem;
mnuLeftAxis: TMenuItem;
mnuBottomAxis: TMenuItem;
MenuItem2: TMenuItem;
mnuChartFooter: TMenuItem;
mnuChartTitle: TMenuItem;
mnuSettings: TMenuItem;
RandomChartSource1: TRandomChartSource;
RandomChartSource2: TRandomChartSource;
RandomChartSource3: TRandomChartSource;
procedure ChartToolset1AxisClickTool1Click(ASender: TChartTool;
Axis: TChartAxis; AHit: TChartAxisHitTests);
procedure ChartToolset1DataPointClickTool1PointClick(ATool: TChartTool;
APoint: TPoint);
procedure ChartToolset1LegendClickTool1Click(ASender: TChartTool;
ALegend: TChartLegend);
procedure ChartToolset1TitleFootClickTool1Click(ASender: TChartTool;
ATitle: TChartTitle);
procedure cbDoubleClickChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure mnuBottomAxisClick(Sender: TObject);
procedure mnuChartFooterClick(Sender: TObject);
procedure mnuChartLegendClick(Sender: TObject);
procedure mnuChartTitleClick(Sender: TObject);
procedure mnuLeftAxisClick(Sender: TObject);
private
procedure ChartEditor(AChart: TChart);
procedure EditAxis(AAxis: TChartAxis; APage: TChartAxisEditorPage);
procedure EditLegend(ALegend: TChartLegend);
procedure EditSeries(ASeries: TBasicChartSeries);
procedure EditTitleFoot(ATitle: TChartTitle);
procedure MenuSeriesClick(Sender: TObject);
public
end;
var
MainForm: TMainForm;
implementation
{$R *.lfm}
uses
TAChartUtils, TACustomSeries,
ceTitleFootDlg, ceLegendDlg, ceSeriesDlg, ceAxisDlg, ceChartEditor, ceImages;
{ TMainForm }
procedure TMainForm.ChartEditor(AChart: TChart);
var
F: TChartEditorForm;
begin
F := TChartEditorForm.Create(nil);
try
F.Chart := AChart;
F.ShowModal;
finally
F.Free;
end;
end;
procedure TMainForm.ChartToolset1TitleFootClickTool1Click(ASender: TChartTool;
ATitle: TChartTitle);
begin
Unused(ASender);
EditTitleFoot(ATitle);
end;
procedure TMainForm.cbDoubleClickChange(Sender: TObject);
var
shift: TShiftState;
s: String;
begin
if cbDoubleClick.Checked then
begin
shift := [ssLeft, ssDouble];
s := 'Double-click';
end else
begin
shift := [ssLeft];
s := 'Click';
end;
Label1.Caption := s + ' on a title, axis, label, grid, data point to open the corresponding editor.';
ChartToolset1DatapointClickTool1.Shift := shift;
ChartToolset1TitleFootClickTool1.Shift := shift;
ChartToolset1LegendClickTool1.Shift := shift;
ChartToolset1AxisClickTool1.Shift := shift;
end;
procedure TMainForm.FormCreate(Sender: TObject);
var
i: Integer;
item: TMenuItem;
begin
ChartImagesDM.ChartImages.Chart := Chart1;
for i := 0 to Chart1.SeriesCount-1 do begin
item := TMenuItem.Create(MainMenu);
item.Caption := TCustomChartSeries(Chart1.Series[i]).Title + '...';
item.OnClick := @MenuSeriesClick;
item.Tag := PtrInt(Chart1.Series[i]);
item.ImageIndex := ChartImagesDM.ChartImages.FirstSeriesIndex + i;
mnuSeries.Add(item);
end;
end;
procedure TMainForm.mnuBottomAxisClick(Sender: TObject);
begin
EditAxis(Chart1.BottomAxis, aepTitle);
end;
procedure TMainForm.ChartToolset1AxisClickTool1Click(ASender: TChartTool;
Axis: TChartAxis; AHit: TChartAxisHitTests);
var
pg: TChartAxisEditorPage;
begin
Unused(ASender);
if (ahtTitle in AHit) then
pg := aepTitle
else if (ahtLabels in AHit) then
pg := aepLabels
else if (ahtLine in AHit) then
pg := aepLine
else if (ahtGrid in AHit) then
pg := aepGrid
else
exit;
EditAxis(Axis, pg);
end;
procedure TMainForm.ChartToolset1DataPointClickTool1PointClick(ATool: TChartTool;
APoint: TPoint);
begin
Unused(APoint);
EditSeries(TDataPointClickTool(ATool).Series);
end;
procedure TMainForm.ChartToolset1LegendClickTool1Click(ASender: TChartTool;
ALegend: TChartLegend);
begin
Unused(ASender);
EditLegend(ALegend);
end;
procedure TMainForm.EditAxis(AAxis: TChartAxis; APage: TChartAxisEditorPage);
var
F: TChartAxisEditor;
begin
if cbUseAllInOneDialog.Checked then
EditChartAxis(AAxis, APage)
else
begin
F := TChartAxisEditor.Create(nil);
try
F.Prepare(AAxis, 'Edit chart axis "%s"');
F.Page := APage;
F.ShowModal;
finally
F.Free;
end;
end;
end;
procedure TMainForm.EditLegend(ALegend: TChartLegend);
var
F: TChartLegendEditor;
begin
if cbUseAllInOneDialog.Checked then
EditChartLegend(ALegend.GetOwner as TChart)
else
begin
F := TChartLegendEditor.Create(nil);
try
F.Prepare(ALegend, 'Edit chart legend');
F.ShowModal;
finally
F.Free;
end;
end;
end;
procedure TMainForm.EditSeries(ASeries: TBasicChartSeries);
var
F: TChartSeriesEditor;
begin
if cbUseAllInOneDialog.Checked then
EditChartSeries(ASeries)
else
begin
F := TChartSeriesEditor.Create(nil);
try
F.Prepare(ASeries, 'Edit series "%s"');
F.ShowModal;
finally
F.Free;
end;
end;
end;
procedure TMainForm.EditTitleFoot(ATitle: TChartTitle);
var
F: TChartTitleFootEditor;
s: String;
begin
if cbUseAllInOneDialog.Checked then
begin
if ATitle = Chart1.Title then
EditChartTitle(ATitle.GetOwner as TChart)
else
if ATitle = Chart1.Foot then
EditChartFooter(ATitle.GetOwner as TChart);
end else
begin
F := TChartTitleFootEditor.Create(nil);
try
s := 'Edit chart %s';
if ATitle = Chart1.Title then s := Format(s, ['title']) else s := Format(s, ['footer']);
F.Prepare(ATitle, s);
F.ShowModal;
finally
F.Free;
end;
end;
end;
procedure TMainForm.MenuSeriesClick(Sender: TObject);
var
ser: TBasicChartSeries;
begin
ser := TBasicChartSeries(TMenuItem(Sender).Tag);
EditSeries(ser);
end;
procedure TMainForm.mnuChartFooterClick(Sender: TObject);
begin
EditTitleFoot(Chart1.Foot);
end;
procedure TMainForm.mnuChartLegendClick(Sender: TObject);
begin
EditLegend(Chart1.Legend);
end;
procedure TMainForm.mnuChartTitleClick(Sender: TObject);
begin
EditTitleFoot(Chart1.Title);
end;
procedure TMainForm.mnuLeftAxisClick(Sender: TObject);
begin
EditAxis(Chart1.LeftAxis, aepTitle);
end;
end.
|