feat: y-axis SI prefix, hide tick from legend, fix table sort
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { useApp } from '@/lib/context';
|
||||
import { resolveName } from '@/lib/localization';
|
||||
import { formatSI } from '@/lib/formatNumber';
|
||||
import { CardShell } from './CardShell';
|
||||
import type { ChartConfig, SignalRow } from '@/lib/types';
|
||||
|
||||
@@ -13,11 +14,27 @@ interface Props {
|
||||
export default function TableViz({ config, rows, onEdit, onDelete }: Props) {
|
||||
const { localeMap } = useApp();
|
||||
|
||||
const sortCol = config.signal_type === 'red' ? 'red' : 'green';
|
||||
|
||||
const latest = new Map<string, { green?: number; red?: number }>();
|
||||
for (const row of rows) {
|
||||
latest.set(`${row.combinator}::${row.item_key}`, { green: row.green, red: row.red });
|
||||
}
|
||||
const tableRows = [...latest.entries()].sort((a, b) => (a[1].green ?? 0) - (b[1].green ?? 0));
|
||||
const tableRows = [...latest.entries()]
|
||||
.sort((a, b) => {
|
||||
const va = a[1][sortCol] ?? 0;
|
||||
const vb = b[1][sortCol] ?? 0;
|
||||
switch (config.order_by) {
|
||||
case 'value_asc':
|
||||
case 'delta_asc':
|
||||
return va - vb;
|
||||
case 'abs_desc':
|
||||
return Math.abs(vb) - Math.abs(va);
|
||||
default:
|
||||
return vb - va;
|
||||
}
|
||||
})
|
||||
.slice(0, config.series_limit);
|
||||
|
||||
return (
|
||||
<CardShell title={config.title} onEdit={onEdit} onDelete={onDelete} empty={rows.length === 0}>
|
||||
@@ -40,12 +57,12 @@ export default function TableViz({ config, rows, onEdit, onDelete }: Props) {
|
||||
<td className="px-2 py-0.5 text-gray-500">{combinator}</td>
|
||||
{config.signal_type !== 'red' && (
|
||||
<td className={`px-2 py-0.5 text-right font-mono ${(vals.green ?? 0) < 0 ? 'text-red-400' : 'text-green-400'}`}>
|
||||
{vals.green?.toLocaleString() ?? '--'}
|
||||
{vals.green != null ? formatSI(vals.green) : '--'}
|
||||
</td>
|
||||
)}
|
||||
{config.signal_type !== 'green' && (
|
||||
<td className="px-2 py-0.5 text-right font-mono text-orange-400">
|
||||
{vals.red?.toLocaleString() ?? '--'}
|
||||
{vals.red != null ? formatSI(vals.red) : '--'}
|
||||
</td>
|
||||
)}
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user