Skip to main content

ChartModel

Trait ChartModel 

Source
pub trait ChartModel {
    // Required methods
    fn x_extent(&self) -> Option<(f64, f64)>;
    fn y_axis(&self, pane: usize, x: &Axis) -> Option<Axis>;
    fn paint(
        &self,
        pane: usize,
        plot: &Plot,
        canvas: &mut Canvas<'_>,
        palette: &ChartPalette,
    );

    // Provided methods
    fn x_kind(&self) -> AxisKind { ... }
    fn x_step(&self) -> Option<f64> { ... }
    fn panes(&self) -> usize { ... }
    fn pane_weight(&self, pane: usize) -> f32 { ... }
    fn pane_title(&self, _pane: usize) -> &str { ... }
    fn category(&self, index: usize) -> Option<&str> { ... }
    fn prepare(&mut self) { ... }
    fn describe(&self) -> String { ... }
}
Expand description

The data of a chart widget (densa_widgets::Chart): panes stacked top to bottom on one horizontal axis, each drawing its own series (candles over a line, volume bars below).

The widget decides what part of x shows (it follows the newest data until the user pans or zooms) and asks each pane for its vertical axis over that part, so panes scale to what is on screen. Painting goes through the series functions of this crate, which allocate nothing.

Required Methods§

Source

fn x_extent(&self) -> Option<(f64, f64)>

The lowest and highest x of the data, or None while there is none. On a Category axis, the edges of the places: (-0.5, n - 0.5) for n bars, so a view of all of them shows every bar whole.

Source

fn y_axis(&self, pane: usize, x: &Axis) -> Option<Axis>

The vertical axis of pane pane while x shows: what its series need, with room around them (see Axis::padded); None if it has nothing there.

Source

fn paint( &self, pane: usize, plot: &Plot, canvas: &mut Canvas<'_>, palette: &ChartPalette, )

Draws the series of pane pane onto plot, in palette’s colors.

Provided Methods§

Source

fn x_kind(&self) -> AxisKind

What the horizontal axis counts.

Source

fn x_step(&self) -> Option<f64>

The distance between two points (a candle’s period, 1.0 between bars), if the data has one: the widget zooms in no further than a few of them, or than all of them when there are fewer.

Source

fn panes(&self) -> usize

How many panes, top to bottom (one is drawn even for zero).

Source

fn pane_weight(&self, pane: usize) -> f32

Pane pane‘s share of the height, against the others’ (above zero).

Source

fn pane_title(&self, _pane: usize) -> &str

The name of pane pane (“Volume”), written on a line of its own above the pane, cut off where the pane ends. A pane without a name (empty, the default) has no such line.

Source

fn category(&self, index: usize) -> Option<&str>

The name of place index of a Category x axis, written under it and in the crosshair’s box; None (the default) for none there.

Source

fn prepare(&mut self)

Called before every frame is painted, to catch up with new data. Does nothing by default.

Source

fn describe(&self) -> String

What the chart shows, for screen readers (“ACME, one-minute candles, last 182.40”). Asked only while one is listening. Empty by default.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§