Code Formatting

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