# -*- coding: utf-8 -*-
"""绘图工具自检：中文渲染 + 布局（用于验证工具链可用）"""
import sys, os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from _draw import setup, canvas, box, arrow, line, title, caption, save, NAV, ACC

setup()
fig, ax = canvas(10, 5.6)
title(ax, '自检：中文渲染与布局（第 4 章插图工具）')
# 树形示例（WBS 风格）
root = box(ax, 40, 92, 20, 8, '教务管理系统', fc=NAV, ec=NAV, tc='white', bold=True)
kids = ['课程管理', '成绩管理', '排课与选课', '评教管理']
w = 18
for i, k in enumerate(kids, start=1):
    cx = 100 / (len(kids) + 1) * i
    box(ax, cx - w / 2, 72, w, 8, k, fs=10)
    line(ax, (50, 84), (cx, 72))
# 流程示例
a = box(ax, 6, 48, 20, 8, '① 识别需求')
b = box(ax, 32, 48, 20, 8, '② 定义范围')
c = box(ax, 58, 48, 20, 8, '③ 创建 WBS')
arrow(ax, (26, 44), (32, 44)); arrow(ax, (52, 44), (58, 44))
caption(ax, '中文、箭头、连线、圆角框均应正常显示')
save(fig, os.path.join(os.path.dirname(os.path.abspath(__file__)), '_selftest.png'))
