Skip to content

Commit

Permalink
fix(client): use the rating formatter specified in tachi-common for h…
Browse files Browse the repository at this point in the history
…istory graphs (#1189)

* fix(client): use the rating formatter specified in tachi-common for history graph

* adjust margins so the rating numbers fit

* museca: drop decimal places from profile rating

* adjust margins again to accommodate for wacca/jubeat/gitadora

* chore: lint
  • Loading branch information
beer-psi authored Oct 3, 2024
1 parent b88771b commit 613aca0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CreateUserMap } from "util/data";
import { ToFixedFloor, UppercaseFirst } from "util/misc";
import { FormatGPTProfileRating, UppercaseFirst } from "util/misc";
import { NumericSOV, StrSOV } from "util/sorts";
import ClassBadge from "components/game/ClassBadge";
import ScoreLeaderboard from "components/game/ScoreLeaderboard";
Expand Down Expand Up @@ -142,9 +142,7 @@ function ProfileLeaderboard({ game, playtype }: GamePT) {
).map((e) => (
<td key={e}>
{r.ratings[e]
? gptConfig.profileRatingAlgs[e].formatter
? gptConfig.profileRatingAlgs[e].formatter!(r.ratings[e]!)
: ToFixedFloor(r.ratings[e]!, 2)
? FormatGPTProfileRating(game, playtype, e, r.ratings[e]!)
: "No Data."}
</td>
))}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ClumpActivity } from "util/activity";
import { ToFixedFloor, UppercaseFirst } from "util/misc";
import { FormatGPTProfileRating, UppercaseFirst } from "util/misc";
import { FormatDate, MillisToSince } from "util/time";
import TimelineChart from "components/charts/TimelineChart";
import useSetSubheader from "components/layout/header/useSetSubheader";
Expand All @@ -17,7 +16,14 @@ import SelectButton from "components/util/SelectButton";
import { useProfileRatingAlg } from "components/util/useScoreRatingAlg";
import { DateTime } from "luxon";
import React, { useMemo, useState } from "react";
import { FormatGame, GetGameConfig, GetGamePTConfig, UserGameStats } from "tachi-common";
import {
FormatGame,
Game,
GetGameConfig,
GetGamePTConfig,
Playtype,
UserGameStats,
} from "tachi-common";
import { UGPTHistory } from "types/api-returns";
import { GamePT, SetState, UGPT } from "types/react";
import FormSelect from "react-bootstrap/FormSelect";
Expand Down Expand Up @@ -110,7 +116,13 @@ function UserHistory({

const currentPropValue = useMemo(() => {
if (mode === "rating" && rating) {
return data[0].ratings[rating] ? ToFixedFloor(data[0].ratings[rating]!, 2) : "N/A";
const ratingValue = data[0].ratings[rating];

if (!ratingValue) {
return "N/A";
}

return FormatGPTProfileRating(game, playtype, rating, ratingValue);
} else if (mode === "ranking") {
return (
<>
Expand Down Expand Up @@ -228,17 +240,21 @@ function UserHistory({
</div>
)}

<RatingTimeline {...{ data, rating }} />
<RatingTimeline {...{ game, playtype, data, rating }} />
</>
)}
</>
);
}

function RatingTimeline({
game,
playtype,
data,
rating,
}: {
game: Game;
playtype: Playtype;
data: UGPTHistory;
rating: keyof UserGameStats["ratings"];
}) {
Expand All @@ -259,12 +275,19 @@ function RatingTimeline({
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
format: (y) => (y ? ToFixedFloor(y, 2) : "N/A"),
format: (y) => (y ? FormatGPTProfileRating(game, playtype, rating, y) : "N/A"),
}}
tooltip={(p) => (
<ChartTooltip>
<div>
{p.point.data.y ? ToFixedFloor(p.point.data.y as number, 2) : "N/A"}{" "}
{p.point.data.y
? FormatGPTProfileRating(
game,
playtype,
rating,
p.point.data.y as number
)
: "N/A"}{" "}
{UppercaseFirst(rating)}
</div>
<small className="text-body-secondary">
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/charts/TimelineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function TimelineChart({
<div style={graphStyle}>
<ResponsiveLine
data={data}
margin={{ top: 40, bottom: 40, left: 40, right: 40 }}
margin={{ top: 40, bottom: 40, left: 60, right: 40 }}
xScale={{ type: "time", format: "%Q" }}
xFormat="time:%Q"
gridXValues={3}
Expand Down
1 change: 1 addition & 0 deletions common/src/config/game-support/museca.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const MUSECA_SINGLE_CONF = {
curatorSkill: {
description:
"The sum of your best 20 Curator Skills. This is identical to how it's calculated in-game.",
formatter: NoDecimalPlace,
},
},

Expand Down

0 comments on commit 613aca0

Please sign in to comment.