diff --git a/src/components/PlayerCareerBattingTable.vue b/src/components/PlayerCareerBattingTable.vue
index 026452f..deeb499 100644
--- a/src/components/PlayerCareerBattingTable.vue
+++ b/src/components/PlayerCareerBattingTable.vue
@@ -6,33 +6,33 @@
- | Season |
- PA |
- AB |
- R |
- H |
- 2B |
- 3B |
- HR |
- RBI |
- SB |
- CS |
- BB |
- SO |
- BA |
- OBP |
- SLG |
- OPS |
- wOBA |
- K% |
- BPHR |
- BPFO |
- BP1B |
- BPLO |
- GIDP |
- HBP |
- SAC |
- IBB |
+ Season |
+ PA |
+ AB |
+ R |
+ H |
+ 2B |
+ 3B |
+ HR |
+ RBI |
+ SB |
+ CS |
+ BB |
+ SO |
+ BA |
+ OBP |
+ SLG |
+ OPS |
+ wOBA |
+ K% |
+ BPHR |
+ BPFO |
+ BP1B |
+ BPLO |
+ GIDP |
+ HBP |
+ SAC |
+ IBB |
@@ -109,6 +109,10 @@ import { aggregateBattingStats, type BattingStat } from '@/services/battingStats
interface BattingStatWithSeason extends BattingStat {
seasonNumber: number
isRegularSeason: boolean
+
+ sortableSeason: string // constructed to sort S1 -> S1 Playoffs -> S2 -> etc
+
+ kPct: string
}
export default {
@@ -118,6 +122,12 @@ export default {
postSeasonBattingStats: { type: Array, required: true },
showPostSeasonStats: { type: Boolean, required: true }
},
+ data() {
+ return {
+ sortKey: 'sortableSeason' as keyof BattingStatWithSeason,
+ sortOrder: 1
+ }
+ },
computed: {
hasBattingStats(): boolean {
return !!(this.regularSeasonBattingStats.length + this.postSeasonBattingStats.length)
@@ -143,7 +153,9 @@ export default {
return {
...stat,
seasonNumber: stat.player.season,
- isRegularSeason: true
+ isRegularSeason: true,
+ sortableSeason: `${`${stat.player.season}`.padStart(3, '0')}-A-Regular`,
+ kPct: this.calculateStrikeoutPercent(stat)
}
}))
}
@@ -153,21 +165,31 @@ export default {
return {
...stat,
seasonNumber: stat.player.season,
- isRegularSeason: false
+ isRegularSeason: false,
+ sortableSeason: `${`${stat.player.season}`.padStart(3, '0')}-B-Playoffs`,
+ kPct: this.calculateStrikeoutPercent(stat)
}
}))
}
- return seasonStats.sort((s1, s2) => {
- return s1.seasonNumber - s2.seasonNumber === 0
- ? s1.isRegularSeason
- ? -1
- : 1
- : s1.seasonNumber - s2.seasonNumber
- })
+ return seasonStats.sort((s1, s2) => s2[this.sortKey] < s1[this.sortKey] ? this.sortOrder : -1 * this.sortOrder)
},
},
methods: {
+ setKey(stat: keyof BattingStatWithSeason): 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 BattingStatWithSeason): string {
+ if (this.sortKey !== stat) return 'faux-arrow'
+
+ return this.sortOrder > 0 ? 'up' : 'down'
+ },
calculateStrikeoutPercent(stat: BattingStat): string {
if (!stat.pa) return 'N/A'
return (stat.so * 100 / stat.pa).toFixed(1)
@@ -175,3 +197,18 @@ export default {
}
}
+
+