schwab_cli/ui/
chart_markers.rs1use ratatui::style::{Color, Modifier, Style};
4use ratatui::text::{Line, Span};
5use ratatui::widgets::canvas::{Context, Line as CanvasLine};
6
7pub fn marker_spans(x_min: f64, x_max: f64, y_min: f64, y_max: f64) -> (f64, f64) {
9 let x_span = (x_max - x_min).max(1.0);
10 let y_span = (y_max - y_min).max(1.0);
11 (x_span * 0.04, y_span * 0.08)
12}
13
14pub fn draw_chart_marker(
16 ctx: &mut Context<'_>,
17 x: f64,
18 y: f64,
19 hx: f64,
20 hy: f64,
21 color: Color,
22 glyph: &'static str,
23) {
24 ctx.draw(&CanvasLine::new(x - hx, y, x + hx, y, color));
25 ctx.draw(&CanvasLine::new(x, y - hy, x, y + hy, color));
26 ctx.print(
27 x,
28 y,
29 Line::from(Span::styled(
30 glyph,
31 Style::default().fg(color).add_modifier(Modifier::BOLD),
32 )),
33 );
34}