From f8ec85d60742c71dff93724bd16be98bb0d85aaf Mon Sep 17 00:00:00 2001 From: alceal Date: Mon, 16 Sep 2024 17:41:13 +0200 Subject: [PATCH] feat: New `axis_position` method and the old one has been renamed to `axis_side` and the corresponding enum values have been updated --- src/axis/mod.rs | 41 ++++++++++++++++++++++++++++------------- src/lib.rs | 2 +- src/traits/layout.rs | 8 ++++++-- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/axis/mod.rs b/src/axis/mod.rs index 797d383..c63255c 100644 --- a/src/axis/mod.rs +++ b/src/axis/mod.rs @@ -1,5 +1,5 @@ use plotly::{ - common::{AxisSide, ExponentFormat}, + common::{AxisSide as AxisSidePlotly, ExponentFormat}, layout::{AxisType as AxisTypePlotly, TicksDirection}, }; @@ -69,7 +69,8 @@ use crate::Rgb; #[derive(Default, Clone)] pub struct Axis { pub(crate) show_axis: Option, - pub(crate) axis_position: Option, + pub(crate) axis_side: Option, + pub(crate) axis_position: Option, pub(crate) axis_type: Option, pub(crate) value_color: Option, pub(crate) value_range: Option>, @@ -118,16 +119,30 @@ impl Axis { self } + /// Sets the side of the axis. + /// + /// # Arguments + /// + /// * `side` - An `AxisSide` enum value representing the side of the axis. + /// + /// # Returns + /// + /// Returns the `Axis` instance with the updated side. + pub fn axis_side(mut self, side: AxisSide) -> Self { + self.axis_side = Some(side); + self + } + /// Sets the position of the axis. /// /// # Arguments /// - /// * `position` - An `AxisPosition` enum value representing the position of the axis. + /// * `position` - A `f64` value representing the position of the axis. /// /// # Returns /// /// Returns the `Axis` instance with the updated position. - pub fn axis_position(mut self, position: AxisPosition) -> Self { + pub fn axis_position(mut self, position: f64) -> Self { self.axis_position = Some(position); self } @@ -451,7 +466,7 @@ impl From<&Axis> for Axis { #[derive(Clone)] pub enum TickDirection { OutSide, - Inside, + InSide, } impl TickDirection { @@ -463,32 +478,32 @@ impl TickDirection { pub fn get_direction(&self) -> TicksDirection { match self { TickDirection::OutSide => TicksDirection::Outside, - TickDirection::Inside => TicksDirection::Inside, + TickDirection::InSide => TicksDirection::Inside, } } } /// Enumeration representing the position of the axis. #[derive(Clone)] -pub enum AxisPosition { +pub enum AxisSide { Top, Bottom, Left, Right, } -impl AxisPosition { +impl AxisSide { /// Converts `AxisPosition` to the corresponding `AxisSide` from the `plotly` crate. /// /// # Returns /// /// Returns the corresponding `AxisSide`. - pub fn get_position(&self) -> AxisSide { + pub fn get_side(&self) -> AxisSidePlotly { match self { - AxisPosition::Top => AxisSide::Top, - AxisPosition::Bottom => AxisSide::Bottom, - AxisPosition::Left => AxisSide::Left, - AxisPosition::Right => AxisSide::Right, + AxisSide::Top => AxisSidePlotly::Top, + AxisSide::Bottom => AxisSidePlotly::Bottom, + AxisSide::Left => AxisSidePlotly::Left, + AxisSide::Right => AxisSidePlotly::Right, } } } diff --git a/src/lib.rs b/src/lib.rs index d5ce260..d93cebb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,7 @@ mod traces; mod traits; pub use crate::aesthetics::{line::LineType, orientation::Orientation}; -pub use crate::axis::{Axis, AxisPosition, AxisType, TickDirection, ValueExponent}; +pub use crate::axis::{Axis, AxisSide, AxisType, TickDirection, ValueExponent}; pub use crate::colors::Rgb; pub use crate::legend::Legend; pub use crate::shapes::Shape; diff --git a/src/traits/layout.rs b/src/traits/layout.rs index 2d0f6ee..10dfdae 100644 --- a/src/traits/layout.rs +++ b/src/traits/layout.rs @@ -103,8 +103,8 @@ pub(crate) trait LayoutPlotly { x_axis_format = x_axis_format.visible(visible); } - if let Some(axis_position) = axis_details.axis_position { - x_axis_format = x_axis_format.side(axis_position.get_position()); + if let Some(axis_position) = axis_details.axis_side { + x_axis_format = x_axis_format.side(axis_position.get_side()); } if let Some(axis_type) = axis_details.axis_type { @@ -202,6 +202,10 @@ pub(crate) trait LayoutPlotly { x_axis_format = x_axis_format.zero_line_width(zero_line_width); } + if let Some(axis_position) = axis_details.axis_position { + x_axis_format = x_axis_format.position(axis_position); + } + x_axis_format }