mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-12-02 17:13:33 +01:00
fix(viewers): summary row as the table's last row, identifiers left out
The CSV summary row read as a floating card: rounded, a repeated "Avg" label in every cell, distinct counts under text columns and an average of the seed column. - The footer follows the column grid: square edges, a 2px top rule and the header's solid fill. It stays at the bottom of the scroll area, which no longer has vertical padding, so no rows show past it; a short table ends on it. - One "Average" select in the first column (or the row-number column) sets the aggregate for every numeric column. Cells show only the value, right-aligned, semibold. A column can override it from its menu, marked by a small label in its cell. - Text, date and identifier columns are empty in the footer; their distinct counts stay in the column menu. - Identifiers (seed, id, run, fold, index, year by name, or small consecutive whole numbers that repeat) are left out of the summary, group averages and default charts. "Treat as number" in the column menu brings one back (#table:num=seed). - Markdown and notebook tables get the same footer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
43e92bef53
commit
4fc3a8b2df
11 files changed
+231
-148
No files matched your search
@@ -31,6 +31,7 @@ export const DataTable = {
|
||||
const s = reactive({
|
||||
query: fromHash?.query || "", sort: fromHash?.sort || null, group: fromHash?.group || null, agg: fromHash?.agg || "mean",
|
||||
ranges: fromHash?.ranges || {}, values: fromHash?.values || {}, sums: fromHash?.sums || {},
|
||||
sum: fromHash?.sum || "mean", numeric: fromHash?.numeric || [],
|
||||
chart: fromHash?.chart || null, x: fromHash?.x || null, y: fromHash?.y || [],
|
||||
limit: PAGE_SIZE, menu: null, toolsOpen: false, copyOpen: false, copied: "", tip: null,
|
||||
});
|
||||
@@ -39,13 +40,22 @@ export const DataTable = {
|
||||
const indexed = (map) => Object.fromEntries(Object.entries(map).map(([name, v]) => [byName(base.value, name)?.index, v]).filter(([i]) => i != null));
|
||||
const filtered = computed(() => filterIndices(base.value, { query: s.query, ranges: indexed(s.ranges), values: indexed(s.values) }));
|
||||
const groupColumn = computed(() => (s.group ? byName(base.value, s.group) : null));
|
||||
const table = computed(() => (groupColumn.value ? groupTable(base.value, filtered.value, groupColumn.value.index, s.agg) : base.value));
|
||||
// Identifier columns (seed, run, fold...) are not measures unless the reader says so.
|
||||
const isMeasure = (c) => c.type === "number" && (!c.identifier || (!table.value?.grouped && s.numeric.includes(c.name)));
|
||||
const isBaseMeasure = (c) => c.type === "number" && (!c.identifier || s.numeric.includes(c.name));
|
||||
const table = computed(() => (groupColumn.value ? groupTable(base.value, filtered.value, groupColumn.value.index, s.agg, isBaseMeasure) : base.value));
|
||||
const rowsInView = computed(() => (groupColumn.value ? table.value.body.map((_, i) => i) : filtered.value));
|
||||
const sortColumn = computed(() => (s.sort ? byName(table.value, s.sort.column) : null));
|
||||
const sorted = computed(() => (sortColumn.value ? sortIndices(table.value, rowsInView.value, sortColumn.value.index, s.sort.dir) : rowsInView.value));
|
||||
const visible = computed(() => sorted.value.slice(0, s.limit));
|
||||
const summary = computed(() => table.value.columns.map((c) => summarize(c, rowsInView.value, s.sums[c.name] || "mean")));
|
||||
const numericColumns = computed(() => table.value.columns.filter((c) => c.type === "number"));
|
||||
// One aggregate for the whole summary row; a column can override it from its menu.
|
||||
const summary = computed(() => table.value.columns.map((c) => summarize(c, rowsInView.value, s.sums[c.name] || s.sum, isMeasure)));
|
||||
const sumOverride = (c) => (s.sums[c.name] && s.sums[c.name] !== s.sum ? s.sums[c.name] : null);
|
||||
// The row's single "Average ▾" goes in the first column when it holds no
|
||||
// value (a name, a group), else in the row-number column.
|
||||
const sumInFirst = computed(() => !!groupColumn.value || !isMeasure(table.value.columns[0] || {}));
|
||||
const hasSummary = computed(() => summary.value.some((x) => x.kind === "number"));
|
||||
const numericColumns = computed(() => table.value.columns.filter((c) => isMeasure(c)));
|
||||
|
||||
// ---- Sorting: ascending, descending, then the file's order ----
|
||||
const sortState = (column) => (s.sort && s.sort.column === column.name ? s.sort.dir : null);
|
||||
@@ -108,7 +118,17 @@ export const DataTable = {
|
||||
const groupable = computed(() => base.value.columns.filter((c) => c.type !== "number" || (c.decimals === 0 && !c.unit && distinctValues(c).size <= 50)));
|
||||
const setGroup = (name) => { s.group = name || null; s.sort = null; s.limit = PAGE_SIZE; s.menu = null; resetChartAxes(); };
|
||||
const setAgg = (fn) => { s.agg = fn; };
|
||||
const setSum = (column, fn) => { s.sums = { ...s.sums, [column.name]: fn }; };
|
||||
const setSum = (column, fn) => {
|
||||
const sums = { ...s.sums };
|
||||
if (!fn || fn === s.sum) delete sums[column.name]; else sums[column.name] = fn;
|
||||
s.sums = sums;
|
||||
};
|
||||
const setRowSum = (fn) => { s.sum = fn; };
|
||||
const treatAsNumber = (column, on) => {
|
||||
const list = new Set(s.numeric);
|
||||
if (on) list.add(column.name); else list.delete(column.name);
|
||||
s.numeric = [...list];
|
||||
};
|
||||
|
||||
// ---- Column menu (stats, sort, filter, group) ----
|
||||
const menuColumn = computed(() => (s.menu ? table.value.columns[s.menu.index] : null));
|
||||
@@ -120,12 +140,12 @@ export const DataTable = {
|
||||
const peak = Math.max(1, ...(stats.histogram || []).map((b) => b.count));
|
||||
return {
|
||||
...stats,
|
||||
typeLabel: column.type === "number" ? (column.decimals ? `Number · ${column.decimals} ${column.decimals === 1 ? "decimal" : "decimals"}` : "Whole number") + (column.unit ? " · %" : "") : column.type === "date" ? "Date" : "Text",
|
||||
typeLabel: column.type === "number" ? (column.identifier && !isMeasure(column) ? "Identifier" : column.decimals ? `Number · ${column.decimals} ${column.decimals === 1 ? "decimal" : "decimals"}` : "Whole number") + (column.unit ? " · %" : "") : column.type === "date" ? "Date" : "Text",
|
||||
rows: [
|
||||
["Values", formatNumber(stats.count)], ["Empty", formatNumber(stats.empty)], ["Distinct", formatNumber(stats.distinct)],
|
||||
...(stats.min != null ? [["Min", fmt(stats.min)], ["Max", fmt(stats.max)]] : []),
|
||||
...(stats.mean != null ? [["Mean", formatKey(column, stats.mean, "mean")]] : []),
|
||||
...(stats.std != null ? [["Std dev", formatKey(column, stats.std, "std")]] : []),
|
||||
...(stats.mean != null && isMeasure(column) ? [["Mean", formatKey(column, stats.mean, "mean")]] : []),
|
||||
...(stats.std != null && isMeasure(column) ? [["Std dev", formatKey(column, stats.std, "std")]] : []),
|
||||
],
|
||||
bars: (stats.histogram || []).map((b, i, all) => ({ x: (i * 216) / all.length + 1, w: Math.max(1, 216 / all.length - 2), h: Math.max(b.count ? 2 : 0, (b.count / peak) * 40), count: b.count,
|
||||
title: `${fmt(b.from)} – ${fmt(b.to)}: ${b.count} ${b.count === 1 ? "row" : "rows"}` })),
|
||||
@@ -259,7 +279,7 @@ export const DataTable = {
|
||||
// ---- Shareable state in the URL fragment ----
|
||||
const snapshot = () => ({
|
||||
view: props.view, query: s.query, sort: s.sort, group: s.group, agg: s.agg, ranges: s.ranges, values: s.values,
|
||||
sums: s.sums, chart: s.chart, x: s.x, y: s.y,
|
||||
sum: s.sum, sums: s.sums, numeric: s.numeric, chart: s.chart, x: s.x, y: s.y,
|
||||
});
|
||||
if (props.stateKey) {
|
||||
let timer;
|
||||
@@ -322,7 +342,8 @@ export const DataTable = {
|
||||
return {
|
||||
s, props, base, table, sorted, visible, summary, numericColumns, filtered, groupColumn, rowsInView,
|
||||
redactParts, cycleSort, setSort, sortState, ariaSort, setRange, rangeValue, chipValues, chipOn, toggleChip,
|
||||
activeFilters, clearFilters, filtering, groupable, setGroup, setAgg, setSum, AGGREGATES, AGGREGATE_LABEL, aggregateShort,
|
||||
activeFilters, clearFilters, filtering, groupable, setGroup, setAgg, setSum, setRowSum, treatAsNumber, isMeasure, sumOverride, sumInFirst, hasSummary,
|
||||
AGGREGATES, AGGREGATE_LABEL, aggregateShort,
|
||||
menuColumn, menuStats, openMenu, closeMenus, sourceColumn, copyAs, download, isChanged, bodyHtml, rowCountText,
|
||||
chart, chartSpec, chartHost, setChartType, setX, yOn, toggleY, seriesIndex, pointerAt, keyStep, tipStyle, chartSummary,
|
||||
MAX_SERIES, PAGE_SIZE, formatNumber,
|
||||
|
||||
Reference in new issue
Block a user