@@ -11,7 +11,7 @@ use crate::{
1111 color:: Color ,
1212 common:: {
1313 Calendar , Dim , ErrorData , Fill , Font , HoverInfo , HoverOn , Label , LegendGroupTitle , Line ,
14- Marker , Mode , Orientation , PlotType , Position , Visible ,
14+ Marker , Mode , Orientation , PlotType , Position , Visible , XAxisId , YAxisId ,
1515 } ,
1616 private:: { NumOrString , NumOrStringCollection } ,
1717 Trace ,
@@ -180,13 +180,13 @@ where
180180 /// `Layout::x_axis`. If "x2", the x coordinates
181181 /// refer to `Layout::x_axis2`, and so on.
182182 #[ serde( rename = "xaxis" ) ]
183- x_axis : Option < String > ,
183+ x_axis : Option < XAxisId > ,
184184 /// Sets a reference between this trace's y coordinates and a 2D cartesian y
185185 /// axis. If "y" (the default value), the y coordinates refer to
186186 /// `Layout::y_axis`. If "y2", the y coordinates
187187 /// refer to `Layout::y_axis2`, and so on.
188188 #[ serde( rename = "yaxis" ) ]
189- y_axis : Option < String > ,
189+ y_axis : Option < YAxisId > ,
190190 /// Only relevant when `stackgroup` is used, and only the first
191191 /// `orientation` found in the `stackgroup` will be used - including if
192192 /// `visible` is "legendonly" but not if it is `false`.
@@ -528,4 +528,26 @@ mod tests {
528528
529529 assert_eq ! ( to_value( trace) . unwrap( ) , expected) ;
530530 }
531+
532+ #[ test]
533+ fn serialize_scatter_axis_ids ( ) {
534+ use crate :: common:: { XAxisId , YAxisId } ;
535+
536+ let x_axis: XAxisId = "x2" . into ( ) ;
537+ let y_axis: YAxisId = "y12" . into ( ) ;
538+
539+ let trace = Scatter :: new ( vec ! [ 0 , 1 ] , vec ! [ 2 , 3 ] )
540+ . x_axis ( x_axis)
541+ . y_axis ( y_axis) ;
542+
543+ let expected = json ! ( {
544+ "type" : "scatter" ,
545+ "x" : [ 0 , 1 ] ,
546+ "y" : [ 2 , 3 ] ,
547+ "xaxis" : "x2" ,
548+ "yaxis" : "y12" ,
549+ } ) ;
550+
551+ assert_eq ! ( to_value( trace) . unwrap( ) , expected) ;
552+ }
531553}
0 commit comments