diff options
Diffstat (limited to 'src/canvas/components/tui_widget/time_chart.rs')
-rw-r--r-- | src/canvas/components/tui_widget/time_chart.rs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/canvas/components/tui_widget/time_chart.rs b/src/canvas/components/tui_widget/time_chart.rs index 60c797bc..04f491bc 100644 --- a/src/canvas/components/tui_widget/time_chart.rs +++ b/src/canvas/components/tui_widget/time_chart.rs @@ -7,7 +7,7 @@ mod canvas; mod points; -use std::cmp::max; +use std::{cmp::max, str::FromStr}; use canvas::*; use tui::{ @@ -213,6 +213,27 @@ impl LegendPosition { } } +#[derive(Debug, PartialEq)] +pub struct ParseLegendPositionError; + +impl FromStr for LegendPosition { + type Err = ParseLegendPositionError; + + fn from_str(s: &str) -> Result<Self, Self::Err> { + match s.to_ascii_lowercase().as_str() { + "top" => Ok(Self::Top), + "top-left" => Ok(Self::TopLeft), + "top-right" => Ok(Self::TopRight), + "left" => Ok(Self::Left), + "right" => Ok(Self::Right), + "bottom-left" => Ok(Self::BottomLeft), + "bottom" => Ok(Self::Bottom), + "bottom-right" => Ok(Self::BottomRight), + _ => Err(ParseLegendPositionError), + } + } +} + /// A group of data points /// /// This is the main element composing a [`TimeChart`]. |