"""Bubble chart template — flow family. Substitution note: d3-graph-gallery.com's "circular packing" pages (https://d3-graph-gallery.com/graph/circularpacking_basic.html and siblings, confirmed by re-checking https://d3-graph-gallery.com/ circularpacking.html's link list) are all `d3.forceSimulation()` bubble demos with flat dummy data, not `d3.pack()`/`d3.hierarchy()` layouts — the same substitution note hier_circle_pack.py already made for its own nested version of this problem. `flow_bubble` needs a FLAT, already-packed bubble chart (not the nested tree hier_circle_pack.py uses), so this is adapted instead from a different, real, verified flat `d3.pack()` bubble-chart source: https://multimedia.report/classes/coding/2018/exercises/basicbubblepackchart/ — which already builds its hierarchy from a flat list exactly the way this template needs (`d3.hierarchy({children: data}).sum(d => d.value)` then `d3.pack().size([...]).padding(...)`, one circle + centered label per leaf), so no nested-to-flat adaptation was even needed here. Field names are wired to this template's own flat `BubbleData` schema (`label`/`value` instead of the fetched source's CSV `Fruit`/`Amount` columns); circle fill color and the radius-proportional label truncation follow the same conventions already used by hier_circle_pack.py for its own leaf circles. """ from __future__ import annotations from pydantic import BaseModel from app.agents.d3.registry import D3Template, register class Bubble(BaseModel): label: str value: float class BubbleData(BaseModel): title: str = "" data: list[Bubble] _HTML = """
""" golden_sample = BubbleData( title="Demo", data=[ Bubble(label="A", value=10), Bubble(label="B", value=20), Bubble(label="C", value=5), ], ) register( D3Template( id="flow_bubble", family="flow", title="Bubble chart", when_to_use="Show relative size of a flat set of named quantities as packed circles (not a hierarchy).", data_requirements="A flat list of labeled values (no nesting).", schema=BubbleData, html_template=_HTML, golden_sample=golden_sample, ) )