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.1.1

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.1.1
File Size Uploaded
spaday_vega-0.1.1.tar.gz 1.5 MB Details

Built distribution (wheel)

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

Total release size: 2.9 MB

Release files / spaday_vega-0.1.1.tar.gz

Download URL spaday_vega-0.1.1.tar.gz
Size 1.5 MB
Tags Source
SHA-256 checksum
How to use checksums
cfb7800df5f14958a3cdaf291408baf5063bec6f69ab5d747e24a80f63989627
BLAKE2b-256 checksum
How to use checksums
0012a0d9eacf3cef8415f325ad19d597ce15a8581a7f4b6b4ad99dd6922b3a7b
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.1.1-py3-none-any.whl

Download URL spaday_vega-0.1.1-py3-none-any.whl
Size 1.5 MB
Tags Python 3
SHA-256 checksum
How to use checksums
2d1366591dde46c495c3389ba4b35308752a40d7df2ea5801a459efb6cbd72e0
BLAKE2b-256 checksum
How to use checksums
91de9cad244ca3bf274230a630b1b585bd1c62b46a94af496fabb003225bfd05
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

0.2.0

2 release files

This release

0.1.1 This release

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