@@ -893,6 +893,114 @@ pub enum Reference {
893893 Paper ,
894894}
895895
896+ #[ derive( Clone , Debug , PartialEq , Eq ) ]
897+ pub enum XAxisId {
898+ X1 ,
899+ X2 ,
900+ X3 ,
901+ X4 ,
902+ Custom ( String ) ,
903+ }
904+
905+ impl XAxisId {
906+ fn as_str ( & self ) -> & str {
907+ match self {
908+ Self :: X1 => "x" ,
909+ Self :: X2 => "x2" ,
910+ Self :: X3 => "x3" ,
911+ Self :: X4 => "x4" ,
912+ Self :: Custom ( value) => value. as_str ( ) ,
913+ }
914+ }
915+ }
916+
917+ impl Serialize for XAxisId {
918+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
919+ where
920+ S : Serializer ,
921+ {
922+ serializer. serialize_str ( self . as_str ( ) )
923+ }
924+ }
925+
926+ impl From < & str > for XAxisId {
927+ fn from ( value : & str ) -> Self {
928+ match value {
929+ "x" | "x1" => Self :: X1 ,
930+ "x2" => Self :: X2 ,
931+ "x3" => Self :: X3 ,
932+ "x4" => Self :: X4 ,
933+ _ => Self :: Custom ( value. to_string ( ) ) ,
934+ }
935+ }
936+ }
937+
938+ impl From < String > for XAxisId {
939+ fn from ( value : String ) -> Self {
940+ Self :: from ( value. as_str ( ) )
941+ }
942+ }
943+
944+ impl From < XAxisId > for String {
945+ fn from ( value : XAxisId ) -> Self {
946+ value. as_str ( ) . to_string ( )
947+ }
948+ }
949+
950+ #[ derive( Clone , Debug , PartialEq , Eq ) ]
951+ pub enum YAxisId {
952+ Y1 ,
953+ Y2 ,
954+ Y3 ,
955+ Y4 ,
956+ Custom ( String ) ,
957+ }
958+
959+ impl YAxisId {
960+ fn as_str ( & self ) -> & str {
961+ match self {
962+ Self :: Y1 => "y" ,
963+ Self :: Y2 => "y2" ,
964+ Self :: Y3 => "y3" ,
965+ Self :: Y4 => "y4" ,
966+ Self :: Custom ( value) => value. as_str ( ) ,
967+ }
968+ }
969+ }
970+
971+ impl Serialize for YAxisId {
972+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
973+ where
974+ S : Serializer ,
975+ {
976+ serializer. serialize_str ( self . as_str ( ) )
977+ }
978+ }
979+
980+ impl From < & str > for YAxisId {
981+ fn from ( value : & str ) -> Self {
982+ match value {
983+ "y" | "y1" => Self :: Y1 ,
984+ "y2" => Self :: Y2 ,
985+ "y3" => Self :: Y3 ,
986+ "y4" => Self :: Y4 ,
987+ _ => Self :: Custom ( value. to_string ( ) ) ,
988+ }
989+ }
990+ }
991+
992+ impl From < String > for YAxisId {
993+ fn from ( value : String ) -> Self {
994+ Self :: from ( value. as_str ( ) )
995+ }
996+ }
997+
998+ impl From < YAxisId > for String {
999+ fn from ( value : YAxisId ) -> Self {
1000+ value. as_str ( ) . to_string ( )
1001+ }
1002+ }
1003+
8961004#[ derive( Serialize , Clone , Debug ) ]
8971005pub struct Pad {
8981006 t : usize ,
@@ -1799,6 +1907,22 @@ mod tests {
17991907 assert_eq ! ( to_value( Reference :: Paper ) . unwrap( ) , json!( "paper" ) ) ;
18001908 }
18011909
1910+ #[ test]
1911+ fn serialize_axis_id ( ) {
1912+ assert_eq ! ( to_value( XAxisId :: X1 ) . unwrap( ) , json!( "x" ) ) ;
1913+ assert_eq ! ( to_value( XAxisId :: X3 ) . unwrap( ) , json!( "x3" ) ) ;
1914+ assert_eq ! (
1915+ to_value( XAxisId :: Custom ( "x7" . to_string( ) ) ) . unwrap( ) ,
1916+ json!( "x7" )
1917+ ) ;
1918+ assert_eq ! ( to_value( YAxisId :: Y1 ) . unwrap( ) , json!( "y" ) ) ;
1919+ assert_eq ! ( to_value( YAxisId :: Y4 ) . unwrap( ) , json!( "y4" ) ) ;
1920+ assert_eq ! (
1921+ to_value( YAxisId :: Custom ( "y8" . to_string( ) ) ) . unwrap( ) ,
1922+ json!( "y8" )
1923+ ) ;
1924+ }
1925+
18021926 #[ test]
18031927 #[ rustfmt:: skip]
18041928 fn serialize_legend_group_title ( ) {
0 commit comments