Commit Latest

This commit is contained in:
2025-06-29 21:30:47 -04:00
parent 6bf92a14f2
commit f8aa26e9dc
2 changed files with 14 additions and 2 deletions

View File

@@ -239,7 +239,8 @@ namespace PortfolioManager.Renderers
sb.Append(Utility.FormatCurrency(zeroPrice.Close));
double parityOffsetPercent = (latestPrice.Close - zeroPrice.Close) / zeroPrice.Close;
sb.Append("(").Append(parityOffsetPercent < 0 ? "" : "+").Append(Utility.FormatPercent(parityOffsetPercent)).Append(")");
image = TextMarkerImageGenerator.GenerateImage(sb.ToString(), 130, 24, FontFactor.FontSize);
// image = TextMarkerImageGenerator.GenerateImage(sb.ToString(), 130, 24, FontFactor.FontSize);
image = TextMarkerImageGenerator.GenerateImage(sb.ToString(), FontFactor.FontSize);
coordinates = new Coordinates(dates[0].ToOADate() - offsets.Offset(OffsetDictionary.OffsetType.HorizontalOffset3PC), values[0] - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, image);
}

View File

@@ -11,7 +11,7 @@ public static class TextMarkerImageGenerator
public static Image GenerateImage(String text,int width=130, int height=24, int fontSize=12)
{
ImageHelper imageHelper = new ImageHelper();
imageHelper.CreateImage(width, height); //, new PointMapping(width,height,width,0,height,0));
imageHelper.CreateImage(width, height);
imageHelper.Fill(SKColors.White);
SKTextAlign align = SKTextAlign.Center;
SKFont font = new SKFont(SKTypeface.FromFamilyName("Arial",500,5,SKFontStyleSlant.Upright), fontSize);
@@ -20,7 +20,18 @@ public static class TextMarkerImageGenerator
imageHelper.DrawLine(SKColors.Black,1, new SKPoint(0,height-1), new SKPoint(width-1,height-1)); // top left to right
imageHelper.DrawLine(SKColors.Black,1, new SKPoint(0,height-1), new SKPoint(0,0)); // left hand side top to bottom
imageHelper.DrawText(text, new SKPoint(width / 2, height-8), SKColors.Black, align, font);
using MemoryStream memoryStream = new MemoryStream();
imageHelper.ToStream().CopyTo(memoryStream);
return new ScottPlot.Image(memoryStream.ToArray());
}
public static Image GenerateImage(String text,int fontSize=12)
{
ImageHelper imageHelper = new ImageHelper();
// SKFont font = new SKFont(SKTypeface.FromFamilyName(familyName: "Helvetica", weight: SKFontStyleWeight.Normal, width: SKFontStyleWidth.UltraCondensed, slant: SKFontStyleSlant.Italic), fontSize, .75f);
SKFont font = new SKFont(SKTypeface.FromFamilyName("Helvetica",500,5,SKFontStyleSlant.Upright), fontSize);
SKTextAlign align = SKTextAlign.Left;
imageHelper.CreateBoundedText(text, SKColors.Black, SKColors.White, align, font);
using MemoryStream memoryStream = new MemoryStream();
imageHelper.ToStream().CopyTo(memoryStream);
return new ScottPlot.Image(memoryStream.ToArray());