From b197aeff103388eca56e2e077759db9ea078668b Mon Sep 17 00:00:00 2001 From: "Sean Kessler (Europa)" Date: Sun, 13 Jul 2025 22:02:01 -0400 Subject: [PATCH] Commit Latest --- .../Renderers/BollingerBandRenderer.cs | 85 ++++++++++--------- .../Views/BollingerBandView.axaml.cs | 20 ----- 2 files changed, 47 insertions(+), 58 deletions(-) diff --git a/PortfolioManager/Renderers/BollingerBandRenderer.cs b/PortfolioManager/Renderers/BollingerBandRenderer.cs index de177ae..e0dc306 100644 --- a/PortfolioManager/Renderers/BollingerBandRenderer.cs +++ b/PortfolioManager/Renderers/BollingerBandRenderer.cs @@ -29,13 +29,13 @@ namespace PortfolioManager.Renderers public TextPlot() { } - public TextPlot(String markerText,SKRect boundingRect,Coordinates coordinates) + public TextPlot(String markerText,SKRect boundingRect,Pixel screenCoordinates) { BoundingRect = boundingRect; - Coordinates = coordinates; + ScreenCoordinates = screenCoordinates; MarkerText = markerText; } - public Coordinates Coordinates { get; set; } + public Pixel ScreenCoordinates { get; set; } public SKRect BoundingRect { get; set; } public String MarkerText { get; set; } } @@ -51,17 +51,17 @@ namespace PortfolioManager.Renderers /// /// /// - public bool PointInRects(String markerText,Coordinates coordinates,ref Coordinates adjustedCoordinates,double factor) + public bool PointInRects(String markerText,Pixel screenCoordinates,ref Pixel adjustedScreenCoordinates,float factor) { foreach(TextPlot textPlot in this) { - if(Math.Round(coordinates.X,2) >= Math.Round(textPlot.BoundingRect.Left,2) && Math.Round(coordinates.X,2) <= Math.Round(textPlot.BoundingRect.Right,2) && - Math.Round(coordinates.Y,2) >= Math.Round(textPlot.BoundingRect.Top,2) && Math.Round(coordinates.Y,2) <= Math.Round(textPlot.BoundingRect.Bottom,2)) + if(Math.Round(screenCoordinates.X,2) >= Math.Round(textPlot.BoundingRect.Left,2) && Math.Round(screenCoordinates.X,2) <= Math.Round(textPlot.BoundingRect.Right,2) && + Math.Round(screenCoordinates.Y,2) >= Math.Round(textPlot.BoundingRect.Top,2) && Math.Round(screenCoordinates.Y,2) <= Math.Round(textPlot.BoundingRect.Bottom,2)) { - MDTrace.WriteLine(LogLevel.DEBUG,$"The text {markerText} at Point:{coordinates.X}:{coordinates.Y} is within Rect:L({textPlot.BoundingRect.Left}),T({textPlot.BoundingRect.Top}),R({textPlot.BoundingRect.Right}),B({textPlot.BoundingRect.Bottom}) with text {textPlot.MarkerText} which is plotted at Coordinates:X:{textPlot.Coordinates.X} Y:{textPlot.Coordinates.Y}"); + MDTrace.WriteLine(LogLevel.DEBUG,$"The text {markerText} at Point:X:{screenCoordinates.X}:Y:{screenCoordinates.Y} is within Rect:L({textPlot.BoundingRect.Left}),T({textPlot.BoundingRect.Top}),R({textPlot.BoundingRect.Right}),B({textPlot.BoundingRect.Bottom}) with text {textPlot.MarkerText} which is plotted at Coordinates:X:{textPlot.ScreenCoordinates.X} Y:{textPlot.ScreenCoordinates.Y}"); SKRect lowestRect = FindLowestAdjacentRect(textPlot.BoundingRect); - adjustedCoordinates.Y = textPlot.Coordinates.Y - factor; - adjustedCoordinates.X = coordinates.X; + adjustedScreenCoordinates.Y = textPlot.ScreenCoordinates.Y - factor; + adjustedScreenCoordinates.X = screenCoordinates.X; return true; } } @@ -188,7 +188,8 @@ namespace PortfolioManager.Renderers } } bollingerBands = BollingerBandGenerator.GenerateBollingerBands(prices); - textPlots.Clear(); +// textPlots.Clear(); +// textPlots = new TextPlots(); CalculateOffsets(); GenerateBollingerBands(); GenerateLeastSquares(); @@ -274,13 +275,15 @@ namespace PortfolioManager.Renderers coordinates = new Coordinates(dates[0].ToOADate() - offsets.Offset(OffsetDictionary.OffsetType.HorizontalOffset3PC), values[0] - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC)); - Coordinates adjCoordinates = new Coordinates(){X=coordinates.X,Y=coordinates.Y}; - if(textPlots.PointInRects(sb.ToString(),coordinates,ref adjCoordinates,offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC))) - { - coordinates.Y = adjCoordinates.Y; - } - SKRect markerRect = new SKRect(){Left=(float)coordinates.X,Top=(float)coordinates.Y,Right=(float)coordinates.X+image.Width,Bottom=(float)coordinates.Y+image.Height}; - textPlots.Add(new TextPlot(sb.ToString(),markerRect,coordinates)); + // Pixel screenCoordinates = Plotter.Plot.GetPixel(coordinates); + // Pixel adjScreenCoordinates = Plotter.Plot.GetPixel(coordinates); + // if(textPlots.PointInRects(sb.ToString(),screenCoordinates,ref adjScreenCoordinates,(float)offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC))) + // { + // coordinates.Y-=offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC); + // } + // screenCoordinates = Plotter.Plot.GetPixel(coordinates); + // SKRect markerRect = new SKRect(){Left=(float)screenCoordinates.X,Top=(float)screenCoordinates.Y,Right=(float)screenCoordinates.X+image.Width,Bottom=(float)screenCoordinates.Y+image.Height}; + // textPlots.Add(new TextPlot(sb.ToString(),markerRect,screenCoordinates)); imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, image); } @@ -333,13 +336,15 @@ namespace PortfolioManager.Renderers Coordinates coordinates = new Coordinates(limit.EffectiveDate.ToOADate(), limit.StopPrice - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC)); - Coordinates adjCoordinates = new Coordinates(){X=coordinates.X,Y=coordinates.Y}; - if(textPlots.PointInRects(sb.ToString(),coordinates,ref adjCoordinates,offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC))) - { - coordinates.Y = adjCoordinates.Y; - } - SKRect markerRect = new SKRect(){Left=(float)coordinates.X,Top=(float)coordinates.Y,Right=(float)coordinates.X+image.Width,Bottom=(float)coordinates.Y+image.Height}; - textPlots.Add(new TextPlot(sb.ToString(),markerRect,coordinates)); + // Pixel screenCoordinates = Plotter.Plot.GetPixel(coordinates); + // Pixel adjScreenCoordinates = Plotter.Plot.GetPixel(coordinates); + // if(textPlots.PointInRects(sb.ToString(),screenCoordinates,ref adjScreenCoordinates,(float)offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC))) + // { + // coordinates.Y-=offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC); + // } + // screenCoordinates = Plotter.Plot.GetPixel(coordinates); + // SKRect markerRect = new SKRect(){Left=(float)screenCoordinates.X,Top=(float)screenCoordinates.Y,Right=(float)screenCoordinates.X+image.Width,Bottom=(float)screenCoordinates.Y+image.Height}; + // textPlots.Add(new TextPlot(sb.ToString(),markerRect,screenCoordinates)); ImageMarker imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, image); } @@ -360,13 +365,15 @@ namespace PortfolioManager.Renderers stopLimit.StopPrice - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC)); - Coordinates adjCoordinates = new Coordinates(){X=coordinates.X,Y=coordinates.Y}; - if(textPlots.PointInRects(sb.ToString(),coordinates,ref adjCoordinates,offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC))) - { - coordinates.Y = adjCoordinates.Y; - } - SKRect markerRect = new SKRect(){Left=(float)coordinates.X,Top=(float)coordinates.Y,Right=(float)coordinates.X+image.Width,Bottom=(float)coordinates.Y+image.Height}; - textPlots.Add(new TextPlot(sb.ToString(),markerRect,coordinates)); + // Pixel screenCoordinates = Plotter.Plot.GetPixel(coordinates); + // Pixel adjScreenCoordinates = Plotter.Plot.GetPixel(coordinates); + // if(textPlots.PointInRects(sb.ToString(),screenCoordinates,ref adjScreenCoordinates,(float)offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC))) + // { + // coordinates.Y-=offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC); + // } + // screenCoordinates = Plotter.Plot.GetPixel(coordinates); + // SKRect markerRect = new SKRect(){Left=(float)screenCoordinates.X,Top=(float)screenCoordinates.Y,Right=(float)screenCoordinates.X+image.Width,Bottom=(float)screenCoordinates.Y+image.Height}; + // textPlots.Add(new TextPlot(sb.ToString(),markerRect,screenCoordinates)); ImageMarker imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, image); } @@ -403,13 +410,15 @@ namespace PortfolioManager.Renderers Coordinates coordinates = new Coordinates(portfolioTrade.TradeDate.ToOADate(), portfolioTrade.Price - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC)); - Coordinates adjCoordinates = new Coordinates(){X=coordinates.X,Y=coordinates.Y}; - if(textPlots.PointInRects(sb.ToString(),coordinates,ref adjCoordinates,offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC))) - { - coordinates.Y = adjCoordinates.Y; - } - SKRect markerRect = new SKRect(){Left=(float)coordinates.X,Top=(float)coordinates.Y,Right=(float)coordinates.X+image.Width,Bottom=(float)coordinates.Y+image.Height}; - textPlots.Add(new TextPlot(sb.ToString(),markerRect,coordinates)); + // Pixel screenCoordinates = Plotter.Plot.GetPixel(coordinates); + // Pixel adjScreenCoordinates = Plotter.Plot.GetPixel(coordinates); + // if(textPlots.PointInRects(sb.ToString(),screenCoordinates,ref adjScreenCoordinates,(float)offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC))) + // { + // coordinates.Y-=offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC); + // } + // screenCoordinates = Plotter.Plot.GetPixel(coordinates); + // SKRect markerRect = new SKRect(){Left=(float)screenCoordinates.X,Top=(float)screenCoordinates.Y,Right=(float)screenCoordinates.X+image.Width,Bottom=(float)screenCoordinates.Y+image.Height}; + // textPlots.Add(new TextPlot(sb.ToString(),markerRect,screenCoordinates)); ImageMarker imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, image); } diff --git a/PortfolioManager/Views/BollingerBandView.axaml.cs b/PortfolioManager/Views/BollingerBandView.axaml.cs index bc05871..884c92b 100644 --- a/PortfolioManager/Views/BollingerBandView.axaml.cs +++ b/PortfolioManager/Views/BollingerBandView.axaml.cs @@ -30,28 +30,8 @@ public partial class BollingerBandView : UserControl if (null!=viewModel && default == viewModel.Plotter) { viewModel.Plotter = new AvaPlot(); - viewModel.Plotter.PointerMoved+=OnPointerMoved; viewModel.OnPlotterLoaded(viewModel.Plotter); } } } - - private void OnPointerMoved(object sender, PointerEventArgs pointerEventArgs) - { - // AvaPlot avaPlot = (sender as AvaPlot); - // if(default == avaPlot)return; - // Point position = pointerEventArgs.GetPosition(this); - // avaPlot.Plot.Remove(); - // avaPlot.Plot.Add.Crosshair(position.X,position.Y); - // avaPlot.Refresh(); - - // Point clientMousePosition = avaPlot.PointToClient(new PixelPoint((int)position.X,(int)position.Y)); - // avaPlot.Plot.Add.Crosshair(clientMousePosition.X,clientMousePosition.Y); - // PointerPoint point = pointerEventArgs.GetCurrentPoint(null); - // Point position = point.Position; -// Point clientPoint = avaPlot.PointToClient(new PixelPoint((int)position.X,(int)position.Y)); -// Coordinates coordinates = avaPlot.Plot.GetCoordinates(position.X, position.Y); -// avaPlot.Plot.Remove(); - // avaPlot.Plot.Add.Crosshair(position.X,position.Y); - } } \ No newline at end of file