@@ -2,9 +2,8 @@ pub mod color;
2
2
3
3
use serde:: { Serialize , Serializer } ;
4
4
5
- use crate :: common :: color:: ColorWrapper ;
5
+ use crate :: color:: { Color , ColorArray } ;
6
6
use crate :: private;
7
- use color:: Color ;
8
7
9
8
#[ derive( Serialize , Clone , Debug ) ]
10
9
#[ serde( untagged) ]
@@ -504,7 +503,7 @@ pub struct Line {
504
503
#[ serde( skip_serializing_if = "Option::is_none" ) ]
505
504
simplify : Option < bool > ,
506
505
#[ serde( skip_serializing_if = "Option::is_none" ) ]
507
- color : Option < ColorWrapper > ,
506
+ color : Option < Box < dyn Color > > ,
508
507
#[ serde( skip_serializing_if = "Option::is_none" ) ]
509
508
cauto : Option < bool > ,
510
509
#[ serde( skip_serializing_if = "Option::is_none" ) ]
@@ -520,7 +519,7 @@ pub struct Line {
520
519
#[ serde( skip_serializing_if = "Option::is_none" , rename = "reversescale" ) ]
521
520
reverse_scale : Option < bool > ,
522
521
#[ serde( skip_serializing_if = "Option::is_none" , rename = "outliercolor" ) ]
523
- outlier_color : Option < ColorWrapper > ,
522
+ outlier_color : Option < Box < dyn Color > > ,
524
523
#[ serde( skip_serializing_if = "Option::is_none" , rename = "outlierwidth" ) ]
525
524
outlier_width : Option < usize > ,
526
525
}
@@ -556,7 +555,7 @@ impl Line {
556
555
}
557
556
558
557
pub fn color < C : Color > ( mut self , color : C ) -> Self {
559
- self . color = Some ( color . to_color ( ) ) ;
558
+ self . color = Some ( Box :: new ( color ) ) ;
560
559
self
561
560
}
562
561
@@ -596,7 +595,7 @@ impl Line {
596
595
}
597
596
598
597
pub fn outlier_color < C : Color > ( mut self , outlier_color : C ) -> Self {
599
- self . outlier_color = Some ( outlier_color . to_color ( ) ) ;
598
+ self . outlier_color = Some ( Box :: new ( outlier_color ) ) ;
600
599
self
601
600
}
602
601
@@ -667,18 +666,21 @@ pub enum ExponentFormat {
667
666
#[ derive( Serialize , Clone , Debug ) ]
668
667
pub struct Gradient {
669
668
r#type : GradientType ,
670
- color : Dim < ColorWrapper > ,
669
+ color : Dim < Box < dyn Color > > ,
671
670
}
672
671
673
672
impl Gradient {
674
- pub fn new < C : Color + Serialize > ( gradient_type : GradientType , color : Dim < C > ) -> Self {
675
- let color = match color {
676
- Dim :: Scalar ( c) => Dim :: Scalar ( c. to_color ( ) ) ,
677
- Dim :: Vector ( c) => Dim :: Vector ( private:: to_color_array ( c) ) ,
678
- } ;
673
+ pub fn new < C : Color > ( gradient_type : GradientType , color : C ) -> Self {
679
674
Gradient {
680
675
r#type : gradient_type,
681
- color,
676
+ color : Dim :: Scalar ( Box :: new ( color) ) ,
677
+ }
678
+ }
679
+
680
+ pub fn new_array < C : Color > ( gradient_type : GradientType , colors : Vec < C > ) -> Self {
681
+ Gradient {
682
+ r#type : gradient_type,
683
+ color : Dim :: Vector ( ColorArray ( colors) . into ( ) ) ,
682
684
}
683
685
}
684
686
}
@@ -749,15 +751,15 @@ pub struct ColorBar {
749
751
#[ serde( rename = "ypad" ) ]
750
752
y_pad : f64 ,
751
753
#[ serde( skip_serializing_if = "Option::is_none" , rename = "outlinecolor" ) ]
752
- outline_color : Option < ColorWrapper > ,
754
+ outline_color : Option < Box < dyn Color > > ,
753
755
#[ serde( rename = "outlinewidth" ) ]
754
756
outline_width : usize ,
755
757
#[ serde( skip_serializing_if = "Option::is_none" , rename = "bordercolor" ) ]
756
- border_color : Option < ColorWrapper > ,
758
+ border_color : Option < Box < dyn Color > > ,
757
759
#[ serde( rename = "borderwidth" ) ]
758
760
border_width : usize ,
759
761
#[ serde( skip_serializing_if = "Option::is_none" , rename = "bgcolor" ) ]
760
- background_color : Option < ColorWrapper > ,
762
+ background_color : Option < Box < dyn Color > > ,
761
763
#[ serde( skip_serializing_if = "Option::is_none" , rename = "tickmode" ) ]
762
764
tick_mode : Option < TickMode > ,
763
765
#[ serde( rename = "nticks" ) ]
@@ -777,7 +779,7 @@ pub struct ColorBar {
777
779
#[ serde( rename = "tickwidth" ) ]
778
780
tick_width : usize ,
779
781
#[ serde( skip_serializing_if = "Option::is_none" , rename = "tickcolor" ) ]
780
- tick_color : Option < ColorWrapper > ,
782
+ tick_color : Option < Box < dyn Color > > ,
781
783
#[ serde( rename = "showticklabels" ) ]
782
784
show_tick_labels : bool ,
783
785
#[ serde( skip_serializing_if = "Option::is_none" , rename = "tickfont" ) ]
@@ -906,7 +908,7 @@ impl ColorBar {
906
908
}
907
909
908
910
pub fn outline_color < C : Color > ( mut self , outline_color : C ) -> ColorBar {
909
- self . outline_color = Some ( outline_color . to_color ( ) ) ;
911
+ self . outline_color = Some ( Box :: new ( outline_color ) ) ;
910
912
self
911
913
}
912
914
@@ -916,7 +918,7 @@ impl ColorBar {
916
918
}
917
919
918
920
pub fn border_color < C : Color > ( mut self , border_color : C ) -> ColorBar {
919
- self . border_color = Some ( border_color . to_color ( ) ) ;
921
+ self . border_color = Some ( Box :: new ( border_color ) ) ;
920
922
self
921
923
}
922
924
@@ -926,7 +928,7 @@ impl ColorBar {
926
928
}
927
929
928
930
pub fn background_color < C : Color > ( mut self , background_color : C ) -> ColorBar {
929
- self . background_color = Some ( background_color . to_color ( ) ) ;
931
+ self . background_color = Some ( Box :: new ( background_color ) ) ;
930
932
self
931
933
}
932
934
@@ -976,7 +978,7 @@ impl ColorBar {
976
978
}
977
979
978
980
pub fn tick_color < C : Color > ( mut self , tick_color : C ) -> ColorBar {
979
- self . tick_color = Some ( tick_color . to_color ( ) ) ;
981
+ self . tick_color = Some ( Box :: new ( tick_color ) ) ;
980
982
self
981
983
}
982
984
@@ -1076,7 +1078,7 @@ pub struct Marker {
1076
1078
#[ serde( skip_serializing_if = "Option::is_none" ) ]
1077
1079
gradient : Option < Gradient > ,
1078
1080
#[ serde( skip_serializing_if = "Option::is_none" ) ]
1079
- color : Option < Dim < ColorWrapper > > ,
1081
+ color : Option < Dim < Box < dyn Color > > > ,
1080
1082
#[ serde( skip_serializing_if = "Option::is_none" ) ]
1081
1083
cauto : Option < bool > ,
1082
1084
#[ serde( skip_serializing_if = "Option::is_none" ) ]
@@ -1096,7 +1098,7 @@ pub struct Marker {
1096
1098
#[ serde( skip_serializing_if = "Option::is_none" , rename = "colorbar" ) ]
1097
1099
color_bar : Option < ColorBar > ,
1098
1100
#[ serde( skip_serializing_if = "Option::is_none" , rename = "outliercolor" ) ]
1099
- outlier_color : Option < ColorWrapper > ,
1101
+ outlier_color : Option < Box < dyn Color > > ,
1100
1102
}
1101
1103
1102
1104
impl Marker {
@@ -1155,13 +1157,12 @@ impl Marker {
1155
1157
}
1156
1158
1157
1159
pub fn color < C : Color > ( mut self , color : C ) -> Self {
1158
- self . color = Some ( Dim :: Scalar ( color . to_color ( ) ) ) ;
1160
+ self . color = Some ( Dim :: Scalar ( Box :: new ( color ) ) ) ;
1159
1161
self
1160
1162
}
1161
1163
1162
- pub fn color_array < C : Color > ( mut self , color : Vec < C > ) -> Self {
1163
- let color = private:: to_color_array ( color) ;
1164
- self . color = Some ( Dim :: Vector ( color) ) ;
1164
+ pub fn color_array < C : Color > ( mut self , colors : Vec < C > ) -> Self {
1165
+ self . color = Some ( Dim :: Vector ( ColorArray ( colors) . into ( ) ) ) ;
1165
1166
self
1166
1167
}
1167
1168
@@ -1211,7 +1212,7 @@ impl Marker {
1211
1212
}
1212
1213
1213
1214
pub fn outlier_color < C : Color > ( mut self , outlier_color : C ) -> Self {
1214
- self . outlier_color = Some ( outlier_color . to_color ( ) ) ;
1215
+ self . outlier_color = Some ( Box :: new ( outlier_color ) ) ;
1215
1216
self
1216
1217
}
1217
1218
}
@@ -1223,7 +1224,7 @@ pub struct Font {
1223
1224
#[ serde( skip_serializing_if = "Option::is_none" ) ]
1224
1225
size : Option < usize > ,
1225
1226
#[ serde( skip_serializing_if = "Option::is_none" ) ]
1226
- color : Option < ColorWrapper > ,
1227
+ color : Option < Box < dyn Color > > ,
1227
1228
}
1228
1229
1229
1230
impl Font {
@@ -1242,7 +1243,7 @@ impl Font {
1242
1243
}
1243
1244
1244
1245
pub fn color < C : Color > ( mut self , color : C ) -> Self {
1245
- self . color = Some ( color . to_color ( ) ) ;
1246
+ self . color = Some ( Box :: new ( color ) ) ;
1246
1247
self
1247
1248
}
1248
1249
}
@@ -1364,9 +1365,9 @@ impl Title {
1364
1365
#[ derive( Serialize , Clone , Debug , Default ) ]
1365
1366
pub struct Label {
1366
1367
#[ serde( skip_serializing_if = "Option::is_none" , rename = "bgcolor" ) ]
1367
- background_color : Option < ColorWrapper > ,
1368
+ background_color : Option < Box < dyn Color > > ,
1368
1369
#[ serde( skip_serializing_if = "Option::is_none" , rename = "bordercolor" ) ]
1369
- border_color : Option < ColorWrapper > ,
1370
+ border_color : Option < Box < dyn Color > > ,
1370
1371
#[ serde( skip_serializing_if = "Option::is_none" ) ]
1371
1372
font : Option < Font > ,
1372
1373
#[ serde( skip_serializing_if = "Option::is_none" ) ]
@@ -1381,12 +1382,12 @@ impl Label {
1381
1382
}
1382
1383
1383
1384
pub fn background_color < C : Color > ( mut self , background_color : C ) -> Self {
1384
- self . background_color = Some ( background_color . to_color ( ) ) ;
1385
+ self . background_color = Some ( Box :: new ( background_color ) ) ;
1385
1386
self
1386
1387
}
1387
1388
1388
1389
pub fn border_color < C : Color > ( mut self , border_color : C ) -> Self {
1389
- self . border_color = Some ( border_color . to_color ( ) ) ;
1390
+ self . border_color = Some ( Box :: new ( border_color ) ) ;
1390
1391
self
1391
1392
}
1392
1393
@@ -1449,7 +1450,7 @@ pub struct ErrorData {
1449
1450
#[ serde( skip_serializing_if = "Option::is_none" ) ]
1450
1451
copy_ystyle : Option < bool > ,
1451
1452
#[ serde( skip_serializing_if = "Option::is_none" ) ]
1452
- color : Option < ColorWrapper > ,
1453
+ color : Option < Box < dyn Color > > ,
1453
1454
#[ serde( skip_serializing_if = "Option::is_none" ) ]
1454
1455
thickness : Option < f64 > ,
1455
1456
#[ serde( skip_serializing_if = "Option::is_none" ) ]
@@ -1510,7 +1511,7 @@ impl ErrorData {
1510
1511
}
1511
1512
1512
1513
pub fn color < C : Color > ( mut self , color : C ) -> Self {
1513
- self . color = Some ( color . to_color ( ) ) ;
1514
+ self . color = Some ( Box :: new ( color ) ) ;
1514
1515
self
1515
1516
}
1516
1517
@@ -1530,7 +1531,7 @@ mod tests {
1530
1531
use serde_json:: { json, to_value} ;
1531
1532
1532
1533
use super :: * ;
1533
- use crate :: NamedColor ;
1534
+ use crate :: color :: NamedColor ;
1534
1535
1535
1536
#[ test]
1536
1537
fn test_serialize_domain ( ) {
@@ -1951,7 +1952,7 @@ mod tests {
1951
1952
"smoothing" : 1.0 ,
1952
1953
"dash" : "dash" ,
1953
1954
"simplify" : true ,
1954
- "color" : "#FFFFFF " ,
1955
+ "color" : "#ffffff " ,
1955
1956
"cauto" : true ,
1956
1957
"cmin" : 0.0 ,
1957
1958
"cmax" : 1.0 ,
@@ -2019,8 +2020,12 @@ mod tests {
2019
2020
#[ test]
2020
2021
#[ rustfmt:: skip]
2021
2022
fn test_serialize_gradient ( ) {
2022
- let gradient = Gradient :: new ( GradientType :: Horizontal , Dim :: Scalar ( "#ffffff" ) ) ;
2023
- let expected = json ! ( { "color" : "#FFFFFF" , "type" : "horizontal" } ) ;
2023
+ let gradient = Gradient :: new ( GradientType :: Horizontal , "#ffffff" ) ;
2024
+ let expected = json ! ( { "color" : "#ffffff" , "type" : "horizontal" } ) ;
2025
+ assert_eq ! ( to_value( gradient) . unwrap( ) , expected) ;
2026
+
2027
+ let gradient = Gradient :: new_array ( GradientType :: Horizontal , vec ! [ "#ffffff" ] ) ;
2028
+ let expected = json ! ( { "color" : [ "#ffffff" ] , "type" : "horizontal" } ) ;
2024
2029
assert_eq ! ( to_value( gradient) . unwrap( ) , expected) ;
2025
2030
}
2026
2031
@@ -2060,7 +2065,7 @@ mod tests {
2060
2065
. size_min ( 1 )
2061
2066
. size_mode ( SizeMode :: Area )
2062
2067
. line ( Line :: new ( ) )
2063
- . gradient ( Gradient :: new ( GradientType :: Radial , Dim :: Scalar ( "#FFFFFF" ) ) )
2068
+ . gradient ( Gradient :: new ( GradientType :: Radial , "#FFFFFF" ) )
2064
2069
. color ( NamedColor :: Blue )
2065
2070
. color_array ( vec ! [ NamedColor :: Black , NamedColor :: Blue ] )
2066
2071
. cauto ( true )
@@ -2071,7 +2076,7 @@ mod tests {
2071
2076
. auto_color_scale ( true )
2072
2077
. reverse_scale ( true )
2073
2078
. show_scale ( true )
2074
- // .color_bar(ColorBar::new()) awaiting fix in other branch
2079
+ . color_bar ( ColorBar :: new ( ) )
2075
2080
. outlier_color ( "#FFFFFF" ) ;
2076
2081
2077
2082
let expected = json ! ( {
@@ -2085,6 +2090,23 @@ mod tests {
2085
2090
"line" : { } ,
2086
2091
"gradient" : { "type" : "radial" , "color" : "#FFFFFF" } ,
2087
2092
"color" : [ "black" , "blue" ] ,
2093
+ "colorbar" : {
2094
+ "borderwidth" : 0 ,
2095
+ "len" : 1 ,
2096
+ "nticks" : 0 ,
2097
+ "outlinewidth" : 1 ,
2098
+ "separate_thousands" : true ,
2099
+ "showticklabels" : true ,
2100
+ "thickness" : 30 ,
2101
+ "ticklen" : 5 ,
2102
+ "tickwidth" : 1 ,
2103
+ "x" : 1.02 ,
2104
+ "xanchor" : "left" ,
2105
+ "xpad" : 10.0 ,
2106
+ "y" : 0.5 ,
2107
+ "yanchor" : "middle" ,
2108
+ "ypad" : 10.0 ,
2109
+ } ,
2088
2110
"cauto" : true ,
2089
2111
"cmin" : 0.0 ,
2090
2112
"cmax" : 1.0 ,
0 commit comments