Numbers outside of the map [still cluttered]

This commit is contained in:
Olaf committed 2026-10-21 10:51:50 +02:00
1 parent b692f94122
commit e39de24921
5 files changed
+274 -45

No files matched your search

+64 -1
View File
@@ -18,7 +18,8 @@ from flight_map.geo import DEFAULT_BOUNDS, Bounds, Projection
from flight_map.lettering import GLYPHS, lettering
from flight_map.maps import map_data, map_lines
from flight_map.network import request_json
from flight_map.plot import SVG_NS, PlotOptions, render
from flight_map.plot import SVG_NS, PlotOptions, render, utc
from flight_map.plot import label as draw_label
from flight_map.record import OpenSky, collect
from flight_map.storage import (
Observation,
@@ -334,6 +335,68 @@ def test_invalid_plot_time_and_empty_data(recorded: tuple[Path, Session], tmp_pa
)
@pytest.mark.parametrize("count", [1, 2, 3, 4])
def test_printed_flight_legend_midpoint_and_two_columns(
recorded: tuple[Path, Session],
local_map: Path,
tmp_path: Path,
monkeypatch: pytest.MonkeyPatch,
count: int,
) -> None:
path, session = recorded
with database(path) as connection:
original = load_observations(connection, session.id, T0, T0 + 90)
for index in range(1, count):
save_observations(
connection,
session,
[
replace(item, icao24=f"{index:06x}", callsign=f"TEST{index}")
for item in original
],
T0 + 90,
)
expected_tracks = make_tracks(
load_observations(connection, session.id, T0, T0 + 90),
Projection(session.bounds),
120,
)
captured = Mock(wraps=draw_label)
monkeypatch.setattr("flight_map.plot.label", captured)
output = tmp_path / "legend.svg"
options = PlotOptions()
assert (
render(path, session.id, output, local_map=local_map, no_terrain=True, options=options)
== count
)
entries = [call for call in captured.call_args_list if re.match(r"^\d+: ", call.args[1])]
assert len(entries) == count
root = ET.parse(output).getroot()
rows = (count + 1) // 2
legend_width = options.width - 2 * options.margin
column_gap = 2 * options.font_height
column_width = (legend_width - column_gap) / 2
for index, call in enumerate(entries):
text, x, y, height = call.args[1:]
flight = root.find(f".//{{{SVG_NS}}}g[@id='flight-{index + 1}']")
assert flight is not None
track = expected_tracks[index]
assert utc((track.start + track.end) / 2) in text
assert flight.attrib["data-start-utc"] == utc(track.start)
assert flight.attrib["data-end-utc"] == utc(track.end)
assert len(re.findall(r"\d{4}-\d{2}-\d{2}", text)) == 1
assert len(re.findall(r"\d{2}:\d{2}:\d{2}", text)) == 1
assert " Alt 900 M" in text and "BARO" not in text.upper() and " TO " not in text
column, row = divmod(index, rows)
assert x == pytest.approx(options.margin + column * (column_width + column_gap))
assert y == pytest.approx(entries[0].args[3] + row * height * 1.8)
assert len(text) * height <= column_width
assert x + len(text) * height <= options.width - options.margin
assert y + height <= options.height - options.margin
if count >= 2:
assert entries[rows].args[2] > entries[0].args[2]
def test_map_cache_and_errors(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
payload = {
"elements": [