Code Formatting

This commit is contained in:
Michael Schimmel
2025-07-12 16:59:27 +02:00
parent 1b0f93c633
commit ce915e503a
+27 -18
View File
@@ -23,7 +23,8 @@ type
TCandleStyle = (csCandleStick, csHiLoBar);
TMycChart = class(TStyledControl)
public type
public
type
TSeries = class abstract(TObject)
private
FOwner: TMycChart;
@@ -33,7 +34,11 @@ type
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<Double, Single>); virtual; abstract;
procedure Paint(
const ACanvas: TCanvas;
StartIndex, Count: Int64;
const AXForm, AYForm: TFunc<Double, Single>
); virtual; abstract;
property MainSeries: TSeries read GetMainSeries;
public
constructor Create(AOwner: TMycChart);
@@ -41,7 +46,7 @@ type
property Owner: TMycChart read FOwner;
end;
private
private
FSeriesList: TList<TSeries>;
FLookback: TWriteable<Int64>;
FIdleSubscrId: TMessageSubscriptionId;
@@ -51,7 +56,8 @@ private
FDragStartPoint: TPointF;
FJumpButtonRect: TRectF;
FJumpButtonHot: Boolean;
FJumpButtonPressed: Boolean; protected
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<TSeries>.Create(true);
FLookback := TWriteable<Int64>.CreateWriteable( 1000 ); // Load more data for panning
FLookback := TWriteable<Int64>.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<T>.CreateEmpty;
FData := TWriteable<TMycDataArray<T>>.CreateWriteable( FCurrData ).Protect;
FData := TWriteable<TMycDataArray<T>>.CreateWriteable(FCurrData).Protect;
end;
function TChartSeriesReceiver<T>.GetData(var Data: TMycDataArray<T>): Boolean;