Skip to main content

LineChart

Struct LineChart 

Source
pub struct LineChart<const N: usize> { /* private fields */ }
Expand description

Gestionnaire du graphique avec axes statiques configurables.

LineChart<N> maintient un historique circulaire de N points de données et gère le rendu du graphique avec grille, axes, graduations et labels.

§Paramètre générique

  • N - Nombre maximum de points historiques (doit être ≤ PLOT_HISTORY_LIMIT = 240)

§Fonctionnement interne

  • Ring buffer : Les données sont stockées dans un tableau fixe avec un pointeur head qui tourne. Quand le buffer est plein, les nouvelles données écrasent les plus anciennes.
  • Historique : Seuls les N points les plus récents sont affichés.
  • Rendu : Les données sont converties en pixels via scale_x() et scale_y(), puis connectées par des lignes (Bresenham).

§Exemple

use embassy_st7789v_plot::{Graphics, AxisConfig, PlotConfig, LineChart};

// Créer la config
let config = PlotConfig {
    x: 10, y: 10, width: 220, height: 200,
    margin_left: 40, margin_right: 10, margin_top: 10, margin_bottom: 30,
    x_axis: AxisConfig::new(0.0, 10.0, 2.0, b"Time"),
    y_axis: AxisConfig::new(0.0, 100.0, 20.0, b"Value"),
    bg_color: Color::BLACK,
    line_color: Color::GREEN,
    axis_color: Color::WHITE,
    grid_color: Color::from_rgb(64, 64, 64),
    text_color: Color::WHITE,
    label_color: Color::CYAN,
};

// Créer et utiliser le graphique
let mut chart: LineChart<100> = LineChart::new(config);
chart.push(10.5);
chart.push(12.3);
chart.push(11.8);

let mut gfx = Graphics::new_no_rst(display);
chart.render(&mut gfx).await;

Implementations§

Source§

impl<const N: usize> LineChart<N>

Source

pub fn new(config: PlotConfig) -> Self

Crée un nouveau gestionnaire de graphique.

§Arguments
  • config - Configuration complète du graphique
§Panics

Panique si :

  • N > PLOT_HISTORY_LIMIT (240)
  • La configuration d’axe X est invalide
  • La configuration d’axe Y est invalide
§Exemple
use embassy_st7789v::{Color};
use embassy_st7789v_plot::{AxisConfig, PlotConfig, LineChart};

let config = PlotConfig {
    x: 10, y: 10, width: 220, height: 200,
    margin_left: 40, margin_right: 10, margin_top: 10, margin_bottom: 30,
    x_axis: AxisConfig::new(0.0, 10.0, 2.0, b"Time"),
    y_axis: AxisConfig::new(0.0, 100.0, 20.0, b"Value"),
    bg_color: Color::BLACK,
    line_color: Color::GREEN,
    axis_color: Color::WHITE,
    grid_color: Color::from_rgb(64, 64, 64),
    text_color: Color::WHITE,
    label_color: Color::CYAN,
};

let chart: LineChart<100> = LineChart::new(config);
Source

pub fn config(&self) -> &PlotConfig

Retourne une référence à la configuration du graphique.

Source

pub fn push(&mut self, value: f32)

Ajoute une nouvelle valeur à l’historique.

Si le buffer est plein (N points), la valeur la plus ancienne est remplacée.

§Arguments
  • value - Valeur à ajouter (sera clampée à la plage Y-axis lors du rendu)
§Exemple
use embassy_st7789v::{Color};
use embassy_st7789v_plot::{AxisConfig, PlotConfig, LineChart};

let config = PlotConfig {
    x: 10, y: 10, width: 220, height: 200,
    margin_left: 40, margin_right: 10, margin_top: 10, margin_bottom: 30,
    x_axis: AxisConfig::new(0.0, 10.0, 2.0, b"Time"),
    y_axis: AxisConfig::new(0.0, 100.0, 20.0, b"Value"),
    bg_color: Color::BLACK,
    line_color: Color::GREEN,
    axis_color: Color::WHITE,
    grid_color: Color::from_rgb(64, 64, 64),
    text_color: Color::WHITE,
    label_color: Color::CYAN,
};

let mut chart: LineChart<100> = LineChart::new(config);
chart.push(50.0);
chart.push(55.5);
Source

pub fn clear(&mut self)

Efface l’historique et réinitialise le graphique.

§Exemple
use embassy_st7789v::{Color};
use embassy_st7789v_plot::{AxisConfig, PlotConfig, LineChart};

let config = PlotConfig {
    x: 10, y: 10, width: 220, height: 200,
    margin_left: 40, margin_right: 10, margin_top: 10, margin_bottom: 30,
    x_axis: AxisConfig::new(0.0, 10.0, 2.0, b"Time"),
    y_axis: AxisConfig::new(0.0, 100.0, 20.0, b"Value"),
    bg_color: Color::BLACK,
    line_color: Color::GREEN,
    axis_color: Color::WHITE,
    grid_color: Color::from_rgb(64, 64, 64),
    text_color: Color::WHITE,
    label_color: Color::CYAN,
};

let mut chart: LineChart<100> = LineChart::new(config);
chart.push(50.0);
chart.clear();
Source

pub async fn render<SPI, DC, RST>(&self, gfx: &mut Graphics<'_, SPI, DC, RST>)
where SPI: SpiDevice, DC: OutputPin, RST: OutputPin,

Affiche le graphique complet avec grille, axes, graduations et courbe.

Cette méthode effectue :

  1. Remplissage du fond
  2. Grille horizontale (Y) et labels des graduations
  3. Grille verticale (X) et labels des graduations
  4. Labels des axes (titres)
  5. Bordures externes
  6. Tracé de la courbe (données)
§Arguments
  • gfx - Contexte graphique initialisé
§Exemple
use embassy_st7789v_plot::{Graphics, AxisConfig, PlotConfig, LineChart};

let config = PlotConfig {
    x: 10, y: 10, width: 220, height: 200,
    margin_left: 40, margin_right: 10, margin_top: 10, margin_bottom: 30,
    x_axis: AxisConfig::new(0.0, 10.0, 2.0, b"Time"),
    y_axis: AxisConfig::new(0.0, 100.0, 20.0, b"Value"),
    bg_color: Color::BLACK,
    line_color: Color::GREEN,
    axis_color: Color::WHITE,
    grid_color: Color::from_rgb(64, 64, 64),
    text_color: Color::WHITE,
    label_color: Color::CYAN,
};

let mut chart: LineChart<100> = LineChart::new(config);
for i in 0..10 {
    chart.push((i as f32) * 10.0);
}

let mut gfx = Graphics::new_no_rst(display);
chart.render(&mut gfx).await;

Auto Trait Implementations§

§

impl<const N: usize> Freeze for LineChart<N>

§

impl<const N: usize> RefUnwindSafe for LineChart<N>

§

impl<const N: usize> Send for LineChart<N>

§

impl<const N: usize> Sync for LineChart<N>

§

impl<const N: usize> Unpin for LineChart<N>

§

impl<const N: usize> UnsafeUnpin for LineChart<N>

§

impl<const N: usize> UnwindSafe for LineChart<N>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.