From 24c402dc6adf4f3c5dd44696a854ee3b81af09de Mon Sep 17 00:00:00 2001 From: alceal Date: Sun, 1 Sep 2024 18:08:31 +0200 Subject: [PATCH] feat: Add write_html method --- src/traits/plot.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/traits/plot.rs b/src/traits/plot.rs index 0c0e886..650a705 100644 --- a/src/traits/plot.rs +++ b/src/traits/plot.rs @@ -4,16 +4,16 @@ use plotly::{Layout, Plot as Plotly, Trace}; /// A trait representing a generic plot that can be displayed or rendered. pub trait Plot { - #[allow(dead_code)] fn get_layout(&self) -> &Layout; - #[allow(dead_code)] + fn get_traces(&self) -> &Vec>; - #[allow(dead_code)] + fn plot(self) where Self: Sized, { let mut plot = Plotly::new(); + plot.set_layout(self.get_layout().clone()); plot.add_traces(self.get_traces().clone()); @@ -22,4 +22,16 @@ pub trait Plot { _ => plot.show(), } } + + fn write_html(self, path: impl Into) + where + Self: Sized, + { + let mut plot = Plotly::new(); + + plot.set_layout(self.get_layout().clone()); + plot.add_traces(self.get_traces().clone()); + + plot.write_html(path.into()); + } }