@@ -7,7 +7,9 @@ import type {
77} from "./lib" ;
88
99export const MAX_VISIBLE_TIME_LABELS : number = 12 ;
10- const EMPTY_TIME_LABEL_PLACEHOLDER : string = " " ;
10+ const ZERO_WIDTH_ZERO : string = "\u200b" ;
11+ const ZERO_WIDTH_ONE : string = "\u200c" ;
12+ const ZERO_WIDTH_SENTINEL : string = "\u200d" ;
1113
1214const formatTimeLabels = ( times : Date [ ] ) : string [ ] => {
1315 if ( times . length === 0 ) {
@@ -25,16 +27,27 @@ const formatTimeLabels = (times: Date[]): string[] => {
2527 const usableSlots : number = Math . max ( MAX_VISIBLE_TIME_LABELS - 2 , 1 ) ;
2628 const spacing : number = Math . ceil ( ( formattedTimes . length - 2 ) / usableSlots ) ;
2729
30+ const encodeHiddenLabel = ( index : number ) : string => {
31+ const binary : string = index . toString ( 2 ) ;
32+ return (
33+ ZERO_WIDTH_SENTINEL +
34+ binary
35+ . split ( "" )
36+ . map ( ( digit : string ) : string =>
37+ digit === "0" ? ZERO_WIDTH_ZERO : ZERO_WIDTH_ONE ,
38+ )
39+ . join ( "" )
40+ ) ;
41+ } ;
42+
2843 return formattedTimes . map (
2944 ( label : string , index : number , array : string [ ] ) : string => {
3045 if ( index === 0 || index === array . length - 1 ) {
3146 return label ;
3247 }
3348
3449 const normalizedIndex : number = index - 1 ;
35- return normalizedIndex % spacing === 0
36- ? label
37- : EMPTY_TIME_LABEL_PLACEHOLDER ;
50+ return normalizedIndex % spacing === 0 ? label : encodeHiddenLabel ( index ) ;
3851 } ,
3952 ) ;
4053} ;
0 commit comments