diff --git a/plotly/src/layout/rangebreaks.rs b/plotly/src/layout/rangebreaks.rs index d502a5a9..3dec6b1a 100644 --- a/plotly/src/layout/rangebreaks.rs +++ b/plotly/src/layout/rangebreaks.rs @@ -1,23 +1,28 @@ -use serde::{Deserialize, Serialize}; +use plotly_derive::FieldSetter; +use serde::Serialize; + +use crate::private::NumOrString; /// Struct representing a rangebreak for Plotly axes. /// See: https://plotly.com/python/reference/layout/xaxis/#layout-xaxis-rangebreaks -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[derive(Debug, Clone, Serialize, PartialEq, FieldSetter)] pub struct RangeBreak { /// Sets the lower and upper bounds for this range break, e.g. ["sat", /// "mon"] #[serde(skip_serializing_if = "Option::is_none")] - pub bounds: Option<[String; 2]>, + #[field_setter(skip)] + pub bounds: Option<[NumOrString; 2]>, /// Sets the pattern by which this range break is generated, e.g. "day of /// week" #[serde(skip_serializing_if = "Option::is_none")] - pub pattern: Option, + pub pattern: Option, /// Sets the values at which this range break occurs. /// See Plotly.js docs for details. #[serde(skip_serializing_if = "Option::is_none")] - pub values: Option>, + #[field_setter(skip)] + pub values: Option>, /// Sets the size of each range break in milliseconds (for time axes). #[serde(skip_serializing_if = "Option::is_none")] @@ -28,45 +33,18 @@ pub struct RangeBreak { pub enabled: Option, } -impl Default for RangeBreak { - fn default() -> Self { - Self::new() - } -} - impl RangeBreak { pub fn new() -> Self { - Self { - bounds: None, - pattern: None, - values: None, - dvalue: None, - enabled: None, - } + Default::default() } - pub fn bounds(mut self, lower: impl Into, upper: impl Into) -> Self { + pub fn bounds>(mut self, lower: T, upper: T) -> Self { self.bounds = Some([lower.into(), upper.into()]); self } - pub fn pattern(mut self, pattern: impl Into) -> Self { - self.pattern = Some(pattern.into()); - self - } - - pub fn values(mut self, values: Vec>) -> Self { - self.values = Some(values.into_iter().map(|v| v.into()).collect()); - self - } - - pub fn dvalue(mut self, dvalue: u64) -> Self { - self.dvalue = Some(dvalue); - self - } - - pub fn enabled(mut self, enabled: bool) -> Self { - self.enabled = Some(enabled); + pub fn values>(mut self, values: Vec) -> Self { + self.values = Some(values.into_iter().map(Into::into).collect()); self } }