Skip to main content

Crate weirdnet_chart

Crate weirdnet_chart 

Source
Expand description

Real-time charts for Weird Brains apps: a renderer-independent core with optional GPUI and Ratatui backends.

The core has no GUI dependencies. It holds time-ordered series in ring buffers (Series), arranges them in panes over one time axis (Chart), tracks the visible window with pan, zoom and live following (Viewport), and lays the visible part out as backend-neutral primitives (Scene) with “nice” value ticks and calendar-aware time ticks. FrameThrottle turns a stream of live updates into redraws at the frame rate.

use weirdnet_chart::{Candle, Chart, Metrics, Pane, Size, YRange, time::MINUTE};

let mut chart = Chart::new();
let candles = chart.add_candles(Chart::MAIN, "BTC-USD").unwrap();
let volume = chart.add_pane(Pane { weight: 1.0, y_range: YRange::AutoFromZero, title: None });
chart.add_volume(volume, candles).unwrap();
chart.show_latest(60 * MINUTE);

// History, then live trades folded into one-minute candles.
chart.push_candle(candles, Candle::new(0, 100.0, 101.0, 99.5, 100.5, 12.0)).unwrap();
chart.apply_trade(candles, 61_000, 100.7, 0.5, MINUTE).unwrap();

let scene = chart.layout(Size::new(800.0, 400.0), &Metrics::PIXELS);
assert_eq!(scene.panes.len(), 2);

§Features

  • ratatui: ratatui::ChartWidget, a Ratatui widget drawn with braille dots.
  • gpui: [gpui::ChartView], a GPUI view drawn with paths and quads, with pan and zoom.

Re-exports§

pub use chart::Chart;
pub use chart::ChartError;
pub use chart::Mark;
pub use chart::Pane;
pub use chart::PaneId;
pub use chart::SeriesId;
pub use chart::SeriesStyle;
pub use chart::Theme;
pub use chart::YRange;
pub use color::Rgba;
pub use scale::LinearScale;
pub use scale::TimeTick;
pub use scene::Align;
pub use scene::Layer;
pub use scene::Metrics;
pub use scene::PaneLayout;
pub use scene::Pos;
pub use scene::Primitive;
pub use scene::Rect;
pub use scene::Scene;
pub use scene::Size;
pub use series::Candle;
pub use series::Change;
pub use series::OutOfOrder;
pub use series::Point;
pub use series::Sample;
pub use series::Series;
pub use throttle::FrameThrottle;
pub use throttle::Redraw;
pub use time::TimeZone;
pub use time::Timestamp;
pub use viewport::Viewport;

Modules§

chart
The chart: panes, series, theme, viewport and live updates.
color
Colours.
ratatui
A Ratatui backend (feature ratatui).
scale
Scales and axis ticks: linear value scales, “nice” numeric ticks and calendar-aware time ticks.
scene
Layout: turning the visible part of a Chart into backend-neutral drawing primitives.
series
The series model: time-ordered ring buffers of points or candles, live updates and downsampling.
throttle
Frame-rate throttling for live redraws.
time
Timestamps, fixed-offset time zones and calendar helpers for time axes.
viewport
The visible time window: pan, zoom and following the live edge.