Skip to content

Commit

Permalink
fix column sizes on aggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
thoughtspile committed Dec 6, 2023
1 parent 0edf94c commit 7f67853
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
1 change: 0 additions & 1 deletion ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
- append
- streaming processing
- table
- fix: column size on aggregation
- datetime format
- Analysis
- Filters
Expand Down
3 changes: 2 additions & 1 deletion src/app/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ export function Dashboard() {
source && setFile(source);
});
const [table] = createResource(file, file => file ? parseCsv(file) : null);
const loading = () => initializing() || (file() && !table());

return (
<Show when={table()} fallback={<Welcome onSubmit={persistSource} loading={initializing() || !table()} />}>
<Show when={table()} fallback={<Welcome onSubmit={persistSource} loading={loading()} />}>
<Table table={table()} />
</Show>
);
Expand Down
31 changes: 19 additions & 12 deletions src/app/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { For, Show, createEffect, createMemo, createSignal, onCleanup, onMount } from 'solid-js';
import { For, Show, createMemo, createSignal, onCleanup, onMount } from 'solid-js';
import './Table.css';
import type ColumnTable from 'arquero/dist/types/table/column-table';
import { FaSolidSortDown, FaSolidSortUp } from 'solid-icons/fa';
Expand All @@ -10,7 +10,6 @@ import { createPipeline } from '../data/pipeline';

export function Table(props: { table: ColumnTable }) {
const [pipeline, setPipeline] = createSignal(createPipeline(props.table));
const order = createMemo(() => pipeline().order);

return (
<>
Expand All @@ -26,7 +25,6 @@ export function Table(props: { table: ColumnTable }) {
}

const rowHeight = 19;
const totalPaddingX = 12;

type TableViewProps = {
table: ColumnTable;
Expand Down Expand Up @@ -62,23 +60,25 @@ function TableView(props: TableViewProps) {
return next;
});
});
onMount(() => {
for (const td of tableRef.querySelectorAll('tr:first-child td, th')) {
resizeObserver.observe(td);
}
});
const observeSize = (el: HTMLElement) => resizeObserver.observe(el);
onCleanup(() => resizeObserver.disconnect());

return (
<table ref={tableRef}>
<thead>
<For each={cols()}>{col =>
<HeaderCell orderBy={props.orderBy} order={props.order} width={colWidths().get(col)} name={col} />
<HeaderCell
ref={observeSize}
orderBy={props.orderBy}
order={props.order}
width={colWidths().get(col)}
name={col}
/>
}</For>
</thead>
<tbody>
<tr style={{ height: `${virtualizer.getVirtualItems()[0].start}px` }}>
<For each={cols()}>{col => <td data-col={col} style={{ 'min-width': `${colWidths().get(col)}px` }} />}</For>
<For each={cols()}>{col => <td ref={observeSize} data-col={col} style={{ 'min-width': `${colWidths().get(col)}px` }} />}</For>
</tr>
<For each={virtualizer.getVirtualItems().map((el) => el.index)}>{(index) => (
<Show when={index < numRows()}><Row table={props.table} cols={cols()} index={index} /></Show>
Expand All @@ -102,10 +102,17 @@ function Row(props: RowProps) {
);
}

function HeaderCell(props: { order: Order, name: string; orderBy: (c: string) => void; width: number }) {
interface HeaderCellProps {
order: Order;
name: string;
orderBy: (c: string) => void;
width: number;
ref: (e: HTMLElement) => void;
}
function HeaderCell(props: HeaderCellProps) {
const dir = () => props.order.col === props.name ? props.order.dir : null;
return (
<th data-col={props.name} onClick={() => props.orderBy(props.name)} style={{ 'min-width': `${props.width}px` }}>
<th ref={props.ref} data-col={props.name} onClick={() => props.orderBy(props.name)} style={{ 'min-width': `${props.width}px` }}>
{props.name}
{dir() === 'desc' && <FaSolidSortUp />}
{dir() === 'asc' && <FaSolidSortDown />}
Expand Down

0 comments on commit 7f67853

Please sign in to comment.