@@ -252,19 +252,8 @@ impl<T: TimeValue + Datelike + Clone> ValueFormatter<T> for Monthly<T> {
252252 }
253253}
254254
255- impl < T : TimeValue + Clone > Ranged for Monthly < T > {
256- type FormatOption = crate :: coord:: ranged:: NoDefaultFormatting ;
257- type ValueType = T ;
258-
259- fn range ( & self ) -> Range < T > {
260- self . 0 . start . clone ( ) ..self . 0 . end . clone ( )
261- }
262-
263- fn map ( & self , value : & Self :: ValueType , limit : ( i32 , i32 ) ) -> i32 {
264- T :: map_coord ( value, & self . 0 . start , & self . 0 . end , limit)
265- }
266-
267- fn key_points < HintType : KeyPointHint > ( & self , hint : HintType ) -> Vec < Self :: ValueType > {
255+ impl < T : TimeValue + Clone > Monthly < T > {
256+ fn bold_key_points < H : KeyPointHint > ( & self , hint : & H ) -> Vec < T > {
268257 let max_points = hint. max_num_points ( ) ;
269258 let start_date = self . 0 . start . date_ceil ( ) ;
270259 let end_date = self . 0 . end . date_floor ( ) ;
@@ -356,7 +345,35 @@ impl<T: TimeValue + Clone> Ranged for Monthly<T> {
356345 }
357346}
358347
359- impl < T : TimeValue + Clone > DiscreteRanged for Monthly < T > {
348+ impl < T : TimeValue + Clone > Ranged for Monthly < T >
349+ where
350+ Range < T > : AsRangedCoord < Value = T > ,
351+ {
352+ type FormatOption = crate :: coord:: ranged:: NoDefaultFormatting ;
353+ type ValueType = T ;
354+
355+ fn range ( & self ) -> Range < T > {
356+ self . 0 . start . clone ( ) ..self . 0 . end . clone ( )
357+ }
358+
359+ fn map ( & self , value : & Self :: ValueType , limit : ( i32 , i32 ) ) -> i32 {
360+ T :: map_coord ( value, & self . 0 . start , & self . 0 . end , limit)
361+ }
362+
363+ fn key_points < HintType : KeyPointHint > ( & self , hint : HintType ) -> Vec < Self :: ValueType > {
364+ if hint. weight ( ) . allow_light_points ( ) && self . size ( ) <= hint. bold_points ( ) * 2 {
365+ let coord: <Range < T > as AsRangedCoord >:: CoordDescType = self . 0 . clone ( ) . into ( ) ;
366+ let normal = coord. key_points ( hint. max_num_points ( ) ) ;
367+ return normal;
368+ }
369+ self . bold_key_points ( & hint)
370+ }
371+ }
372+
373+ impl < T : TimeValue + Clone > DiscreteRanged for Monthly < T >
374+ where
375+ Range < T > : AsRangedCoord < Value = T > ,
376+ {
360377 fn size ( & self ) -> usize {
361378 let ( start_year, start_month) = {
362379 let ceil = self . 0 . start . date_ceil ( ) ;
@@ -455,7 +472,10 @@ impl<T: TimeValue + Datelike + Clone> ValueFormatter<T> for Yearly<T> {
455472 }
456473}
457474
458- impl < T : TimeValue + Clone > Ranged for Yearly < T > {
475+ impl < T : TimeValue + Clone > Ranged for Yearly < T >
476+ where
477+ Range < T > : AsRangedCoord < Value = T > ,
478+ {
459479 type FormatOption = crate :: coord:: ranged:: NoDefaultFormatting ;
460480 type ValueType = T ;
461481
@@ -468,6 +488,9 @@ impl<T: TimeValue + Clone> Ranged for Yearly<T> {
468488 }
469489
470490 fn key_points < HintType : KeyPointHint > ( & self , hint : HintType ) -> Vec < Self :: ValueType > {
491+ if hint. weight ( ) . allow_light_points ( ) && self . size ( ) <= hint. bold_points ( ) * 2 {
492+ return Monthly ( self . 0 . clone ( ) ) . key_points ( hint) ;
493+ }
471494 let max_points = hint. max_num_points ( ) ;
472495 let start_date = self . 0 . start . date_ceil ( ) ;
473496 let end_date = self . 0 . end . date_floor ( ) ;
@@ -498,7 +521,10 @@ impl<T: TimeValue + Clone> Ranged for Yearly<T> {
498521 }
499522}
500523
501- impl < T : TimeValue + Clone > DiscreteRanged for Yearly < T > {
524+ impl < T : TimeValue + Clone > DiscreteRanged for Yearly < T >
525+ where
526+ Range < T > : AsRangedCoord < Value = T > ,
527+ {
502528 fn size ( & self ) -> usize {
503529 let year_start = self . 0 . start . date_ceil ( ) . year ( ) ;
504530 let year_end = self . 0 . end . date_floor ( ) . year ( ) ;
@@ -883,6 +909,7 @@ mod test {
883909
884910 #[ test]
885911 fn test_yearly_date_range ( ) {
912+ use crate :: coord:: BoldPoints ;
886913 let range = Utc . ymd ( 1000 , 8 , 5 ) ..Utc . ymd ( 2999 , 1 , 1 ) ;
887914 let ranged_coord = range. yearly ( ) ;
888915
@@ -910,7 +937,7 @@ mod test {
910937
911938 let range = Utc . ymd ( 2019 , 8 , 5 ) ..Utc . ymd ( 2020 , 1 , 1 ) ;
912939 let ranged_coord = range. yearly ( ) ;
913- let kps = ranged_coord. key_points ( 23 ) ;
940+ let kps = ranged_coord. key_points ( BoldPoints ( 23 ) ) ;
914941 assert ! ( kps. len( ) == 1 ) ;
915942 }
916943
@@ -919,13 +946,15 @@ mod test {
919946 let range = Utc . ymd ( 2019 , 8 , 5 ) ..Utc . ymd ( 2020 , 9 , 1 ) ;
920947 let ranged_coord = range. monthly ( ) ;
921948
922- let kps = ranged_coord. key_points ( 15 ) ;
949+ use crate :: coord:: BoldPoints ;
950+
951+ let kps = ranged_coord. key_points ( BoldPoints ( 15 ) ) ;
923952
924953 assert ! ( kps. len( ) <= 15 ) ;
925954 assert ! ( kps. iter( ) . all( |x| x. day( ) == 1 ) ) ;
926955 assert ! ( kps. into_iter( ) . any( |x| x. month( ) != 9 ) ) ;
927956
928- let kps = ranged_coord. key_points ( 5 ) ;
957+ let kps = ranged_coord. key_points ( BoldPoints ( 5 ) ) ;
929958 assert ! ( kps. len( ) <= 5 ) ;
930959 assert ! ( kps. iter( ) . all( |x| x. day( ) == 1 ) ) ;
931960 let kps: Vec < _ > = kps. into_iter ( ) . map ( |x| x. month ( ) ) . collect ( ) ;
0 commit comments