Fixed concurrent processing

This commit is contained in:
Michael Schimmel
2025-07-16 14:12:07 +02:00
parent bc75f08477
commit 342eb07c42
8 changed files with 192 additions and 105 deletions
+22 -29
View File
@@ -64,18 +64,19 @@ type
constructor Create(AParent: TPanel);
end;
TDragPoint = record
Point: TPointF;
Idx: Int64;
BarX: Single;
end;
TAxisLayer = class abstract(TLayer)
private
FOwner: TMycChart;
protected
function GetOwner: TMycChart; override; final;
// Paint crosshair and other axis related overlays
procedure Paint(
const Canvas: TCanvas;
const Viewport: TRectF;
ViewStartIndex, ViewCount: Int64;
IdxAtMousePos: Integer
); virtual; abstract;
procedure Paint(const Canvas: TCanvas; const Viewport: TRectF; const MousePos: TDragPoint); virtual; abstract;
public
constructor Create(AOwner: TMycChart);
end;
@@ -83,12 +84,7 @@ type
TXAxisLayer = class(TAxisLayer)
protected
// Paint crosshair and time caption
procedure Paint(
const Canvas: TCanvas;
const Viewport: TRectF;
ViewStartIndex, ViewCount: Int64;
IdxAtMousePos: Integer
); override;
procedure Paint(const Canvas: TCanvas; const Viewport: TRectF; const MousePos: TDragPoint); override;
// This function delivers the text for the caption.
function GetCaption(Idx: Int64): String; virtual; abstract;
end;
@@ -124,11 +120,6 @@ type
property Weight: Single read FWeight write SetWeight;
end;
TDragPoint = record
Point: TPointF;
Idx: Int64;
end;
private
FPanelList: TObjectList<TPanel>;
FXAxisSeries: TMycChart.TXAxisLayer;
@@ -175,6 +166,8 @@ type
property Panels[Index: Integer]: TPanel read GetPanel; default;
// The rectangle occupied by the jump-to-latest button, used for hit testing.
property JumpButtonRect: TRectF read FJumpButtonRect;
property ViewCount: Int64 read FViewCount;
property ViewStartIndex: Int64 read FViewStartIndex;
end;
implementation
@@ -232,11 +225,16 @@ end;
function TMycChart.CreateDragPoint(X, Y: Single): TDragPoint;
begin
var rect := LocalRect;
Result.Point.X := X;
Result.Point.Y := Y;
Result.Idx := Round((LocalRect.Right - X) * (FViewCount - 1) / LocalRect.Width);
Result.Idx := Round((rect.Right - X) * (FViewCount - 1) / rect.Width);
if (Result.Idx < 0) or (Result.Idx >= FXAxisSeries.Series.Count) then
Result.Idx := -1;
Result.BarX := NaN;
if Result.Idx >= 0 then
Result.BarX := rect.Right - (Result.Idx * (FViewCount - 1)) / (FViewCount - 1) * (rect.Width / (FViewCount - 1));
end;
function TMycChart.GetPanel(Index: Integer): TPanel;
@@ -356,7 +354,7 @@ begin
begin
// Do not draw crosshair if mouse is over the jump button
if not FJumpButtonRect.Contains(FMousePos.Point) then
FXAxisSeries.Paint(Self.Canvas, rect, FViewStartIndex, FViewCount, FViewStartIndex + FMousePos.Idx);
FXAxisSeries.Paint(Self.Canvas, rect, FMousePos);
end;
// --- Draw the "jump to latest" button (code unchanged) ---
@@ -839,12 +837,7 @@ end;
{ TMycChart.TXAxisLayer }
procedure TMycChart.TXAxisLayer.Paint(
const Canvas: TCanvas;
const Viewport: TRectF;
ViewStartIndex, ViewCount: Int64;
IdxAtMousePos: Integer
);
procedure TMycChart.TXAxisLayer.Paint(const Canvas: TCanvas; const Viewport: TRectF; const MousePos: TDragPoint);
var
caption: string;
captionRect: TRectF;
@@ -853,11 +846,11 @@ var
textSize: TRectF;
begin
// Do not draw if no data or view is invalid
if (not Assigned(Series)) or (Series.Count = 0) or (ViewCount <= 1) then
if (not Assigned(Series)) or (Series.Count = 0) then
exit;
// Snap X to the candle's center
candleX := Viewport.Right - ((IdxAtMousePos - ViewStartIndex) * (ViewCount - 1)) / (ViewCount - 1) * (Viewport.Width / (ViewCount - 1));
// 1. Snap X to the candle's center
candleX := MousePos.BarX;
// 2. Draw the vertical line at the snapped position
Canvas.Stroke.Kind := TBrushKind.Solid;
@@ -866,7 +859,7 @@ begin
Canvas.DrawLine(PointF(candleX, Viewport.Top), PointF(candleX, Viewport.Bottom), 1.0);
// 3. Get the caption for the index
caption := GetCaption(IdxAtMousePos);
caption := GetCaption(FOwner.ViewStartIndex + MousePos.Idx);
if caption.IsEmpty then
exit;