Skip to content

Commit 16259e2

Browse files
committed
ordinal
1 parent a7c7ab6 commit 16259e2

File tree

1 file changed

+5
-23
lines changed

1 file changed

+5
-23
lines changed

docs/summary-table.md

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ async function summary(div, filters, refresh) {
145145
if (distinct.size <= capped && !distinct.has(v)) distinct.add(v);
146146
}
147147

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) {
151151
let counts = new Map();
152152
let nulls = 0;
153153
for (const v of values) {
@@ -161,6 +161,7 @@ async function summary(div, filters, refresh) {
161161
const others = d3.sum(counts, ([key, c]) => visible.has(key) ? 0 : c);
162162

163163
const bars = [...visible];
164+
if (ordinal) bars.sort(([a], [b]) => +a - +b);
164165

165166
const Other = {toString() {return ""}}
166167
const Null = {toString() {return "ø"}};
@@ -178,7 +179,7 @@ async function summary(div, filters, refresh) {
178179
marginTop: 0,
179180
marginBottom: 13,
180181
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)"}),
182183
Plot.text(bars, Plot.stackX({text: "0", x: "1", fill: "var(--plot-background)", pointerEvents: "none"})),
183184
]
184185
});
@@ -208,25 +209,6 @@ async function summary(div, filters, refresh) {
208209
});
209210
}
210211

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-
}
230212
// temporal, quantitative
231213
else {
232214
const niceK = 5;

0 commit comments

Comments
 (0)