Bases: Component
A Vega-Lite spec drawn by vega-embed; data is an optional CSV/TSV/JSON file.
When data is given it is staged into the page and the spec's data
becomes a reference to that file. Scatter is the ready-made plot of
columns against each other; this is a specification in full.
cg.ui.Chart(
spec={
"mark": "bar",
"data": {"values": [{"day": "2026-06-10", "sessions": 3}]},
"encoding": {
"x": {"field": "day", "type": "temporal"},
"y": {"field": "sessions", "type": "quantitative"},
},
}
)
Source code in capturegraph-lib/capturegraph/ui/chart.py
| class Chart(Component):
"""A Vega-Lite ``spec`` drawn by vega-embed; ``data`` is an optional CSV/TSV/JSON file.
When ``data`` is given it is staged into the page and the spec's ``data``
becomes a reference to that file. ``Scatter`` is the ready-made plot of
columns against each other; this is a specification in full.
```python
cg.ui.Chart(
spec={
"mark": "bar",
"data": {"values": [{"day": "2026-06-10", "sessions": 3}]},
"encoding": {
"x": {"field": "day", "type": "temporal"},
"y": {"field": "sessions", "type": "quantitative"},
},
}
)
```
"""
spec: dict[str, JSONValue]
data: Blob | None = None
def html(self, render: Render) -> str:
"""The specification drawn, its ``data`` staged into the page first."""
spec: dict[str, JSONValue] = dict(self.spec)
if self.data is not None:
href = render.stage(self.data)
data: dict[str, JSONValue] = {"url": href}
kind = _FORMATS.get(self.data.suffix.lower())
if kind is not None:
data["format"] = {"type": kind}
spec["data"] = data
return embed(render, spec)
|
html(render)
The specification drawn, its data staged into the page first.
Source code in capturegraph-lib/capturegraph/ui/chart.py
| def html(self, render: Render) -> str:
"""The specification drawn, its ``data`` staged into the page first."""
spec: dict[str, JSONValue] = dict(self.spec)
if self.data is not None:
href = render.stage(self.data)
data: dict[str, JSONValue] = {"url": href}
kind = _FORMATS.get(self.data.suffix.lower())
if kind is not None:
data["format"] = {"type": kind}
spec["data"] = data
return embed(render, spec)
|