Datasette Charts updates its developer interface for custom SQLite charts
Datasette Charts 0.4a0 refines its extension interface for third-party chart types. PyPI records the pre-release package, and the release note adds a plugin tutorial and interactive examples.
The 0.4a0 package is available
The Python Package Index has published the 0.4a0 pre-release of datasette-charts. PyPI recorded the first distribution file at 23:58:38 UTC on November 27, or 02:58:38 on November 28 in Istanbul. A Python wheel and a source archive are available. In his release note, Simon Willison said he tried the existing extension mechanism by building an experimental plugin, then revised the interface to address the difficulties it exposed. Datasette provides a web interface for browsing and querying SQLite data. The charting plugin adds visual exploration, and this release focuses on developers who want to supply their own chart types.
Custom chart types register through a hook
The distributed package defines a `register_chart_types` hook through which plugins return chart type classes. A class can supply a name and describe channels such as the horizontal axis, vertical axis and series. A channel can declare whether it needs a column and which aggregations it accepts. For example, a chart can require a category on one axis and accept a row count on the other. The built-in histogram, bar, line, scatter, map and stacked bar types use the same registration mechanism, giving extension authors examples of how a chart declares the data it can work with.
Python prepares the query and JavaScript renders it
The chart type interface has separate steps for proposing a chart from a data profile, generating a query and drawing the result. The compile step can return SQL, bound parameters and a limit on result rows. A JavaScript module then draws those results in the browser. A chart that groups a large table of events by week can query the grouped values and send the renderer just the rows it needs. The chart specification is the contract between the two sides. When a graph looks surprising, developers can inspect the grouped output before checking how the renderer maps it to marks on the screen.
The examples include annotations
The release note also introduces a tutorial for plugin authors and a gallery with interactive examples. The gallery shows features such as horizontal reference lines, shaded ranges and callouts attached to individual points. An annotation can travel in the chart specification, so a shared link can preserve it. For instance, a monthly chart can include a line at the date when a new collection method started. A colleague opening the chart can then see that date alongside the change in the data. A custom chart type declares the kinds of annotation its renderer can draw.
A small table can exercise the extension interface
PyPI marks the release as a pre-release. A developer evaluating it can use a small fixture with two ordinary groups, a missing value and a third group made up of several rows. The query output can establish the expected groups and values before the rendering is checked. A shared chart link can then be reopened to see whether the same series and annotations are present. The published package contains the registration interface described in the release note. Compatibility for a particular installed extension still depends on its channel definitions, dependencies and the version of Datasette it runs on.
Illustrative photo · Nicoguaro / Wikimedia Commons ↗ · CC BY 4.0 · Illustrative chart made in R in 2016. The Wikimedia Commons preview was placed on a white background and converted to WebP.
Sources and verification
- Primary sourceSimon Willison ↗
- Technical documentPyPI release metadata ↗
- BackgroundFreeLLMArena ↗
- Reporting / cross-checkPython Package Index ↗
Reader discussion
Which bottleneck would you expect as this solution scales?
No comments yet. Be the first to contribute.
Write a comment