Skip to main content
spaday-vega logo, a star field inside a browser window

Declarative Vega and Vega-Lite visualizations for spaday.

Build Status codecov License PyPI

Usage

VegaChart accepts either grammar through the same typed Python component. Vega-Embed selects the correct runtime from the specification's $schema.

from spaday.backends.starlette import serve
from spaday_vega import VegaChart, package

spec = {
    "$schema": "https://vega.github.io/schema/vega-lite/v6.json",
    "data": {"name": "values"},
    "datasets": {"values": []},
    "mark": "bar",
    "encoding": {
        "x": {"field": "category", "type": "nominal"},
        "y": {"field": "value", "type": "quantitative"},
    },
}
data = {"values": [{"category": "A", "value": 12}, {"category": "B", "value": 21}]}

page = VegaChart(spec=spec, data=data, renderer="svg", actions=False)
app = serve(page, packages=[package], title="Vega-Lite chart")

data maps Vega dataset names to rows and signals maps signal names to values. Updating either property applies the change to the current view, preserving scroll position and chart interaction state. Set signal_listeners to the signal names that should produce vega-signal events; each event contains the signal's name and value in detail.

The bundled <vega-chart> custom element dispatches vega-ready after rendering, vega-update after applying data or signals, and vega-error when either operation fails. It also accepts serializable Vega-Embed options. Updating spec, options, renderer, or actions redraws the visualization and finalizes the previous view.

The element exposes its Vega view property for JavaScript code that needs the rest of the View API.

Theming

Chart defaults follow spaday's shell palette. Set a component token on the chart or any ancestor to theme Vega without changing its specification:

Token Controls Shell fallback
--spa-vega-background Chart background --spa-surface
--spa-vega-text Titles, guides, and text marks --spa-muted
--spa-vega-axis Axis domains and ticks --spa-muted
--spa-vega-grid Grid lines and legend gradient outline --spa-border
--spa-vega-mark Default mark color --spa-accent
--spa-vega-danger Rendering errors --spa-danger

These are Vega configuration defaults. Colors declared by the specification or options.config still win. Python authors can discover the same mapping as spaday_vega.TOKENS and set a token with VegaChart(...).css(spa_vega_mark="#4c78a8").

Browser examples

The browser example runs Python through Pyodide, so it needs no install or server. Each timer event travels from the browser to a Python model through Spaday and transports. Python returns three named datasets and a Vega signal, and each chart applies them to its existing view. Hovering a point sends a watched Vega signal back through Spaday and transports. The example includes native Vega and Vega-Lite specifications.

Run the examples locally

python -m pip install -e ".[examples]"
python -m spaday_vega.example

Open http://127.0.0.1:8028 for the example.

Metadata

Release files for spaday-vega 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spaday-vega 0.2.0
File Size Uploaded
spaday_vega-0.2.0.tar.gz 1.5 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for spaday-vega 0.2.0
File Interpreter ABI Platform
spaday_vega-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 2.9 MB

Release files / spaday_vega-0.2.0.tar.gz

Download URL spaday_vega-0.2.0.tar.gz
Size 1.5 MB
Tags Source
SHA-256 checksum
How to use checksums
18205fa0826f74ab7e7dd25e6f83815278155ca8609d717d2ee1d0e5b39fe7bb
BLAKE2b-256 checksum
How to use checksums
db78ffa8657771f18276b32efd9730ca76e7879acb88cd68059836bf706ae035
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / spaday_vega-0.2.0-py3-none-any.whl

Download URL spaday_vega-0.2.0-py3-none-any.whl
Size 1.5 MB
Tags Python 3
SHA-256 checksum
How to use checksums
830e11358e52902c500e33e225f662312044440d8651719cc8c15ae49cccf644
BLAKE2b-256 checksum
How to use checksums
e1aa0b4bdb752fc8b2348f5d5ea86ace9a571c947e61b32dd462234dab11a645
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page