# -*- coding: utf-8 -*-
"""图 5-20　预测型开发方法
需求→设计→编码→测试→交付 纵向阶梯流程（每步向右下错开，折线箭头）。
"""
import os
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from matplotlib.patches import FancyArrowPatch
from _draw import setup, save, canvas, box, NAV, ACC

setup()

fig, ax = canvas(9.0, 5.2, (0, 100), (16, 100))

steps = ['需求', '设计', '编码', '测试', '交付']
w, h = 18.0, 9.5
x0, y0, dx, dy = 5.0, 92.0, 19.0, 15.2

centers = []
for i, s in enumerate(steps):
    x = x0 + i * dx
    y = y0 - i * dy
    box(ax, x, y, w, h, s, fs=13, bold=True)
    centers.append((x, y))

for i in range(len(steps) - 1):
    x, y = centers[i]
    nx, ny = centers[i + 1]
    p1 = (x + w, y - h / 2)                 # 本步右缘中点
    p2 = (nx + 5.5, ny)                     # 下一步顶边偏左
    a = FancyArrowPatch(p1, p2, arrowstyle='-|>', mutation_scale=15,
                        linewidth=1.5, color=ACC,
                        connectionstyle='angle,angleA=0,angleB=90,rad=0',
                        shrinkA=0, shrinkB=0)
    ax.add_patch(a)

fig.tight_layout()
out = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..',
                   'assets', '图5-20-预测型开发方法.png')
save(fig, out)
