# -*- coding: utf-8 -*-
"""图 5-37　工作节点图例（按教材 p115 图意重绘）
3 行方格：第一行 ES | 工期 | EF；第二行 工作编号（跨列）；第三行 LS | 总时差 | LF。
"""
import os, sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from _draw import setup, canvas, INK, save
from matplotlib.patches import Rectangle

HERE = os.path.dirname(os.path.abspath(__file__))
OUT = os.path.join(HERE, '..', 'assets', '图5-37-工作节点图例.png')

setup()
fig, ax = canvas(6.0, 3.4, xlim=(0, 100), ylim=(0, 100))
W, H = 62.0, 42.0
x0, y0 = 19, 29
rh = H / 3
ax.add_patch(Rectangle((x0, y0), W, H, fill=True, fc='white', ec=INK, lw=1.6, zorder=3))
for k in (1, 2):
    ax.plot([x0, x0 + W], [y0 + rh * k, y0 + rh * k], color=INK, lw=1.3, zorder=4)
for row_y0 in (y0 + 2 * rh, y0):          # 第一、三行的两条竖线
    for fx in (1 / 3, 2 / 3):
        ax.plot([x0 + W * fx, x0 + W * fx], [row_y0, row_y0 + rh], color=INK, lw=1.3, zorder=4)

cells = [(1 / 6, 2.5, 'ES'), (1 / 2, 2.5, '工期'), (5 / 6, 2.5, 'EF'),
         (1 / 2, 1.5, '工作编号'),
         (1 / 6, 0.5, 'LS'), (1 / 2, 0.5, '总时差'), (5 / 6, 0.5, 'LF')]
for fx, fy, txt in cells:
    ax.text(x0 + W * fx, y0 + rh * fy, txt, ha='center', va='center',
            fontsize=13, color=INK, zorder=5)
save(fig, OUT)
