@@ -79,8 +79,8 @@ pub struct Plot {
7979/// Text labels (from LABELS clause)
8080#[ derive( Debug , Clone , PartialEq , Serialize , Deserialize ) ]
8181pub struct Labels {
82- /// Label assignments (label type → text)
83- pub labels : HashMap < String , String > ,
82+ /// Label assignments (label type → text, None = suppress )
83+ pub labels : HashMap < String , Option < String > > ,
8484}
8585
8686/// Theme styling (from THEME clause)
@@ -301,7 +301,7 @@ impl Plot {
301301 label_source. to_string ( )
302302 } ;
303303
304- labels. labels . insert ( primary. to_string ( ) , column_name) ;
304+ labels. labels . insert ( primary. to_string ( ) , Some ( column_name) ) ;
305305 }
306306 }
307307 }
@@ -635,7 +635,7 @@ mod tests {
635635 } ;
636636 labels
637637 . labels
638- . insert ( "pos1" . to_string ( ) , "Custom X Label" . to_string ( ) ) ;
638+ . insert ( "pos1" . to_string ( ) , Some ( "Custom X Label" . to_string ( ) ) ) ;
639639 spec. labels = Some ( labels) ;
640640
641641 spec. compute_aesthetic_labels ( ) ;
@@ -644,7 +644,7 @@ mod tests {
644644 // User-specified label should be preserved
645645 assert_eq ! (
646646 labels. labels. get( "pos1" ) ,
647- Some ( & "Custom X Label" . to_string( ) )
647+ Some ( & Some ( "Custom X Label" . to_string( ) ) )
648648 ) ;
649649 // pos2 should still be computed from variants
650650 assert ! ( labels. labels. contains_key( "pos2" ) ) ;
@@ -684,7 +684,7 @@ mod tests {
684684
685685 let labels = spec. labels . as_ref ( ) . unwrap ( ) ;
686686 // First layer's pos1 mapping should win
687- assert_eq ! ( labels. labels. get( "pos1" ) , Some ( & "date" . to_string( ) ) ) ;
687+ assert_eq ! ( labels. labels. get( "pos1" ) , Some ( & Some ( "date" . to_string( ) ) ) ) ;
688688 }
689689
690690 #[ test]
@@ -711,7 +711,7 @@ mod tests {
711711 // The stroke label should be "stroke" (extracted from __ggsql_aes_stroke__)
712712 assert_eq ! (
713713 labels. labels. get( "stroke" ) ,
714- Some ( & "stroke" . to_string( ) ) ,
714+ Some ( & Some ( "stroke" . to_string( ) ) ) ,
715715 "Stroke aesthetic should use 'stroke' as label"
716716 ) ;
717717 }
@@ -736,7 +736,7 @@ mod tests {
736736 // The size label should be "size", not "color"
737737 assert_eq ! (
738738 labels. labels. get( "size" ) ,
739- Some ( & "size" . to_string( ) ) ,
739+ Some ( & Some ( "size" . to_string( ) ) ) ,
740740 "Non-color aesthetic should keep its name"
741741 ) ;
742742 }
@@ -758,17 +758,17 @@ mod tests {
758758 } ) ;
759759 spec. labels = Some ( Labels {
760760 labels : HashMap :: from ( [
761- ( "x" . to_string ( ) , "X Axis" . to_string ( ) ) ,
762- ( "y" . to_string ( ) , "Y Axis" . to_string ( ) ) ,
761+ ( "x" . to_string ( ) , Some ( "X Axis" . to_string ( ) ) ) ,
762+ ( "y" . to_string ( ) , Some ( "Y Axis" . to_string ( ) ) ) ,
763763 ] ) ,
764764 } ) ;
765765
766766 spec. initialize_aesthetic_context ( ) ;
767767 spec. transform_aesthetics_to_internal ( ) ;
768768
769769 let labels = spec. labels . as_ref ( ) . unwrap ( ) ;
770- assert_eq ! ( labels. labels. get( "pos1" ) , Some ( & "X Axis" . to_string( ) ) ) ;
771- assert_eq ! ( labels. labels. get( "pos2" ) , Some ( & "Y Axis" . to_string( ) ) ) ;
770+ assert_eq ! ( labels. labels. get( "pos1" ) , Some ( & Some ( "X Axis" . to_string( ) ) ) ) ;
771+ assert_eq ! ( labels. labels. get( "pos2" ) , Some ( & Some ( "Y Axis" . to_string( ) ) ) ) ;
772772 assert ! ( !labels. labels. contains_key( "x" ) ) ;
773773 assert ! ( !labels. labels. contains_key( "y" ) ) ;
774774 }
@@ -787,8 +787,8 @@ mod tests {
787787 } ) ;
788788 spec. labels = Some ( Labels {
789789 labels : HashMap :: from ( [
790- ( "x" . to_string ( ) , "Category" . to_string ( ) ) ,
791- ( "y" . to_string ( ) , "Value" . to_string ( ) ) ,
790+ ( "x" . to_string ( ) , Some ( "Category" . to_string ( ) ) ) ,
791+ ( "y" . to_string ( ) , Some ( "Value" . to_string ( ) ) ) ,
792792 ] ) ,
793793 } ) ;
794794
@@ -797,8 +797,11 @@ mod tests {
797797
798798 let labels = spec. labels . as_ref ( ) . unwrap ( ) ;
799799 // x maps to pos2 (second position), y maps to pos1 (first position)
800- assert_eq ! ( labels. labels. get( "pos1" ) , Some ( & "Value" . to_string( ) ) ) ;
801- assert_eq ! ( labels. labels. get( "pos2" ) , Some ( & "Category" . to_string( ) ) ) ;
800+ assert_eq ! ( labels. labels. get( "pos1" ) , Some ( & Some ( "Value" . to_string( ) ) ) ) ;
801+ assert_eq ! (
802+ labels. labels. get( "pos2" ) ,
803+ Some ( & Some ( "Category" . to_string( ) ) )
804+ ) ;
802805 }
803806
804807 #[ test]
@@ -814,17 +817,20 @@ mod tests {
814817 } ) ;
815818 spec. labels = Some ( Labels {
816819 labels : HashMap :: from ( [
817- ( "angle" . to_string ( ) , "Angle" . to_string ( ) ) ,
818- ( "radius" . to_string ( ) , "Distance" . to_string ( ) ) ,
820+ ( "angle" . to_string ( ) , Some ( "Angle" . to_string ( ) ) ) ,
821+ ( "radius" . to_string ( ) , Some ( "Distance" . to_string ( ) ) ) ,
819822 ] ) ,
820823 } ) ;
821824
822825 spec. initialize_aesthetic_context ( ) ;
823826 spec. transform_aesthetics_to_internal ( ) ;
824827
825828 let labels = spec. labels . as_ref ( ) . unwrap ( ) ;
826- assert_eq ! ( labels. labels. get( "pos1" ) , Some ( & "Angle" . to_string( ) ) ) ;
827- assert_eq ! ( labels. labels. get( "pos2" ) , Some ( & "Distance" . to_string( ) ) ) ;
829+ assert_eq ! ( labels. labels. get( "pos1" ) , Some ( & Some ( "Angle" . to_string( ) ) ) ) ;
830+ assert_eq ! (
831+ labels. labels. get( "pos2" ) ,
832+ Some ( & Some ( "Distance" . to_string( ) ) )
833+ ) ;
828834 }
829835
830836 #[ test]
@@ -840,9 +846,9 @@ mod tests {
840846 } ) ;
841847 spec. labels = Some ( Labels {
842848 labels : HashMap :: from ( [
843- ( "title" . to_string ( ) , "My Chart" . to_string ( ) ) ,
844- ( "color" . to_string ( ) , "Category" . to_string ( ) ) ,
845- ( "x" . to_string ( ) , "X Axis" . to_string ( ) ) ,
849+ ( "title" . to_string ( ) , Some ( "My Chart" . to_string ( ) ) ) ,
850+ ( "color" . to_string ( ) , Some ( "Category" . to_string ( ) ) ) ,
851+ ( "x" . to_string ( ) , Some ( "X Axis" . to_string ( ) ) ) ,
846852 ] ) ,
847853 } ) ;
848854
@@ -851,9 +857,15 @@ mod tests {
851857
852858 let labels = spec. labels . as_ref ( ) . unwrap ( ) ;
853859 // Material labels should remain unchanged
854- assert_eq ! ( labels. labels. get( "title" ) , Some ( & "My Chart" . to_string( ) ) ) ;
855- assert_eq ! ( labels. labels. get( "color" ) , Some ( & "Category" . to_string( ) ) ) ;
860+ assert_eq ! (
861+ labels. labels. get( "title" ) ,
862+ Some ( & Some ( "My Chart" . to_string( ) ) )
863+ ) ;
864+ assert_eq ! (
865+ labels. labels. get( "color" ) ,
866+ Some ( & Some ( "Category" . to_string( ) ) )
867+ ) ;
856868 // Position label should be transformed
857- assert_eq ! ( labels. labels. get( "pos1" ) , Some ( & "X Axis" . to_string( ) ) ) ;
869+ assert_eq ! ( labels. labels. get( "pos1" ) , Some ( & Some ( "X Axis" . to_string( ) ) ) ) ;
858870 }
859871}
0 commit comments