跳到正文
Simon Willison·· 1 天前AI 評分52

datasette-charts 0.1a0 發佈,支援 Datasette 全結果集圖表

datasette-charts 0.1a0

AI 導讀

Simon Willison 發佈 Datasette 圖表插件 datasette-charts 0.1a0,支援以資料表或任意 SQL 查詢建立圖表,並透過聚合查詢涵蓋完整結果集。

正文

I've been thinking about this problem for over a year now, but on Sunday I finally fired up Claude Fable 5.2 to build an initial prototype. The prototype went so well that this is now a full plugin.

You can try it out in Datasette Lite here. It looks like this:

Screenshot of a Datasette table page for a "stats" table showing a new Charts panel. A row of suggested chart thumbnail cards sits at the top, each with a small preview, a title and a plain-English description: "Total downloads per week of date", "Total downloads by package", "Distribution of downloads", "Total downloads per week of date by package" (selected) and "Rows per week of date". A note says suggestions are based on a sample of rows while charts use every row. Below, the selected chart is shown full size as a multi-series line chart of total downloads over time, with a color legend for sqlite-utils, csv-diff, datasette, llm, shot-scraper and Other. A sidebar on the right has dropdowns for Chart type (Line chart), Time (date, per week), Value (downloads, show Total) and Split by (package, keep top 5), plus a checked "Group the rest as Other" option. Under the chart are a "View and edit this chart's SQL" link, a "Copy link to this chart" button, an expandable Data section and a Close button.

The new charts plugin works against any table or arbitrary SQL query in Datasette. It defines several different chart types (using vendored D3, Observable Plot, and topojson-client), each with a set of heuristics for identifying when they might be a good match for a specific set of rows.

Those suggestion thumbnails at the top are actual visualizations driven by the data, and selecting one pulls up the full chart along with tools for modifying it. You can also manually construct a chart from scratch.

As with other Datasette visualization plugins, the current state of your chart is persisted in a #fragment in the URL - so you can bookmark charts or share them with others.

The most important feature is that the charts take all rows into account. Previous charting plugins like datasette-vega would only show charts for the current page of results, generally up to 100 rows.

The new plugin compiles each chart to a SQL query that aggregates across the entire result set (potentially millions of rows) using GROUP BY, time bucketing, and window functions. Each query returns a result capped at 5,000 rows, suitable for display on the chart. The plugin uses sampling to help suggest charts for larger tables without evaluating the full result set.

I'm really happy with this initial release of the plugin. It's still very much an alpha, but it's the closest I've got to the dream of Datasette helping visualize data with as little required direction from the user as possible.

來源:Simon Willison · simonwillison.net