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
headqui 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()etscale_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>
impl<const N: usize> LineChart<N>
Sourcepub fn new(config: PlotConfig) -> Self
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);Sourcepub fn config(&self) -> &PlotConfig
pub fn config(&self) -> &PlotConfig
Retourne une référence à la configuration du graphique.
Sourcepub fn push(&mut self, value: f32)
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);Sourcepub fn clear(&mut self)
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();Sourcepub async fn render<SPI, DC, RST>(&self, gfx: &mut Graphics<'_, SPI, DC, RST>)
pub async fn render<SPI, DC, RST>(&self, gfx: &mut Graphics<'_, SPI, DC, RST>)
Affiche le graphique complet avec grille, axes, graduations et courbe.
Cette méthode effectue :
- Remplissage du fond
- Grille horizontale (Y) et labels des graduations
- Grille verticale (X) et labels des graduations
- Labels des axes (titres)
- Bordures externes
- 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more