PlotSpec and headless rendering
PlotSpec is the chart as data: title, axes, ranges, series, theme, and size. It is defined in crisol-plot-core, re-exported by crisol-plot, and rendered by three backends:
| Backend | Entry point | Needs a window? |
|---|---|---|
| Desktop plot | crisol::components::plot::Plot | yes |
| Python | crisol.plot(...), Chart.svg()/png() | no |
| Headless renderer | crisol_plot_render::render_svg/png/pdf | no |
The version field freezes the meaning. A newer spec is rejected instead of being misread.
Build and render
use crisol_plot_core::spec::{PlotSpec, SeriesKind, SeriesSpec};
use crisol_plot_render::{Format, render_pdf, render_png, render_svg};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let spec = PlotSpec::new(640, 360)
.title("Signal")
.x_label("t (s)")
.y_label("V")
.series(SeriesSpec::line("signal", vec![[0.0, 1.0], [1.0, 2.0], [2.0, 1.5]]))
.series(SeriesSpec::scatter("samples", vec![[0.5, 1.4], [1.5, 1.8]]));
let svg = render_svg(&spec)?;
assert!(svg.starts_with("<svg"));
let png = render_png(&spec)?;
assert!(png.starts_with(b"\x89PNG"));
let pdf = render_pdf(&spec)?;
assert!(pdf.starts_with(b"%PDF"));
let json = serde_json::to_string_pretty(&spec)?;
let restored: PlotSpec = serde_json::from_str(&json)?;
assert_eq!(restored, spec);
assert_eq!(restored.series[0].kind, SeriesKind::Line);
assert_eq!(Format::Svg, Format::Svg);
println!("plot spec rendered {} SVG bytes", svg.len());
Ok(())
}PlotSpec::validate checks the size, the version, reversed ranges, and that every series has at least one finite point. The renderer calls it before drawing.
JSON form
A notebook cell, a host message, or a Python call can carry the same document:
{
"version": 1,
"title": "Signal",
"width": 640,
"height": 360,
"x_label": "t (s)",
"y_label": "V",
"series": [
{ "name": "signal", "kind": "line", "points": [[0.0, 1.0], [1.0, 2.0]] }
]
}PlotSpec derives Serialize/Deserialize; PLOT_SPEC_VERSION is the current value. Add optional fields freely, but bump the version when an existing field changes meaning.
Page presets
use crisol_plot_core::spec::{PagePreset, PlotSpec};
let page = PlotSpec::new(900, 600).preset(PagePreset::Journal, 300);
assert!(page.width > 0 && page.height > 0);The same PagePreset values (Screen, HalfPage, Letter, Journal) are used by the desktop PDF export and the Python Chart.
Command-line report
crisol-headless reads a HostSpec, finds its plot widgets, and writes the first one:
cargo run -p crisol-headless -- crates/crisol-headless/fixtures/report.json --out report.svgSee Headless applications for the CLI, the wasm size lane, and the CI matrix.