Skip to main content

Crate bland

Crate bland 

Source
Expand description

BLAND — pure-Rust technical drawing.

A library for paper-ready, monochrome, hatch-patterned plots in the visual tradition of 1960s-80s engineering reports. Output is SVG — resolution-independent, prints clean on any printer, embeds cleanly into LaTeX, PDF pipelines, and HTML documents.

DAMPED OSCILLATION0246810-0.500.51t [s]x(t)responseenvelope

§Quick start

use bland::{Figure, PaperSize, Stroke};

let xs: Vec<f64> = (0..=100).map(|i| i as f64 / 10.0).collect();
let ys: Vec<f64> = xs.iter().map(|t| (-t / 4.0).exp() * t.cos()).collect();
let env: Vec<f64> = xs.iter().map(|t| (-t / 4.0).exp()).collect();

let fig = Figure::new()
    .size(PaperSize::A5Landscape)
    .title("Damped oscillation")
    .xlabel("t [s]")
    .ylabel("x(t)")
    .line(&xs, &ys, |s| s.label("response"))
    .line(&xs, &env, |s| s.label("envelope").stroke(Stroke::Dashed))
    .hline(0.0, |s| s.stroke(Stroke::Dotted))
    .legend_top_right();

std::fs::write("oscillation.svg", fig.to_svg()).unwrap();

§Why monochrome?

  • Prints clean. Plots look the same on a laser printer, a color printer, and a photocopy. No “figure unreadable in proceedings” surprises.
  • Accessible by default. Hatching, stroke dashing, and marker shape distinguish series — so plots survive grayscale rendering and are legible to readers with color vision deficiency.

§Histograms with hatched fills

STANDARD NORMAL — 2000 SAMPLES-20200.10.20.30.4zdensitysamples

§Grouped bar charts

TEST BENCH RESULTSABCD0100200300400specimenyield (MPa)trial 1trial 2

§Heatmaps with monochrome ramps

2D GAUSSIAN DENSITY-2-1012-2-1012xy1.62e-60.2460.4920.7380.984density

§Iso-line contours

SIN(X) · COS(Y)-202-202xy

§Box plots with computed Tukey fences

DISTRIBUTION BY GROUPcontroltreated57.51012.515responseQ1–Q3

§Vector fields

VECTOR FIELD F = (−Y, X)-5-2.502.55-5-2.502.55xy

§Polar coordinates

POLAR PLOTSr = 1 + cos θr = |cos 3θ|30°60°90°120°150°180°210°240°270°300°330°

§Smith chart

S₁₁ SWEEPΓ(f)0.20.5125+0.2-0.2+0.5-0.5+1-1+2-2+5-5

§Geographic basemaps

EARTH — MERCATOR-202-1012

§Lunar maria

LUNAR NEAR SIDE — MAJOR MARIA-50050-40-200204060

§Features

  • Series: line, scatter, bar (grouped), area, histogram, heatmap, polygon, error bars, box plots, stem plots, quiver / vector fields, contour iso-lines, reference rules.
  • Hatch patterns: 15 presets — diagonals, crosshatch, dots, brick, zigzag, checker. Build your own via Hatch::DEFAULT_RAMP for heatmap shading.
  • Markers: 12 presets, alternating open / filled / cross variants.
  • Stroke dashes: solid, dashed, dotted, dash-dot, long-dash, fine.
  • Paper presets: A4, A5, Letter, Legal, Square — portrait & landscape.
  • Themes: Theme::report_1972 (serif), Theme::blueprint (monospace), Theme::gazette (newspaper).
  • Engineering TitleBlock with project / drawn-by / date / scale / sheet / revision.
  • Annotations: in-data text and arrows with anti-overlap halos.
  • Linear and log axes with nice-rounded tick placement.
  • Projections: polar, Smith, Mercator, equirectangular.
  • Built-in basemaps: Earth coastlines & borders (Natural Earth 1:110m, optional 1:50m via the high-res-basemaps feature), reference parallels, lunar maria.
  • Multi-panel layouts via multi_panel.
  • Composite helpers: bode, qq_plot.
  • Pure Rust, zero dependencies.

Re-exports§

pub use basemaps::Basemap;
pub use basemaps::BasemapOpts;
pub use basemaps::Resolution;

Modules§

basemaps
Static base-layer data for geographic figures.
gui
Native-webview viewer for Figure.

Structs§

AreaOpts
BarOpts
BodeOpts
Options for bode.
BoxPlotOpts
BoxStats
Box-plot summary: quartiles plus Tukey-fence whisker endpoints. min / max are the inlier whisker endpoints, not the raw extrema — extreme observations are returned in outliers.
ContourOpts
ErrorBarOpts
Figure
The plot document. Build with Figure::new() and chain methods.
GraticuleOpts
Configuration for graticule.
HeatmapOpts
Per-call options for Figure::heatmap.
HistogramOpts
HlineOpts
LineOpts
Per-call options for Figure::line.
PanelGridOpts
Grid layout configuration for multi_panel.
PolarGridOpts
Options for Figure::polar_grid.
PolygonOpts
QqOpts
Options for qq_plot.
QuiverOpts
ScatterOpts
SmithGridOpts
Options for Figure::smith_grid.
StemOpts
Theme
A theme is a bag of typographic, geometric, and stroke defaults. Every figure carries one. Use Theme::report_1972, Theme::blueprint, or Theme::gazette for the built-in presets, then mutate fields directly to derive variants.
TitleBlock
VlineOpts

Enums§

AxesStyle
Whether the figure draws axis lines / ticks at all.
BinStrategy
Strategy for picking the number of bins when bin_edges is not set.
Clip
Plot-area clip shape.
ColorbarPosition
Position for a colorbar attached to a heatmap.
Err
Per-point error: either symmetric half-width or (lower, upper).
GridStyle
Hatch
Hatch pattern preset.
LegendPosition
Marker
Normalize
Normalization mode for histogram bin values.
Origin
PaperSize
Built-in paper presets (dimensions in pixels at 96 DPI).
Projection
Coordinate projection applied to series points before scaling.
Stroke
Dash preset for a stroked element.
TextAnchor
TickDirection
Tick mark direction relative to the plotting frame.
TitleBlockPosition
TitleCase
Title case transform applied to figure titles by some themes.

Functions§

bode
Render a Bode plot — magnitude (dB, log-x) on top, phase (degrees, log-x) on the bottom — as a stacked two-panel SVG. omegas are angular frequencies; mag_db and phase_deg are pre-computed.
boxplot_stats
equirect
Equirectangular / plate carrée — degree-for-degree pass-through.
format_lat
Format a latitude value with N/S suffix.
format_lon
Format a longitude value with E/W suffix.
gamma_from_z
Convert normalized impedance (r, x) to reflection coefficient (Re Γ, Im Γ).
graticule
Generates graticule polylines (meridians + parallels) over the given lon/lat range. Returns a vector of (xs, ys) tuples in degrees — each is one full meridian or parallel ready to be added as a line series.
mercator
Project (lon, lat) in degrees through Mercator. Latitudes are clamped to ±85.051° to avoid infinity at the poles.
multi_panel
Compose figures into a single SVG. Each panel is rendered at its native viewBox and placed into a nested <svg>.
normal_quantile
Inverse standard-normal CDF (probit). Beasley-Springer / Moro approximation; ~1e-9 accurate across the usual range.
polar_circle
Returns (thetas, rs) tracing a full circle of radius r. Useful for concentric reference rings on a polar plot.
polar_from_xy
Inverse of project: Cartesian → (θ, r).
polar_project
Project (θ, r) (polar, radians) to (x, y) (Cartesian).
qq_plot
Returns a Q-Q plot — sample quantiles vs theoretical quantiles of the standard normal — as a fully-built Figure. With reference enabled (default), draws a y = x reference line.
quantile
Linearly-interpolated quantile (R’s “type 7” / NumPy default). p is in [0, 1]. Empty input returns 0.
smith_r_circle
Full circle of constant normalized resistance r in Γ space. Center (r/(r+1), 0), radius 1/(r+1). Tangent to the unit disk at (1, 0).
smith_x_arc
Full circle of constant reactance x. Center (1, 1/x), radius 1/|x|. Only the portion inside the unit disk is meaningful — the figure’s circle clip masks the rest.
z_from_gamma
Inverse: (Γ_re, Γ_im) to (r, x). Returns (NAN, NAN) at Γ = 1.