File tree 1 file changed +32
-2
lines changed
1 file changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -96,8 +96,38 @@ export const getFilters = (data) => {
96
96
return acc ;
97
97
} , { lowerBounds : [ ] , counts : [ 0 ] } ) ;
98
98
99
- // Initialize de value of the filters
100
- filters [ field ] . value = field == 'refs' ? filters [ field ] . counts . length - 2 : 0 ;
99
+ // Initialize the value of the filters
100
+ let threshold = 0 ;
101
+ switch ( field ) {
102
+ case 'refs' :
103
+ threshold = 5000 ;
104
+ break ;
105
+ case 'concepts' :
106
+ threshold = 200 ;
107
+ break ;
108
+ case 'works' :
109
+ case 'authors' :
110
+ case 'institutions' :
111
+ case 'sources' :
112
+ threshold = 50 ;
113
+ break ;
114
+ case 'countries' :
115
+ case 'funders' :
116
+ threshold = 25 ;
117
+ break ;
118
+ }
119
+
120
+ // Get the filter value closest to the threshold
121
+ let idxAbove = filters [ field ] . counts . findIndex ( ( el ) => el >= threshold ) ;
122
+ let idxBelow = filters [ field ] . counts . findLastIndex ( ( el ) => el < threshold ) ;
123
+ let diffAbove = Math . abs ( threshold - filters [ field ] . counts [ idxAbove ] ) ;
124
+ let diffBelow = Math . abs ( threshold - filters [ field ] . counts [ idxBelow ] ) ;
125
+ filters [ field ] . value = diffAbove < diffBelow ? idxAbove : idxBelow ;
126
+
127
+ if ( field === 'refs' ) {
128
+ // We want at least 2 occurences of refs by default
129
+ filters [ field ] . value = Math . min ( filters [ field ] . value , filters [ field ] . counts . length - 2 ) ;
130
+ }
101
131
} ) ;
102
132
103
133
return filters ;
You can’t perform that action at this time.
0 commit comments