mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-12-02 17:13:33 +01:00
The CSV/TSV viewer (explorer, gists, the author's preview) becomes an analysis view that runs on the anonymized text already in the page: click-to-sort headers (numbers, dates, natural text; stable, empty cells last), a search box and per-column range or value filters, a summary row (Average by default; Sum, Median, Min, Max, Count, Std dev) over the filtered rows, group by with an aggregate, column stats with a histogram, copy as CSV or Markdown and download of the current view, and a Chart view (bar, line, scatter) drawn in inline SVG. The view lives in the URL fragment (#table:group=model, #table-2:... for a gist file) so a link can carry it; links without it open as before. Markdown and notebook tables (pandas DataFrames) get sortable headers, an optional summary row and "Open as table" for the full view. Redaction slots keep rendering; sorting uses the XXXX-n text. The 1 MB limit holds: rows render 200 at a time as one escaped HTML string while aggregates, filters and charts use every row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
160 lines
19 KiB
HTML
160 lines
19 KiB
HTML
<div class="dt" :class="{ 'is-chart': view === 'chart', 'is-grouped': !!groupColumn }">
|
||
<div class="dt-toolbar" role="toolbar" :aria-label="'Analyze ' + (label || name || 'table')">
|
||
<label class="dt-search">
|
||
<svg class="ui-icon" aria-hidden="true"><use href="#ui-icon-search"></use></svg>
|
||
<span class="sr-only">Filter rows</span>
|
||
<input type="search" class="dt-search-input" placeholder="Filter rows" autocomplete="off" spellcheck="false" :value="s.query" @input="s.query = $event.target.value" @keydown.esc="s.query = ''">
|
||
</label>
|
||
<span class="dt-chip" v-for="f in activeFilters" :key="f.key"><span class="dt-chip-name">{{ f.name }}</span><template v-for="(seg, si) in redactParts(f.text)" :key="si"><span v-if="seg.n" class="redact-slot" role="img" :aria-label="'Redacted term ' + seg.n"><i>{{ seg.n }}</i></span><template v-else>{{ seg.t }}</template></template><button type="button" class="dt-chip-x" :aria-label="'Remove the ' + f.name + ' filter'" @click="f.clear()"><svg class="ui-icon" aria-hidden="true"><use href="#project-icon-close"></use></svg></button></span>
|
||
<button type="button" class="dt-link" v-if="activeFilters.length > 1 || (activeFilters.length && s.query)" @click="clearFilters()">Clear</button>
|
||
<span class="dt-count" aria-live="polite">{{ rowCountText }}</span>
|
||
<div class="dt-tools">
|
||
<label class="dt-select" :class="{ 'is-on': !!groupColumn }">
|
||
<span class="dt-select-label">Group by</span>
|
||
<select :value="s.group || ''" @change="setGroup($event.target.value)" aria-label="Group rows by">
|
||
<option value="">None</option>
|
||
<option v-for="c in groupable" :key="c.index" :value="c.name">{{ c.name }}</option>
|
||
</select>
|
||
<svg class="ui-icon dt-caret" aria-hidden="true"><use href="#ui-icon-chevron-down"></use></svg>
|
||
</label>
|
||
<label class="dt-select is-on" v-if="groupColumn">
|
||
<span class="sr-only">Aggregate of each group</span>
|
||
<select :value="s.agg" @change="setAgg($event.target.value)" aria-label="Aggregate of each group">
|
||
<option v-for="[fn, text] in AGGREGATES" :key="fn" :value="fn">{{ text }}</option>
|
||
</select>
|
||
<svg class="ui-icon dt-caret" aria-hidden="true"><use href="#ui-icon-chevron-down"></use></svg>
|
||
</label>
|
||
<div class="dt-copy">
|
||
<button type="button" class="btn btn-sm btn-ghost dt-copy-btn" :class="{ 'is-on': s.copyOpen }" aria-haspopup="true" :aria-expanded="s.copyOpen ? 'true' : 'false'" :title="isChanged() ? 'Copy or download this view' : 'Copy or download the table'" @click="s.copyOpen = !s.copyOpen"><svg class="ui-icon" aria-hidden="true"><use :href="s.copied && s.copied !== 'error' ? '#ui-icon-check' : '#project-icon-copy'"></use></svg><span>{{ s.copied === 'csv' ? 'Copied CSV' : s.copied === 'md' ? 'Copied Markdown' : s.copied === 'error' ? 'Copy failed' : 'Copy' }}</span><svg class="ui-icon dt-caret" aria-hidden="true"><use href="#ui-icon-chevron-down"></use></svg></button>
|
||
<div class="tb-menu dt-copy-menu" v-if="s.copyOpen" role="menu">
|
||
<div class="tb-menu-label">{{ isChanged() ? 'This view · ' + formatNumber(sorted.length) + (groupColumn ? ' groups' : ' rows') : 'All ' + formatNumber(sorted.length) + ' rows' }}</div>
|
||
<button type="button" role="menuitem" @click="copyAs('csv')"><svg class="ui-icon" aria-hidden="true"><use href="#project-icon-copy"></use></svg>Copy as CSV</button>
|
||
<button type="button" role="menuitem" @click="copyAs('md')"><svg class="ui-icon" aria-hidden="true"><use href="#ui-icon-code"></use></svg>Copy as Markdown table</button>
|
||
<button type="button" role="menuitem" @click="download()"><svg class="ui-icon" aria-hidden="true"><use href="#ui-icon-download"></use></svg>Download as CSV</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="dt-tools-m">
|
||
<button type="button" class="btn btn-sm btn-ghost btn-icon-only dt-tools-btn" :class="{ 'is-on': s.toolsOpen || !!groupColumn }" aria-label="Table tools" aria-haspopup="true" :aria-expanded="s.toolsOpen ? 'true' : 'false'" @click="s.toolsOpen = !s.toolsOpen"><svg class="ui-icon" aria-hidden="true"><use href="#project-icon-filter"></use></svg></button>
|
||
<div class="tb-menu dt-tools-menu" v-if="s.toolsOpen" role="menu">
|
||
<label class="dt-menu-field"><span>Group by</span><select :value="s.group || ''" @change="setGroup($event.target.value)"><option value="">None</option><option v-for="c in groupable" :key="c.index" :value="c.name">{{ c.name }}</option></select></label>
|
||
<label class="dt-menu-field" v-if="groupColumn"><span>Aggregate</span><select :value="s.agg" @change="setAgg($event.target.value)"><option v-for="[fn, text] in AGGREGATES" :key="fn" :value="fn">{{ text }}</option></select></label>
|
||
<template v-if="activeFilters.length"><div class="tb-menu-sep"></div><div class="dt-menu-note">Filters</div><button type="button" role="menuitem" v-for="f in activeFilters" :key="'m' + f.key" @click="f.clear()"><svg class="ui-icon" aria-hidden="true"><use href="#project-icon-close"></use></svg>{{ f.name }}: {{ f.text }}</button></template>
|
||
<div class="tb-menu-sep"></div>
|
||
<button type="button" role="menuitem" @click="copyAs('csv')"><svg class="ui-icon" aria-hidden="true"><use href="#project-icon-copy"></use></svg>Copy as CSV</button>
|
||
<button type="button" role="menuitem" @click="copyAs('md')"><svg class="ui-icon" aria-hidden="true"><use href="#ui-icon-code"></use></svg>Copy as Markdown table</button>
|
||
<button type="button" role="menuitem" @click="download()"><svg class="ui-icon" aria-hidden="true"><use href="#ui-icon-download"></use></svg>Download as CSV</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<template v-if="view === 'chart'">
|
||
<div class="dt-chart-controls">
|
||
<div class="seg-filter dt-chart-type" role="radiogroup" aria-label="Chart type">
|
||
<button type="button" role="radio" class="seg-chip" v-for="t in ['bar', 'line', 'scatter']" :key="t" :class="{ active: chartSpec.type === t }" :aria-checked="chartSpec.type === t ? 'true' : 'false'" @click="setChartType(t)">{{ t === 'bar' ? 'Bar' : t === 'line' ? 'Line' : 'Scatter' }}</button>
|
||
</div>
|
||
<label class="dt-select is-on">
|
||
<span class="dt-select-label">X</span>
|
||
<select :value="chartSpec.x" @change="setX($event.target.value)" aria-label="Column on the x axis">
|
||
<option v-for="c in table.columns" :key="c.index" :value="c.name">{{ c.name }}</option>
|
||
</select>
|
||
<svg class="ui-icon dt-caret" aria-hidden="true"><use href="#ui-icon-chevron-down"></use></svg>
|
||
</label>
|
||
<div class="dt-y" role="group" aria-label="Columns to plot">
|
||
<span class="dt-select-label">Y</span>
|
||
<button type="button" class="dt-y-chip" v-for="c in numericColumns.filter(c => c.name !== chartSpec.x)" :key="c.index" :class="{ 'is-on': yOn(c.name) }" :aria-pressed="yOn(c.name) ? 'true' : 'false'" @click="toggleY(c.name)"><span class="dt-key" v-if="yOn(c.name)" :class="['is-' + chartSpec.type]" :style="{ '--key': 'var(--dt-series-' + (seriesIndex(c.name) + 1) + ')' }"></span>{{ c.name }}</button>
|
||
</div>
|
||
</div>
|
||
<figure class="dt-chart" ref="chartHost" @mouseleave="leaveChart()">
|
||
<figcaption class="dt-chart-notes" v-if="chart && chart.notes.length">{{ chart.notes.join(' ') }}</figcaption>
|
||
<div class="dt-legend" v-if="chart && !chart.empty && chart.series.length > 1"><span class="dt-legend-item" v-for="(ser, si) in chart.series" :key="ser.name"><span class="dt-key" :class="'is-' + chart.kind" :style="{ '--key': 'var(--dt-series-' + (si + 1) + ')' }"></span>{{ ser.name }}</span></div>
|
||
<p class="dt-chart-empty" v-if="chart && chart.empty">{{ chart.empty }}</p>
|
||
<svg v-if="chart && !chart.empty" class="dt-svg" :width="chart.width" :height="chart.height" :viewBox="'0 0 ' + chart.width + ' ' + chart.height" role="img" :aria-label="chartSummary" tabindex="0" @keydown="keyStep($event)" @blur="leaveChart()">
|
||
<template v-if="chart.kind === 'bar'">
|
||
<line v-for="t in chart.xTicks" :key="'g' + t.v" class="dt-grid" :x1="t.x" :x2="t.x" :y1="chart.plot.y" :y2="chart.plot.y + chart.plot.h"></line>
|
||
<rect v-if="s.tip" class="dt-hover-band" :x="0" :y="chart.categories[s.tip.index].hit.y" :width="chart.width" :height="chart.categories[s.tip.index].hit.h"></rect>
|
||
<path v-for="m in chart.marks" :key="m.key" class="dt-bar" :d="m.path" :style="{ fill: 'var(--dt-series-' + (m.series + 1) + ')' }" :class="{ 'is-dim': s.tip && s.tip.index !== m.cat }"></path>
|
||
<line class="dt-axis" :x1="chart.zero" :x2="chart.zero" :y1="chart.plot.y" :y2="chart.plot.y + chart.plot.h"></line>
|
||
<text v-for="(cat, ci) in chart.categories" :key="'c' + ci" class="dt-cat" :x="chart.plot.x - 10" :y="cat.y" text-anchor="end" dominant-baseline="central">{{ cat.label.length > 28 ? cat.label.slice(0, 27) + '…' : cat.label }}</text>
|
||
<template v-if="chart.showValues"><text v-for="m in chart.marks" :key="'v' + m.key" class="dt-value" :x="m.lx" :y="m.ly" :text-anchor="m.anchor" dominant-baseline="central">{{ m.label }}</text></template>
|
||
<text v-for="t in chart.xTicks" :key="'t' + t.v" class="dt-tick" :x="t.x" :y="chart.plot.y + chart.plot.h + 16" text-anchor="middle">{{ t.label }}</text>
|
||
<rect class="dt-hit" x="0" :y="chart.plot.y" :width="chart.width" :height="chart.plot.h" @pointermove="pointerAt($event)" @pointerdown="pointerAt($event)"></rect>
|
||
</template>
|
||
<template v-else>
|
||
<line v-for="(t, ti) in chart.yTicks" :key="'g' + ti" class="dt-grid" :x1="chart.plot.x" :x2="chart.plot.x + chart.plot.w" :y1="t.y" :y2="t.y"></line>
|
||
<text v-for="(t, ti) in chart.yTicks" :key="'y' + ti" class="dt-tick" :x="chart.plot.x - 8" :y="t.y" text-anchor="end" dominant-baseline="central">{{ t.label }}</text>
|
||
<line class="dt-axis" :x1="chart.plot.x" :x2="chart.plot.x + chart.plot.w" :y1="chart.plot.y + chart.plot.h" :y2="chart.plot.y + chart.plot.h"></line>
|
||
<text v-for="(t, ti) in chart.xTicks" :key="'x' + ti" class="dt-tick" :x="t.x" :y="chart.plot.y + chart.plot.h + 18" :text-anchor="t.anchor || 'middle'">{{ t.label.length > 18 ? t.label.slice(0, 17) + '…' : t.label }}</text>
|
||
<line v-if="s.tip && chart.kind === 'line'" class="dt-crosshair" :x1="s.tip.crossX" :x2="s.tip.crossX" :y1="chart.plot.y" :y2="chart.plot.y + chart.plot.h"></line>
|
||
<path v-for="(ser, si) in chart.series" :key="'p' + si" class="dt-line" :d="ser.path" :style="{ stroke: 'var(--dt-series-' + (si + 1) + ')' }"></path>
|
||
<template v-for="(ser, si) in chart.series" :key="'d' + si"><circle v-for="d in ser.dots" :key="d.i" class="dt-dot" :class="{ 'is-on': s.tip && s.tip.index === d.i }" :cx="d.x" :cy="d.y" :r="s.tip && s.tip.index === d.i ? 5 : 4" :style="{ fill: 'var(--dt-series-' + (si + 1) + ')' }"></circle></template>
|
||
<rect class="dt-hit" :x="chart.plot.x - 12" :y="chart.plot.y" :width="chart.plot.w + 24" :height="chart.plot.h" @pointermove="pointerAt($event)" @pointerdown="pointerAt($event)"></rect>
|
||
</template>
|
||
</svg>
|
||
<div class="dt-axis-label" v-if="chart && !chart.empty"><template v-if="chart.kind === 'bar'">{{ chart.axisLabel }}</template><template v-else>{{ chart.yLabel ? chart.yLabel + ' by ' : 'By ' }}{{ chart.xLabel }}</template></div>
|
||
<div class="dt-tip" v-if="s.tip && chart && !chart.empty" :style="tipStyle" role="status">
|
||
<div class="dt-tip-title" v-if="s.tip.title"><template v-for="(seg, si) in redactParts(s.tip.title)" :key="si"><span v-if="seg.n" class="redact-slot" role="img" :aria-label="'Redacted term ' + seg.n"><i>{{ seg.n }}</i></span><template v-else>{{ seg.t }}</template></template></div>
|
||
<div class="dt-tip-row" v-for="(r, ri) in s.tip.rows" :key="ri"><span class="dt-key is-line" :style="{ '--key': 'var(--dt-series-' + (ri + 1) + ')' }"></span><b>{{ r.value }}</b><span>{{ r.name }}</span></div>
|
||
<div class="dt-tip-note" v-if="s.tip.note">{{ s.tip.note }}</div>
|
||
</div>
|
||
</figure>
|
||
</template>
|
||
|
||
<div class="csv-table-wrap dt-wrap" v-else tabindex="0" role="region" :aria-label="'Table view of ' + (label || name || 'table')">
|
||
<table class="csv-table dt-table">
|
||
<thead><tr>
|
||
<th class="csv-rownum" scope="col" v-if="!groupColumn"><span class="sr-only">Row</span></th>
|
||
<th scope="col" v-for="c in table.columns" :key="c.index" :class="{ 'is-num': c.type === 'number', 'is-sorted': !!sortState(c) }" :aria-sort="ariaSort(c)">
|
||
<span class="dt-th"><button type="button" class="dt-sort" :title="'Sort by ' + c.name" @click="cycleSort(c)"><span class="dt-th-name"><template v-for="(seg, si) in redactParts(c.name)" :key="si"><span v-if="seg.n" class="redact-slot" role="img" :aria-label="'Redacted term ' + seg.n"><i>{{ seg.n }}</i></span><template v-else>{{ seg.t }}</template></template></span><span class="dt-th-agg" v-if="c.agg">{{ aggregateShort(c.agg) }}</span><svg class="dt-sort-icon" :class="sortState(c) ? 'is-' + sortState(c) : ''" viewBox="0 0 10 14" aria-hidden="true"><path class="up" d="M5 1.5 8.5 5.5h-7z"/><path class="down" d="M5 12.5 1.5 8.5h7z"/></svg></button><button type="button" class="dt-col-btn" :data-col="c.index" :class="{ 'is-on': s.menu && s.menu.index === c.index }" :aria-label="'Stats and filters for ' + c.name" aria-haspopup="dialog" :aria-expanded="s.menu && s.menu.index === c.index ? 'true' : 'false'" @click.stop="openMenu(c.index, $event)"><svg class="ui-icon" aria-hidden="true"><use href="#ui-icon-chevron-down"></use></svg></button></span>
|
||
</th>
|
||
</tr></thead>
|
||
<tbody v-if="sorted.length" v-html="bodyHtml"></tbody>
|
||
<tbody v-else><tr class="dt-empty-row"><td :colspan="table.columns.length + (groupColumn ? 0 : 1)">No rows match. <button type="button" class="dt-link" @click="clearFilters()">Clear the filters</button></td></tr></tbody>
|
||
<tfoot v-if="sorted.length">
|
||
<tr class="dt-summary">
|
||
<td class="csv-rownum" v-if="!groupColumn"><span aria-hidden="true">Σ</span><span class="sr-only">Summary</span></td>
|
||
<td v-for="(c, ci) in table.columns" :key="c.index" :class="{ 'is-num': c.type === 'number' }">
|
||
<span class="dt-sum" v-if="summary[ci].kind === 'number'"><label class="dt-sum-fn"><span class="sr-only">Summary of {{ c.name }}</span><select :value="summary[ci].fn" @change="setSum(c, $event.target.value)"><option v-for="[fn, text] in AGGREGATES" :key="fn" :value="fn">{{ text }}</option></select><span class="dt-sum-fn-label" aria-hidden="true">{{ aggregateShort(summary[ci].fn) }}</span></label><b class="dt-sum-value">{{ summary[ci].text }}</b></span>
|
||
<span class="dt-sum is-text" v-else>{{ summary[ci].text }}</span>
|
||
</td>
|
||
</tr>
|
||
</tfoot>
|
||
</table>
|
||
<div class="dt-more" v-if="sorted.length > visible.length">
|
||
<span>Showing {{ formatNumber(visible.length) }} of {{ formatNumber(sorted.length) }} rows. Sums, filters and charts use all of them.</span>
|
||
<button type="button" class="btn btn-sm" @click="showMore()">Show {{ formatNumber(Math.min(PAGE_SIZE, sorted.length - visible.length)) }} more</button>
|
||
<button type="button" class="dt-link" @click="showAll()">Show all</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="dt-menu" v-if="s.menu && menuColumn && menuStats" role="dialog" tabindex="-1" :aria-label="'Column ' + menuColumn.name" :style="{ left: s.menu.left + 'px', top: s.menu.top + 'px' }" @click.stop>
|
||
<div class="dt-menu-head"><b><template v-for="(seg, si) in redactParts(menuColumn.name)" :key="si"><span v-if="seg.n" class="redact-slot" role="img" :aria-label="'Redacted term ' + seg.n"><i>{{ seg.n }}</i></span><template v-else>{{ seg.t }}</template></template></b><span>{{ menuStats.typeLabel }}</span></div>
|
||
<dl class="dt-stats"><div v-for="[k, v] in menuStats.rows" :key="k"><dt>{{ k }}</dt><dd>{{ v }}</dd></div></dl>
|
||
<figure class="dt-hist" v-if="menuStats.bars.length">
|
||
<svg width="218" height="42" viewBox="0 0 218 42" role="img" :aria-label="'Distribution of ' + menuColumn.name"><rect v-for="(b, bi) in menuStats.bars" :key="bi" :x="b.x" :y="42 - b.h" :width="b.w" :height="b.h" rx="1.5"><title>{{ b.title }}</title></rect></svg>
|
||
<figcaption><span>{{ menuStats.histFrom }}</span><span>{{ menuStats.histTo }}</span></figcaption>
|
||
</figure>
|
||
<ul class="dt-top" v-if="menuStats.top && menuStats.top.length"><li v-for="t in menuStats.top" :key="t.value"><span class="dt-top-name"><template v-for="(seg, si) in redactParts(t.value)" :key="si"><span v-if="seg.n" class="redact-slot" role="img" :aria-label="'Redacted term ' + seg.n"><i>{{ seg.n }}</i></span><template v-else>{{ seg.t }}</template></template></span><span class="dt-top-bar" :style="{ width: Math.max(4, t.share) + '%' }"></span><span class="dt-top-n">{{ t.count }}</span></li></ul>
|
||
<div class="dt-menu-sec">
|
||
<div class="seg-filter dt-menu-sort" role="group" aria-label="Sort">
|
||
<button type="button" class="seg-chip" :class="{ active: sortState(menuColumn) === 'asc' }" @click="setSort(menuColumn, sortState(menuColumn) === 'asc' ? null : 'asc')">{{ menuColumn.type === 'text' ? 'A → Z' : 'Low → high' }}</button>
|
||
<button type="button" class="seg-chip" :class="{ active: sortState(menuColumn) === 'desc' }" @click="setSort(menuColumn, sortState(menuColumn) === 'desc' ? null : 'desc')">{{ menuColumn.type === 'text' ? 'Z → A' : 'High → low' }}</button>
|
||
</div>
|
||
</div>
|
||
<div class="dt-menu-sec" v-if="sourceColumn(menuColumn) && sourceColumn(menuColumn).type === 'number'">
|
||
<div class="dt-menu-label">Show rows between</div>
|
||
<div class="dt-range"><input type="text" inputmode="decimal" class="dt-range-input" placeholder="Min" aria-label="Minimum" :value="rangeValue(menuColumn, 0)" @change="setRange(menuColumn, 0, $event.target.value)" @keydown.enter="setRange(menuColumn, 0, $event.target.value)"><span>–</span><input type="text" inputmode="decimal" class="dt-range-input" placeholder="Max" aria-label="Maximum" :value="rangeValue(menuColumn, 1)" @change="setRange(menuColumn, 1, $event.target.value)" @keydown.enter="setRange(menuColumn, 1, $event.target.value)"></div>
|
||
</div>
|
||
<div class="dt-menu-sec" v-else-if="chipValues(menuColumn).length">
|
||
<div class="dt-menu-label">Show only</div>
|
||
<div class="dt-chips"><button type="button" class="dt-value-chip" v-for="v in chipValues(menuColumn)" :key="v.value" :class="{ 'is-on': chipOn(menuColumn, v.value) }" :aria-pressed="chipOn(menuColumn, v.value) ? 'true' : 'false'" @click="toggleChip(menuColumn, v.value)"><template v-for="(seg, si) in redactParts(v.label)" :key="si"><span v-if="seg.n" class="redact-slot" role="img" :aria-label="'Redacted term ' + seg.n"><i>{{ seg.n }}</i></span><template v-else>{{ seg.t }}</template></template><span class="dt-value-n">{{ v.count }}</span></button></div>
|
||
</div>
|
||
<div class="dt-menu-sec" v-if="!groupColumn && groupable.some(g => g.name === menuColumn.name)">
|
||
<button type="button" class="dt-menu-action" @click="setGroup(menuColumn.name)"><svg class="ui-icon" aria-hidden="true"><use href="#ui-icon-list"></use></svg>Group by {{ menuColumn.name }}</button>
|
||
</div>
|
||
<div class="dt-menu-sec" v-else-if="groupColumn && menuColumn.index === 0">
|
||
<button type="button" class="dt-menu-action" @click="setGroup(null)"><svg class="ui-icon" aria-hidden="true"><use href="#project-icon-close"></use></svg>Ungroup</button>
|
||
</div>
|
||
</div>
|
||
</div>
|