Skip to content

Commit

Permalink
Value modifiers for graphs (c1 * 2 + 3)
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalw0lf committed Mar 16, 2024
1 parent d04c0f9 commit 056c941
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 19 deletions.
14 changes: 12 additions & 2 deletions uChartForm.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,6 +23,7 @@ object ChartForm: TChartForm
Height = 33
Align = alTop
TabOrder = 0
ExplicitWidth = 693
object Label1: TLabel
Left = 8
Top = 10
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
132 changes: 118 additions & 14 deletions uChartForm.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -41,6 +56,8 @@ TChartForm = class(TForm)
PointToCell: TDictionary<TPoint, TPoint>;
public
{ Public declarations }
SeriesDescrs: array of TSeriesDescr;
procedure LoadSeries(S: string);
procedure UpdateData2();
procedure SaveAutosave();
procedure LoadAutosave();
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -167,40 +255,47 @@ 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.SeriesCount<Length(GrList) do
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(GrList) do
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(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();
Expand All @@ -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));
Expand All @@ -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.
6 changes: 3 additions & 3 deletions uDataForm.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 056c941

Please sign in to comment.