diff --git a/uChartForm.dfm b/uChartForm.dfm index 8cd076f..0666402 100644 --- a/uChartForm.dfm +++ b/uChartForm.dfm @@ -11,12 +11,10 @@ object ChartForm: TChartForm Font.Name = 'Tahoma' Font.Style = [] FormStyle = fsMDIChild - OldCreateOrder = False Position = poDefault Visible = True OnCreate = FormCreate OnDestroy = FormDestroy - PixelsPerInch = 96 TextHeight = 13 object Panel1: TPanel Left = 0 @@ -25,6 +23,7 @@ object ChartForm: TChartForm Height = 33 Align = alTop TabOrder = 0 + ExplicitWidth = 693 object Label1: TLabel Left = 8 Top = 10 @@ -57,6 +56,14 @@ object ChartForm: TChartForm Caption = 'X - DateTime' TabOrder = 1 end + object CBDots: TCheckBox + Left = 528 + Top = 8 + Width = 97 + Height = 17 + Caption = 'Dots' + TabOrder = 2 + end end object Chart: TChart Left = 0 @@ -75,9 +82,12 @@ object ChartForm: TChartForm Align = alClient Color = clWhite TabOrder = 1 + ExplicitWidth = 693 + ExplicitHeight = 538 DefaultCanvas = 'TGDIPlusCanvas' ColorPaletteIndex = 13 object Series1: TLineSeries + HoverElement = [heCurrent] Brush.BackColor = clDefault Pointer.InflateMargins = True Pointer.Style = psRectangle diff --git a/uChartForm.pas b/uChartForm.pas index cf009e2..e2838a4 100644 --- a/uChartForm.pas +++ b/uChartForm.pas @@ -12,6 +12,20 @@ interface 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; @@ -20,6 +34,7 @@ TChartForm = class(TForm) CBXAxisDateTime: TCheckBox; Chart: TChart; Series1: TLineSeries; + CBDots: TCheckBox; procedure SpeedButton1Click(Sender: TObject); procedure ComboBox1Change(Sender: TObject); procedure ComboBox1KeyDown(Sender: TObject; var Key: Word; @@ -41,6 +56,8 @@ TChartForm = class(TForm) PointToCell: TDictionary; public { Public declarations } + SeriesDescrs: array of TSeriesDescr; + procedure LoadSeries(S: string); procedure UpdateData2(); procedure SaveAutosave(); procedure LoadAutosave(); @@ -133,6 +150,77 @@ procedure TChartForm.LoadData(Buf: AnsiString); 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); @@ -158,7 +246,7 @@ procedure TChartForm.SpeedButton1Click(Sender: TObject); procedure TChartForm.UpdateData2; var - GrList,a:tStringArray; + //GrList,a:tStringArray; i:Integer; cx,cy,r:Integer; x,y:Extended; @@ -167,18 +255,19 @@ procedure TChartForm.UpdateData2; s:string; RowCount: Integer; begin - GrList:=SplitStrToArr(ComboBox1.Text,[' '],True); + //GrList:=SplitStrToArr(ComboBox1.Text,[' '],True); + LoadSeries(ComboBox1.Text); RowCount := DataForm.Grid.RowCount; PointToCell.Clear(); - while Chart.SeriesCountLength(GrList) do + while Chart.SeriesCount>Length(SeriesDescrs) do begin Chart.RemoveSeries(Chart.SeriesCount-1); end; @@ -186,21 +275,27 @@ procedure TChartForm.UpdateData2; XList := TList.Create(); YList := TList.Create(); - for i:=0 to Length(GrList)-1 do + 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; +// 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:=GrList[i]+' '+s; + Ser.Title:=SeriesDescrs[i].Caption+' '+s; XList.Clear(); YList.Clear(); @@ -214,6 +309,8 @@ procedure TChartForm.UpdateData2; 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)); @@ -235,10 +332,17 @@ procedure TChartForm.UpdateData2; Ser.EndUpdate(); end; - DataForm.ShowProgress((i+1) / Length(GrList)); + 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. diff --git a/uDataForm.pas b/uDataForm.pas index 4112558..05614e6 100644 --- a/uDataForm.pas +++ b/uDataForm.pas @@ -402,13 +402,13 @@ procedure TDataForm.Graph1Click(Sender: TObject); arr:tStringArray; begin s:=ChartForm.ComboBox1.Text; - arr:=SplitStrToArr(s,[' '],True); + arr:=SplitStrToArr(s,[';'],True); Grid.SelectionNormalize; for i:=Grid.Selection.Col1 to Grid.Selection.Col2 do begin - s1:=IntToStr(i); + s1:='c' + IntToStr(i); if StrIndexInArray(arr,s1,False)<0 then - s:=s+' '+s1; + s:=s+';'+s1; end; ChartForm.ComboBox1.Text:=s; ChartForm.UpdateData2();