Datasets:
File size: 1,976 Bytes
00a49c9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | """Check the app's figure without a browser: trace structure, palette, axes."""
import umap_app as app
PALETTE = set(app.THEMES["light"]["series"] + app.THEMES["dark"]["series"]
+ [app.THEMES["light"]["other"], app.THEMES["dark"]["other"],
app.THEMES["light"]["grid"], app.THEMES["dark"]["grid"]])
df = app.load_nodes()
print(f"nodes {len(df):,} · coords x[{df.x.min():.1f},{df.x.max():.1f}] "
f"y[{df.y.min():.1f},{df.y.max():.1f}]")
CASES = {
"top 3, light": dict(mode="light"),
"top 3, dark": dict(mode="dark"),
"highlight Homo sapiens": dict(highlight="Homo sapiens"),
"restrict to 2 species": dict(shown=("Bos taurus", "Mus musculus")),
"colour by tissue1": dict(group_by="tissue1"),
}
for name, kwargs in CASES.items():
fig, visible = app.build_figure(df, **kwargs)
hues = {t.marker.color for t in fig.data}
drawn = sum(len(t.x) for t in fig.data)
coloured = sum(len(t.x) for t in fig.data if t.marker.color
not in (app.THEMES["light"]["other"], app.THEMES["dark"]["other"],
app.THEMES["light"]["grid"], app.THEMES["dark"]["grid"]))
assert hues <= PALETTE, f"{name}: off-palette colour {hues - PALETTE}"
assert drawn == len(df), f"{name}: {drawn} points drawn, expected {len(df)}"
assert len([t for t in fig.data if t.showlegend is not False]) <= 4
assert fig.layout.xaxis.visible is False and fig.layout.yaxis.visible is False
assert fig.layout.xaxis.scaleanchor == "y", "aspect ratio not locked"
assert all("customdata" in t.hovertemplate for t in fig.data)
print(f"\n{name}")
print(f" traces {len(fig.data)} · all {drawn:,} nodes drawn · "
f"{coloured:,} in a series hue")
for t in fig.data:
print(f" {(t.name or '—'):<34} {len(t.x):>7,} {t.marker.color}")
print("\nall figure checks passed: palette clean, every node drawn, "
"axes hidden, aspect locked, hover wired")
|