Files
Flypaper/src/Flypaper.Web/Components/Pages/Dashboard/WorldMap.razor
T
TomandClaude Opus 5.5 8eeb7894a3
Build and deploy / build (push) Successful in 1m27s
Build and deploy / deploy (push) Successful in 20s
Polish dashboard layout and use German number formats
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 21:09:52 +01:00

65 lines
2.7 KiB
Plaintext

@using System.Globalization
<section class="card map-card">
<div class="card-head">
<h2>Herkunft</h2>
@if (_max > 0)
{
<div class="map-legend" aria-label="Fänge pro Land">
<span class="swatch level-0" title="keine"></span>
<span>1</span>
@for (var level = 1; level <= Levels; level++)
{
<span class="swatch @($"level-{level}")"></span>
}
<span>@Formatting.Number(_max)</span>
</div>
}
</div>
<div class="map-wrap">
<svg class="world-map" viewBox="0 0 @Map.Width.ToString(CultureInfo.InvariantCulture) @Map.Height.ToString(CultureInfo.InvariantCulture)" role="img" aria-label="Weltkarte der Fänge nach Land">
@foreach (var country in Map.Countries)
{
var count = Count(country.Code);
<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)
{
var count = Count(marker.Code);
if (count > 0)
{
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>
@if (_max == 0)
{
<p class="map-empty">Sobald Bots anklopfen, färbt sich die Karte nach Herkunftsland.</p>
}
</div>
</section>
@code {
private const int Levels = 5;
private int _max;
[Parameter, EditorRequired] public required IReadOnlyDictionary<string, int> CatchesByCountry { get; set; }
private static WorldMapData Map => WorldMapData.Instance;
protected override void OnParametersSet() => _max = CatchesByCountry.Count == 0 ? 0 : CatchesByCountry.Values.Max();
private int Count(string? code) => code is not null && CatchesByCountry.TryGetValue(code, out var count) ? count : 0;
private static string Title(string name, int count) => $"{name}: {count:N0} {(count == 1 ? "Fang" : "Fänge")}";
private int Level(int count) =>
count == 0 || _max == 0 ? 0 : Math.Max(1, (int)Math.Ceiling(Math.Log(count + 1) / Math.Log(_max + 1) * Levels));
}