Commit 5b04bea
feat(tooling): local style-variant experimentation script (#6378)
## Summary
Adds `scripts/style-experiment.py` — a local sandbox for A/B-testing
plot style variants (canvas size, fonts, palette, line weights, ...) on
real spec/library combos before committing to a style change. Motivated
by the observation that the current 4800×2700 canvas with title=24pt /
axis=20pt / tick=16pt / line=3 looks crisp at detail view (1600 px) but
shrinks to **<8 px effective text** at thumbnail / mobile display sizes.
Rather than guess at the right new defaults, this script lets us render
the same spec×library through several variants in one shot and compare
side-by-side at multiple display widths.
## How it works
- Mimics `agentic/workflows/modules/regen/render.py` exactly: `uv run
python -P <impl>`, `MPLBACKEND=Agg`, `ANYPLOT_THEME=<theme>`, xvfb
fallback for headless bokeh.
- Patches the implementation source **in place** and restores it via
`try/finally` + `atexit` + SIGINT/SIGTERM/SIGHUP handlers. In-place is
required because some impls (highcharts) resolve
`Path(__file__).parents[3]` for shared assets and break if the file is
copied to a temp dir.
- All output (PNG + HTML + run logs + manifest.json + compare.html)
lands under `/tmp/anyplot-style-experiments/<timestamp>/` — never inside
the repo, never on GCS.
- Pre/post `git diff --name-only plots/` check guards against patches
not being restored on hard kills.
## Starter variants (`scripts/style-variants.yaml`)
| variant | what it does |
|---|---|
| `baseline` | unchanged production style |
| `smaller_canvas` | 4800×2700 → 2400×1350 (effective text doubles at
thumbnail scale) |
| `bigger_fonts` | title 24→40pt, axis 20→32pt, tick 16→26pt, line 3→5 |
| `combo_smaller_canvas_modest_fonts` | halved canvas + modest font bump
(28/22/18) |
| `palette_tableau` | swap Okabe-Ito for Tableau-10 (sanity check, not a
real proposal) |
New variants are pure YAML — no script changes. Patches are `{find,
replace}` literal or `{regex, replace}` and can be keyed per-library or
`"*"` for all.
## Usage
```bash
uv run python scripts/style-experiment.py \
--spec scatter-basic --spec dendrogram-basic \
--library matplotlib --library plotly \
--variant baseline --variant smaller_canvas --variant bigger_fonts \
--theme both --open
```
The generated `compare.html` shows rows = (spec, library), columns =
variants × {light, dark}, with a dropdown to toggle thumbnail width
between 160 / 320 / 640 / 1200 px — the same render evaluated at mobile
/ grid / detail / large display scale.
## Verified
- Smoke test on `scatter-basic / matplotlib / [baseline, smaller_canvas]
/ light` → baseline produces 4766×2672, smaller_canvas produces
2375×1342 (exactly half), both PNGs render correctly, `git status` clean
on `plots/` after the run.
- `uv.lock` is bumped 2.2.0 → 2.3.0 to sync with `pyproject.toml`.
## Test plan
- [ ] Run on 2–3 specs across matplotlib + plotly + altair with all 5
starter variants
- [ ] Open `compare.html` and step through the thumbnail-width toggle to
evaluate readability at mobile (160 px) and grid (320 px) scales
- [ ] Confirm `git status` stays clean on `plots/` after every run
- [ ] Pick a winning variant (or define a new one in YAML) and follow up
with a PR that updates `prompts/default-style-guide.md` +
`prompts/library/*.md`
https://claude.ai/code/session_01LnqUDs4Fpo1d87qeHbvVx6
---
_Generated by [Claude
Code](https://claude.ai/code/session_01LnqUDs4Fpo1d87qeHbvVx6)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 69307ac commit 5b04bea
3 files changed
Lines changed: 555 additions & 1 deletion
0 commit comments