Flow maps that read like a metro map. Instead of one line per
origin–destination pair, milkflow aggregates places, keeps the pairs that
matter, routes every flow through a few shared corridors and draws the
result — with widths by volume and an honest account of what was left out.
The same data as one straight line per pair:
Experimental. Version 0.1: the API and the drawing contract may change before 1.0. A corridor is a graphical aggregation, not an observed route.
Documentation, gallery and a playground that runs in the browser: https://strategicprojects.github.io/milkflow/ (English, Português, Español, Français).
- Corridors, not spaghetti: a sparse skeleton (Delaunay + pruning) that all flows are routed through; classed widths (1–2–5); every figure says how much of the volume it shows.
- Three layouts: geographic, pinned (places stay on the map, segments bend to 0°/45°/90°) and schematic (octilinear, like a transit diagram).
- Lines by category: one coloured line per category (transport mode, product, period…), ordered to avoid crossings.
- Filters for dense matrices: top-k per place, dominant flows (Nystuen & Dacey), disparity (Serrano et al.), largest, share, threshold.
- Outputs: SVG, a self-contained interactive HTML page (zoom, focus, rich
tooltips), TikZ for LaTeX, vector PDF from the command line (
--pdf, in a build with--features pdf), GeoJSON for web maps and GIS (--geojson, optiongeojson: the drawn figure as GeoJSON — each paint operation in paint order, in the input's coordinates (reproject before using it as RFC 7946 lon/lat);places[].usestells which segments/categories each place's flows use), and a JSON drawing contract for your own renderer. - Styles: themes (light, dark, print, base map), palettes, parallel rails, one lane per direction, round / mitre / smooth corners; legends and tooltips in Portuguese, English, Spanish or French.
- Deterministic: the same input gives the same bytes from Rust, JavaScript (WebAssembly), Python and R.
| Language | Package | Source |
|---|---|---|
| Rust | milkflow (library), milkflow-cli (command line) |
crates/milk, crates/milk-cli |
| JavaScript / TypeScript | milkflow (WebAssembly) |
crates/milk-wasm |
| Python | milkflow |
crates/milk-py |
| R | milkflow |
r/milkflow |
The Rust, JavaScript and Python packages are on crates.io, npm and PyPI
(cargo add milkflow, npm install milkflow, pip install milkflow); the
R package is not on CRAN yet and installs from this repository.
brew install strategicprojects/tap/milkflow # Homebrew, macOS and Linux
cargo install milkflow-cli # or with Rust 1.85 or later
milkflow exemplos/cidade.json --schematic --html --out out --name city
# out/city-corredores.svg the corridors, geographic
# out/city-esquematico.svg the schematic drawing
# out/city.html the interactive page
# out/city-spec.json the drawing contractmilkflow INPUT.json takes a JSON file with nodes (id, x, y, and
optionally label, group) and flows (origin, destination, value,
optionally category). A few options:
milkflow in.json --pin --corners smooth # places stay on the map
milkflow in.json --schematic --theme dark --palette amber
milkflow in.json --directions split --direction-colours
milkflow in.json --filter dominant --group # dominant flows between groups
milkflow in.json --aggregate 30 # 30 places, neighbours merged (Ward)
milkflow in.json --tikz standalone --lang fr # LaTeX, French legend
milkflow in.json --geojson # NAME.geojson, in the input's coordinates
milkflow in.json --schematic --pdf # NAME.pdf, NAME-esquematico.pdf--aggregate K merges neighbouring places without groups of your own
until K remain, each group drawn at and named after its heaviest place;
--aggregate-keep id1,id2 protects nodes. --aggregate-method ward (the
default) merges the neighbouring pair of least
m_a·m_b/(m_a+m_b)·d² between mass-weighted centroids (compact groups of
similar weight); --aggregate-method gravity sends the lightest group to
its near neighbour of largest mass / distance² (heavy neighbours stay
apart). Near neighbours are the Delaunay edges that are
Gabriel edges (they jump over no place) no longer than 4 times their median;
a place without one (an island, a far capital) stays alone and does not
count in K, and a warning says so. Both methods are spatial heuristics:
they ignore who exchanges flow with whom.
--pdf needs the optional pdf feature (cargo install … milkflow-cli --features pdf): the SVG is converted by rpic-render (svg2pdf, the Go
font embedded, no system dependency), with the labels laid out again for the
Go font's widths. tools/pdf.sh remains the LaTeX route (--tikz standalone).
The Homebrew formula is in packaging/homebrew/.
let out = milkflow::pipeline::run_json(input_json, r#"{"schematic": true}"#)?;import { flowmap } from "milkflow";
const { svg, schematicSvg, spec } = flowmap(input, { schematic: true });import milkflow
m = milkflow.flowmap(nodes, flows, schematic=True)
m.svglibrary(milkflow)
m <- flowmap(nodes, flows, schematic = TRUE)
plot(m)cargo test --workspace # the core and the command line
crates/milk-wasm/build.sh # the npm package (needs wasm-pack)
site/build.sh # the documentation site, into site/dist
tools/galeria.sh # a gallery of styles, into out/galeriaMinimum Rust version: 1.85.
Each release is archived at Zenodo. The DOI
10.5281/zenodo.24779953 always
points to the latest version; version 0.1.0 is
10.5281/zenodo.24779954. The
metadata for a citation are in CITATION.cff.
MIT or Apache-2.0, at your option.