"""Plot iso[49] at n=9, the counterexample to Conjecture 4.4."""
import sys
import os
sys.path.insert(0, '/Users/didericis/Code/math-research/papers/'
                'level_resolutions_of_maximal_planar_graphs/experiments')
import networkx as nx
import matplotlib.pyplot as plt
from triangulation_gen import enumerate_all_triangulations

OUT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

tris = enumerate_all_triangulations(9)
G = tris[49]
print(f'iso[49] degree sequence: {sorted([G.degree(v) for v in G.nodes()], reverse=True)}')
print(f'iso[49] edges: {sorted(G.edges())}')

# Use planar layout
_, emb = nx.check_planarity(G)
pos = nx.combinatorial_embedding_to_pos(emb)

fig, ax = plt.subplots(figsize=(8, 7))
nx.draw_networkx_edges(G, pos, ax=ax, edge_color='#333', width=1.5)
# Color vertices by degree
degree_color = {4: '#3b82f6', 5: '#dc2626'}
node_colors = [degree_color[G.degree(v)] for v in G.nodes()]
nx.draw_networkx_nodes(G, pos, ax=ax, node_color=node_colors,
                       node_size=600, edgecolors='black', linewidths=1.2)
nx.draw_networkx_labels(G, pos, ax=ax, font_color='white',
                        font_size=11, font_weight='bold')
ax.set_aspect('equal'); ax.axis('off')
ax.set_title('iso[49] at $n=9$: degree sequence (5,5,5,5,5,5,4,4,4).\n'
             'NOT a valid derived level graph of any Even Level Graph.\n'
             'Blue = degree 4, Red = degree 5.', fontsize=11)
fig.tight_layout()
out = os.path.join(OUT_DIR, 'fig_n9_counterexample.png')
fig.savefig(out, dpi=180, bbox_inches='tight')
plt.close(fig)
print(f'wrote {out}')
