Draw the bandmap the way N1MM draws it

The bandmap was a list of frequencies and callsigns. It is now a frequency
scale with the stations written out beside it and a leader line from each
callsign back to where the station really is.

BandmapLayout does the placing and has no UI reference, so the rule is unit
tested: put the label centred on its frequency, and if it would cover the one
above, push it below instead. That is N1MM's CalculateOffset, and it is what
keeps three stations a hundred hertz apart readable.

The scale stops short of the top and bottom edges, or the first and last
frequency numbers come out cut in half.

VfoMarker draws the receiver as a bar as wide as the mode passes, rather than a
line. Only the receiver is fed: the radio does not report a transmit VFO or a
second radio yet, so VfoRole has the other two roles ready and nothing draws
them. Band-plan colouring of the scale is left out because the segments differ
by ITU region and there is no band-plan table to read them from.

Checked by running the program against a fake cluster node under Xvfb and
looking at the result: twelve spots, three of them stacked with fanned leaders.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-27 16:15:01 +00:00
parent 2b5ab54e94
commit b9f0166777
11 changed files with 443 additions and 48 deletions

View File

@@ -0,0 +1,52 @@
using Nonemm.Core;
namespace Nonemm.Spotting;
/// Works out where each callsign goes. Two stations a hundred hertz apart would
/// have their text on top of each other, so a label that would cover the one
/// above is pushed below it and a leader line runs back to the real frequency.
/// This is what N1MM does.
public static class BandmapLayout
{
/// N1MM leaves this much between two labels it had to separate.
private const double Gap = 0.5;
public static IReadOnlyList<BandmapLabel> Place(
IEnumerable<Spot> spots,
BandmapScale scale,
double labelHeight)
{
List<BandmapLabel> placed = [];
double? above = null;
foreach (Spot spot in spots
.Where(s => scale.Shows(s.Frequency))
.OrderBy(s => s.Frequency.Hertz))
{
double markY = scale.YFor(spot.Frequency);
double labelY = markY - (labelHeight / 2);
if (above is { } previous && previous + labelHeight > labelY)
{
labelY = previous + labelHeight + Gap;
}
placed.Add(new BandmapLabel(spot, markY, labelY));
above = labelY;
}
return placed;
}
/// The frequency ticks to draw, every `step` from the first round frequency
/// at or below the top of the scale.
public static IReadOnlyList<Frequency> Ticks(BandmapScale scale, Frequency step)
{
List<Frequency> ticks = [];
long first = scale.Low.Hertz - (scale.Low.Hertz % step.Hertz);
for (long at = first; at <= scale.High.Hertz; at += step.Hertz)
{
if (at >= scale.Low.Hertz)
{
ticks.Add(Frequency.FromHertz(at));
}
}
return ticks;
}
}