diff --git a/src/components/PlayerCareerPitchingTable.vue b/src/components/PlayerCareerPitchingTable.vue index 4e6c135..9361373 100644 --- a/src/components/PlayerCareerPitchingTable.vue +++ b/src/components/PlayerCareerPitchingTable.vue @@ -6,39 +6,39 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -116,6 +116,14 @@ import { hitsPer9, hrsPer9, outsToInnings, winPercentage } from '@/services/util interface PitchingStatWithSeason extends PitchingStat { seasonNumber: number isRegularSeason: boolean + + sortableSeason: string // constructed to sort S1 -> S1 Playoffs -> S2 -> etc + + // added for sortable table + winPct: string + irsPct: string + hPer9: string + hrPer9: string } export default { @@ -125,6 +133,12 @@ export default { postSeasonPitchingStats: { type: Array, required: true }, showPostSeasonStats: { type: Boolean, required: true } }, + data() { + return { + sortKey: 'sortableSeason' as keyof PitchingStatWithSeason, + sortOrder: 1 + } + }, computed: { hasPitchingStats(): boolean { return !!(this.regularSeasonPitchingStats.length + this.postSeasonPitchingStats.length) @@ -158,7 +172,12 @@ export default { return { ...stat, seasonNumber: stat.player.season, - isRegularSeason: true + isRegularSeason: true, + sortableSeason: `${`${stat.player.season}`.padStart(3, '0')}-A-Regular`, + winPct: this.winPercentage(stat), + irsPct: this.formatIRSPercentage(stat), + hPer9: this.hitsPer9(stat), + hrPer9: this.hrsPer9(stat) } })) } @@ -168,21 +187,47 @@ export default { return { ...stat, seasonNumber: stat.player.season, - isRegularSeason: false + isRegularSeason: false, + sortableSeason: `${`${stat.player.season}`.padStart(3, '0')}-B-Playoffs`, + winPct: this.winPercentage(stat), + irsPct: this.formatIRSPercentage(stat), + hPer9: this.hitsPer9(stat), + hrPer9: this.hrsPer9(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) + + // return seasonStats.sort((s1, s2) => { + // return s1.seasonNumber - s2.seasonNumber === 0 + // ? s1.isRegularSeason + // ? -1 + // : 1 + // : s1.seasonNumber - s2.seasonNumber + // }) }, }, methods: { + // setKey(stat: keyof PitchingStatWithSeason): void { + // this.setKey(stat) + + // this.pitchingStats.sort((s1, s2) => s2[stat] < s1[stat] ? this.sortOrder : -1 * this.sortOrder) + // }, + setKey(stat: keyof PitchingStatWithSeason): 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 PitchingStatWithSeason): string { + if (this.sortKey !== stat) return 'faux-arrow' + + return this.sortOrder > 0 ? 'up' : 'down' + }, outsToInnings(stat: PitchingStat): string { return outsToInnings(stat) }, @@ -203,3 +248,18 @@ export default { } } + +
SeasonWLW-L%ERAGGSSVHDBSVIPHRERHRBBSOHBPBKWPIRIRSIRS%WHIPH/9HR/9BB/9SO/9SO/BBSeasonWLW-L%ERAGGSSVHDBSVIPHRERHRBBSOHBPBKWPIRIRSIRS%WHIPH/9HR/9BB/9SO/9SO/BB
S{{ stat.seasonNumber }}{{ stat.isRegularSeason ? '' : ' / Playoffs' }} {{ stat.win }} {{ stat.loss }}