import json
import networkx as nx
import matplotlib.pyplot as plt
import os

def load_sequences(filename):
    with open(filename, 'r') as f:
        data = json.load(f)
    return data['sequences']

def create_graph(sequences):
    G = nx.DiGraph()
    #for seq in sequences:
    for i in range(len(sequences) - 1):
        G.add_edge(sequences[i], sequences[i + 1])
    return G

def draw_graph_with_thumbnails(G, image_folder):
    pos = {}
    x = 1
    for node in G.nodes():
        pos[node] = (1, -x)  # Устанавливаем позиции узлов по вертикали
        x += 1

    plt.figure(figsize=(8, 6))
    nx.draw(G, pos, with_labels=True, node_size=100, node_color='skyblue', font_size=10, font_weight='bold')

    # for node, (x, y) in pos.items():
    #     image_path = f"{image_folder}/{node}.svg"
    #     if os.path.exists(image_path):
    #         img = plt.imread(image_path)
    #         plt.imshow(img, aspect='auto', extent=(x - 0.5, x + 0.5, y - 0.5, y + 0.5), zorder=0)

    plt.gca().invert_yaxis()  # Инвертируем ось y для вертикального отображения
    plt.show()

def main():
    sequences = load_sequences('valid_sequences.json')
    G = create_graph(sequences)
    draw_graph_with_thumbnails(G, 'path_to_img')
