weirdnet-chart
Real-time charts for Weird Brains apps on Weirdnet: line, area, bar, candlestick, OHLC and volume series with axes, pan, zoom and live updates. The core is renderer-independent and has no GUI dependencies; GPUI and Ratatui backends are optional features.
- Series. Time-ordered ring buffers of points or candles (
Series). Appending is O(1), the oldest samples drop off at capacity, a push with the newest timestamp replaces it in place (a live candle), and trades fold into fixed-interval candles. - Panes. Any number of panes stacked over one time axis, each with its own y axis (auto, auto from zero, or fixed), for example price above volume.
- Axes. "Nice" value ticks with compact labels, and calendar-aware time ticks from milliseconds to decades that land on whole local minutes, hours, days, months and years for a fixed UTC offset.
- Viewport. Pan, zoom around a point, span limits, and following the newest data; panning back to the live edge resumes following.
- Big data, small frames. Only the visible range is laid out. Lines are reduced to the first, lowest, highest and last point per pixel column (spikes and gaps survive), and candles merge into wider bars when they would be thinner than three pixels.
- Frame-rate redraws.
FrameThrottleturns a burst of updates into one frame now and at most one more after the frame interval. - Scenes.
Chart::layoutproduces backend-neutral rectangles, lines, polylines, areas and text in clip layers, so a new backend only has to draw five primitives.
Quick start
[]
= { = "0.1", = ["ratatui"] }
use ;
let mut chart = new;
let candles = chart.add_candles.unwrap;
let volume = chart.add_pane;
chart.add_volume.unwrap;
chart.show_latest;
chart.push_candle.unwrap;
// Live trades update the open candle or start the next one.
chart.apply_trade.unwrap;
Ratatui
ratatui::ChartWidget draws with braille dots (two across and four down per cell) on
ratatui-core, so it works with ratatui 0.30:
use ;
terminal.draw?;
pan_columns; // like dragging four columns right
zoom_columns; // zoom in around a column
Pair it with FrameThrottle::poll and FrameThrottle::timeout in the event loop so live data
redraws at the frame rate. The terminal_snapshot example
renders into a buffer and prints it:
cargo run --example terminal_snapshot --features ratatui.
GPUI
gpui::ChartView is a view that owns the chart, draws it with paths, quads and shaped text,
pans on drag and horizontal scroll, and zooms on vertical scroll. Feed it from a task:
view.update;
update_chart coalesces redraws to 60 frames per second (set_fps changes that).
gpui::paint_scene draws a laid-out scene in your own element or canvas.
The backend builds against gpui 0.2.2 from crates.io. An app that pins GPUI to a git
revision can point this crate at the same revision with [patch.crates-io], as long as that
revision's gpui is semver-compatible. On Linux, GPUI needs the X11, Wayland, xkbcommon,
Vulkan, fontconfig and freetype development packages; on Debian and Ubuntu:
libxkbcommon-dev libxkbcommon-x11-dev libx11-xcb-dev libxcb1-dev libwayland-dev libvulkan-dev libfontconfig-dev libfreetype-dev.
gpui 0.2.2 also pulls in xattr 0.2.3, which needs libc 0.2.189 or older on Linux; this
repository's Cargo.lock pins it there.
Features
| Feature | Default | What it adds |
|---|---|---|
ratatui |
no | ratatui::ChartWidget, render_scene, column-based pan and zoom |
gpui |
no | gpui::ChartView, paint_scene |
gpui-test-support |
no | GPUI's headless test platform, for this crate's own tests |
Time zones
Charts carry no time-zone database. Pass the UTC offset for the visible range with
Chart::set_time_zone(TimeZone::Fixed(seconds)); timestamps are milliseconds since the Unix
epoch.
Licence
BSD-3-Clause, copyright Weird Brains LLC. See LICENSE.