r"""
Six layouts of the same hypergraph
==================================

The HAT-VIS similarity layout places similar vertices close to each other;
the HyperGodot force-directed layout balances centroid springs and
repulsion; the membership-aware layout of hatvis keeps the similarity
geometry but pushes non-members out of hyperedge discs; the circular,
spectral and bipartite layouts are classical alternatives. The layout quality
table reports the stress against the similarity distances and the number of
intrusions (non-members inside a hull).
"""

# %%
import matplotlib.pyplot as plt
import pandas as pd

import hatvis as hv
from hatvis.plotting import draw_hypergraph, resolve_layout

H = hv.datasets.load_manufacturing_cps()
names = ["similarity", "force", "membership", "circular", "spectral", "bipartite"]
# [snippet:layouts]
layouts = {name: resolve_layout(H, None, name, random_state=0) for name in names}
quality = pd.DataFrame({name: hv.layout_quality(H, pos) for name, pos in layouts.items()}).T
print(quality.round(3))
# [/snippet:layouts]

# %%
fig, axes = plt.subplots(2, 3, figsize=(15, 9.5))
for ax, (name, pos) in zip(axes.ravel(), layouts.items(), strict=False):
    draw_hypergraph(H, pos=pos, ax=ax, legend=False, title=f"{name} (intrusions: {int(quality.loc[name, 'intrusions'])})")
plt.tight_layout()
