SummarizeColumn = (data, col) => {
let content,
value,
format,
finiteFormat,
el,
chart,
missing_label,
pct_missing,
min,
max;
const notFiniteFormat = d3.format(",.0f");
const type = getType(data, col);
const col1 = htl.html`<td style="white-space: nowrap;vertical-align:middle;padding-right:5px;padding-left:3px;">${icon_fns[
type
]()}<strong style="vertical-align:middle;">${
col === "" ? "unlabeled" : col
}</strong></td>`;
switch (type) {
case "ordinal":
format = d3.format(",.0f");
const categories = d3
.rollups(
data,
(v) => ({ count: v.length, pct: v.length / data.length || 1 }),
(d) => d[col]
)
.sort((a, b) => b[1].count - a[1].count)
.map((d) => {
let obj = {};
obj[col] = d[0] === null || d[0] === "" ? "(missing)" : d[0];
obj.count = d[1].count;
obj.pct = d[1].pct;
return obj;
});
const stack_chart = SmallStack(categories, col);
el = htl.html`<tr style="font-family:sans-serif;font-size:13px;">
${col1}
<td><div style="position:relative;">${stack_chart}</div></td>
</tr>`;
value = {
column: col,
type,
min: null,
max: null,
n_categories: categories.length
};
break;
case "date":
const start = d3.min(data, (d) => +d[col]);
const end = d3.max(data, (d) => +d[col]);
chart = Histogram(data, col, type);
el = htl.html`<tr style="font-family:sans-serif;font-size:13px;">
${col1}
<td><div style="position:relative;">${chart}</div></td>
</tr>`;
value = { column: col, type, min: start, max: end, n_categories: null };
break;
default:
min = d3.min(data, (d) => +d[col]);
max = d3.max(data, (d) => +d[col]);
chart = Histogram(data, col, type);
el = htl.html`<tr style="font-family:sans-serif;font-size:13px;">
${col1}
<td><div style="position:relative;top:3px;">${chart}</div></td>
</tr>`;
value = { column: col, type, min, max, n_categories: null };
break;
}
el.value = value;
el.appendChild(html`<style>td {vertical-align:middle;} </style>`);
return el;
}