use std::time::Instant;
use ratatui_core::{
buffer::Buffer,
layout::{Constraint, Rect},
};
use tui_pantry::{Ingredient, PropInfo, layout::render_centered};
use super::SkeletonLineChart;
use crate::AnimationMode;
const DESCRIPTION: &str = "Braille line chart with filled area below drifting sine-wave traces.";
const PROPS: &[PropInfo] = &[
PropInfo {
name: "elapsed_ms",
ty: "u64",
description: "Timestamp driving the animation cycle",
},
PropInfo {
name: "mode",
ty: "AnimationMode",
description: "Breathe (uniform pulse), Sweep (traveling highlight), Plasma (dual sine waves), Noise (TV noise)",
},
PropInfo {
name: "lines",
ty: "u16",
description: "Number of overlapping wave traces (default: 2)",
},
PropInfo {
name: "filled",
ty: "bool",
description: "Fill area below each wave with █ (default: true)",
},
];
pub fn ingredients() -> Vec<Box<dyn Ingredient>> {
VARIANTS
.iter()
.map(|&(mode, braille, name)| -> Box<dyn Ingredient> {
Box::new(LineChartVariant {
epoch: Instant::now(),
mode,
braille,
variant: name,
})
})
.collect()
}
const VARIANTS: &[(AnimationMode, bool, &str)] = &[
(AnimationMode::Breathe, false, "Breathe (default)"),
(AnimationMode::Sweep, false, "Sweep"),
(AnimationMode::Plasma, false, "Plasma"),
(AnimationMode::Noise, false, "Noise"),
(AnimationMode::Breathe, true, "Braille Breathe"),
(AnimationMode::Sweep, true, "Braille Sweep"),
(AnimationMode::Plasma, true, "Braille Plasma"),
];
fn elapsed_ms(epoch: Instant) -> u64 {
epoch.elapsed().as_millis() as u64
}
struct LineChartVariant {
epoch: Instant,
mode: AnimationMode,
braille: bool,
variant: &'static str,
}
impl Ingredient for LineChartVariant {
fn group(&self) -> &str {
"Line Chart"
}
fn name(&self) -> &str {
self.variant
}
fn source(&self) -> &str {
"tui_skeleton::line_chart"
}
fn description(&self) -> &str {
DESCRIPTION
}
fn props(&self) -> &[PropInfo] {
PROPS
}
fn animated(&self) -> bool {
true
}
fn render(&self, area: Rect, buf: &mut Buffer) {
render_centered(
SkeletonLineChart::new(elapsed_ms(self.epoch))
.mode(self.mode)
.braille(self.braille),
None,
Some(Constraint::Length(10)),
area,
buf,
);
}
}