import networkx as nx
import matplotlib.pyplot as plt
from matplotlib import rc
import arabic_reshaper
from bidi.algorithm import get_display
import matplotlib.font_manager as fm

# مسیر فونت فارسی
font_path = '/home/matin/Downloads/B-NAZANIN.TTF'

# اضافه کردن فونت به سیستم
font_prop = fm.FontProperties(fname=font_path)
fm.fontManager.addfont(font_path)

# تنظیمات فونت برای Matplotlib
rc('font', family='sans-serif')
rc('font', serif='B Nazanin')
plt.rcParams['font.sans-serif'] = ['B Nazanin']
plt.rcParams['font.serif'] = ['B Nazanin']
plt.rcParams['font.family'] = 'B Nazanin'
plt.rcParams['font.size'] = 10

# ایجاد گراف جهت‌دار
G = nx.DiGraph()

# افزودن گره‌ها و یال‌ها به گراف
G.add_edges_from([
    (get_display(arabic_reshaper.reshape("مدیر عامل")), get_display(arabic_reshaper.reshape("مدیر مالی"))),
    (get_display(arabic_reshaper.reshape("مدیر عامل")), get_display(arabic_reshaper.reshape("مدیر فناوری اطلاعات"))),
    (get_display(arabic_reshaper.reshape("مدیر مالی")), get_display(arabic_reshaper.reshape("حسابدار"))),
    (get_display(arabic_reshaper.reshape("مدیر فناوری اطلاعات")), get_display(arabic_reshaper.reshape("کارشناس امنیت"))),
    (get_display(arabic_reshaper.reshape("مدیر فناوری اطلاعات")), get_display(arabic_reshaper.reshape("کارشناس شبکه")))
])

# تنظیم موقعیت گره‌ها
pos = nx.spring_layout(G)

# رسم نمودار
plt.figure(figsize=(10, 6))
nx.draw(G, pos, with_labels=True, labels={node: node for node in G.nodes()}, node_size=3000, node_color="lightblue", font_size=10, font_color="black", arrows=True, font_family=font_prop.get_name())
plt.title(get_display(arabic_reshaper.reshape("چارت سازمانی")), fontproperties=font_prop)
plt.show()