From 2b9488faff6a202b59ad00bdba3201b3c2c5fd34 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Sun, 23 Mar 2025 13:04:16 -0400 Subject: [PATCH] ui: Make pnl default settings pretty * Make profit (green) and loss (red) easier to read against dark bg * Hide 'SOD' and 'Day' columns (just show totals) --- .../Trading/PNL/Settings/PNLSettings.cs | 21 ++++++- .../spark/ShellWindowSettings/Pnl/Default.pnl | Bin 0 -> 10875 bytes .../ShellWindowSettingsDirectoryStore.cs | 59 ++++++++++++++++++ src/client/spark/Spark.csproj | 4 ++ .../spark/core/FontsAndColors/BTSColors.cs | 8 +-- .../core/FontsAndColors/BTSCoreColors.cs | 2 + 6 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 src/client/spark/ShellWindowSettings/Pnl/Default.pnl create mode 100644 src/client/spark/ShellWindowSettingsDirectoryStore.cs diff --git a/src/client/spark/Modules/Trading/PNL/Settings/PNLSettings.cs b/src/client/spark/Modules/Trading/PNL/Settings/PNLSettings.cs index f0cf93eca..2951a8289 100644 --- a/src/client/spark/Modules/Trading/PNL/Settings/PNLSettings.cs +++ b/src/client/spark/Modules/Trading/PNL/Settings/PNLSettings.cs @@ -9,9 +9,13 @@ using mbts.user.settings; using ProtoBuf; +using Spark.Core; + using System; using System.Collections.Generic; +using System.IO; using System.Linq; +using System.Reflection; using System.Windows; using System.Windows.Media; @@ -110,7 +114,22 @@ namespace bts.shell.pnl { GridSettings _grid_backing; PNLCellAppearanceProto _grid_cell_appearance_backing; - public static PNLSettings Default => + static LazyOnce defaultProfile; + + static PNLSettings() { + defaultProfile = new(() => { + var binDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + var store = ShellWindowSettingsDirectoryStore.Create( + Path.Combine(binDir, "ShellWindowSettings", "Pnl"), "*." + mbts.spark.UserSettings.FileExtensions.PNL); + return store.Profiles.GetValueOrDefault("Default") + ?? store.Profiles.Values.FirstOrDefault() + ?? historicDefault; + }); + } + + public static PNLSettings Default => defaultProfile.Value; + + static PNLSettings historicDefault => new PNLSettings { _sorting_criteria = new[] { new SortingCriteria(nameof(Columns.Account), true), diff --git a/src/client/spark/ShellWindowSettings/Pnl/Default.pnl b/src/client/spark/ShellWindowSettings/Pnl/Default.pnl new file mode 100644 index 0000000000000000000000000000000000000000..59cc8286dae8ad7a7ef867c51de3a3f34beecd76 GIT binary patch literal 10875 zcmbtaO>7&-6{aLhT8<=B+O)OWv<_oiwj}F6ar^_fl^q#r9LHj4IR+L50CCj8B z(oN(OtM=5RkM5-iP$2LzmjY=Hg-?aiLt`L^`j|rw0n!3KxPhC*ee>R%+F(CTSt*(}C6)VGCVo-QjqSaeF8ikok(tV=_<4>~)h* zGIz+_CG#Pfdt^Q)^9h;zWFC-tNahilFUWjF<}sP4WcGTfKQed7+$HlNnUBeQLgqf1 z2V@?Sc|_(hnWtn%`wu<&VfO34{`dRL!prd+@YSo3c|VyaPdX`n!YUJ`v*c5jBIEuU=-u=oyn8B}j~Wp_LB_sMGwl*&m^R)`B9Y;WuoDjTJu z-vjsc2na^G@#DK1=x^7gn<+7%KyO96e%x^uevPJT=<2%?JqDpKFXb*@^1bElsF;O2 z1GK!j*bT5*u^(XhsIawhJ6e-)f$)4iA$5%i^I{kXSBpChl&dbv5z)6)*p}`6uX)%llJql0#sKHZjsa*I7 zH-iwhpEXLA^LO2u`F+9z)`*ad=3h>;j}?lo=TM3t?iG}@ zt5V>l9Pf=M;IT9TU!CQpHwrgzDk$FDpvOc%K;Mnl3qH*Sd20ib&z0*@+&$jgpyNWm zc8U~J?F^KV6euE{aUK;iHy9_5DOZ@}k-|ie&M2pZz$K32q{Tbyj8vg1Rz^FcofK*G zjqy@9Sy#l$GsVoFol(z5lq>W(+9z*~vCQA1Irs!bmC9ChGb%Dx)c&9|sw2cL^rvAfA;ks`^LM@jERF{NUF&7Qk1>= z=J2PzBPe!LM;Av?6AwRo_N@QB6E?13_ddVZd+{e?pj=veZ@aja{Y7@pAMn!PaP-NO z-+hzO+s@Y7{_^GTzsE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SCNe}x7HK3`bJ{%xyoj% pa}^taJn*^7_Mblb=ij^J^`lCpB|4a)1{tvJuaPR;C literal 0 HcmV?d00001 diff --git a/src/client/spark/ShellWindowSettingsDirectoryStore.cs b/src/client/spark/ShellWindowSettingsDirectoryStore.cs new file mode 100644 index 000000000..6439c9aec --- /dev/null +++ b/src/client/spark/ShellWindowSettingsDirectoryStore.cs @@ -0,0 +1,59 @@ +#nullable enable +using bts.collections; + +using Spark.Core; +using Spark.Core.Protobuf; + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace bts.shell; + +static class ShellWindowSettingsDirectoryStore { + public static ShellWindowSettingsDirectoryStore Create(string path, string searchPattern) => + new(path, searchPattern); +} + +class ShellWindowSettingsDirectoryStore { + readonly LazyOnce> profiles; + + public ShellWindowSettingsDirectoryStore(string path, string searchPattern) => + profiles = new(() => { + try { + return Directory.EnumerateFiles(path, searchPattern).Select(SingleFileStore.FromPath).ToDictionary(sfs => sfs.Name); + } catch (Exception ex) { + Log.Ui.error($"Failed to enumerate {typeof(T)} settings files in '{path}'. {ex}"); + } + return new(0); + }); + + public IReadOnlyDictionary Profiles => + MappedDictionary.create(profiles.Value, sfs => sfs.Value); + + class SingleFileStore { + LazyOnce value; + + public SingleFileStore(string path) { + Name = Path.GetFileNameWithoutExtension(path); + value = new(LoadValue); + + T? LoadValue() { + try { + using var f = File.OpenRead(path); + return ProtobufSerializationHelper.deserialize(f); + } catch (Exception ex) { + Log.Ui.error($"Failed to load {typeof(T)} file '{path}'. {ex}"); + } + return default; + } + } + + public static SingleFileStore FromPath(string path) => + new(path); + + public string Name { get; } + public T? Value => value.Value; + } +} diff --git a/src/client/spark/Spark.csproj b/src/client/spark/Spark.csproj index a1203d145..479ed7763 100644 --- a/src/client/spark/Spark.csproj +++ b/src/client/spark/Spark.csproj @@ -77,6 +77,10 @@ + + + + diff --git a/src/client/spark/core/FontsAndColors/BTSColors.cs b/src/client/spark/core/FontsAndColors/BTSColors.cs index 07fa8e843..aa87b6800 100644 --- a/src/client/spark/core/FontsAndColors/BTSColors.cs +++ b/src/client/spark/core/FontsAndColors/BTSColors.cs @@ -254,9 +254,9 @@ namespace mbts.ui { public static class PNL { public static BTSColor foreground => UI.default_foreground; public static BTSColor anchor => Colors.Gold; - public static BTSColor profit => Colors.Green; + public static BTSColor profit => BTSCoreColors.spring_green; public static BTSColor net_zero => BTSCoreColors.gray; - public static BTSColor loss => BTSCoreColors.venetian_red; + public static BTSColor loss => BTSCoreColors.fire_brick; public static BTSColor header_row_background => 0xffaaaaaa; // group background colors public static BTSColor group_row_background1 => 0x19141420; @@ -276,8 +276,8 @@ namespace mbts.ui { } public static Color anchor_color => Colors.Gold; - public static Color profit_color => Colors.Green; - public static Color loss_color => BTSCoreColors.venetian_red; + public static Color profit_color => profit; + public static Color loss_color => loss; public static Color header_row_background_color => 0xffaaaaaa.argb_color(); // group background colors public static Color group_row_background_color1 => group_row_background1; diff --git a/src/client/spark/core/FontsAndColors/BTSCoreColors.cs b/src/client/spark/core/FontsAndColors/BTSCoreColors.cs index 6ee1c203f..5d303a376 100644 --- a/src/client/spark/core/FontsAndColors/BTSCoreColors.cs +++ b/src/client/spark/core/FontsAndColors/BTSCoreColors.cs @@ -83,6 +83,7 @@ public static BTSColor green => 0xff00c000; public static BTSColor green_p_light => 0xff99ee90; public static BTSColor green_dark_light => 0xff255d25; + public static BTSColor spring_green => 0xff00fb76; public static BTSColor light_sea_green => 0xff17b794; public static BTSColor very_light_malachite_green => 0xff52e887; public static BTSColor may_green => 0xff43a23c; @@ -100,6 +101,7 @@ public static BTSColor red_light_dark => 0xffd69a9a; public static BTSColor red_light_dark_saturated => 0xffd67e7e; public static BTSColor permanent_geranium_lake => 0xffde3429; + public static BTSColor fire_brick => 0xffb1373a; public static BTSColor fire_opal => 0xfff05454; public static BTSColor paradise_pink => 0xffe94560; public static BTSColor tulip => 0xffff878d;