fix(web): center compact tier chart labels

This commit is contained in:
dahyeon committed 2026-06-08 01:15:55 -07:00
1 parent e9081d77c9
commit 42d4854f9c
1 file changed
+60 -23
+60 -23
View File
@@ -52,6 +52,19 @@ const QUEUE_LABELS: Record<string, string> = {
RANKED_FLEX_SR: "자유랭크", RANKED_FLEX_SR: "자유랭크",
}; };
const TIER_COMPACT_NAMES: Record<string, string> = {
IRON: "I",
BRONZE: "B",
SILVER: "S",
GOLD: "G",
PLATINUM: "P",
EMERALD: "E",
DIAMOND: "D",
MASTER: "M",
GRANDMASTER: "GM",
CHALLENGER: "C",
};
type PeriodKey = "30" | "90" | "all"; type PeriodKey = "30" | "90" | "all";
type SummaryVariant = "footer" | "inline"; type SummaryVariant = "footer" | "inline";
type SummaryDirection = "up" | "down" | "flat"; type SummaryDirection = "up" | "down" | "flat";
@@ -111,6 +124,20 @@ function formatTierLabel(entry: {
return `${name}${rank ? ` ${rank}` : ""} · ${entry.leaguePoints ?? 0}LP`; return `${name}${rank ? ` ${rank}` : ""} · ${entry.leaguePoints ?? 0}LP`;
} }
function formatTierCompactLabel(entry: {
tier: string;
rank?: string;
leaguePoints?: number;
}) {
const tier = TIER_COMPACT_NAMES[entry.tier] ?? entry.tier;
const lp = entry.leaguePoints ?? 0;
if (APEX_TIERS.has(entry.tier)) {
return `${tier} ${lp}LP`;
}
const rank = normalizeRank(entry.rank);
return `${tier}${rank} ${lp}LP`;
}
function formatTierShort(tier: string) { function formatTierShort(tier: string) {
return TIER_NAMES[tier] ?? tier; return TIER_NAMES[tier] ?? tier;
} }
@@ -146,6 +173,10 @@ type ChartPoint = {
losses?: number; losses?: number;
}; };
function isSamePoint(left: ChartPoint, right: ChartPoint) {
return left.ts === right.ts && left.value === right.value;
}
function TierTooltip({ function TierTooltip({
active, active,
payload, payload,
@@ -252,6 +283,18 @@ export default function TierHistoryChart({
return { first, last, peak, direction }; return { first, last, peak, direction };
}, [points]); }, [points]);
const xDomain = useMemo(() => {
if (summaryVariant !== "inline" || points.length < 2) {
return ["dataMin", "dataMax"] as const;
}
const min = points[0].ts;
const max = points[points.length - 1].ts;
const span = Math.max(1, max - min);
const padding = Math.max(span * 0.08, 12 * 60 * 60 * 1000);
return [min - padding, max + padding] as const;
}, [points, summaryVariant]);
const header = ( const header = (
<div className="flex flex-wrap items-center justify-between gap-2 border-b border-base-content/10 bg-base-200/40 px-4 py-2.5"> <div className="flex flex-wrap items-center justify-between gap-2 border-b border-base-content/10 bg-base-200/40 px-4 py-2.5">
<h2 className="text-[11px] font-bold uppercase tracking-wider text-base-content/40"> <h2 className="text-[11px] font-bold uppercase tracking-wider text-base-content/40">
@@ -336,7 +379,7 @@ export default function TierHistoryChart({
dataKey="ts" dataKey="ts"
type="number" type="number"
scale="time" scale="time"
domain={["dataMin", "dataMax"]} domain={xDomain}
tickFormatter={formatDate} tickFormatter={formatDate}
tick={{ fontSize: 10, fill: "currentColor" }} tick={{ fontSize: 10, fill: "currentColor" }}
className="text-base-content/40" className="text-base-content/40"
@@ -358,28 +401,7 @@ export default function TierHistoryChart({
/> />
{summaryVariant === "inline" && summary && ( {summaryVariant === "inline" && summary && (
<> <>
<ReferenceLine {!isSamePoint(summary.peak, summary.last) && (
y={summary.peak.value}
stroke="transparent"
label={{
value: `최고 ${formatTierLabel(summary.peak)}`,
position: "insideLeft",
fill: "currentColor",
fontSize: 10,
className: "text-amber-400",
}}
/>
<ReferenceLine
y={summary.last.value}
stroke="transparent"
label={{
value: `현재 ${formatTierLabel(summary.last)}`,
position: "insideRight",
fill: "currentColor",
fontSize: 10,
className: "text-primary",
}}
/>
<ReferenceDot <ReferenceDot
x={summary.peak.ts} x={summary.peak.ts}
y={summary.peak.value} y={summary.peak.value}
@@ -387,7 +409,15 @@ export default function TierHistoryChart({
stroke="currentColor" stroke="currentColor"
fill="currentColor" fill="currentColor"
className="text-amber-400" className="text-amber-400"
label={{
value: formatTierCompactLabel(summary.peak),
position: "top",
fill: "currentColor",
fontSize: 10,
className: "text-amber-400",
}}
/> />
)}
<ReferenceDot <ReferenceDot
x={summary.last.ts} x={summary.last.ts}
y={summary.last.value} y={summary.last.value}
@@ -395,6 +425,13 @@ export default function TierHistoryChart({
stroke="currentColor" stroke="currentColor"
fill="currentColor" fill="currentColor"
className="text-primary" className="text-primary"
label={{
value: formatTierCompactLabel(summary.last),
position: "top",
fill: "currentColor",
fontSize: 10,
className: "text-primary",
}}
/> />
</> </>
)} )}