//! A [`tui::widgets::Chart`] but slightly more specialized to show right-aligned timeseries
//! data.
//!
//! Generally should be updated to be in sync with [`chart.rs`](https://github.com/ratatui-org/ratatui/blob/main/src/widgets/chart.rs);
//! the specializations are factored out to `time_chart/points.rs`.
mod canvas;
mod points;
use std::cmp::max;
use canvas::*;
use tui::{
buffer::Buffer,
layout::{Alignment, Constraint, Flex, Layout, Rect},
style::{Color, Style, Styled},
symbols::{self, Marker},
text::{Line, Span},
widgets::{block::BlockExt, Block, Borders, GraphType, Widget},
};
use unicode_width::UnicodeWidthStr;
pub const DEFAULT_LEGEND_CONSTRAINTS: (Constraint, Constraint) =
(Constraint::Ratio(1, 4), Constraint::Length(4));
/// A single graph point.
pub type Point = (f64, f64);
/// An X or Y axis for the [`TimeChart`] widget
#[derive(Debug, Default, Clone, PartialEq)]
pub struct Axis<'a> {
/// Title displayed next to axis end
pub(crate) title: Option<Line<'a>>,
/// Bounds for the axis (all data points outside these limits will not be represented)
pub(crate) bounds: [f64; 2],
/// A list of labels to put to the left or below the axis
pub(crate) labels: Option<Vec<Span<'a>>>,
/// The style used to draw the axis itself
pub(crate) style: Style,
/// The alignment of the labels of the Axis
pub(crate) labels_alignment: Alignment,
}
impl<'a> Axis<'a> {
/// Sets the axis title
///
/// It will be displayed at the end of the axis. For an X axis this is the right, for a Y axis,
/// this is the top.
///
/// This is a fluent setter method which must be chained or used as it consumes self
#[must_use = "method moves the value of self and returns the modified value"]
pub fn title<T>(mut self, title: T) -> Axis<'a>
where
T: Into<Line<'a>>,
{
self.title = Some(title.into());
self
}
/// Sets the bounds of this axis
///
/// In other words, sets the min and max value on this axis.
///
/// This is a fluent setter method which must be chained or used as it consumes self
#[must_use = "method moves the value of self