Skip to main content

schwab_cli/ui/
chart_markers.rs

1//! High-visibility markers for ratatui canvas charts (Braille dots are too small alone).
2
3use ratatui::style::{Color, Modifier, Style};
4use ratatui::text::{Line, Span};
5use ratatui::widgets::canvas::{Context, Line as CanvasLine};
6
7/// Crosshair arm lengths in chart data units.
8pub 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
14/// Bold glyph + crosshair — much easier to see than a single Braille pixel.
15pub 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}