Expand description
§weirdnet-render
Structured data drawn to PNG. Inputs are plain data, not any application’s types:
Table: column names and rows of text cells, drawn as a grid with an 8×8 bitmap font (numbers right-aligned, long cells cut with~, characters without a glyph shown as?).Chart: x values and named series of numbers (gaps allowed), drawn as a line chart;legendnames each series’ color.- JSON describing either one (
json_png,Drawing::from_json):{"columns": ["a", "b"], "rows": [[1, "x"], [2, null]]}, a table;[{"a": 1, "b": "x"}, {"a": 2}], a table whose columns are the keys, sorted;[[1, "x"], [2, "y"]], a table with columns1,2, …;{"x": [0, 1, 2], "series": [{"name": "a", "values": [1, null, 3]}], "width": 900, "height": 320}, a chart (x,widthandheightare optional).
Every entry point checks its input against Limits (columns, rows, cell length, series,
points, image width, height and pixel count, JSON size) and returns an Error instead of
drawing something unbounded. A chart with no finite value is Error::Empty.
use weirdnet_render::{Limits, Table, table_png, json_png};
let t = Table { columns: vec!["name".into(), "temp".into()], rows: vec![vec!["north".into(), "21.5".into()]] };
let png = table_png(&t, &Limits::default()).unwrap();
assert_eq!(&png[1..4], b"PNG");
let png = json_png(r#"{"series":[{"name":"t","values":[1,2,3]}]}"#, &Limits::default()).unwrap();
assert_eq!(&png[1..4], b"PNG");The crate knows nothing about where the data comes from; an application translates its own result types into these (Muninn does that for code-space charts in reports).
BSD-3-Clause. The glyphs come from the font8x8 crate (MIT).
Structs§
- Chart
- A line chart:
xpositions (a missing one is its index) and the series over them. - Limits
- What a caller is willing to have drawn. Anything over a limit is an
Error::TooLarge. - Series
- One line of a chart;
None(or a non-finite number) is a gap. - Table
- A table: column names and rows of cell text (each row as long as
columns).
Enums§
Constants§
- CHART_
HEIGHT - CHART_
WIDTH - Default chart size when JSON does not give one.
Functions§
- chart_
png - Draw the series over x as a
width×heightPNG.Error::Emptywhen no value (or no x) is there to draw. - json_
png - Read JSON text (at most
max_json_bytes) as a table or chart and draw it. - legend
- The legend: series names with their colors’ names, in drawing order.
- render
- Draw a table or a chart.
- table_
png - Draw a table as PNG; its size follows from the text (checked against the limits first).