Align milestone charts and self-share flow

This commit is contained in:
2026-08-14 13:04:09 +02:00
parent aa3b4d02ab
commit 8e34f97afb
4 changed files with 25 additions and 12 deletions

View File

@@ -74,14 +74,16 @@ def render_card(card):
ceiling = float(trend.get("ceiling") or max(total * 1.25, 1.25))
points = [(left + round((_timestamp(point.get("at")) - start_ms) / span * width), top + height - round(float(point.get("total", 0)) / ceiling * height)) for point in raw_points]
target_y = top + height - round(float(trend.get("target") or total) / ceiling * height)
for fraction in (0, 0.25, 0.5, 0.75, 1):
y = top + round(height * fraction)
draw.line((left, y, left + width, y), fill="#dde5ef", width=1)
draw.line((left, target_y, left + width, target_y), fill="#bfdbfe", width=2)
# Exactly five levels: for 20 scans, 5 / 10 / 15 / 20 / 25.
for index in range(1, 6):
value = total * index / 4
y = top + height - round(value / ceiling * height)
is_target = index == 4
draw.line((left, y, left + width, y), fill="#bfdbfe" if is_target else "#dde5ef", width=2 if is_target else 1)
draw.text((left - 15, y - 12), _format_axis(value), font=font("DejaVuSans.ttf", 18), fill=blue if is_target else slate, anchor="ra")
draw.line(points, fill=blue, width=5, joint="curve")
x, y = points[-1]
draw.ellipse((x - 8, y - 8, x + 8, y + 8), fill="#ffffff", outline=blue, width=5)
draw.text((left - 12, target_y - 34), f"{total:,}", font=font("DejaVuSans-Bold.ttf", 20), fill=blue, anchor="ra")
draw.text((left, top + height + 27), trend.get("startLabel") or "Created", font=font("DejaVuSans.ttf", 19), fill=slate)
draw.text((left + width, top + height + 27), trend.get("endLabel") or "Reached", font=font("DejaVuSans.ttf", 19), fill=slate, anchor="ra")
draw.text((870, 530), "VERIFIED SCAN DATA", font=font("DejaVuSans-Bold.ttf", 18), fill=mint)
@@ -97,6 +99,10 @@ def _timestamp(value):
return 0
def _format_axis(value):
return f"{value:g}" if value < 1000 else f"{value:,.0f}"
def post_x(text, card):
oauth = OAuth1Session(required("X_API_KEY"), client_secret=required("X_API_SECRET"), resource_owner_key=required("X_ACCESS_TOKEN"), resource_owner_secret=required("X_ACCESS_TOKEN_SECRET"))
path = render_card(card) if card else None