diff --git a/src/Flypaper.Web/Components/Pages/Dashboard/DashboardPage.razor b/src/Flypaper.Web/Components/Pages/Dashboard/DashboardPage.razor index 893217f..0d2468c 100644 --- a/src/Flypaper.Web/Components/Pages/Dashboard/DashboardPage.razor +++ b/src/Flypaper.Web/Components/Pages/Dashboard/DashboardPage.razor @@ -29,7 +29,7 @@
- + @@ -114,5 +114,5 @@ } private static string Origin(TrapEventEntity trapEvent) => - string.Join(", ", new[] { trapEvent.City, trapEvent.Country }.Where(part => !string.IsNullOrEmpty(part))); + string.Join(", ", new[] { trapEvent.City, CountryNames.Display(trapEvent.CountryCode, trapEvent.Country) }.Where(part => !string.IsNullOrEmpty(part))); } diff --git a/src/Flypaper.Web/Components/Pages/Dashboard/TopTable.razor b/src/Flypaper.Web/Components/Pages/Dashboard/TopTable.razor index dd7fb74..b64777b 100644 --- a/src/Flypaper.Web/Components/Pages/Dashboard/TopTable.razor +++ b/src/Flypaper.Web/Components/Pages/Dashboard/TopTable.razor @@ -45,9 +45,12 @@ [Parameter] public Func? KeyFormatter { get; set; } + [Parameter] public Func? LabelFormatter { get; set; } + private string Display(TopEntry entry) { var key = KeyFormatter?.Invoke(entry.Key) ?? entry.Key; - return entry.Label is null ? key : $"{key} · {entry.Label}"; + var label = LabelFormatter is null ? entry.Label : LabelFormatter(entry.Key, entry.Label); + return label is null ? key : $"{key} · {label}"; } } diff --git a/src/Flypaper.Web/Components/Pages/Dashboard/WorldMap.razor b/src/Flypaper.Web/Components/Pages/Dashboard/WorldMap.razor index 896309c..dd99c6c 100644 --- a/src/Flypaper.Web/Components/Pages/Dashboard/WorldMap.razor +++ b/src/Flypaper.Web/Components/Pages/Dashboard/WorldMap.razor @@ -6,14 +6,20 @@ @foreach (var country in Map.Countries) { var count = Count(country.Code); - @Title(country.Name, count) + @Title(CountryNames.Display(country.Code, country.Name)!, count) } @foreach (var marker in Map.Markers) { var count = Count(marker.Code); if (count > 0) { - @Title(marker.Name, count) + var x = marker.X.ToString(CultureInfo.InvariantCulture); + var y = marker.Y.ToString(CultureInfo.InvariantCulture); + + @Title(CountryNames.Display(marker.Code, marker.Name)!, count) + + + } } diff --git a/src/Flypaper.Web/Components/Shared/CountryNames.cs b/src/Flypaper.Web/Components/Shared/CountryNames.cs new file mode 100644 index 0000000..5c3dc21 --- /dev/null +++ b/src/Flypaper.Web/Components/Shared/CountryNames.cs @@ -0,0 +1,40 @@ +namespace Flypaper.Web.Components.Shared; + +public static class CountryNames +{ + private static readonly Dictionary ShortNames = new(StringComparer.OrdinalIgnoreCase) + { + ["BN"] = "Brunei", + ["BO"] = "Bolivien", + ["CD"] = "Kongo (Dem. Rep.)", + ["CG"] = "Kongo", + ["CI"] = "Elfenbeinküste", + ["CN"] = "China", + ["CY"] = "Zypern", + ["CZ"] = "Tschechien", + ["FM"] = "Mikronesien", + ["GB"] = "Vereinigtes Königreich", + ["HK"] = "Hongkong", + ["IR"] = "Iran", + ["KP"] = "Nordkorea", + ["KR"] = "Südkorea", + ["LA"] = "Laos", + ["MD"] = "Moldau", + ["MK"] = "Nordmazedonien", + ["MO"] = "Macau", + ["PS"] = "Palästina", + ["RU"] = "Russland", + ["SY"] = "Syrien", + ["SZ"] = "Eswatini", + ["TL"] = "Osttimor", + ["TW"] = "Taiwan", + ["TZ"] = "Tansania", + ["US"] = "USA", + ["VA"] = "Vatikanstadt", + ["VE"] = "Venezuela", + ["VN"] = "Vietnam" + }; + + public static string? Display(string? code, string? name) => + code is not null && ShortNames.TryGetValue(code, out var shortName) ? shortName : name ?? code; +} diff --git a/src/Flypaper.Web/wwwroot/app.css b/src/Flypaper.Web/wwwroot/app.css index ac36959..b99c638 100644 --- a/src/Flypaper.Web/wwwroot/app.css +++ b/src/Flypaper.Web/wwwroot/app.css @@ -498,11 +498,20 @@ tbody th { } .world-map .marker { + cursor: default; +} + +.world-map .marker .hit { + fill: transparent; + pointer-events: all; +} + +.world-map .marker .dot { stroke: var(--surface); stroke-width: 1.5; } -.world-map .marker:hover { +.world-map .marker:hover .dot { stroke: var(--text); } diff --git a/test/Flypaper.Tests/Web/CountryNamesTests.cs b/test/Flypaper.Tests/Web/CountryNamesTests.cs new file mode 100644 index 0000000..a7fe472 --- /dev/null +++ b/test/Flypaper.Tests/Web/CountryNamesTests.cs @@ -0,0 +1,24 @@ +using Flypaper.Web.Components.Shared; +using Shouldly; + +namespace Flypaper.Tests.Web; + +public sealed class CountryNamesTests +{ + [Theory] + [InlineData("TW", "Republik China", "Taiwan")] + [InlineData("CN", "Volksrepublik China", "China")] + [InlineData("HK", "Sonderverwaltungszone Hongkong", "Hongkong")] + [InlineData("MO", "Sonderverwaltungszone Macau", "Macau")] + [InlineData("US", "Vereinigte Staaten von Amerika", "USA")] + [InlineData("ru", "Russische Föderation", "Russland")] + public void Uses_common_short_names(string code, string official, string expected) => + CountryNames.Display(code, official).ShouldBe(expected); + + [Theory] + [InlineData("DE", "Deutschland", "Deutschland")] + [InlineData("NL", null, "NL")] + [InlineData(null, "Unbekannt", "Unbekannt")] + public void Keeps_other_names(string? code, string? name, string expected) => + CountryNames.Display(code, name).ShouldBe(expected); +}