| 135 | |
| 136 | |
| 137 | def write_svg() -> None: |
| 138 | chart_bottom = TOP + (len(ROWS) - 1) * ROW_H + 40 |
| 139 | parts = [ |
| 140 | f'<svg xmlns="http://www.w3.org/2000/svg" width="{W}" height="{H}" viewBox="0 0 {W} {H}">', |
| 141 | '<rect width="100%" height="100%" fill="white"/>', |
| 142 | f'<circle cx="{LEFT + 8}" cy="26" r="8" fill="{rgb(CLOSED)}"/>', |
| 143 | f'<text x="{LEFT + 24}" y="32" font-family="Times New Roman" font-size="21" fill="{rgb(TEXT)}">Closed</text>', |
| 144 | f'<circle cx="{LEFT + 134}" cy="26" r="8" fill="{rgb(OPEN)}"/>', |
| 145 | f'<text x="{LEFT + 150}" y="32" font-family="Times New Roman" font-size="21" fill="{rgb(TEXT)}">Open</text>', |
| 146 | ] |
| 147 | |
| 148 | for tick in [10, 20, 30]: |
| 149 | x = x_pos(tick) |
| 150 | parts.append(f'<line x1="{x}" y1="{TOP - 18}" x2="{x}" y2="{chart_bottom}" stroke="{rgb(GRID)}" stroke-width="1"/>') |
| 151 | parts.append( |
| 152 | f'<text x="{x}" y="{chart_bottom + 28}" font-family="Times New Roman" ' |
| 153 | f'font-size="19" text-anchor="middle" fill="{rgb(MUTED)}">{tick}M</text>' |
| 154 | ) |
| 155 | parts.append( |
| 156 | f'<text x="{LEFT}" y="{chart_bottom + 68}" font-family="Times New Roman" ' |
| 157 | f'font-size="19" fill="{rgb(TEXT)}">TokenCost (million tokens, lower is better)</text>' |
| 158 | ) |
| 159 | |
| 160 | for idx, (name, group, tokens) in enumerate(ROWS): |
| 161 | y = TOP + idx * ROW_H |
| 162 | value = tokens / 1_000_000 |
| 163 | color = color_for(group, name) |
| 164 | label_color = PAPERFLOW if name == "PaperFlow" else TEXT |
| 165 | x_end = x_pos(value) |
| 166 | parts.append(f'<line x1="{LEFT}" y1="{y + 24}" x2="{RIGHT}" y2="{y + 24}" stroke="rgb(244,244,244)" stroke-width="1"/>') |
| 167 | parts.append( |
| 168 | f'<text x="{LEFT - 22}" y="{y + 8}" font-family="Times New Roman" ' |
| 169 | f'font-size="24" font-weight="700" text-anchor="end" fill="{rgb(label_color)}">{name}</text>' |
| 170 | ) |
| 171 | parts.append( |
| 172 | f'<rect x="{LEFT}" y="{y - BAR_H / 2}" width="{x_end - LEFT}" height="{BAR_H}" ' |
| 173 | f'rx="5" fill="{rgb(color)}"/>' |
| 174 | ) |
| 175 | parts.append( |
| 176 | f'<text x="{x_end + 12}" y="{y + 8}" font-family="Times New Roman" ' |
| 177 | f'font-size="22" font-weight="700" fill="{rgb(color)}">{value:.1f}M</text>' |
| 178 | ) |
| 179 | |
| 180 | parts.append("</svg>") |
| 181 | SVG_OUT.write_text("\n".join(parts), encoding="utf-8") |
| 182 | |
| 183 | |
| 184 | def main() -> None: |