@@ -145,9 +145,9 @@ async function summary(div, filters, refresh) {
145
145
if (distinct .size <= capped && ! distinct .has (v)) distinct .add (v);
146
146
}
147
147
148
- // categorical
149
- if (type === " Utf8 " ) {
150
- const stackOptions = {order : " sum " , reverse : true };
148
+ const categorical = type === " Utf8 " ;
149
+ const ordinal = ! categorical && distinct . size <= 10 ;
150
+ if (categorical || ordinal) {
151
151
let counts = new Map ();
152
152
let nulls = 0 ;
153
153
for (const v of values) {
@@ -161,6 +161,7 @@ async function summary(div, filters, refresh) {
161
161
const others = d3 .sum (counts, ([key , c ]) => visible .has (key) ? 0 : c);
162
162
163
163
const bars = [... visible];
164
+ if (ordinal) bars .sort (([a ], [b ]) => + a - + b);
164
165
165
166
const Other = {toString () {return " …" }}
166
167
const Null = {toString () {return " ø" }};
@@ -178,7 +179,7 @@ async function summary(div, filters, refresh) {
178
179
marginTop: 0 ,
179
180
marginBottom: 13 ,
180
181
marks: [
181
- Plot .barX (bars, {x: " 1" , insetRight: 1 , fill : ([x ]) => typeof x === " string " ? " var(--theme-foreground-focus)" : " gray " }),
182
+ Plot .barX (bars, {x: " 1" , insetRight: 1 , fill : ([x ]) => typeof x === " object " ? " gray " : " var(--theme-foreground-focus)" }),
182
183
Plot .text (bars, Plot .stackX ({text: " 0" , x: " 1" , fill: " var(--plot-background)" , pointerEvents: " none" })),
183
184
]
184
185
});
@@ -208,25 +209,6 @@ async function summary(div, filters, refresh) {
208
209
});
209
210
}
210
211
211
- // ordinal
212
- else if (distinct .size <= 10 ) {
213
- const stackOptions = {order: " z" };
214
- chart = Plot .plot ({
215
- width,
216
- height,
217
- style: " overflow: visible;" ,
218
- x: {axis: null },
219
- y: {axis: null },
220
- marginLeft: 2 ,
221
- marginRight: 2 ,
222
- marginTop: 0 ,
223
- marginBottom: 13 ,
224
- marks: [
225
- Plot .barX (values, Plot .stackX (stackOptions, Plot .groupZ ({x: " count" }, {z: Plot .identity , insetRight: 1 , fill: " var(--theme-foreground-focus)" }))),
226
- Plot .text (values, Plot .stackX (stackOptions, Plot .groupZ ({x: " count" , text: " first" }, {z: Plot .identity , fill: " var(--plot-background)" }))),
227
- ]
228
- });
229
- }
230
212
// temporal, quantitative
231
213
else {
232
214
const niceK = 5 ;
0 commit comments