Skip to content

Commit

Permalink
fix(stats): Fix sorting.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronmussig committed Sep 3, 2024
1 parent a00f4a4 commit 46a0ef8
Show file tree
Hide file tree
Showing 2 changed files with 260 additions and 218 deletions.
43 changes: 42 additions & 1 deletion components/stats/PhylumPd.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<template>
<v-data-table
:custom-sort="customSort"
:headers="headers"
:items="rowsToDisplay"
class="gtdb-table"
Expand All @@ -21,7 +22,7 @@
</template>

<template v-slot:item.abs="{ item }">
{{ parseFloat((item.unscaled-item.scaled).toFixed(2)) }}
{{ parseFloat((item.scaled - item.unscaled).toFixed(2)) }}
</template>

</v-data-table>
Expand All @@ -41,6 +42,7 @@ function round(n: number, places: number) {
return parseFloat(n.toFixed(places));
}
export default Vue.extend({
props: {
rows: {
Expand Down Expand Up @@ -110,6 +112,45 @@ export default Vue.extend({
],
collapsePhyla: false
}
},
methods: {
customSort(items: any, index: any, isDescending: any) {
// Check if any of the values are undefined or null
if (index === undefined || index === null || isDescending === undefined || isDescending === null) {
console.log('nothing to do, returning all items')
return items;
}
const isDesc = isDescending[0] === true;
const column = index[0];
items.sort((a: any, b: any) => {
if (column === 'abs') {
const aDelta = a.scaled - a.unscaled;
const bDelta = b.scaled - b.unscaled;
if (isDesc) {
return bDelta - aDelta;
} else {
return aDelta - bDelta;
}
} else if (column === 'scaled') {
if (isDesc) {
return b.scaled - a.scaled;
} else {
return a.scaled - b.scaled;
}
} else if (column === 'unscaled') {
if (isDesc) {
return b.unscaled - a.unscaled;
} else {
return a.unscaled - b.unscaled;
}
}
});
return items;
}
}
})
</script>
Expand Down
Loading

0 comments on commit 46a0ef8

Please sign in to comment.