Show common country names and enlarge map marker hit area

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
TomandClaude Opus 5.5 committed 2026-11-15 12:47:44 +01:00
1 parent 31cef44bf3
commit 552abffd29
6 files changed
+88 -6

No files matched your search

@@ -29,7 +29,7 @@
<WorldMap CatchesByCountry="data.CatchesByCountry" /> <WorldMap CatchesByCountry="data.CatchesByCountry" />
<section class="tops"> <section class="tops">
<TopTable Title="Top 10 Länder" KeyLabel="Land" Entries="data.TopCountries" ShowFlags="true" /> <TopTable Title="Top 10 Länder" KeyLabel="Land" Entries="data.TopCountries" ShowFlags="true" LabelFormatter="CountryNames.Display" />
<TopTable Title="Top 10 Provider (ASN)" KeyLabel="Provider" Entries="data.TopProviders" /> <TopTable Title="Top 10 Provider (ASN)" KeyLabel="Provider" Entries="data.TopProviders" />
<TopTable Title="Top 10 IPs" KeyLabel="IP" Entries="data.TopIps" /> <TopTable Title="Top 10 IPs" KeyLabel="IP" Entries="data.TopIps" />
<TopTable Title="Top 10 Ziele" KeyLabel="Ziel" Entries="data.TopTargets" KeyFormatter="Formatting.Target" /> <TopTable Title="Top 10 Ziele" KeyLabel="Ziel" Entries="data.TopTargets" KeyFormatter="Formatting.Target" />
@@ -114,5 +114,5 @@
} }
private static string Origin(TrapEventEntity trapEvent) => 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)));
} }
@@ -45,9 +45,12 @@
[Parameter] public Func<string?, string?>? KeyFormatter { get; set; } [Parameter] public Func<string?, string?>? KeyFormatter { get; set; }
[Parameter] public Func<string?, string?, string?>? LabelFormatter { get; set; }
private string Display(TopEntry entry) private string Display(TopEntry entry)
{ {
var key = KeyFormatter?.Invoke(entry.Key) ?? entry.Key; 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}";
} }
} }
@@ -6,14 +6,20 @@
@foreach (var country in Map.Countries) @foreach (var country in Map.Countries)
{ {
var count = Count(country.Code); var count = Count(country.Code);
<path d="@country.Path" class="@($"level-{Level(count)}")"><title>@Title(country.Name, count)</title></path> <path d="@country.Path" class="@($"level-{Level(count)}")"><title>@Title(CountryNames.Display(country.Code, country.Name)!, count)</title></path>
} }
@foreach (var marker in Map.Markers) @foreach (var marker in Map.Markers)
{ {
var count = Count(marker.Code); var count = Count(marker.Code);
if (count > 0) if (count > 0)
{ {
<circle cx="@marker.X.ToString(CultureInfo.InvariantCulture)" cy="@marker.Y.ToString(CultureInfo.InvariantCulture)" r="5" class="@($"marker level-{Level(count)}")"><title>@Title(marker.Name, count)</title></circle> var x = marker.X.ToString(CultureInfo.InvariantCulture);
var y = marker.Y.ToString(CultureInfo.InvariantCulture);
<g class="@($"marker level-{Level(count)}")">
<title>@Title(CountryNames.Display(marker.Code, marker.Name)!, count)</title>
<circle class="hit" cx="@x" cy="@y" r="14" />
<circle class="dot" cx="@x" cy="@y" r="6" />
</g>
} }
} }
</svg> </svg>
@@ -0,0 +1,40 @@
namespace Flypaper.Web.Components.Shared;
public static class CountryNames
{
private static readonly Dictionary<string, string> 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;
}
+10 -1
View File
@@ -498,11 +498,20 @@ tbody th {
} }
.world-map .marker { .world-map .marker {
cursor: default;
}
.world-map .marker .hit {
fill: transparent;
pointer-events: all;
}
.world-map .marker .dot {
stroke: var(--surface); stroke: var(--surface);
stroke-width: 1.5; stroke-width: 1.5;
} }
.world-map .marker:hover { .world-map .marker:hover .dot {
stroke: var(--text); stroke: var(--text);
} }
@@ -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);
}