From ce915e503a97bc257537355df92b76db2b097a71 Mon Sep 17 00:00:00 2001 From: Michael Schimmel Date: Sat, 12 Jul 2025 16:59:27 +0200 Subject: [PATCH] Code Formatting --- AuraTrader/Myc.Fmx.Chart.pas | 93 ++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 42 deletions(-) diff --git a/AuraTrader/Myc.Fmx.Chart.pas b/AuraTrader/Myc.Fmx.Chart.pas index f24f163..96f06b9 100644 --- a/AuraTrader/Myc.Fmx.Chart.pas +++ b/AuraTrader/Myc.Fmx.Chart.pas @@ -23,35 +23,41 @@ type TCandleStyle = (csCandleStick, csHiLoBar); TMycChart = class(TStyledControl) - public type - TSeries = class abstract(TObject) - private - FOwner: TMycChart; - function GetMainSeries: TSeries; - protected - function GetCount: Int64; virtual; abstract; - function GetValueRange(StartIndex, Count: Int64; out Min, Max: Double): Boolean; virtual; abstract; - function Update: Boolean; virtual; abstract; - // The signature is changed to support viewport painting - procedure Paint(const ACanvas: TCanvas; StartIndex, Count: Int64; const AXForm, AYForm: TFunc); virtual; abstract; - property MainSeries: TSeries read GetMainSeries; - public - constructor Create(AOwner: TMycChart); - property Count: Int64 read GetCount; - property Owner: TMycChart read FOwner; - end; + public + type + TSeries = class abstract(TObject) + private + FOwner: TMycChart; + function GetMainSeries: TSeries; + protected + function GetCount: Int64; virtual; abstract; + function GetValueRange(StartIndex, Count: Int64; out Min, Max: Double): Boolean; virtual; abstract; + function Update: Boolean; virtual; abstract; + // The signature is changed to support viewport painting + procedure Paint( + const ACanvas: TCanvas; + StartIndex, Count: Int64; + const AXForm, AYForm: TFunc + ); virtual; abstract; + property MainSeries: TSeries read GetMainSeries; + public + constructor Create(AOwner: TMycChart); + property Count: Int64 read GetCount; + property Owner: TMycChart read FOwner; + end; -private - FSeriesList: TList; - FLookback: TWriteable; - FIdleSubscrId: TMessageSubscriptionId; - FViewStartIndex: Int64; - FViewCount: Int64; - FIsDragging: Boolean; - FDragStartPoint: TPointF; - FJumpButtonRect: TRectF; - FJumpButtonHot: Boolean; - FJumpButtonPressed: Boolean; protected + private + FSeriesList: TList; + FLookback: TWriteable; + FIdleSubscrId: TMessageSubscriptionId; + FViewStartIndex: Int64; + FViewCount: Int64; + FIsDragging: Boolean; + FDragStartPoint: TPointF; + FJumpButtonRect: TRectF; + FJumpButtonHot: Boolean; + FJumpButtonPressed: Boolean; + protected procedure Paint; override; procedure DoIdle; procedure MouseWheel(Shift: TShiftState; WheelDelta: Integer; var Handled: Boolean); override; @@ -180,7 +186,7 @@ begin inherited Create(AOwner); FSeriesList := TObjectList.Create(true); - FLookback := TWriteable.CreateWriteable( 1000 ); // Load more data for panning + FLookback := TWriteable.CreateWriteable(1000); // Load more data for panning FViewStartIndex := 0; FViewCount := 100; // Show 100 items by default FIsDragging := false; @@ -362,7 +368,6 @@ begin // The formula for that is FViewStartIndex := FViewStartIndex + indexDelta; -> StartIndex + (negative) = decrease. FViewStartIndex := FViewStartIndex + indexDelta; - // Clamp values mainSeries := FSeriesList[0]; maxIndex := 0; @@ -375,8 +380,10 @@ begin maxIndex := 0; end; - if (FViewStartIndex < 0) then FViewStartIndex := 0; - if (FViewStartIndex > maxIndex) then FViewStartIndex := maxIndex; + if (FViewStartIndex < 0) then + FViewStartIndex := 0; + if (FViewStartIndex > maxIndex) then + FViewStartIndex := maxIndex; FDragStartPoint := TPointF.Create(X, Y); Repaint; @@ -417,9 +424,12 @@ begin newViewCount := Round(FViewCount * zoomFactor); // Clamp zoom level - if (newViewCount < 10) then newViewCount := 10; - if (newViewCount > mainSeries.Count) then newViewCount := mainSeries.Count; - if (newViewCount = FViewCount) then exit; + if (newViewCount < 10) then + newViewCount := 10; + if (newViewCount > mainSeries.Count) then + newViewCount := mainSeries.Count; + if (newViewCount = FViewCount) then + exit; // Adjust start index to keep anchor point stable if (FViewCount > 0) then @@ -431,7 +441,8 @@ begin FViewCount := newViewCount; // Clamp start index - if (FViewStartIndex < 0) then FViewStartIndex := 0; + if (FViewStartIndex < 0) then + FViewStartIndex := 0; if (FViewStartIndex + FViewCount > mainSeries.Count) then begin FViewStartIndex := mainSeries.Count - FViewCount; @@ -494,7 +505,8 @@ begin exit; // Transform maps an index from the viewport to a screen coordinate - xTransform := function(index: Double): Single + xTransform := + function(index: Double): Single begin if (FViewCount <= 1) then begin @@ -505,10 +517,7 @@ begin end; yTransform := - function(value: Double): Single - begin - Result := rect.Top + (1 - (value - globalMin) / (globalMax - globalMin)) * rect.Height; - end; + function(value: Double): Single begin Result := rect.Top + (1 - (value - globalMin) / (globalMax - globalMin)) * rect.Height; end; for series in FSeriesList do begin @@ -762,7 +771,7 @@ begin inherited Create; FLookback := ALookback; FCurrData := TMycDataArray.CreateEmpty; - FData := TWriteable>.CreateWriteable( FCurrData ).Protect; + FData := TWriteable>.CreateWriteable(FCurrData).Protect; end; function TChartSeriesReceiver.GetData(var Data: TMycDataArray): Boolean;