Crate wbi_rs

Crate wbi_rs 

Source
Expand description

§wbi_rs

A lightweight Rust library + CLI to fetch, store, visualize, and summarize World Bank Indicators API data.

§Highlights

  • Synchronous API client (api::Client)
  • Tidy data model (models::DataPoint)
  • Summary stats (stats::grouped_summary)
  • CSV/JSON export (storage)
  • SVG/PNG charts (viz) with legend placement, locale formatting, and multiple plot types

§Feature flags

  • online: enables live API tests/examples. (The library itself works without it.)

Country-consistent styling is available as a runtime option via viz::plot_chart(.., Some(true)) or the CLI --country-styles flag.

§Quick example

use wbi_rs::{Client, DateSpec};
use wbi_rs::viz::{LegendMode, PlotKind};

// 1) Fetch observations
let client = Client::default();
let data = client.fetch(
    &["DEU".into(), "USA".into()],
    &["SP.POP.TOTL".into()],
    Some(DateSpec::Range { start: 2010, end: 2020 }),
    None,
)?;

// 2) Plot to SVG (line chart, legend on the right, English locale)
wbi_rs::viz::plot_chart(
    &data,
    "pop.svg",
    1000,
    600,
    "en",
    LegendMode::Right,
    "Population (2010–2020)",
    PlotKind::Line,
    0.3, // loess_span (ignored unless PlotKind::Loess)
    None, // no country styles in tests
)?;

// 3) Print grouped summary stats
let summaries = wbi_rs::stats::grouped_summary(&data);
for s in summaries {
    println!("{:?}", s);
}

Re-exports§

pub use api::Client;
pub use models::DataPoint;
pub use models::DateSpec;
pub use models::GroupKey;

Modules§

api
models
stats
storage
style
Flexible, testable style assignment system for country-consistent styling.
viz
Visualization utilities: render multi-series charts to SVG or PNG.
viz_plotters_adapter
Adapter helpers to use SeriesStyle with the plotters crate.
viz_style
Styling utilities to consistently map (country, indicator) to colors, shapes, and line styles.