@@ -1043,6 +1043,115 @@ pub enum AxisSide {
10431043 Right ,
10441044}
10451045
1046+ #[ derive( Serialize , Debug , Clone ) ]
1047+ pub enum PatternShape {
1048+ #[ serde( rename = "" ) ]
1049+ None ,
1050+ #[ serde( rename = "-" ) ]
1051+ HorizonalLine ,
1052+ #[ serde( rename = "|" ) ]
1053+ VerticalLine ,
1054+ #[ serde( rename = "/" ) ]
1055+ RightDiagonalLine ,
1056+ #[ serde( rename = "\\ " ) ]
1057+ LeftDiagonalLine ,
1058+ #[ serde( rename = "+" ) ]
1059+ Cross ,
1060+ #[ serde( rename = "x" ) ]
1061+ DiagonalCross ,
1062+ #[ serde( rename = "." ) ]
1063+ Dot ,
1064+ }
1065+
1066+ #[ derive( Serialize , Debug , Clone ) ]
1067+ #[ serde( rename_all = "lowercase" ) ]
1068+ pub enum PatternFillMode {
1069+ Replace ,
1070+ Overlay ,
1071+ }
1072+
1073+ #[ serde_with:: skip_serializing_none]
1074+ #[ derive( Serialize , Clone , Debug , Default ) ]
1075+ pub struct Pattern {
1076+ shape : Option < Dim < PatternShape > > ,
1077+ #[ serde( rename = "fillmode" ) ]
1078+ fill_mode : Option < PatternFillMode > ,
1079+ #[ serde( rename = "bgcolor" ) ]
1080+ background_color : Option < Dim < Box < dyn Color > > > ,
1081+ #[ serde( rename = "fgcolor" ) ]
1082+ foreground_color : Option < Dim < Box < dyn Color > > > ,
1083+ #[ serde( rename = "fgopacity" ) ]
1084+ foreground_opacity : Option < f64 > ,
1085+ size : Option < Dim < f64 > > ,
1086+ solidity : Option < Dim < f64 > > ,
1087+ }
1088+
1089+ impl Pattern {
1090+ pub fn new ( ) -> Self {
1091+ Default :: default ( )
1092+ }
1093+
1094+ pub fn shape ( mut self , shape : PatternShape ) -> Self {
1095+ self . shape = Some ( Dim :: Scalar ( shape) ) ;
1096+ self
1097+ }
1098+
1099+ pub fn shape_array ( mut self , shape : Vec < PatternShape > ) -> Self {
1100+ self . shape = Some ( Dim :: Vector ( shape) ) ;
1101+ self
1102+ }
1103+
1104+ pub fn fill_mode ( mut self , fill_mode : PatternFillMode ) -> Self {
1105+ self . fill_mode = Some ( fill_mode) ;
1106+ self
1107+ }
1108+
1109+ pub fn background_color < C : Color > ( mut self , color : C ) -> Self {
1110+ self . background_color = Some ( Dim :: Scalar ( Box :: new ( color) ) ) ;
1111+ self
1112+ }
1113+
1114+ pub fn background_color_array < C : Color > ( mut self , colors : Vec < C > ) -> Self {
1115+ self . background_color = Some ( Dim :: Vector ( ColorArray ( colors) . into ( ) ) ) ;
1116+ self
1117+ }
1118+
1119+ pub fn foreground_color < C : Color > ( mut self , color : C ) -> Self {
1120+ self . foreground_color = Some ( Dim :: Scalar ( Box :: new ( color) ) ) ;
1121+ self
1122+ }
1123+
1124+ pub fn foreground_color_array < C : Color > ( mut self , colors : Vec < C > ) -> Self {
1125+ self . foreground_color = Some ( Dim :: Vector ( ColorArray ( colors) . into ( ) ) ) ;
1126+ self
1127+ }
1128+
1129+ pub fn foreground_opacity ( mut self , opacity : f64 ) -> Self {
1130+ self . foreground_opacity = Some ( opacity) ;
1131+ self
1132+ }
1133+
1134+ pub fn size ( mut self , size : f64 ) -> Self {
1135+ self . size = Some ( Dim :: Scalar ( size) ) ;
1136+ self
1137+ }
1138+
1139+ pub fn size_array ( mut self , size : Vec < f64 > ) -> Self {
1140+ self . size = Some ( Dim :: Vector ( size) ) ;
1141+ self
1142+ }
1143+
1144+ pub fn solidity ( mut self , solidity : f64 ) -> Self {
1145+ self . solidity = Some ( Dim :: Scalar ( solidity) ) ;
1146+ self
1147+ }
1148+
1149+ pub fn solidity_array ( mut self , solidity : Vec < f64 > ) -> Self {
1150+ self . solidity = Some ( Dim :: Vector ( solidity) ) ;
1151+ self
1152+ }
1153+ }
1154+
10461155#[ serde_with:: skip_serializing_none]
10471156#[ derive( Serialize , Clone , Debug , Default ) ]
10481157pub struct Marker {
@@ -1076,6 +1185,7 @@ pub struct Marker {
10761185 color_bar : Option < ColorBar > ,
10771186 #[ serde( rename = "outliercolor" ) ]
10781187 outlier_color : Option < Box < dyn Color > > ,
1188+ pattern : Option < Pattern > ,
10791189}
10801190
10811191impl Marker {
@@ -1192,6 +1302,11 @@ impl Marker {
11921302 self . outlier_color = Some ( Box :: new ( outlier_color) ) ;
11931303 self
11941304 }
1305+
1306+ pub fn pattern ( mut self , pattern : Pattern ) -> Self {
1307+ self . pattern = Some ( pattern) ;
1308+ self
1309+ }
11951310}
11961311
11971312#[ serde_with:: skip_serializing_none]
@@ -2132,6 +2247,63 @@ mod tests {
21322247 assert_eq ! ( to_value( tick_format_stop) . unwrap( ) , expected) ;
21332248 }
21342249
2250+ #[ test]
2251+ fn test_serialize_pattern_shape ( ) {
2252+ assert_eq ! ( to_value( PatternShape :: None ) . unwrap( ) , json!( "" ) ) ;
2253+ assert_eq ! ( to_value( PatternShape :: HorizonalLine ) . unwrap( ) , json!( "-" ) ) ;
2254+ assert_eq ! ( to_value( PatternShape :: VerticalLine ) . unwrap( ) , json!( "|" ) ) ;
2255+ assert_eq ! (
2256+ to_value( PatternShape :: RightDiagonalLine ) . unwrap( ) ,
2257+ json!( "/" )
2258+ ) ;
2259+ assert_eq ! (
2260+ to_value( PatternShape :: LeftDiagonalLine ) . unwrap( ) ,
2261+ json!( "\\ " )
2262+ ) ;
2263+ assert_eq ! ( to_value( PatternShape :: Cross ) . unwrap( ) , json!( "+" ) ) ;
2264+ assert_eq ! ( to_value( PatternShape :: DiagonalCross ) . unwrap( ) , json!( "x" ) ) ;
2265+ assert_eq ! ( to_value( PatternShape :: Dot ) . unwrap( ) , json!( "." ) ) ;
2266+ }
2267+
2268+ #[ test]
2269+ fn test_serialize_pattern_fill_mode ( ) {
2270+ assert_eq ! (
2271+ to_value( PatternFillMode :: Replace ) . unwrap( ) ,
2272+ json!( "replace" )
2273+ ) ;
2274+ assert_eq ! (
2275+ to_value( PatternFillMode :: Overlay ) . unwrap( ) ,
2276+ json!( "overlay" )
2277+ ) ;
2278+ }
2279+
2280+ #[ test]
2281+ fn test_serialize_pattern ( ) {
2282+ let pattern = Pattern :: new ( )
2283+ . shape_array ( vec ! [
2284+ PatternShape :: HorizonalLine ,
2285+ PatternShape :: VerticalLine ,
2286+ ] )
2287+ . fill_mode ( PatternFillMode :: Overlay )
2288+ . background_color_array ( vec ! [ NamedColor :: Black , NamedColor :: Blue ] )
2289+ . foreground_color_array ( vec ! [ NamedColor :: Red , NamedColor :: Green ] )
2290+ . foreground_opacity ( 0.9 )
2291+ . size_array ( vec ! [ 10.0 , 20.0 ] )
2292+ . solidity_array ( vec ! [ 0.1 , 0.2 ] ) ;
2293+
2294+ let expected = json ! ( {
2295+ "shape" : [ "-" , "|" ] ,
2296+ "fillmode" : "overlay" ,
2297+ "bgcolor" : [ "black" , "blue" ] ,
2298+ "fgcolor" : [ "red" , "green" ] ,
2299+ "fgopacity" : 0.9 ,
2300+ "size" : [ 10.0 , 20.0 ] ,
2301+ "solidity" : [ 0.1 , 0.2 ]
2302+ } ) ;
2303+
2304+ assert_eq ! ( to_value( pattern) . unwrap( ) , expected) ;
2305+ }
2306+
21352307 #[ test]
21362308 fn test_serialize_marker ( ) {
21372309 let marker = Marker :: new ( )
@@ -2155,7 +2327,13 @@ mod tests {
21552327 . reverse_scale ( true )
21562328 . show_scale ( true )
21572329 . color_bar ( ColorBar :: new ( ) )
2158- . outlier_color ( "#FFFFFF" ) ;
2330+ . outlier_color ( "#FFFFFF" )
2331+ . pattern (
2332+ Pattern :: new ( )
2333+ . shape ( PatternShape :: Cross )
2334+ . foreground_color ( NamedColor :: Red )
2335+ . size ( 10.0 ) ,
2336+ ) ;
21592337
21602338 let expected = json ! ( {
21612339 "symbol" : "circle" ,
@@ -2177,7 +2355,12 @@ mod tests {
21772355 "autocolorscale" : true ,
21782356 "reversescale" : true ,
21792357 "showscale" : true ,
2180- "outliercolor" : "#FFFFFF"
2358+ "outliercolor" : "#FFFFFF" ,
2359+ "pattern" : {
2360+ "shape" : "+" ,
2361+ "fgcolor" : "red" ,
2362+ "size" : 10.0
2363+ }
21812364 } ) ;
21822365
21832366 assert_eq ! ( to_value( marker) . unwrap( ) , expected) ;
0 commit comments