Skip to main content

Crate weirdnet_render

Crate weirdnet_render 

Source
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; legend names 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 columns 1, 2, …;
    • {"x": [0, 1, 2], "series": [{"name": "a", "values": [1, null, 3]}], "width": 900, "height": 320}, a chart (x, width and height are 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: x positions (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§

Drawing
Something to draw, as read from JSON.
Error

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×height PNG. Error::Empty when 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).

Type Aliases§

Result