-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuChartForm.pas
More file actions
348 lines (310 loc) · 8.5 KB
/
uChartForm.pas
File metadata and controls
348 lines (310 loc) · 8.5 KB
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
unit uChartForm;
{$WARN IMPLICIT_STRING_CAST OFF}
{$WARN IMPLICIT_STRING_CAST_LOSS OFF}
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, System.Types,
ExtCtrls, StdCtrls, uUtil, Buttons, Math, VclTee.TeeGDIPlus, VCLTee.TeEngine,
VCLTee.Series, VCLTee.TeeProcs, VCLTee.Chart, Generics.Collections;
type
TSeriesDescr = record
public
type
TExpr = record
ColIndex: Integer;
Mult, Add: Double;
function Adjust(X: Double): Double;
end;
public
X, Y: TExpr;
Caption: string;
Style: (ssLine, ssDot);
end;
TChartForm = class(TForm)
Panel1: TPanel;
Label1: TLabel;
ComboBox1: TComboBox;
SpeedButton1: TSpeedButton;
CBXAxisDateTime: TCheckBox;
Chart: TChart;
Series1: TLineSeries;
CBDots: TCheckBox;
procedure SpeedButton1Click(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure ComboBox1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
// procedure AChartCustomMouseHitLabel(Sender: TObject; XValue, YValue: Real;
// var AxisLabel: string);
// procedure AChartDataToolTip(Sender: TObject; MousePoint: TPoint;
// DataPoint: TSLRealPoint; var Text: string);
procedure ChartXAxisCustomLabel(Sender: TObject; SampleValue: Real;
var AxisLabel: string);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure ChartClickSeries(Sender: TCustomChart; Series: TChartSeries;
ValueIndex: Integer; Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
// (PointIndex, SeriesIndex) -> (CellCol, CellRow)
PointToCell: TDictionary<TPoint, TPoint>;
public
{ Public declarations }
SeriesDescrs: array of TSeriesDescr;
procedure LoadSeries(S: string);
procedure UpdateData2();
procedure SaveAutosave();
procedure LoadAutosave();
function SaveData():AnsiString;
procedure LoadData(Buf:AnsiString);
end;
var
ChartForm: TChartForm;
implementation
uses uDataForm, uMainForm, uScriptForm;
{$R *.dfm}
{ TChartForm }
//procedure TChartForm.AChartCustomMouseHitLabel(Sender: TObject; XValue,
// YValue: Real; var AxisLabel: string);
//begin
//// ScriptForm.AddLog('CustomMouseHitLabel: '+AxisLabel);
// if CBXAxisDateTime.Checked then
// AxisLabel:=DateTime2Str(XValue,'dd.mm.yy hh:nn:ss.zzz')+' : '+R2S(YValue);
//end;
//
//procedure TChartForm.AChartDataToolTip(Sender: TObject; MousePoint: TPoint;
// DataPoint: TSLRealPoint; var Text: string);
//begin
//// ScriptForm.AddLog('DataToolTip: '+Text);
// if CBXAxisDateTime.Checked then
// Text:=DateTime2Str(DataPoint.X,'hh:nn:ss.zzz');
//end;
procedure TChartForm.ChartClickSeries(Sender: TCustomChart;
Series: TChartSeries; ValueIndex: Integer; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
p: TPoint;
begin
if (Button = mbLeft) and (ssDouble in Shift) then
begin
if PointToCell.TryGetValue(Point(ValueIndex, Series.SeriesIndex), p) then
begin
DataForm.Grid.Row := p.Y;
DataForm.Grid.Col := p.X;
end;
end;
end;
procedure TChartForm.ChartXAxisCustomLabel(Sender: TObject; SampleValue: Real;
var AxisLabel: string);
begin
// ScriptForm.AddLog('XAxisCustomLabel: '+AxisLabel);
end;
procedure TChartForm.ComboBox1Change(Sender: TObject);
begin
MainForm.ProjModified:=True;
end;
procedure TChartForm.ComboBox1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key=VK_RETURN then
SpeedButton1Click(nil);
end;
procedure TChartForm.FormCreate(Sender: TObject);
begin
PointToCell := TDictionary<TPoint, TPoint>.Create();
end;
procedure TChartForm.FormDestroy(Sender: TObject);
begin
PointToCell.Free;
end;
procedure TChartForm.LoadAutosave;
var
s:AnsiString;
begin
LoadEntireFile(ExePath+'Autosave\GraphCfg.txt',s);
ComboBox1.Text:=s;
end;
procedure TChartForm.LoadData(Buf: AnsiString);
begin
ComboBox1.Text:=GetNextWord(Buf,[#13,#10]);
UpdateData2();
end;
function SplitLexems(const S: string): TStringDynArray;
var
a: string;
i, CurType, PrevType: Integer;
begin
a := ''; PrevType := -1;
for i := 1 to Length(s) do
begin
case S[i] of
'0'..'9', '.', 'a'..'z', 'A'..'Z': CurType := 1;
' ': CurType := 2;
else CurType := 3;
end;
if CurType <> PrevType then
begin
if a <> '' then Result := Result + [a];
a := '';
end;
PrevType := CurType;
if S[i] <> ' ' then
a := a + S[i];
end;
if a <> '' then Result := Result + [a];
end;
procedure TChartForm.LoadSeries(S: string);
var
SerDesc, AxisDesc : TStringDynArray;
i: Integer;
procedure LoadExpr(const E: string; var Expr: TSeriesDescr.TExpr);
var
L: TStringDynArray;
i: Integer;
begin
Expr.ColIndex := 0;
Expr.Mult := 1;
Expr.Add := 0;
L := SplitLexems(E);
for i := 0 to Length(L) - 1 do
begin
if L[i][1] = 'c' then
Expr.ColIndex := StrToInt(Copy(L[i], 2, MaxInt))
else
if L[i] = '*' then
Expr.Mult := S2R(L[i+1])
else
if L[i] = '+' then
Expr.Add := S2R(L[i+1]);
end;
end;
begin
SerDesc := S.Split([';'], TStringSplitOptions.ExcludeEmpty);
SetLength(SeriesDescrs, Length(SerDesc));
for i := 0 to Length(SerDesc) - 1 do
begin
SeriesDescrs[i].Caption := SerDesc[i];
AxisDesc := SerDesc[i].Split([':']);
LoadExpr(AxisDesc[0], SeriesDescrs[i].Y);
if Length(AxisDesc) >= 2 then
LoadExpr(AxisDesc[1], SeriesDescrs[i].X)
else
begin
SeriesDescrs[i].X.ColIndex := 0;
SeriesDescrs[i].X.Mult := 1;
SeriesDescrs[i].X.Add := 0;
end;
end;
end;
procedure TChartForm.SaveAutosave;
begin
SaveEntireFile(ExePath+'Autosave\GraphCfg.txt',ComboBox1.Text);
end;
function TChartForm.SaveData: AnsiString;
begin
Result:=ComboBox1.Text;
end;
procedure TChartForm.SpeedButton1Click(Sender: TObject);
begin
UpdateData2();
end;
const
ContrastColors:array[0..14] of TColor = (
$0000FF, $00FF00, $FF0000,
$000080, $008000, $800000,
$808000, $800080, $008080,
$FF8000, $8000FF, $00FF80,
$80FF00, $FF0080, $0080FF);
procedure TChartForm.UpdateData2;
var
//GrList,a:tStringArray;
i:Integer;
cx,cy,r:Integer;
x,y:Extended;
XList, YList: TList<Double>;
Ser: TLineSeries;
s:string;
RowCount: Integer;
begin
//GrList:=SplitStrToArr(ComboBox1.Text,[' '],True);
LoadSeries(ComboBox1.Text);
RowCount := DataForm.Grid.RowCount;
PointToCell.Clear();
while Chart.SeriesCount < Length(SeriesDescrs) do
begin
Ser := TLineSeries.Create(Self);
Ser.LineHeight :=2;
Ser.Color := ContrastColors[Chart.SeriesCount mod Length(ContrastColors)];
Chart.AddSeries(Ser);
end;
while Chart.SeriesCount>Length(SeriesDescrs) do
begin
Chart.RemoveSeries(Chart.SeriesCount-1);
end;
XList := TList<Double>.Create();
YList := TList<Double>.Create();
for i:=0 to Length(SeriesDescrs)-1 do
begin
Ser := Chart.Series[i] as TLineSeries;
Ser.BeginUpdate();
try
Ser.Pointer.Visible := CBDots.Checked;
Ser.Pointer.Size := 2;
Ser.Transparency := IfThen(CBDots.Checked, 100, 0);
Ser.Clear();
// a:=SplitStrToArr(GrList[i],['/']);
// if Length(a)=0 then Continue;
// cy:=StrToInt(a[0]);
// if Length(a)>=2 then
// cx:=StrToInt(a[1])
// else
// cx:=0;
cy := SeriesDescrs[i].Y.ColIndex;
cx := SeriesDescrs[i].X.ColIndex;
s:=(DataForm.Grid.Cell[cy,0] as TCalcCell).Caption;
Ser.Title:=SeriesDescrs[i].Caption+' '+s;
XList.Clear();
YList.Clear();
for r:=1 to RowCount-1 do
begin
if cx=0 then
x:=r
else
x:=DataForm.GetV(r,cx);
y:=DataForm.GetV(r,cy);
if (not IsNaN(y)) and (not IsNaN(x)) then
begin
x := SeriesDescrs[i].X.Adjust(x);
y := SeriesDescrs[i].Y.Adjust(y);
XList.Add(x);
YList.Add(y);
PointToCell.AddOrSetValue(Point(XList.Count-1, i), Point(cy, r));
end;
end;
with Ser.XValues do
begin
Value:=TChartValues(XList.ToArray());
Count:=XList.Count;
Modified:=True;
end;
with Ser.YValues do
begin
Value:=TChartValues(YList.ToArray());
Count:=YList.Count;
Modified:=True;
end;
finally
Ser.EndUpdate();
end;
DataForm.ShowProgress((i+1) / Length(SeriesDescrs));
end;
XList.Free;
YList.Free;
end;
{ TSeriesDescr.TExpr }
function TSeriesDescr.TExpr.Adjust(X: Double): Double;
begin
Result := X * Mult + Add;
end;
end.