"""Diagrama forward P/E x venit pentru 11_selectia_simbolului.md (marcaj pe_venit).
Matrice 2x2: coloane = forward P/E (mic / mare), randuri = venit (creste / scade).
Fiecare cifra si eticheta vine din textul din jurul marcajului sau din citatele
lui (vezi caption-ul din josul SVG-ului). Nu e grafic de pret, deci nu foloseste
svg_candles / pchart.
Ruleaza:
.venv/bin/python gen/selectia/pe_venit.py
Scrie gen/selectia/pe_venit.svg (fara dependinte, SVG construit ca string).
"""
import html
import re
from pathlib import Path
W, H = 700, 620
X0, X1 = 120, 660
Y0, Y1 = 110, 520
COL_MID = (X0 + X1) / 2.0
ROW_MID = (Y0 + Y1) / 2.0
C1 = (X0 + COL_MID) / 2.0
C2 = (COL_MID + X1) / 2.0
R1 = (Y0 + ROW_MID) / 2.0
R2 = (ROW_MID + Y1) / 2.0
GRAY, BLUE = "#777", "#1a5fb4"
BLACK = "#000"
TINT = "#eaf1fb"
texts = []
def text(x, y, s, size=14, weight="normal", fill=BLACK, anchor="middle", transform=""):
texts.append((x, y, s, size, weight, fill, anchor, transform))
def cell_outline(x, y, w, h, accent=False):
fill = TINT if accent else "#fff"
stroke = BLUE if accent else "#999"
return (
f''
)
parts = [
f'")
svg = "\n".join(parts) + "\n"
# ---------------------------------------------------------------- verificare in-script
assert 'filter=' not in svg and 'gradient' not in svg, "fara umbre/gradienti"
seen = set()
for m in re.finditer(r']*font-size="(\d+)"', svg):
x, y, size = float(m.group(1)), float(m.group(2)), int(m.group(3))
assert 0 <= x <= W and 0 <= y <= H, f"eticheta in afara panzei: {x},{y}"
assert size >= 13, f"font sub 13: {size}"
key = (round(x), round(y))
assert key not in seen, f"doua texte pe aceeasi pozitie: {key}"
seen.add(key)
assert "~23" in svg and "~15" in svg, "cifrele sursa lipsesc"
OUT = Path(__file__).with_suffix(".svg")
OUT.write_text(svg, encoding="utf-8")
print(f"scris {OUT} ({len(svg)} bytes, {len(texts)} etichete, {W}x{H})")