# -*- coding: utf-8 -*-
"""图 6-12　挣值报告 —— 教材第 139 页

Project 2016「报表」视图中的挣值报告（报表页，不是表格）：
· 顶部选项卡「文件 … 报表 … 报表设计 图表设计 格式」，当前选中「报表」
· 「报表」组：新建报表／仪表板／资源／成本（黑框圈出，上方注「下拉菜单筛选"挣值报告"」）／进行中／入门／自定义／最近
· 左：报表页标题「挣值」＋主图（纵轴 ¥60,000…-¥60,000，横轴 11/12→12/4，BCWS/ACWP/BCWP 三条曲线，
  顶部黑色数据标签条 ¥298,714.29／¥20,400.00／¥16,800.00）＋下部「差异」小图（CPI、SPI，纵轴 1.7／1／0.4）
· 右：任务窗格「字段列表」（任务/资源、选择类别、编辑按钮带箭头、域树、筛选/分组/大纲）与「设置坐标轴格式」
· 中部：叠加「编辑时间刻度」对话框（单位 天／日期格式／计数 1／开始 2024年11月12日／完成 2024年12月4日）
"""
import os
import sys

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from matplotlib.patches import Circle, FancyArrowPatch, Rectangle

from _draw import setup, canvas, save, INK, NAV, ACC, FILL, LINE
import _draw

HERE = os.path.dirname(os.path.abspath(__file__))
OUT = os.path.join(HERE, '..', 'assets', '图6-12-挣值报告.png')

TABS = ['文件', '任务', '资源', '报表', '项目', '视图', '帮助', '报表设计', '图表设计', '格式']
ACTIVE_TAB = '报表'

# 主图：11/12 起逐日（到 12/4）的三条累计值
BCWS = [0, 1200, 3600, 6000, 8400, 10800, 13200, 15600, 19200, 22800, 26400, 30000,
        33600, 37200, 39600, 42000, 44400, 46800, 48800, 50400, 51400, 52000, 52400]
ACWP = [0, 800, 2400, 4800, 7200, 9600, 12000, 14400, 16000, 17200, 18000, 18600,
        19000, 19300, 19500, 19700, 19850, 20000, 20100, 20200, 20300, 20380, 20400]
BCWP = [0, 400, 1000, 1800, 2600, 3600, 4600, 5600, 6600, 7800, 9000, 10000,
        10800, 11600, 12400, 13200, 14000, 14800, 15400, 16000, 16400, 16700, 16800]

# 「差异」小图
CPI = [1.60, 1.50, 1.40, 1.30, 1.22, 1.15, 1.10, 1.05, 1.01, 0.98, 0.95, 0.93,
       0.91, 0.89, 0.87, 0.86, 0.85, 0.84, 0.835, 0.83, 0.825, 0.82, 0.82]
SPI = [1.60, 1.45, 1.30, 1.15, 1.02, 0.90, 0.80, 0.72, 0.65, 0.60, 0.56, 0.53,
       0.50, 0.48, 0.46, 0.44, 0.43, 0.42, 0.41, 0.40, 0.39, 0.38, 0.37]

# ── 主图几何 ──
CX0, CX1 = 10.8, 60.2          # 绘图区左右
CY0, CY1 = 43.6, 68.2          # 绘图区上下
CN = len(BCWS)
VMAX = 60000.0


def yv(v):
    return CY0 + (v + VMAX) / (2 * VMAX) * (CY1 - CY0)


def xd(i):
    return CX0 + i / (CN - 1) * (CX1 - CX0)


def panel(ax, x, y, w, h, title, fs=5.4, close=True, qmark=False):
    """任务窗格/对话框外壳：标题条 + 白底。"""
    ax.add_patch(Rectangle((x, y - h), w, h, facecolor='white', edgecolor='#a0aec0',
                           linewidth=0.8, zorder=12))
    ax.add_patch(Rectangle((x, y - 3.6), w, 3.6, facecolor='#edf2f7', edgecolor='#a0aec0',
                           linewidth=0.8, zorder=13))
    ax.text(x + 0.9, y - 1.8, title, ha='left', va='center', fontsize=fs,
            color='#2d3748', zorder=14)
    if qmark:
        ax.text(x + w - 4.4, y - 1.8, '?', ha='center', va='center', fontsize=5.6,
                color='#4a5568', zorder=14)
    if close:
        ax.text(x + w - 1.6, y - 1.8, '×', ha='center', va='center', fontsize=6.4,
                color='#4a5568', zorder=14)


def field(ax, x, y, w, h, text, fs=4.9, fc='white', ec='#a0aec0', ta='left', pad=0.55, z=15):
    ax.add_patch(Rectangle((x, y - h), w, h, facecolor=fc, edgecolor=ec, linewidth=0.6,
                           zorder=z))
    if ta == 'left':
        ax.text(x + pad, y - h / 2, text, ha='left', va='center', fontsize=fs,
                color=INK, zorder=z + 1)
    else:
        ax.text(x + w / 2, y - h / 2, text, ha='center', va='center', fontsize=fs,
                color=INK, zorder=z + 1)


def radio(ax, x, y, label, on=False, fs=4.9, z=15):
    ax.add_patch(Circle((x, y), 0.42, facecolor='white', edgecolor='#718096',
                        linewidth=0.6, zorder=z))
    if on:
        ax.add_patch(Circle((x, y), 0.20, facecolor=ACC, edgecolor='none', zorder=z + 1))
    ax.text(x + 1.2, y, label, ha='left', va='center', fontsize=fs, color=INK, zorder=z + 1)


def checkbox(ax, x, y, label, on=False, fs=4.9, z=15):
    ax.add_patch(Rectangle((x - 0.45, y - 0.45), 0.9, 0.9, facecolor='white',
                           edgecolor='#718096', linewidth=0.6, zorder=z))
    if on:
        ax.text(x, y, '✓', ha='center', va='center', fontsize=4.6, color=ACC, zorder=z + 1)
    ax.text(x + 1.1, y, label, ha='left', va='center', fontsize=fs, color=INK, zorder=z + 1)


def draw_chrome(ax):
    ax.add_patch(Rectangle((1.0, 1.5), 98.0, 96.8, facecolor='white',
                           edgecolor='#2d3748', linewidth=1.3, zorder=1))
    ax.add_patch(Rectangle((1.15, 94.8), 97.7, 3.35, facecolor='#f7fafc',
                           edgecolor='#cbd5e0', linewidth=0.6, zorder=2))
    ax.text(2.2, 96.45, '教务管理系统-成本管理实验.mpp   —   Project Professional',
            ha='left', va='center', fontsize=5.6, color='#4a5568', zorder=3)
    ax.text(97.4, 96.45, '—   □   ×', ha='right', va='center', fontsize=6.2,
            color='#4a5568', zorder=3)

    x = 2.3
    for t in TABS:
        w = 5.0
        if t == ACTIVE_TAB:
            ax.add_patch(Rectangle((x - 0.3, 91.15), w, 3.4, facecolor=FILL,
                                   edgecolor=ACC, linewidth=1.0, zorder=4))
        ax.text(x + (w - 0.3) / 2, 92.85, t, ha='center', va='center', fontsize=5.9,
                color=(NAV if t == ACTIVE_TAB else INK),
                fontweight='bold' if t == ACTIVE_TAB else 'normal', zorder=5)
        x += w + 0.45
    ax.add_patch(Rectangle((84.2, 91.5), 12.6, 2.7, facecolor='white',
                           edgecolor='#cbd5e0', linewidth=0.6, zorder=4))
    ax.text(90.5, 92.85, '操作说明搜索', ha='center', va='center', fontsize=5.4,
            color='#718096', zorder=5)

    # ── 功能区 ──
    ax.add_patch(Rectangle((1.15, 79.0), 97.7, 12.0, facecolor='#f7fafc',
                           edgecolor='#e2e8f0', linewidth=0.6, zorder=2))
    ax.text(2.6, 80.4, '项目', ha='left', va='center', fontsize=4.7,
            color='#718096', zorder=4)
    _draw.box(ax, 2.6, 88.0, 8.2, 6.0, '比较项目', fc='white', ec='#cbd5e0', tc=INK,
              fs=4.9, radius=0.45, lw=0.6)
    ax.text(12.0, 80.4, '报表', ha='left', va='center', fontsize=4.7,
            color='#718096', zorder=4)
    items = ['新建报表', '仪表板', '资源', '成本', '进行中', '入门', '自定义', '最近']
    cost_cx = None
    for i, it in enumerate(items):
        bx = 12.0 + i * 8.85
        _draw.box(ax, bx, 88.0, 8.35, 6.0, it, fc='white', ec='#cbd5e0', tc=INK,
                  fs=4.9, radius=0.45, lw=0.6)
        if it == '成本':
            ax.add_patch(Rectangle((bx - 0.26, 81.65), 8.87, 6.7, fill=False,
                                   edgecolor=INK, linewidth=1.8, zorder=6))
            cost_cx = bx + 8.35 / 2
    for sx in (11.4, 83.4):
        ax.plot([sx, sx], [79.6, 90.2], color='#e2e8f0', lw=0.8, zorder=3)
    _draw.box(ax, 84.6, 88.0, 12.0, 6.0, '查看报表', fc='white', ec='#cbd5e0', tc=INK,
              fs=4.9, radius=0.45, lw=0.6)
    # 引出注记：下拉菜单筛选「挣值报告」
    ax.add_patch(FancyArrowPatch((cost_cx, 89.6), (cost_cx, 88.5), arrowstyle='-|>',
                                 mutation_scale=9, color='#c53030', lw=0.9,
                                 shrinkA=0, shrinkB=0, zorder=18))
    ax.text(cost_cx, 89.7, '下拉菜单筛选“挣值报告”', ha='center', va='bottom',
            fontsize=5.0, color='#c53030', zorder=9,
            bbox=dict(boxstyle='round,pad=0.15', fc='white', ec='none'))


def draw_report_page(ax):
    """报表页：标题「挣值」+ 主图 + 「差异」小图。"""
    ax.add_patch(Rectangle((2.0, 3.0), 61.2, 75.0, facecolor='white',
                           edgecolor='#cbd5e0', linewidth=0.8, zorder=2))
    ax.text(4.2, 74.6, '挣值', ha='left', va='center', fontsize=12.5, color='#2d3748',
            fontweight='bold', zorder=4)

    # ── 主图：网格与坐标轴 ──
    for v in range(-60000, 60001, 20000):
        yy = yv(v)
        col = '#a0aec0' if v == 0 else '#e2e8f0'
        ax.plot([CX0, CX1], [yy, yy], color=col, lw=0.7 if v == 0 else 0.5, zorder=3)
        ax.text(CX0 - 0.6, yy, f'¥{v:,}.00' if v >= 0 else f'-¥{abs(v):,}.00',
                ha='right', va='center', fontsize=4.6, color='#4a5568', zorder=4)
    ax.plot([CX0, CX0], [CY0, CY1], color='#a0aec0', lw=0.7, zorder=4)
    ax.plot([CX0, CX1], [CY0, CY0], color='#a0aec0', lw=0.7, zorder=4)

    # 图例
    lx = CX0 + 1.2
    for lab, col in [('BCWS（计划价值）', '#1a365d'), ('ACWP（实际成本）', '#2b6cb0'),
                     ('BCWP（挣值）', '#d69e2e')]:
        ax.plot([lx, lx + 2.0], [66.9, 66.9], color=col, lw=1.8, zorder=6)
        ax.text(lx + 2.4, 66.9, lab, ha='left', va='center', fontsize=4.7,
                color='#4a5568', zorder=6)
        lx += 11.6

    # 三条曲线
    ax.plot([xd(i) for i in range(CN)], [yv(v) for v in BCWS], color='#1a365d',
            lw=2.2, zorder=7, solid_capstyle='round')
    ax.plot([xd(i) for i in range(CN)], [yv(v) for v in ACWP], color='#2b6cb0',
            lw=2.0, zorder=7, solid_capstyle='round')
    ax.plot([xd(i) for i in range(CN)], [yv(v) for v in BCWP], color='#d69e2e',
            lw=2.0, zorder=7, solid_capstyle='round')

    # 横轴日期（11/12 → 12/4）
    import datetime
    d0 = datetime.date(2024, 11, 12)
    for i in range(CN):
        d = d0 + datetime.timedelta(days=i)
        if i % 3 == 0 or i == CN - 1:
            ax.text(xd(i), CY0 - 1.5, f'{d.month}/{d.day}', ha='center', va='top',
                    fontsize=4.5, color='#4a5568', zorder=5)

    # 顶部黑色数据标签条
    ax.add_patch(Rectangle((CX0, 68.9), CX1 - CX0, 2.2, facecolor='#1a202c',
                           edgecolor='none', zorder=9))
    chips = [('EAC', '¥298,714.29', 0.22, '#f6e05e'), ('AC', '¥20,400.00', 0.52, '#63b3ed'),
             ('BCWP', '¥16,800.00', 0.80, '#f6ad55')]
    for lab, val, frac, col in chips:
        cx = CX0 + (CX1 - CX0) * frac
        ax.add_patch(Rectangle((cx - 1.2, 69.45), 0.9, 0.9, facecolor=col,
                               edgecolor='none', zorder=10))
        ax.text(cx - 0.1, 69.9, f'{lab}  {val}', ha='left', va='center', fontsize=4.8,
                color='white', zorder=10)

    # ── 「差异」小图 ──
    dx0, dx1, dy0, dy1 = 9.2, 31.5, 9.6, 25.6
    ax.add_patch(Rectangle((5.6, 6.4), 27.4, 24.4, facecolor='white',
                           edgecolor='#e2e8f0', linewidth=0.7, zorder=3))
    ax.text(6.8, 29.4, '差异', ha='left', va='center', fontsize=6.4, color='#2d3748',
            fontweight='bold', zorder=5)

    def yv2(v):
        return dy0 + (v - 0.3) / (1.75 - 0.3) * (dy1 - dy0)

    for v in (1.7, 1.0, 0.4):
        yy = yv2(v)
        ax.plot([dx0, dx1], [yy, yy], color='#a0aec0' if v == 1.0 else '#e2e8f0',
                lw=0.7 if v == 1.0 else 0.5, zorder=4)
        ax.text(dx0 - 0.5, yy, f'{v}', ha='right', va='center', fontsize=4.5,
                color='#4a5568', zorder=5)
    ax.plot([dx0, dx0], [dy0, dy1], color='#a0aec0', lw=0.6, zorder=4)
    ax.plot([dx0, dx1], [dy0, dy0], color='#a0aec0', lw=0.6, zorder=4)
    ax.plot([dx0 + i / (CN - 1) * (dx1 - dx0) for i in range(CN)],
            [yv2(v) for v in CPI], color='#2b6cb0', lw=1.6, zorder=6)
    ax.plot([dx0 + i / (CN - 1) * (dx1 - dx0) for i in range(CN)],
            [yv2(v) for v in SPI], color='#c53030', lw=1.6, zorder=6)
    for lx2, lab, col in [(dx0 + 9.0, 'CPI', '#2b6cb0'), (dx0 + 15.6, 'SPI', '#c53030')]:
        ax.plot([lx2, lx2 + 2.2], [27.2, 27.2], color=col, lw=1.5, zorder=7)
        ax.text(lx2 + 2.6, 27.2, lab, ha='left', va='center', fontsize=4.5, color=col,
                zorder=7)
    for i in (0, 7, 14, 22):
        d = d0 + datetime.timedelta(days=i)
        ax.text(dx0 + i / (CN - 1) * (dx1 - dx0), dy0 - 1.4, f'{d.month}/{d.day}',
                ha='center', va='top', fontsize=4.3, color='#4a5568', zorder=5)


def draw_panes(ax):
    """右侧两个任务窗格。"""
    # ── 字段列表 ──
    PX, PY, PW = 64.5, 78.0, 17.0
    panel(ax, PX, PY, PW, 72.0, '字段列表', fs=5.2)
    ax.add_patch(Rectangle((PX, PY - 7.4), PW, 3.8, facecolor='#f7fafc',
                           edgecolor='#e2e8f0', linewidth=0.6, zorder=13))
    ax.text(PX + 3.4, PY - 5.5, '任务', ha='center', va='center', fontsize=4.9,
            color=INK, fontweight='bold', zorder=14)
    ax.text(PX + 9.2, PY - 5.5, '资源', ha='center', va='center', fontsize=4.9,
            color='#4a5568', zorder=14)
    ax.plot([PX + 0.6, PX + 6.2], [PY - 7.3, PY - 7.3], color=ACC, lw=1.2, zorder=14)

    ax.text(PX + 0.9, PY - 9.4, '选择类别:', ha='left', va='center', fontsize=4.7,
            color=INK, zorder=14)
    field(ax, PX + 5.4, PY - 8.0, 5.6, 2.6, '时间', fs=4.7)
    field(ax, PX + 11.6, PY - 8.0, 5.0, 2.6, '编辑', fs=4.7, fc='#f7fafc', ec='#718096')
    # 「编辑」按钮被箭头指出
    ax.add_patch(FancyArrowPatch((PX + 14.1, PY - 12.6), (PX + 14.1, PY - 10.4),
                                 arrowstyle='-|>', mutation_scale=9, color='#c53030',
                                 lw=0.9, shrinkA=0, shrinkB=0, zorder=18))
    ax.text(PX + 14.1, PY - 12.9, '单击“编辑”', ha='center', va='top', fontsize=4.5,
            color='#c53030', zorder=16)

    # 域树
    tree = [('成本', True, 0), ('工时', False, 1), ('成本', False, 1), ('材料', False, 1),
            ('基线对齐', True, 0), ('ACWP', False, 1), ('BCWS', False, 1), ('BCWP', False, 1),
            ('完成时成本', False, 1), ('任务', True, 0), ('实际开始时间', False, 1),
            ('实际完成时间', False, 1), ('实际工期', False, 1), ('完成百分比', False, 1),
            ('资源名称', True, 0), ('名称', False, 1), ('类型', False, 1)]
    ty = PY - 15.6
    for name, head, lvl in tree:
        tx = PX + 1.2 + lvl * 1.6
        if head:
            ax.text(tx - 0.2, ty, '▼', ha='left', va='center', fontsize=3.4,
                    color='#718096', zorder=15)
            ax.text(tx + 1.0, ty, name, ha='left', va='center', fontsize=4.8,
                    color=INK, fontweight='bold', zorder=15)
        else:
            checkbox(ax, tx + 0.9, ty, name, on=(name in ('ACWP', 'BCWS', 'BCWP')), fs=4.7)
        ty -= 2.05

    # 底部：筛选/分组依据/大纲级别
    ax.plot([PX + 0.4, PX + PW - 0.4], [28.4, 28.4], color='#e2e8f0', lw=0.7, zorder=14)
    ax.text(PX + 0.9, 25.8, '筛选:', ha='left', va='center', fontsize=4.7, color=INK,
            zorder=14)
    field(ax, PX + 4.4, 27.0, 11.6, 2.6, '活动任务', fs=4.7)
    ax.text(PX + 0.9, 21.8, '分组依据:', ha='left', va='center', fontsize=4.7, color=INK,
            zorder=14)
    field(ax, PX + 6.6, 23.0, 9.4, 2.6, '不分组', fs=4.7)
    ax.text(PX + 0.9, 17.8, '大纲级别:', ha='left', va='center', fontsize=4.7, color=INK,
            zorder=14)
    field(ax, PX + 6.6, 19.0, 9.4, 2.6, '项目摘要', fs=4.7)
    checkbox(ax, PX + 1.8, 14.2, '显示层次结构', on=False, fs=4.7)

    # ── 设置坐标轴格式 ──
    QX, QW, QH = 82.6, 15.4, 52.0
    panel(ax, QX, PY, QW, QH, '设置坐标轴格式', fs=5.0)
    ax.add_patch(Rectangle((QX, PY - 7.4), QW, 3.8, facecolor='#f7fafc',
                           edgecolor='#e2e8f0', linewidth=0.6, zorder=13))
    ax.text(QX + 0.7, PY - 5.5, '坐标轴选项', ha='left', va='center', fontsize=4.7,
            color=INK, fontweight='bold', zorder=14)
    ax.text(QX + 9.4, PY - 5.5, '文本选项', ha='left', va='center', fontsize=4.7,
            color='#4a5568', zorder=14)
    ax.plot([QX + 0.5, QX + 6.3], [PY - 7.3, PY - 7.3], color=ACC, lw=1.2, zorder=14)

    ax.text(QX + 0.9, PY - 9.2, '坐标轴选项', ha='left', va='center', fontsize=4.8,
            color=INK, fontweight='bold', zorder=14)
    ax.text(QX + 0.9, PY - 12.0, '坐标轴类型', ha='left', va='center', fontsize=4.8,
            color=INK, zorder=14)
    radio(ax, QX + 1.4, PY - 14.4, '根据数据自动选择', fs=4.6)
    radio(ax, QX + 1.4, PY - 16.8, '文本坐标轴', fs=4.6)
    radio(ax, QX + 1.4, PY - 19.2, '日期坐标轴', on=True, fs=4.6)

    ax.text(QX + 0.9, PY - 22.2, '纵坐标轴交叉', ha='left', va='center', fontsize=4.8,
            color=INK, zorder=14)
    radio(ax, QX + 1.4, PY - 24.6, '自动', fs=4.6)
    radio(ax, QX + 1.4, PY - 27.0, '分类编号', fs=4.6)
    radio(ax, QX + 1.4, PY - 29.4, '最大分类', fs=4.6)

    ax.text(QX + 0.9, PY - 32.4, '坐标轴位置', ha='left', va='center', fontsize=4.8,
            color=INK, zorder=14)
    radio(ax, QX + 1.4, PY - 34.8, '在刻度线上', fs=4.6)
    radio(ax, QX + 1.4, PY - 37.2, '刻度线之间', on=True, fs=4.6)
    checkbox(ax, QX + 1.9, PY - 40.0, '逆序类别', fs=4.6)

    for i, sec in enumerate(('刻度线', '标签', '数字')):
        yy = PY - 43.4 - i * 3.0
        ax.text(QX + 0.9, yy, '▶', ha='left', va='center', fontsize=3.6,
                color='#718096', zorder=14)
        ax.text(QX + 2.4, yy, sec, ha='left', va='center', fontsize=4.8, color=INK,
                zorder=14)
        ax.plot([QX + 0.5, QX + QW - 0.5], [yy - 1.5, yy - 1.5], color='#edf2f7',
                lw=0.6, zorder=14)


def draw_dialog(ax):
    """叠加在报表页上的「编辑时间刻度」对话框。"""
    x, y, w, h = 34.4, 39.8, 24.2, 32.0
    # 投影
    ax.add_patch(Rectangle((x + 0.55, y - h - 0.55), w, h, facecolor='#a0aec0',
                           edgecolor='none', alpha=0.35, zorder=19))
    ax.add_patch(Rectangle((x, y - h), w, h, facecolor='white', edgecolor='#2d3748',
                           linewidth=1.0, zorder=20))
    ax.add_patch(Rectangle((x, y - 3.4), w, 3.4, facecolor='#edf2f7',
                           edgecolor='#2d3748', linewidth=1.0, zorder=21))
    ax.text(x + 1.0, y - 1.7, '编辑时间刻度', ha='left', va='center', fontsize=6.4,
            color='#1a202c', zorder=22)
    ax.text(x + w - 4.4, y - 1.7, '?', ha='center', va='center', fontsize=5.8,
            color='#4a5568', zorder=22)
    ax.text(x + w - 1.5, y - 1.7, '×', ha='center', va='center', fontsize=6.6,
            color='#4a5568', zorder=22)

    lx, cx, cw = x + 1.2, x + 9.4, w - 10.6
    rows = [('单位:', '天', 34.6), ('日期格式(G):', '1/28, 1/29, …', 30.4),
            ('计数:', '1', 26.2), ('开始时间:', '2024年11月12日', 22.0),
            ('完成时间:', '2024年12月4日', 17.8)]
    for lab, val, ry in rows:
        ax.text(lx, ry, lab, ha='left', va='center', fontsize=5.1, color=INK, zorder=24)
        field(ax, cx, ry + 1.4, cw, 2.8, val, fs=5.1, z=24)
        if lab == '计数:':
            ax.add_patch(Rectangle((cx + cw - 2.0, ry + 1.4), 2.0, 1.4, facecolor='#f7fafc',
                                   edgecolor='#a0aec0', linewidth=0.5, zorder=25))
            ax.text(cx + cw - 1.0, ry + 2.1, '▲', ha='center', va='center', fontsize=2.8,
                    color='#4a5568', zorder=26)
            ax.add_patch(Rectangle((cx + cw - 2.0, ry - 0.0), 2.0, 1.4, facecolor='#f7fafc',
                                   edgecolor='#a0aec0', linewidth=0.5, zorder=25))
            ax.text(cx + cw - 1.0, ry + 0.7, '▼', ha='center', va='center', fontsize=2.8,
                    color='#4a5568', zorder=26)
    ax.plot([x + 0.6, x + w - 0.6], [15.4, 15.4], color='#e2e8f0', lw=0.6, zorder=22)
    for lab, bx, bw, fcb in [('确定', x + w - 12.6, 5.8, '#ebf8ff'),
                             ('取消', x + w - 6.4, 5.8, '#f7fafc')]:
        ax.add_patch(Rectangle((bx, 10.9), bw, 3.2, facecolor=fcb, edgecolor='#718096',
                               linewidth=0.7, zorder=22))
        ax.text(bx + bw / 2, 12.5, lab, ha='center', va='center', fontsize=5.2,
                color=INK, zorder=23)


def main():
    setup()
    fig, ax = canvas(15.6, 9.9, xlim=(0, 100), ylim=(0, 100))
    draw_chrome(ax)
    draw_report_page(ax)
    draw_panes(ax)
    draw_dialog(ax)
    save(fig, OUT)


if __name__ == '__main__':
    main()
