@@ -148,23 +148,22 @@ async function summary(div, filters, refresh) {
148
148
// categorical
149
149
if (type === " Utf8" ) {
150
150
const stackOptions = {order: " sum" , reverse: true };
151
- const counts = new Map ();
151
+ let counts = new Map ();
152
152
let nulls = 0 ;
153
153
for (const v of values) {
154
154
if (v == null ) {nulls++ ; continue ;}
155
155
if (counts .has (v)) counts .set (v, 1 + counts .get (v)); else counts .set (v, 1 );
156
156
}
157
- const topX = d3 .sort (counts, ([, c ]) => - c).slice (0 , 10 );
158
- const visible = new Map (topX .filter (([, c ]) => c / count > 0.3 ));
157
+ counts = d3 .sort (counts, ([, c ]) => - c);
158
+ const topX = counts .slice (0 , 10 );
159
+ let visible = new Map (topX .filter (([, c ]) => c / count > 0.07 ));
160
+ if (counts .length === visible .size + 1 ) visible = new Map (counts); // if the “others” group has a single value, use it
159
161
const others = d3 .sum (counts, ([key , c ]) => visible .has (key) ? 0 : c);
160
162
161
- // TODO:
162
- // - if the “others” group has a single value, use it
163
- // - if a category is already named "Others", use "…" instead
164
-
165
163
const bars = [... visible];
166
- const Other = {toString () {return " Other" }};
167
- const Null = {toString () {return " null" }};
164
+
165
+ const Other = {toString () {return " …" }}
166
+ const Null = {toString () {return " ø" }};
168
167
if (others) bars .push ([Other, others]);
169
168
if (nulls) bars .push ([Null, nulls]);
170
169
0 commit comments