From 1081d6297fa241cce5480e71941c7352975c831e Mon Sep 17 00:00:00 2001 From: Mikhail Shabanov Date: Mon, 22 Aug 2022 15:16:05 +0200 Subject: [PATCH] feat: vertical tanks tree connections added --- ...litzStatisticsProClient.StrawberryShake.cs | 18 ++---- ...litzStatisticsProClient.StrawberryShake.cs | 16 ++--- ...litzStatisticsProClient.StrawberryShake.cs | 14 ++--- ...litzStatisticsProClient.StrawberryShake.cs | 10 +-- ...litzStatisticsProClient.StrawberryShake.cs | 2 +- .../Pages/PlayerInfoTanksTreeBase.cs | 2 +- WotBlitzStatisticsPro.Blazor/Program.cs | 4 +- .../Services/ISvgHelper.cs | 2 + .../Services/SvgHelper.cs | 63 ++++++++++++++++--- 9 files changed, 85 insertions(+), 46 deletions(-) diff --git a/WotBlitzStatisticsPro.Blazor/Generated/Serialization/MarkOfMasterySerializer.WotBlitzStatisticsProClient.StrawberryShake.cs b/WotBlitzStatisticsPro.Blazor/Generated/Serialization/MarkOfMasterySerializer.WotBlitzStatisticsProClient.StrawberryShake.cs index 64aed85..dc1b833 100644 --- a/WotBlitzStatisticsPro.Blazor/Generated/Serialization/MarkOfMasterySerializer.WotBlitzStatisticsProClient.StrawberryShake.cs +++ b/WotBlitzStatisticsPro.Blazor/Generated/Serialization/MarkOfMasterySerializer.WotBlitzStatisticsProClient.StrawberryShake.cs @@ -11,24 +11,18 @@ namespace WotBlitzStatisticsPro.Blazor.GraphQl { return serializedValue switch { - "NONE" => MarkOfMastery.None, - "RANK3" => MarkOfMastery.Rank3, - "RANK2" => MarkOfMastery.Rank2, - "RANK1" => MarkOfMastery.Rank1, - "MASTER" => MarkOfMastery.Master, - _ => throw new global::StrawberryShake.GraphQLClientException()}; + "NONE" => MarkOfMastery.None, "RANK3" => MarkOfMastery.Rank3, "RANK2" => MarkOfMastery.Rank2, "RANK1" => MarkOfMastery.Rank1, "MASTER" => MarkOfMastery.Master, _ => throw new global::StrawberryShake.GraphQLClientException()} + + ; } public global::System.Object Format(global::System.Object? runtimeValue) { return runtimeValue switch { - MarkOfMastery.None => "NONE", - MarkOfMastery.Rank3 => "RANK3", - MarkOfMastery.Rank2 => "RANK2", - MarkOfMastery.Rank1 => "RANK1", - MarkOfMastery.Master => "MASTER", - _ => throw new global::StrawberryShake.GraphQLClientException()}; + MarkOfMastery.None => "NONE", MarkOfMastery.Rank3 => "RANK3", MarkOfMastery.Rank2 => "RANK2", MarkOfMastery.Rank1 => "RANK1", MarkOfMastery.Master => "MASTER", _ => throw new global::StrawberryShake.GraphQLClientException()} + + ; } } } diff --git a/WotBlitzStatisticsPro.Blazor/Generated/Serialization/RealmTypeSerializer.WotBlitzStatisticsProClient.StrawberryShake.cs b/WotBlitzStatisticsPro.Blazor/Generated/Serialization/RealmTypeSerializer.WotBlitzStatisticsProClient.StrawberryShake.cs index cde294a..e052ebb 100644 --- a/WotBlitzStatisticsPro.Blazor/Generated/Serialization/RealmTypeSerializer.WotBlitzStatisticsProClient.StrawberryShake.cs +++ b/WotBlitzStatisticsPro.Blazor/Generated/Serialization/RealmTypeSerializer.WotBlitzStatisticsProClient.StrawberryShake.cs @@ -11,22 +11,18 @@ namespace WotBlitzStatisticsPro.Blazor.GraphQl { return serializedValue switch { - "RU" => RealmType.Ru, - "EU" => RealmType.Eu, - "NA" => RealmType.Na, - "ASIA" => RealmType.Asia, - _ => throw new global::StrawberryShake.GraphQLClientException()}; + "RU" => RealmType.Ru, "EU" => RealmType.Eu, "NA" => RealmType.Na, "ASIA" => RealmType.Asia, _ => throw new global::StrawberryShake.GraphQLClientException()} + + ; } public global::System.Object Format(global::System.Object? runtimeValue) { return runtimeValue switch { - RealmType.Ru => "RU", - RealmType.Eu => "EU", - RealmType.Na => "NA", - RealmType.Asia => "ASIA", - _ => throw new global::StrawberryShake.GraphQLClientException()}; + RealmType.Ru => "RU", RealmType.Eu => "EU", RealmType.Na => "NA", RealmType.Asia => "ASIA", _ => throw new global::StrawberryShake.GraphQLClientException()} + + ; } } } diff --git a/WotBlitzStatisticsPro.Blazor/Generated/Serialization/RequestLanguageSerializer.WotBlitzStatisticsProClient.StrawberryShake.cs b/WotBlitzStatisticsPro.Blazor/Generated/Serialization/RequestLanguageSerializer.WotBlitzStatisticsProClient.StrawberryShake.cs index 6d9fa5e..6fd96d8 100644 --- a/WotBlitzStatisticsPro.Blazor/Generated/Serialization/RequestLanguageSerializer.WotBlitzStatisticsProClient.StrawberryShake.cs +++ b/WotBlitzStatisticsPro.Blazor/Generated/Serialization/RequestLanguageSerializer.WotBlitzStatisticsProClient.StrawberryShake.cs @@ -11,20 +11,18 @@ namespace WotBlitzStatisticsPro.Blazor.GraphQl { return serializedValue switch { - "RU" => RequestLanguage.Ru, - "EN" => RequestLanguage.En, - "DE" => RequestLanguage.De, - _ => throw new global::StrawberryShake.GraphQLClientException()}; + "RU" => RequestLanguage.Ru, "EN" => RequestLanguage.En, "DE" => RequestLanguage.De, _ => throw new global::StrawberryShake.GraphQLClientException()} + + ; } public global::System.Object Format(global::System.Object? runtimeValue) { return runtimeValue switch { - RequestLanguage.Ru => "RU", - RequestLanguage.En => "EN", - RequestLanguage.De => "DE", - _ => throw new global::StrawberryShake.GraphQLClientException()}; + RequestLanguage.Ru => "RU", RequestLanguage.En => "EN", RequestLanguage.De => "DE", _ => throw new global::StrawberryShake.GraphQLClientException()} + + ; } } } diff --git a/WotBlitzStatisticsPro.Blazor/Generated/State/WotBlitzStatisticsProClientEntityIdFactory.WotBlitzStatisticsProClient.StrawberryShake.cs b/WotBlitzStatisticsPro.Blazor/Generated/State/WotBlitzStatisticsProClientEntityIdFactory.WotBlitzStatisticsProClient.StrawberryShake.cs index 2b0c883..b8e7786 100644 --- a/WotBlitzStatisticsPro.Blazor/Generated/State/WotBlitzStatisticsProClientEntityIdFactory.WotBlitzStatisticsProClient.StrawberryShake.cs +++ b/WotBlitzStatisticsPro.Blazor/Generated/State/WotBlitzStatisticsProClientEntityIdFactory.WotBlitzStatisticsProClient.StrawberryShake.cs @@ -13,16 +13,18 @@ namespace WotBlitzStatisticsPro.Blazor.GraphQl.State global::System.String __typename = obj.GetProperty("__typename").GetString()!; return __typename switch { - "Achievement" => ParseAchievementEntityId(obj, __typename), - _ => throw new global::System.NotSupportedException()}; + "Achievement" => ParseAchievementEntityId(obj, __typename), _ => throw new global::System.NotSupportedException()} + + ; } public global::System.String Format(global::StrawberryShake.EntityId entityId) { return entityId.Name switch { - "Achievement" => FormatAchievementEntityId(entityId), - _ => throw new global::System.NotSupportedException()}; + "Achievement" => FormatAchievementEntityId(entityId), _ => throw new global::System.NotSupportedException()} + + ; } private global::StrawberryShake.EntityId ParseAchievementEntityId(global::System.Text.Json.JsonElement obj, global::System.String type) diff --git a/WotBlitzStatisticsPro.Blazor/Generated/State/WotBlitzStatisticsProClientStoreAccessor.WotBlitzStatisticsProClient.StrawberryShake.cs b/WotBlitzStatisticsPro.Blazor/Generated/State/WotBlitzStatisticsProClientStoreAccessor.WotBlitzStatisticsProClient.StrawberryShake.cs index 88f3c81..54e7917 100644 --- a/WotBlitzStatisticsPro.Blazor/Generated/State/WotBlitzStatisticsProClientStoreAccessor.WotBlitzStatisticsProClient.StrawberryShake.cs +++ b/WotBlitzStatisticsPro.Blazor/Generated/State/WotBlitzStatisticsProClientStoreAccessor.WotBlitzStatisticsProClient.StrawberryShake.cs @@ -6,7 +6,7 @@ namespace WotBlitzStatisticsPro.Blazor.GraphQl.State [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.2.2.0")] public partial class WotBlitzStatisticsProClientStoreAccessor : global::StrawberryShake.StoreAccessor { - public WotBlitzStatisticsProClientStoreAccessor(global::StrawberryShake.IOperationStore operationStore, global::StrawberryShake.IEntityStore entityStore, global::StrawberryShake.IEntityIdSerializer entityIdSerializer, global::System.Collections.Generic.IEnumerable requestFactories, global::System.Collections.Generic.IEnumerable resultDataFactories) : base(operationStore, entityStore, entityIdSerializer, requestFactories, resultDataFactories) + public WotBlitzStatisticsProClientStoreAccessor(global::StrawberryShake.IOperationStore operationStore, global::StrawberryShake.IEntityStore entityStore, global::StrawberryShake.IEntityIdSerializer entityIdSerializer, global::System.Collections.Generic.IEnumerable requestFactories, global::System.Collections.Generic.IEnumerable resultDataFactories): base(operationStore, entityStore, entityIdSerializer, requestFactories, resultDataFactories) { } } diff --git a/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoTanksTreeBase.cs b/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoTanksTreeBase.cs index 1bf3968..56a4307 100644 --- a/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoTanksTreeBase.cs +++ b/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoTanksTreeBase.cs @@ -110,7 +110,7 @@ namespace WotBlitzStatisticsPro.Blazor.Pages foreach (var nextRow in treeItem.NextRows) { Connections.Add(SvgHelper.TankTreeConnectionPath(treeItem.Row, nextRow.Row, tier, CardWidth, CardHeigth)); - // TODO: Calc ConnectionsInVerticalView + ConnectionsInVerticalView.Add(SvgHelper.TankTreeConnectionVerticalPath(treeItem.Row, nextRow.Row, tier, CardWidth, CardHeigth, LeftMargin)); } } diff --git a/WotBlitzStatisticsPro.Blazor/Program.cs b/WotBlitzStatisticsPro.Blazor/Program.cs index 0ffdbd1..2f134b5 100644 --- a/WotBlitzStatisticsPro.Blazor/Program.cs +++ b/WotBlitzStatisticsPro.Blazor/Program.cs @@ -55,11 +55,11 @@ namespace WotBlitzStatisticsPro.Blazor //var useMock = Environment.GetEnvironmentVariable("USE_GRAPH_QL_MOCK"); //if (useMock != null && useMock == "true") //{ - builder.Services.AddTransient(); + //builder.Services.AddTransient(); //} //else //{ - //builder.Services.AddTransient(); + builder.Services.AddTransient(); //} var host = builder.Build(); diff --git a/WotBlitzStatisticsPro.Blazor/Services/ISvgHelper.cs b/WotBlitzStatisticsPro.Blazor/Services/ISvgHelper.cs index 8a31a3e..00e89b5 100644 --- a/WotBlitzStatisticsPro.Blazor/Services/ISvgHelper.cs +++ b/WotBlitzStatisticsPro.Blazor/Services/ISvgHelper.cs @@ -8,5 +8,7 @@ namespace WotBlitzStatisticsPro.Blazor.Services ElementDimensions CalculateTextBlockSize(string text, string fontFace, int fontSize); string TankTreeConnectionPath(int rowStart, int rowEnd, int tierStart, int cardWidth, int cardHeight); + + string TankTreeConnectionVerticalPath(int rowStart, int rowEnd, int tierStart, int cardWidth, int cardHeight, int leftMargin); } } diff --git a/WotBlitzStatisticsPro.Blazor/Services/SvgHelper.cs b/WotBlitzStatisticsPro.Blazor/Services/SvgHelper.cs index f13de80..9d6ae40 100644 --- a/WotBlitzStatisticsPro.Blazor/Services/SvgHelper.cs +++ b/WotBlitzStatisticsPro.Blazor/Services/SvgHelper.cs @@ -12,11 +12,16 @@ namespace WotBlitzStatisticsPro.Blazor.Services // Tank Tree dimensions const int CardMargin = 20; + private readonly int _halfMargin; + private readonly int _quarterMargin; + // Tank Tree path corners private readonly string _leftDown; private readonly string _rightDown; private readonly string _leftUp; private readonly string _rightUp; + private readonly string _upRight; + private readonly string _upLeft; private readonly IJSRuntime _jsRuntime; @@ -24,13 +29,15 @@ namespace WotBlitzStatisticsPro.Blazor.Services { _jsRuntime = jsRuntime; - int halfMargin = CardMargin / 2; - int quarterMargin = CardMargin / 4; + _halfMargin = CardMargin / 2; + _quarterMargin = CardMargin / 4; - _leftDown = $"h {halfMargin} c {quarterMargin} 0, {halfMargin} {quarterMargin}, {halfMargin} {halfMargin}"; - _rightDown = $"c 0 {quarterMargin}, {quarterMargin} {halfMargin}, {halfMargin} {halfMargin} h {halfMargin}"; - _leftUp = $"h {halfMargin} c {quarterMargin} 0, {halfMargin} -{quarterMargin}, {halfMargin} -{halfMargin}"; - _rightUp = $"c 0 -{quarterMargin}, {quarterMargin} -{halfMargin}, {halfMargin} -{halfMargin} h {halfMargin}"; + _leftDown = $"c {_quarterMargin} 0, {_halfMargin} {_quarterMargin}, {_halfMargin} {_halfMargin}"; + _rightDown = $"c 0 {_quarterMargin}, {_quarterMargin} {_halfMargin}, {_halfMargin} {_halfMargin}"; + _leftUp = $"c {_quarterMargin} 0, {_halfMargin} -{_quarterMargin}, {_halfMargin} -{_halfMargin}"; + _rightUp = $"c 0 -{_quarterMargin}, {_quarterMargin} -{_halfMargin}, {_halfMargin} -{_halfMargin}"; + _upRight = $"c 0 -{_quarterMargin}, -{_quarterMargin} -{_halfMargin}, -{_halfMargin} -{_halfMargin}"; + _upLeft = $"c -{_quarterMargin} 0, -{_halfMargin} -{_quarterMargin}, -{_halfMargin} -{_halfMargin}"; } public ElementDimensions CalculateTextBlockSize(string text, string fontFace, int fontSize) @@ -51,8 +58,6 @@ namespace WotBlitzStatisticsPro.Blazor.Services int startXPoint = (tierStart - 1) * (cardWidth + horizontalMargin) + cardWidth + CardMargin; int startYpoint = rowStart * (cardHeight + CardMargin) + (cardHeight / 2) + CardMargin; - int stopYPoint = rowEnd * (cardHeight + CardMargin) + (cardHeight / 2) + CardMargin; - var path = new StringBuilder($"M {startXPoint} {startYpoint}"); if(rowStart == rowEnd) { @@ -60,19 +65,61 @@ namespace WotBlitzStatisticsPro.Blazor.Services return path.ToString(); } + int stopYPoint = rowEnd * (cardHeight + CardMargin) + (cardHeight / 2) + CardMargin; int verticalLineHeight = Math.Abs(stopYPoint - startYpoint) - CardMargin; if(rowStart < rowEnd) { + path.AppendLine($"h {_halfMargin}"); path.AppendLine(_leftDown); path.AppendLine($"v {verticalLineHeight}"); path.AppendLine(_rightDown); + path.AppendLine($"h {_halfMargin}"); } else { + path.AppendLine($"h {_halfMargin}"); path.AppendLine(_leftUp); path.AppendLine($"v -{verticalLineHeight}"); path.AppendLine(_rightUp); + path.AppendLine($"h {_halfMargin}"); + } + + return path.ToString(); + } + + public string TankTreeConnectionVerticalPath(int rowStart, int rowEnd, int tierStart, int cardWidth, int cardHeight, int leftMargin) + { + int verticalMargin = 2 * CardMargin; + + int startYPoint = (10 - tierStart) * (cardWidth + verticalMargin) + CardMargin; + int startXPoint = rowStart * (cardHeight + CardMargin) + (cardHeight / 2) + CardMargin + leftMargin; + + var path = new StringBuilder($"M {startXPoint} {startYPoint}"); + if (rowStart == rowEnd) + { + path.AppendLine($"v -{verticalMargin}"); + return path.ToString(); + } + + int stopXPoint = rowEnd * (cardHeight + CardMargin) + (cardHeight / 2) + CardMargin + leftMargin; + int horizontalWidth = Math.Abs(stopXPoint - startXPoint) - CardMargin; + + if (rowStart < rowEnd) + { + path.AppendLine($"v -{_halfMargin}"); + path.AppendLine(_rightUp); + path.AppendLine($"h {horizontalWidth}"); + path.AppendLine(_leftUp); + path.AppendLine($"v -{_halfMargin}"); + } + else + { + path.AppendLine($"v -{_halfMargin}"); + path.AppendLine(_upRight); + path.AppendLine($"h -{horizontalWidth}"); + path.AppendLine(_upLeft); + path.AppendLine($"v -{_halfMargin}"); } return path.ToString();