latkit¶
latkit is a GPU-accelerated visualization library for large networks, such as power grids. It renders interactive views in the browser with WebGPU, and images and video from the command line.
The 70,000-bus ACTIVSg70k grid as one 765 kV line opens: a DC power flow finds where its power goes,
amber on the branches that pick it up and cyan on those it leaves, and each bus stands as high as its
frequency. Drawn by the latkit command line in the Line opening example.
Install¶
npm install latkit # in the browser
cargo install latkit-cli # pictures and video from the command line
cargo add latkit # in Rust
Quickstart¶
quickstart(canvas) draws a dataset on a canvas; destroy the gpu and data it returns when the
page is done with them. The package’s consumer test type-checks and renders this file.
import { loadLatkit, Patch, field, type Scene } from 'latkit';
/** A complete, type-checked example, also rendered by the installed-package test. */
export async function quickstart(canvas: HTMLCanvasElement) {
const { Data, Gpu } = await loadLatkit();
const data = new Data('grid').apply(
new Patch().replace('Bus', [101, 102], { x: [0, 30], y: [0, 20], kv: [230, 115] }),
);
const scene: Scene = {
space: 'plane',
marks: [
{
vertices: {
of: ['grid', 'Bus'],
position: ['x', 'y'],
radius: 6,
color: field('kv').colormap('viridis'),
},
},
],
};
const gpu = await Gpu.create();
const view = gpu.view(scene);
gpu.canvas(canvas).show([view]);
view.setData(data);
view.fit();
return { gpu, view, data };
}
A dataset is named tables of columns, changed by patches. A scene says what to draw:
marks naming tables, in a space, with a theme and controls. A view draws a scene from the
datasets it is given, on a canvas or into pictures. Scenes, expressions, and patches are plain data
that need no WebAssembly; loadLatkit() loads it for data and drawing.
Examples¶
- ACTIVSg10k
1,456 machines swinging after a fault, traced from a recording on a plot.
- Globe
Routes along great circles on a globe, comets flowing on them.
- Diagram
Blocks in nested groups, laid out and wired port to port.
- Terrain
112,000 lit faces in three dimensions.
- Clifford
260,000 translucent points of a strange attractor.
Every picture is drawn by latkit; the Examples hold them all with the code that draws them. The Guide covers data, scenes, views, and pictures, the Command line draws them from JSON, Performance measures what each costs, and the reference lists every option.