From cfa1013f51244e390b86a8f69260067676e85c5b Mon Sep 17 00:00:00 2001 From: maxim Date: Wed, 21 Jul 2021 20:56:48 +0000 Subject: [PATCH] Merged revision(s) 65470-65471 #15a417978a-#15a417978a from trunk: TAChart/TChartLiveView: Simplification ........ TAChart/LiveView demo: fix typo. ........ git-svn-id: branches/fixes_2_2@65484 - --- .../tachart/demo/liveview/liveviewdemo.lpi | 3 +- .../tachart/demo/liveview/liveviewdemo.lpr | 2 +- components/tachart/demo/liveview/main.lfm | 7 +--- components/tachart/demo/liveview/main.pas | 20 +++++----- components/tachart/tachartliveview.pas | 40 +++++++++---------- 5 files changed, 32 insertions(+), 40 deletions(-) diff --git a/components/tachart/demo/liveview/liveviewdemo.lpi b/components/tachart/demo/liveview/liveviewdemo.lpi index 77dce07cff..e1b60d26c1 100644 --- a/components/tachart/demo/liveview/liveviewdemo.lpi +++ b/components/tachart/demo/liveview/liveviewdemo.lpi @@ -15,7 +15,6 @@ - @@ -43,7 +42,7 @@ - + diff --git a/components/tachart/demo/liveview/liveviewdemo.lpr b/components/tachart/demo/liveview/liveviewdemo.lpr index b9011079fc..cff45ef3ab 100644 --- a/components/tachart/demo/liveview/liveviewdemo.lpr +++ b/components/tachart/demo/liveview/liveviewdemo.lpr @@ -19,7 +19,7 @@ begin RequireDerivedFormResource:=True; Application.Scaled:=True; Application.Initialize; - Application.CreateForm(TMainFrom, MainFrom); + Application.CreateForm(TMainForm, MainForm); Application.Run; end. diff --git a/components/tachart/demo/liveview/main.lfm b/components/tachart/demo/liveview/main.lfm index 8f55bdd266..8ee08ab468 100644 --- a/components/tachart/demo/liveview/main.lfm +++ b/components/tachart/demo/liveview/main.lfm @@ -1,4 +1,4 @@ -object MainFrom: TMainFrom +object MainForm: TMainForm Left = 299 Height = 446 Top = 130 @@ -7,7 +7,7 @@ object MainFrom: TMainFrom ClientHeight = 446 ClientWidth = 723 OnCreate = FormCreate - LCLVersion = '2.1.0.0' + LCLVersion = '2.3.0.0' object Chart1: TChart AnchorSideLeft.Control = Owner AnchorSideTop.Control = Owner @@ -106,7 +106,6 @@ object MainFrom: TMainFrom Width = 69 BorderSpacing.Left = 24 Caption = 'Viewport size' - ParentColor = False Visible = False end object seViewportSize: TFloatSpinEdit @@ -120,7 +119,6 @@ object MainFrom: TMainFrom Width = 73 Alignment = taRightJustify BorderSpacing.Left = 8 - MaxValue = 0 OnChange = seViewportSizeChange TabOrder = 2 Value = 5 @@ -170,7 +168,6 @@ object MainFrom: TMainFrom Width = 40 BorderSpacing.Left = 24 Caption = 'ExtentY' - ParentColor = False end end object ChartNavScrollBar1: TChartNavScrollBar diff --git a/components/tachart/demo/liveview/main.pas b/components/tachart/demo/liveview/main.pas index 4ae0a643c3..176a1844ba 100644 --- a/components/tachart/demo/liveview/main.pas +++ b/components/tachart/demo/liveview/main.pas @@ -10,9 +10,9 @@ uses type - { TMainFrom } + { TMainForm } - TMainFrom = class(TForm) + TMainForm = class(TForm) btnAddDataPoint: TButton; Chart1: TChart; Chart1LineSeries1: TLineSeries; @@ -38,7 +38,7 @@ type end; var - MainFrom: TMainFrom; + MainForm: TMainForm; implementation @@ -47,9 +47,9 @@ implementation uses Math, TAChartUtils; -{ TMainFrom } +{ TMainForm } -procedure TMainFrom.btnAddDataPointClick(Sender: TObject); +procedure TMainForm.btnAddDataPointClick(Sender: TObject); const TWO_PI = 2.0 * pi; var @@ -60,7 +60,7 @@ begin Chart1Lineseries1.AddXY(x, y); end; -procedure TMainFrom.cbFixedExtentChange(Sender: TObject); +procedure TMainForm.cbFixedExtentChange(Sender: TObject); begin Chart1.Extent.YMin := -1.5; Chart1.Extent.YMax := 1.5; @@ -68,7 +68,7 @@ begin Chart1.Extent.UseYMax := cbFixedExtent.Checked; end; -procedure TMainFrom.cbLiveModeChange(Sender: TObject); +procedure TMainForm.cbLiveModeChange(Sender: TObject); begin ChartLiveView1.Active := cbLiveMode.Checked; seViewportSize.Visible := cbLiveMode.Checked; @@ -77,12 +77,12 @@ begin lblExtentY.Visible := cbLiveMode.Checked; end; -procedure TMainFrom.cbExtentYChange(Sender: TObject); +procedure TMainForm.cbExtentYChange(Sender: TObject); begin ChartLiveView1.ExtentY := TChartLiveViewExtentY(cbExtentY.ItemIndex); end; -procedure TMainFrom.FormCreate(Sender: TObject); +procedure TMainForm.FormCreate(Sender: TObject); begin // Add three data points to start with btnAddDataPointClick(nil); @@ -95,7 +95,7 @@ begin cbExtentY.ItemIndex := ord(ChartLiveView1.ExtentY); end; -procedure TMainFrom.seViewportSizeChange(Sender: TObject); +procedure TMainForm.seViewportSizeChange(Sender: TObject); begin ChartLiveView1.ViewportSize := seViewportSize.Value; end; diff --git a/components/tachart/tachartliveview.pas b/components/tachart/tachartliveview.pas index c740728beb..868bff0830 100644 --- a/components/tachart/tachartliveview.pas +++ b/components/tachart/tachartliveview.pas @@ -198,7 +198,7 @@ var fext, lext: TDoubleRect; // "full extent", "logical extent" variables w: double; i, j: Integer; - yminAx, ymaxAx, yminSer, ymaxSer: Double; + ymin, ymax: Double; dy: Double; ser: TChartSeries; axis: TChartAxis; @@ -238,8 +238,8 @@ begin // Ignore x-axes if (axis.Alignment in [calTop, calBottom]) then Continue; - ymaxAx := -Infinity; - yminAx := Infinity; + ymax := -Infinity; + ymin := Infinity; // Step through all active non-rotated series attached to this axis for j := 0 to FChart.SeriesCount-1 do begin @@ -248,50 +248,46 @@ begin ser := TChartSeries(FChart.Series[j]); if (not ser.Active) or (ser.GetAxisY <> axis) or ser.IsRotated then continue; - yminSer := Infinity; - ymaxSer := -Infinity; - ser.FindYRange(lext.a.x, lext.b.x, yminSer, ymaxSer); - yminAx := Min(yminAx, yminSer); - ymaxAx := Max(ymaxAx, ymaxSer); + ser.FindYRange(lext.a.x, lext.b.x, ymin, ymax); end; end; // Only if an axis has no active non-rotated series, we have -infinity - if ymaxAx > -Infinity then + if ymax > -Infinity then begin - if ymaxAx = yminAx then + if ymax = ymin then begin - if yminAx = 0 then + if ymin = 0 then begin - yminAx := -1; - ymaxAx := +1; + ymin := -1; + ymax := +1; end else // Set the range to 10% around the value, take care of the sign! begin - dy := abs(yminAx) * 0.1; - yminAx := yminAx - dy; - ymaxAx := ymaxAx + dy; + dy := abs(ymin) * 0.1; + ymin := ymin - dy; + ymax := ymax + dy; end; end; end else begin - yminAx := -1; - ymaxAx := +1; + ymin := -1; + ymax := +1; end; // Only if the user did not set its own range we set the axis range // determined above. if (not FAxisRanges[i].UseMin) then begin - axis.Range.Min := yminAx; + axis.Range.Min := ymin; axis.Range.UseMin := true; // we had stored the original UseMin in FAxisRanges - lext.a.y := axis.GetTransform.AxisToGraph(yminAx); + lext.a.y := Min(lext.a.y, axis.GetTransform.AxisToGraph(ymin)); end; if (not FAxisRanges[i].UseMax) then begin - axis.Range.Max := ymaxAx; + axis.Range.Max := ymax; axis.Range.UseMax := true; // we had stored the original UseMax in FAxisRanges - lext.b.y := axis.GetTransform.AxisToGraph(ymaxAx); + lext.b.y := Max(lext.b.y, axis.GetTransform.AxisToGraph(ymax)); end; end; // series loop end; // axes loop