viz

The viz collection draws charts from tables, maps from rasters and vector layers, and renders reports to HTML and PDF. Every block runs without network and produces the same bytes from the same inputs, so a rerun with nothing changed hits the cache all the way down.

Charts🔗

BlockDescription
viz.histogramDistribution of a numeric column
viz.barA value per category, stacked or grouped
viz.lineA value over an ordered column, one line per group
viz.scatterTwo numeric columns, with an optional trend line
viz.boxDistribution per category
viz.heatmapA value over two categories
viz.vegaliteAny Vega-Lite chart, from a spec

The typed charts take a table and a few column names. Each also outputs the Vega-Lite spec it built: when you need something the form does not offer, take that spec, edit it, and render it with viz.vegalite -- or have ai.viz write one.

A spec for viz.vegalite names its data the way SQL does -- {"data": {"name": "t0"}} for the first connected table -- and gets data from the connected tables only. Specs with data.url, inline data.values, image marks or links are refused before anything renders.

Every chart renders as png, svg, or html (a static page with the SVG inline; it runs no script and loads nothing).

Maps🔗

BlockDescription
viz.raster_mapA raster as a map: one band with a colour map, or three as RGB, optionally over a hillshade
viz.raster_histogram_plotThe distribution of a raster band's values
viz.choroplethVector features shaded by a column, in classes

viz.raster_map reads the raster at the size it will be drawn -- from its overviews when it has them -- so a statewide mosaic needs memory for the picture, not the data. gdal.add_overviews upstream makes that read cheap.

Galleries🔗

Inside a map, a chart block runs once per item. Gather the charts with a reduce:

BlockDescription
viz.contact_sheetA labelled grid of the charts, one PNG
viz.pagesThe charts one per page, as a PDF

Each chart is labelled with its item's key -- the state, the year -- with no extra wiring. Use ${item.key} in a chart's title to label the charts themselves.

Reports🔗

BlockDescription
viz.report_htmlRender a report to sanitized, self-contained HTML
viz.report_pdfPrint that HTML to PDF

A report is a directory: report.md (Markdown with tables; no HTML), optionally specs/<name>.vl.json charts and stats.json named statistics. It is written by ai.report or by you, and the data it cites comes from a base.bundle.

  • Numbers come from statistics. {{stat:mean_biomass}} in the text is replaced by the value of a query in stats.json, run by the renderer over the bundle's tables -- so every number in the report traces to a computation.
  • Figures are ![caption](bundle:<member>) for an image in the bundle, or ![caption](spec:<name>) for a chart in specs/. Any other image -- a path, a URL -- fails the render.
  • The page is safe to open. HTML in the Markdown is shown as text, the result is sanitized, every image is inline, and the page loads nothing from anywhere. The PDF is printed from that same page.

See Writing reports for a walk-through.

Installation🔗

spade install file:///path/to/blocks/viz