-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
225 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React, { useMemo, useState } from "react"; | ||
import { useEpisodeList, useTournamentList } from "api/episode/useEpisode"; | ||
import SelectMenu from "../../elements/SelectMenu"; | ||
import TeamChart, { type ChartData } from "./TeamChart"; | ||
import { useUserRatingHistoryList } from "api/compete/useCompete"; | ||
import { useQueryClient } from "@tanstack/react-query"; | ||
import { useEpisodeId } from "contexts/EpisodeContext"; | ||
|
||
const EpisodeChart: React.FC = () => { | ||
const { episodeId } = useEpisodeId(); | ||
const queryClient = useQueryClient(); | ||
|
||
const [selectedEpisode, setSelectedEpisode] = useState(episodeId); | ||
|
||
const episodeList = useEpisodeList({}, queryClient); | ||
const tournamentList = useTournamentList( | ||
{ episodeId: selectedEpisode }, | ||
queryClient, | ||
); | ||
const ratingHistory = useUserRatingHistoryList({ | ||
episodeId: selectedEpisode, | ||
}); | ||
|
||
const ratingData: Record<string, ChartData[]> | undefined = useMemo(() => { | ||
if (!ratingHistory.isSuccess) return undefined; | ||
const ratingRecord: Record<string, ChartData[]> = {}; | ||
return ratingHistory.data.reduce((record, teamData) => { | ||
if (teamData.team_rating !== undefined) { | ||
record[teamData.team_rating.team.name] = | ||
teamData.team_rating.rating_history.map((match) => [ | ||
match.timestamp.getTime(), | ||
match.rating, | ||
]); | ||
} | ||
return record; | ||
}, ratingRecord); | ||
}, [ratingHistory]); | ||
|
||
return ( | ||
<div className="flex flex-1 flex-col gap-8"> | ||
<SelectMenu | ||
options={ | ||
episodeList.data?.results?.map((ep) => ({ | ||
value: ep.name_short, | ||
label: ep.name_long, | ||
})) ?? [] | ||
} | ||
label={"Select Episode"} | ||
value={selectedEpisode} | ||
onChange={setSelectedEpisode} | ||
loading={tournamentList.isLoading} | ||
/> | ||
|
||
<TeamChart | ||
yAxisLabel="Rating" | ||
values={ratingData} | ||
loading={ratingHistory.isLoading} | ||
loadingMessage="Loading rankings data..." | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default EpisodeChart; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import type Highcharts from "highcharts"; | ||
|
||
export const formatNumber = (value: number, decimals = 0): string => { | ||
return Number(value).toLocaleString(undefined, { | ||
minimumFractionDigits: decimals > 0 ? decimals : 0, | ||
maximumFractionDigits: decimals > 0 ? decimals : 0, | ||
}); | ||
}; | ||
|
||
export const highchartsOptionsBase: Highcharts.Options = { | ||
chart: { | ||
zooming: { | ||
type: "x", | ||
}, | ||
panning: { | ||
enabled: true, | ||
type: "x", | ||
}, | ||
panKey: "shift", | ||
numberFormatter: formatNumber, | ||
}, | ||
time: { | ||
useUTC: true, | ||
}, | ||
credits: { | ||
href: 'javascript:window.open("https://www.highcharts.com/?credits", "_blank")', | ||
}, | ||
exporting: { | ||
sourceWidth: 1600, | ||
sourceHeight: 800, | ||
allowHTML: true, | ||
}, | ||
xAxis: { | ||
type: "datetime", | ||
title: { | ||
text: "Local Date & Time", | ||
}, | ||
tickPixelInterval: 200, | ||
crosshair: { | ||
width: 1, | ||
}, | ||
dateTimeLabelFormats: { | ||
day: "%e %b", | ||
hour: "%I:%M %P", | ||
minute: "%I:%M:%S %P", | ||
}, | ||
}, | ||
yAxis: { | ||
allowDecimals: false, | ||
}, | ||
tooltip: { | ||
split: true, | ||
valueDecimals: 0, | ||
}, | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.