P1b: System.Drawing aus der Fachlogik entfernt
- TradeRowColoring liefert jetzt eine TradeRowTint-Kategorie (Loss/SmallWin/BigWin) statt einer System.Drawing.Color. Die Schwellenlogik bleibt getestet, die konkrete Farbe legt die UI fest (neu: Ui/TradeRowPalette.cs im CopyTrading-Modul). Bessere Schichtung und Voraussetzung dafuer, dass das Modul spaeter net8.0 wird. - TradeRowColoringTests prueft die Kategorie statt der Farbe (gleiche Abdeckung). - Models/DashboardRow.cs: verwaistes using System.Drawing entfernt. System.Drawing liegt damit ausschliesslich noch in UI-Ordnern - die Fachlogik in Core und Modulen ist frei davon. 442 Tests gruen, --smoke-ui gruen. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,18 +1,34 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace PolyTrader.Modules.CopyTrading.Logic
|
||||
{
|
||||
/// <summary>Farbkategorie einer Trade-Zeile. Die konkrete Farbe legt die jeweilige UI fest.</summary>
|
||||
public enum TradeRowTint
|
||||
{
|
||||
/// <summary>< 0 % – Verlust.</summary>
|
||||
Loss,
|
||||
|
||||
/// <summary>0–10 % – kleiner Gewinn.</summary>
|
||||
SmallWin,
|
||||
|
||||
/// <summary>> 10 % – deutlicher Gewinn.</summary>
|
||||
BigWin
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reine Zeilenfärbung nach realisiertem/unrealisiertem PnL-Prozent (getestet, damit die
|
||||
/// Schwellen belastbar sind): Verlust rot, 0–10 % hellgrün, > 10 % kräftiges Grün.
|
||||
/// Reine Einstufung von Trade-Zeilen nach realisiertem/unrealisiertem PnL-Prozent (getestet,
|
||||
/// damit die Schwellen belastbar sind): Verlust, 0–10 %, > 10 %.
|
||||
///
|
||||
/// <para>Liefert bewusst eine <see cref="TradeRowTint"/>-Kategorie statt einer Farbe: Die
|
||||
/// Modul-Logik ist damit frei von <c>System.Drawing</c> (seit .NET 7 Windows-only) und die
|
||||
/// Zuordnung Kategorie → Farbe liegt dort, wo sie hingehört – in der jeweiligen Oberfläche.</para>
|
||||
/// </summary>
|
||||
public static class TradeRowColoring
|
||||
{
|
||||
public static readonly Color Loss = Color.FromArgb(245, 200, 200); // < 0 % – rot
|
||||
public static readonly Color SmallWin = Color.FromArgb(212, 240, 212); // 0–10 % – hellgrün
|
||||
public static readonly Color BigWin = Color.FromArgb(140, 214, 140); // > 10 % – grün
|
||||
/// <summary>Schwelle, ab der ein Gewinn als deutlich gilt (in Prozent, exklusiv).</summary>
|
||||
public const decimal BigWinThresholdPercent = 10m;
|
||||
|
||||
public static Color ForPnlPercent(decimal pnlPercent) =>
|
||||
pnlPercent < 0m ? Loss : (pnlPercent > 10m ? BigWin : SmallWin);
|
||||
public static TradeRowTint ForPnlPercent(decimal pnlPercent) =>
|
||||
pnlPercent < 0m
|
||||
? TradeRowTint.Loss
|
||||
: (pnlPercent > BigWinThresholdPercent ? TradeRowTint.BigWin : TradeRowTint.SmallWin);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
@@ -156,7 +156,7 @@ namespace PolyTrader.Modules.CopyTrading.Ui
|
||||
{
|
||||
foreach (DataGridViewRow row in dgvTrades.Rows)
|
||||
if (row.DataBoundItem is ClosedTradeRow r)
|
||||
row.DefaultCellStyle.BackColor = TradeRowColoring.ForPnlPercent(r.PnlPercent);
|
||||
row.DefaultCellStyle.BackColor = TradeRowPalette.ForPnlPercent(r.PnlPercent);
|
||||
}
|
||||
|
||||
private string ResolveAccount(int accountId, bool isDemo)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
@@ -84,7 +84,7 @@ namespace PolyTrader.Modules.CopyTrading.Ui
|
||||
{
|
||||
foreach (DataGridViewRow row in dgvOpen.Rows)
|
||||
if (row.DataBoundItem is OpenTradeRow r)
|
||||
row.DefaultCellStyle.BackColor = TradeRowColoring.ForPnlPercent(r.UnrealizedPct);
|
||||
row.DefaultCellStyle.BackColor = TradeRowPalette.ForPnlPercent(r.UnrealizedPct);
|
||||
}
|
||||
|
||||
private string ResolveAccount(int accountId, bool isDemo)
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.Drawing;
|
||||
using PolyTrader.Modules.CopyTrading.Logic;
|
||||
|
||||
namespace PolyTrader.Modules.CopyTrading.Ui
|
||||
{
|
||||
/// <summary>
|
||||
/// WinForms-Farbpalette zu den <see cref="TradeRowTint"/>-Kategorien. Die Schwellenlogik liegt
|
||||
/// (getestet) in <see cref="TradeRowColoring"/>; hier steht nur noch, wie die Kategorien aussehen.
|
||||
/// Die Avalonia-UI bekommt später ihre eigene Palette zu denselben Kategorien.
|
||||
/// </summary>
|
||||
internal static class TradeRowPalette
|
||||
{
|
||||
public static readonly Color Loss = Color.FromArgb(245, 200, 200); // rot
|
||||
public static readonly Color SmallWin = Color.FromArgb(212, 240, 212); // hellgrün
|
||||
public static readonly Color BigWin = Color.FromArgb(140, 214, 140); // grün
|
||||
|
||||
public static Color For(TradeRowTint tint) => tint switch
|
||||
{
|
||||
TradeRowTint.Loss => Loss,
|
||||
TradeRowTint.BigWin => BigWin,
|
||||
_ => SmallWin
|
||||
};
|
||||
|
||||
/// <summary>Bequemlichkeit für die Grids: PnL-Prozent direkt in die Zeilenfarbe.</summary>
|
||||
public static Color ForPnlPercent(decimal pnlPercent) => For(TradeRowColoring.ForPnlPercent(pnlPercent));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user