Commit Latest

This commit is contained in:
2025-07-13 22:02:01 -04:00
parent 9535715556
commit b197aeff10
2 changed files with 47 additions and 58 deletions

View File

@@ -29,13 +29,13 @@ namespace PortfolioManager.Renderers
public TextPlot() public TextPlot()
{ {
} }
public TextPlot(String markerText,SKRect boundingRect,Coordinates coordinates) public TextPlot(String markerText,SKRect boundingRect,Pixel screenCoordinates)
{ {
BoundingRect = boundingRect; BoundingRect = boundingRect;
Coordinates = coordinates; ScreenCoordinates = screenCoordinates;
MarkerText = markerText; MarkerText = markerText;
} }
public Coordinates Coordinates { get; set; } public Pixel ScreenCoordinates { get; set; }
public SKRect BoundingRect { get; set; } public SKRect BoundingRect { get; set; }
public String MarkerText { get; set; } public String MarkerText { get; set; }
} }
@@ -51,17 +51,17 @@ namespace PortfolioManager.Renderers
/// </summary> /// </summary>
/// <param name="coordinates"></param> /// <param name="coordinates"></param>
/// <returns></returns> /// <returns></returns>
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) 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) && 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(coordinates.Y,2) >= Math.Round(textPlot.BoundingRect.Top,2) && Math.Round(coordinates.Y,2) <= Math.Round(textPlot.BoundingRect.Bottom,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); SKRect lowestRect = FindLowestAdjacentRect(textPlot.BoundingRect);
adjustedCoordinates.Y = textPlot.Coordinates.Y - factor; adjustedScreenCoordinates.Y = textPlot.ScreenCoordinates.Y - factor;
adjustedCoordinates.X = coordinates.X; adjustedScreenCoordinates.X = screenCoordinates.X;
return true; return true;
} }
} }
@@ -188,7 +188,8 @@ namespace PortfolioManager.Renderers
} }
} }
bollingerBands = BollingerBandGenerator.GenerateBollingerBands(prices); bollingerBands = BollingerBandGenerator.GenerateBollingerBands(prices);
textPlots.Clear(); // textPlots.Clear();
// textPlots = new TextPlots();
CalculateOffsets(); CalculateOffsets();
GenerateBollingerBands(); GenerateBollingerBands();
GenerateLeastSquares(); GenerateLeastSquares();
@@ -274,13 +275,15 @@ namespace PortfolioManager.Renderers
coordinates = new Coordinates(dates[0].ToOADate() - offsets.Offset(OffsetDictionary.OffsetType.HorizontalOffset3PC), coordinates = new Coordinates(dates[0].ToOADate() - offsets.Offset(OffsetDictionary.OffsetType.HorizontalOffset3PC),
values[0] - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC)); values[0] - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC));
Coordinates adjCoordinates = new Coordinates(){X=coordinates.X,Y=coordinates.Y}; // Pixel screenCoordinates = Plotter.Plot.GetPixel(coordinates);
if(textPlots.PointInRects(sb.ToString(),coordinates,ref adjCoordinates,offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC))) // Pixel adjScreenCoordinates = Plotter.Plot.GetPixel(coordinates);
{ // if(textPlots.PointInRects(sb.ToString(),screenCoordinates,ref adjScreenCoordinates,(float)offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC)))
coordinates.Y = adjCoordinates.Y; // {
} // coordinates.Y-=offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC);
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)); // 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); imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, image);
} }
@@ -333,13 +336,15 @@ namespace PortfolioManager.Renderers
Coordinates coordinates = new Coordinates(limit.EffectiveDate.ToOADate(), Coordinates coordinates = new Coordinates(limit.EffectiveDate.ToOADate(),
limit.StopPrice - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC)); limit.StopPrice - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC));
Coordinates adjCoordinates = new Coordinates(){X=coordinates.X,Y=coordinates.Y}; // Pixel screenCoordinates = Plotter.Plot.GetPixel(coordinates);
if(textPlots.PointInRects(sb.ToString(),coordinates,ref adjCoordinates,offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC))) // Pixel adjScreenCoordinates = Plotter.Plot.GetPixel(coordinates);
{ // if(textPlots.PointInRects(sb.ToString(),screenCoordinates,ref adjScreenCoordinates,(float)offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC)))
coordinates.Y = adjCoordinates.Y; // {
} // coordinates.Y-=offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC);
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)); // 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); ImageMarker imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, image);
} }
@@ -360,13 +365,15 @@ namespace PortfolioManager.Renderers
stopLimit.StopPrice - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC)); stopLimit.StopPrice - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC));
Coordinates adjCoordinates = new Coordinates(){X=coordinates.X,Y=coordinates.Y}; // Pixel screenCoordinates = Plotter.Plot.GetPixel(coordinates);
if(textPlots.PointInRects(sb.ToString(),coordinates,ref adjCoordinates,offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC))) // Pixel adjScreenCoordinates = Plotter.Plot.GetPixel(coordinates);
{ // if(textPlots.PointInRects(sb.ToString(),screenCoordinates,ref adjScreenCoordinates,(float)offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC)))
coordinates.Y = adjCoordinates.Y; // {
} // coordinates.Y-=offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC);
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)); // 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); ImageMarker imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, image);
} }
@@ -403,13 +410,15 @@ namespace PortfolioManager.Renderers
Coordinates coordinates = new Coordinates(portfolioTrade.TradeDate.ToOADate(), Coordinates coordinates = new Coordinates(portfolioTrade.TradeDate.ToOADate(),
portfolioTrade.Price - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC)); portfolioTrade.Price - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC));
Coordinates adjCoordinates = new Coordinates(){X=coordinates.X,Y=coordinates.Y}; // Pixel screenCoordinates = Plotter.Plot.GetPixel(coordinates);
if(textPlots.PointInRects(sb.ToString(),coordinates,ref adjCoordinates,offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC))) // Pixel adjScreenCoordinates = Plotter.Plot.GetPixel(coordinates);
{ // if(textPlots.PointInRects(sb.ToString(),screenCoordinates,ref adjScreenCoordinates,(float)offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC)))
coordinates.Y = adjCoordinates.Y; // {
} // coordinates.Y-=offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC);
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)); // 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); ImageMarker imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, image);
} }

View File

@@ -30,28 +30,8 @@ public partial class BollingerBandView : UserControl
if (null!=viewModel && default == viewModel.Plotter) if (null!=viewModel && default == viewModel.Plotter)
{ {
viewModel.Plotter = new AvaPlot(); viewModel.Plotter = new AvaPlot();
viewModel.Plotter.PointerMoved+=OnPointerMoved;
viewModel.OnPlotterLoaded(viewModel.Plotter); 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<Crosshair>();
// 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<Crosshair>();
// avaPlot.Plot.Add.Crosshair(position.X,position.Y);
}
} }