Skip to content

Commit

Permalink
Move all sort options under select
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore committed Oct 20, 2024
1 parent ca7b7f1 commit 830c03b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 108 deletions.
118 changes: 33 additions & 85 deletions ome2024-ngff-challenge/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,18 @@
}
let sortedBy = "";
let sortAscending = true;
function handleSort(colname) {
if (sortedBy === colname) {
sortAscending = !sortAscending;
let sortAscending = false;
function toggleSortAscending() {
sortAscending = !sortAscending;
ngffTable.sortTable(sortedBy, sortAscending);
}
function handleSort(event) {
sortedBy = event.target.value;
if (sortedBy === "") {
ngffTable.sortTable("index", true);
} else {
// start by sorting descending (biggest first)
sortAscending = false;
ngffTable.sortTable(sortedBy, sortAscending);
}
sortedBy = colname;
ngffTable.sortTable(colname, sortAscending);
}
// Main filtering function
Expand Down Expand Up @@ -318,74 +320,29 @@
</div>
<div class="clear"></div>
</div>
Sort by:
<div class="sortButtons">
<!-- <ColumnSort
col_label={"Rating"}
col_name={"rating"}
{handleSort}
{sortedBy}
{sortAscending}
/> -->
<ColumnSort
col_label={"X"}
col_name={"size_x"}
{handleSort}
{sortedBy}
{sortAscending}
/>
<ColumnSort
col_label={"Y"}
col_name={"size_y"}
{handleSort}
{sortedBy}
{sortAscending}
/>
<ColumnSort
col_label={"Z"}
col_name={"size_z"}
{handleSort}
{sortedBy}
{sortAscending}
/>
<ColumnSort
col_label={"C"}
col_name={"size_c"}
{handleSort}
{sortedBy}
{sortAscending}
/>
<ColumnSort
col_label={"T"}
col_name={"size_t"}
{handleSort}
{sortedBy}
{sortAscending}
/>
</div>
<div class="sortButtons">
<ColumnSort
col_label={"Chunks"}
col_name={"chunk_pixels"}
{handleSort}
{sortedBy}
{sortAscending}
/>
<ColumnSort
col_label={"Shards"}
col_name={"shard_pixels"}
{handleSort}
{sortedBy}
{sortAscending}
/>
<ColumnSort
col_label={"Data size"}
col_name={"written"}
{handleSort}
{sortedBy}
{sortAscending}
/>
<div>Sort by:</div>
<div class="selectWrapper">
<select
on:change={handleSort}
>
<option value="">--</option
>
<hr />
{#each ["x", "y", "z", "c", "t"] as dim}
<option value="size_{dim}">Size: {dim.toUpperCase()}</option>
{/each}
<hr />
<option value="written">Data Size (bytes)</option>
<option value="chunk_pixels">Chunk Size (pixels)</option>
<option value="shard_pixels">Shard Size (pixels)</option>
</select>
<div>
<ColumnSort
toggleAscending={toggleSortAscending}
sortAscending={sortAscending} />
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -553,13 +510,4 @@
.results h3 {
margin: 10px;
}
.sortButtons {
display: flex;
flex-direction: row;
border: solid var(--border-color) 1px;
border-radius: 5px;
width: fit-content;
margin: 5px 0;
}
</style>
23 changes: 9 additions & 14 deletions ome2024-ngff-challenge/src/ColumnSort.svelte
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
<script>
export let col_name;
export let col_label;
export let handleSort;
export let sortedBy;
export let toggleAscending;
export let sortAscending;
</script>

<button on:click={() => handleSort(col_name)}>
{col_label}

<span class="acc" class:strong={sortedBy==col_name && sortAscending}>^</span>
<span class="dec" class:strong={sortedBy==col_name && !sortAscending}>^</span>

<button on:click={() => toggleAscending()}>
<span class="acc" class:strong={sortAscending}>^</span>
<span class="dec" class:strong={!sortAscending}>^</span>
</button>

<style>
button {
background-color: var(--light-background);
border: none;
border: solid var(--border-color) 1px;
border-radius: 5px;
text-wrap: none;
white-space: nowrap;
position: relative;
padding-right: 20px;
padding-left: 5px;
padding: 9px 10px 11px 10px;
outline: none;
margin: 0;
border-radius: 0;
height: 35px;
}
button:focus-visible {
outline: 4px solid gold;
}
Expand Down
14 changes: 5 additions & 9 deletions ome2024-ngff-challenge/src/tableStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function loadMultiscales(url, signal) {
}

class NgffTable {
constructor(sortBy = "rating", sortAscending = false) {
constructor(sortBy = "index", sortAscending = true) {
this.store = writable([]);
this.selectedRow = writable(null);

Expand Down Expand Up @@ -129,7 +129,7 @@ class NgffTable {

addRows(rows) {
// Each row is a dict {"url": "http...zarr"}
rows = rows.map((row) => {
rows = rows.map((row, index) => {
// Validating csv files don't contain whitespaces
// Object.entries(row).forEach(([key, value]) => {
// if (value?.startsWith && (value.startsWith(" ") || value?.endsWith(" ")) || (key && key.startsWith(" ") || key.endsWith(" "))) {
Expand Down Expand Up @@ -166,16 +166,11 @@ class NgffTable {
let shards = row.shards.split(",").map((dim) => parseInt(dim));
row.shard_pixels = shards.reduce((prev, curr) => prev * curr, 1);
}
row.rating = Math.random() * 4;
// add index for sorting
row.index = Math.random() * (1 + index);
return row;
});

// Add a higher rating for a couple of samples within this collection
if (rows.length > 1) {
rows[getRandomInt(rows.length)].rating = 10 + Math.random() * 5;
rows[getRandomInt(rows.length)].rating = 5 + Math.random() * 5;
}

console.log("Adding rows", rows);

this.store.update((table) => {
Expand Down Expand Up @@ -336,6 +331,7 @@ class NgffTable {
}

sortTable(colName, ascending = true) {
console.log("sortTable", colName, ascending);
this.sortColumn = colName;
this.sortAscending = ascending;
let isNumber = this.isColumnNumeric(colName);
Expand Down

0 comments on commit 830c03b

Please sign in to comment.