ZZoutian/figure2data-database-v2
figure2data databasev2 — 40K v6 合成科研图表数据集(最终交付版) 生成日期:2026-09-17 生成器:generator 1.6.0 / dataset_generation_revision v6(含两次 hotfix) 规模:40,000 样本(10 图族 / 33 亚型;area、matrix 冻结不生成,set_relation 已删除) 目录结构 databasev2/ ├── figure2data.sqlite3 # 主数据库(2.0 GB:40,000 samples / 280,000 documents) ├── schema/ # sqlite schema ├── shards/ # 数据资产(shard = (样本序号-1)//1000) │ └── shard_000 .. shard_039/ │ ├── images/ # PNG… See the full description on the dataset page: https://huggingface.co/datasets/ZZoutian/figure2data-database-v2.
06.3k
1"""database_yh §14.2 test_renderer_waterfall:浮动柱 + 累积域 y-lim(§7)。"""2 3from __future__ import annotations4 5import numpy as np6import pytest7 8from databasev1.recipes import get_recipe9from databasev1.recipes.registry import build_context, finalize_panel10import random11 12 13@pytest.mark.parametrize("seed", [2, 7, 13, 41])14def test_waterfall_bars_visible(make_docs, audit, seed):15 docs, rendered = make_docs("bar", "waterfall", seed=seed)16 bad = [i for i in audit("t", docs)17 if i["check"] in ("bbox_bounds", "panel_bounds", "semantic_contract")]18 assert not bad, f"seed={seed}: {bad[:3]}"19 gp = rendered["gt"]["panels"][0]20 box = gp["plot_bbox_px"]21 for sg in gp["series_geometry"]:22 for rect in sg.get("rects_px") or []:23 x1, y1 = max(rect[0], box[0]), max(rect[1], box[1])24 x2, y2 = min(rect[2], box[2]), min(rect[3], box[3])25 inter = max(0.0, x2 - x1) * max(0.0, y2 - y1)26 area = max(1e-9, (rect[2] - rect[0]) * (rect[3] - rect[1]))27 assert inter / area >= 0.5, f"柱体不可见: rect={rect} plot={box}"28 29 30def test_waterfall_ylim_covers_cumulative():31 """§7.2:y 轴 lim 覆盖 start + 全部中间累积 + end(recipe 级确定性断言)。"""32 for seed in range(12):33 ctx = build_context(family="bar", subtype="waterfall", difficulty="medium",34 style_group="scientific_default", rng=random.Random(seed),35 panel_id="panel_1", seed_base=seed)36 p = finalize_panel(get_recipe("bar", "waterfall")["fn"](ctx["rng"], ctx))37 lim = p["axes"]["y"].get("lim")38 assert lim is not None, "waterfall 缺显式 y lim"39 assert p["extras"]["bar"]["zero_base"] is False40 s = p["series"][0]41 base = np.asarray(s["base"], float)42 vals = np.asarray(s["values"], float)43 lo_v = float(np.min(np.minimum(base, base + vals)))44 hi_v = float(np.max(np.maximum(base, base + vals)))45 assert lim[0] <= lo_v + 1e-9 and lim[1] >= hi_v - 1e-9, \46 f"seed={seed}: lim={lim} 未覆盖柱体域 [{lo_v:.3g},{hi_v:.3g}]"47 # §11.1:矩形数 == 类别数48 assert len(s["truth"]["value"]) == len(s["truth"]["category"])49 