diff --git a/src/components/PlayerCareerFieldingTable.vue b/src/components/PlayerCareerFieldingTable.vue
index f939e46..8962860 100644
--- a/src/components/PlayerCareerFieldingTable.vue
+++ b/src/components/PlayerCareerFieldingTable.vue
@@ -6,20 +6,20 @@
- | Season |
- Pos |
- XCh |
- XH |
- E |
- PB |
- SBa |
- CSc |
- CS% |
- wF% |
+ Season |
+ Pos |
+ XCh |
+ XH |
+ E |
+ PB |
+ SBa |
+ CSc |
+ CS% |
+ wF% |
-
+
| S{{ stat.seasonNumber }}{{ stat.isRegularSeason ? '' : ' / Playoffs' }} |
{{ stat.pos }} |
{{ stat.xCheckCount }} |
@@ -33,7 +33,7 @@
-
+
| Career |
{{ stat.pos }} |
{{ stat.xCheckCount }} |
@@ -45,7 +45,7 @@
{{ formatCaughtStealingPercent(stat) }} |
{{ formatWeightedFieldingPercent(stat) }} |
-
+
| Career / Playoffs |
{{ stat.pos }} |
{{ stat.xCheckCount }} |
@@ -71,31 +71,23 @@ import { POS_MAP } from '@/services/utilities'
interface FieldingStatWithSeason extends FieldingStat {
seasonNumber: number
isRegularSeason: boolean
-}
-function compareFieldingStats(s1: FieldingStatWithSeason, s2: FieldingStatWithSeason): number {
- if (s1.seasonNumber - s2.seasonNumber !== 0) {
- return s1.seasonNumber - s2.seasonNumber
- }
-
- if (s1.isRegularSeason !== s2.isRegularSeason) {
- return s1.isRegularSeason
- ? -1
- : 1
- }
-
- // at this point stats are same season and also both regular or post season stats
- // and must be sorted on position order
- return POS_MAP[s1.pos] - POS_MAP[s2.pos]
+ sortableSeason: string // constructed to sort S1 -> S1 Playoffs -> S2 -> etc
}
export default {
- name: "PlayerCareerFieldingTable",
+ name: 'PlayerCareerFieldingTable',
props: {
regularSeasonFieldingStats: { type: Array, required: true },
postSeasonFieldingStats: { type: Array, required: true },
showPostSeasonStats: { type: Boolean, required: true }
},
+ data() {
+ return {
+ sortKey: 'sortableSeason' as keyof FieldingStatWithSeason,
+ sortOrder: 1
+ }
+ },
computed: {
hasFieldingStats(): boolean {
return !!(this.regularSeasonFieldingStats.length + this.postSeasonFieldingStats.length)
@@ -125,7 +117,8 @@ export default {
return {
...stat,
seasonNumber: stat.player.season,
- isRegularSeason: true
+ isRegularSeason: true,
+ sortableSeason: `${`${stat.player.season}`.padStart(3, '0')}-A-Regular-${POS_MAP[stat.pos]}`
}
}))
}
@@ -135,15 +128,30 @@ export default {
return {
...stat,
seasonNumber: stat.player.season,
- isRegularSeason: false
+ isRegularSeason: false,
+ sortableSeason: `${`${stat.player.season}`.padStart(3, '0')}-B-Playoffs-${POS_MAP[stat.pos]}`
}
}))
}
- return seasonStats.sort(compareFieldingStats)
+ return seasonStats.sort((s1, s2) => s2[this.sortKey] < s1[this.sortKey] ? this.sortOrder : -1 * this.sortOrder)
},
},
methods: {
+ setKey(stat: keyof FieldingStatWithSeason): void {
+ if (this.sortKey === stat) {
+ // if key currently selected, flip sort order
+ this.sortOrder *= -1
+ } else {
+ this.sortKey = stat
+ this.sortOrder = stat === 'sortableSeason' ? 1 : -1
+ }
+ },
+ getArrow(stat: keyof FieldingStatWithSeason): string {
+ if (this.sortKey !== stat) return 'faux-arrow'
+
+ return this.sortOrder > 0 ? 'up' : 'down'
+ },
formatCaughtStealingPercent(stat: FieldingStat): string {
if (stat.stolenBaseCheckCount === 0 || Number.isNaN(stat.caughtStealingPercent)) {
return '-'