1- use serde:: { Deserialize , Serialize } ;
1+ use plotly_derive:: FieldSetter ;
2+ use serde:: Serialize ;
3+
4+ use crate :: private:: NumOrString ;
25
36/// Struct representing a rangebreak for Plotly axes.
47/// See: https://plotly.com/python/reference/layout/xaxis/#layout-xaxis-rangebreaks
5- #[ derive( Debug , Clone , Serialize , Deserialize , PartialEq ) ]
8+ #[ derive( Debug , Clone , Serialize , PartialEq , FieldSetter ) ]
69pub struct RangeBreak {
710 /// Sets the lower and upper bounds for this range break, e.g. ["sat",
811 /// "mon"]
912 #[ serde( skip_serializing_if = "Option::is_none" ) ]
10- pub bounds : Option < [ String ; 2 ] > ,
13+ #[ field_setter( skip) ]
14+ pub bounds : Option < [ NumOrString ; 2 ] > ,
1115
1216 /// Sets the pattern by which this range break is generated, e.g. "day of
1317 /// week"
1418 #[ serde( skip_serializing_if = "Option::is_none" ) ]
15- pub pattern : Option < String > ,
19+ pub pattern : Option < NumOrString > ,
1620
1721 /// Sets the values at which this range break occurs.
1822 /// See Plotly.js docs for details.
1923 #[ serde( skip_serializing_if = "Option::is_none" ) ]
20- pub values : Option < Vec < String > > ,
24+ #[ field_setter( skip) ]
25+ pub values : Option < Vec < NumOrString > > ,
2126
2227 /// Sets the size of each range break in milliseconds (for time axes).
2328 #[ serde( skip_serializing_if = "Option::is_none" ) ]
@@ -28,45 +33,18 @@ pub struct RangeBreak {
2833 pub enabled : Option < bool > ,
2934}
3035
31- impl Default for RangeBreak {
32- fn default ( ) -> Self {
33- Self :: new ( )
34- }
35- }
36-
3736impl RangeBreak {
3837 pub fn new ( ) -> Self {
39- Self {
40- bounds : None ,
41- pattern : None ,
42- values : None ,
43- dvalue : None ,
44- enabled : None ,
45- }
38+ Default :: default ( )
4639 }
4740
48- pub fn bounds ( mut self , lower : impl Into < String > , upper : impl Into < String > ) -> Self {
41+ pub fn bounds < T : Into < NumOrString > > ( mut self , lower : T , upper : T ) -> Self {
4942 self . bounds = Some ( [ lower. into ( ) , upper. into ( ) ] ) ;
5043 self
5144 }
5245
53- pub fn pattern ( mut self , pattern : impl Into < String > ) -> Self {
54- self . pattern = Some ( pattern. into ( ) ) ;
55- self
56- }
57-
58- pub fn values ( mut self , values : Vec < impl Into < String > > ) -> Self {
59- self . values = Some ( values. into_iter ( ) . map ( |v| v. into ( ) ) . collect ( ) ) ;
60- self
61- }
62-
63- pub fn dvalue ( mut self , dvalue : u64 ) -> Self {
64- self . dvalue = Some ( dvalue) ;
65- self
66- }
67-
68- pub fn enabled ( mut self , enabled : bool ) -> Self {
69- self . enabled = Some ( enabled) ;
46+ pub fn values < T : Into < NumOrString > > ( mut self , values : Vec < T > ) -> Self {
47+ self . values = Some ( values. into_iter ( ) . map ( Into :: into) . collect ( ) ) ;
7048 self
7149 }
7250}
0 commit comments