Skip to main content

spaday-vega

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.

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.

[!NOTE] This library was generated using copier from the Base Python Project Template repository.

Metadata

Release files for spaday-vega 0.1.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.1.0
File Size Uploaded
spaday_vega-0.1.0.tar.gz 1.5 MB Details

Built distribution (wheel)

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

Total release size: 2.9 MB

Release files / spaday_vega-0.1.0.tar.gz

Download URL spaday_vega-0.1.0.tar.gz
Size 1.5 MB
Tags Source
SHA-256 checksum
How to use checksums
55a51d3a8f535dd3aef002a446180cd12eb26704c9455183a4a0a3194397eafd
BLAKE2b-256 checksum
How to use checksums
366e6582b8f652a3fe4e2084844cbcf5fba0c16379518d1640434e99cfe91898
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.0-py3-none-any.whl

Download URL spaday_vega-0.1.0-py3-none-any.whl
Size 1.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
c2f167b8643ea8df6d7ce73374250e68efe58b4b707137dd2562ccfd1a530b1e
BLAKE2b-256 checksum
How to use checksums
651829cab628c8e6f4b1549e0ca433dfca93df0ba11e3939cb93769ff972a4ad
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

0.1.1

2 release files

This release

0.1.0 This release

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