From b6dad78d022aefb4532a766c022c1a9ecee298f7 Mon Sep 17 00:00:00 2001 From: dahyeon Date: Mon, 8 Jun 2026 01:28:10 -0700 Subject: [PATCH] fix(web): add adaptive compact tier guides --- apps/web/src/components/TierHistoryChart.tsx | 138 ++++++++++++++++--- 1 file changed, 122 insertions(+), 16 deletions(-) diff --git a/apps/web/src/components/TierHistoryChart.tsx b/apps/web/src/components/TierHistoryChart.tsx index 508361c8..6a5f375c 100644 --- a/apps/web/src/components/TierHistoryChart.tsx +++ b/apps/web/src/components/TierHistoryChart.tsx @@ -46,6 +46,7 @@ const TIER_SPAN = 400; const RANK_SPAN = 100; const RANK_INDEX: Record = { IV: 0, III: 1, II: 2, I: 3 }; +const RANK_BY_INDEX = ["IV", "III", "II", "I"]; const QUEUE_LABELS: Record = { RANKED_SOLO_5x5: "솔로랭크", @@ -173,10 +174,94 @@ type ChartPoint = { losses?: number; }; +type YGuide = { + value: number; + label: string; +}; + function isSamePoint(left: ChartPoint, right: ChartPoint) { return left.ts === right.ts && left.value === right.value; } +function nearestApexPoint(value: number, points: ChartPoint[]) { + const apexPoints = points.filter((point) => APEX_TIERS.has(point.tier)); + if (apexPoints.length === 0) return null; + + return apexPoints.reduce((best, point) => + Math.abs(point.value - value) < Math.abs(best.value - value) ? point : best, + ); +} + +function compactEntryFromLadderValue(value: number, points: ChartPoint[]) { + const rounded = Math.max(0, Math.round(value)); + const masterBase = tierIndex("MASTER") * TIER_SPAN; + + if (rounded >= masterBase) { + const apexPoint = nearestApexPoint(rounded, points); + const apexTier = apexPoint?.tier ?? "MASTER"; + const apexBase = tierIndex(apexTier) * TIER_SPAN; + if (rounded >= apexBase) { + return { + tier: apexTier, + leaguePoints: rounded - apexBase, + }; + } + + return { + tier: "MASTER", + leaguePoints: rounded - masterBase, + }; + } + + const tierIdx = Math.min( + TIER_ORDER.length - 1, + Math.floor(rounded / TIER_SPAN), + ); + const tier = TIER_ORDER[tierIdx]; + const withinTier = rounded - tierIdx * TIER_SPAN; + const rankIdx = Math.min(3, Math.floor(withinTier / RANK_SPAN)); + + return { + tier, + rank: RANK_BY_INDEX[rankIdx], + leaguePoints: withinTier - rankIdx * RANK_SPAN, + }; +} + +function buildAdaptiveYGuides(points: ChartPoint[]): YGuide[] { + if (points.length === 0) return []; + + const min = Math.min(...points.map((point) => point.value)); + const max = Math.max(...points.map((point) => point.value)); + const paddedMin = min - 60; + const paddedMax = max + 60; + const steps = [50, 100, 200, 400, 800, 1200]; + + for (const step of steps) { + const start = Math.ceil(paddedMin / step) * step; + const end = Math.floor(paddedMax / step) * step; + const count = Math.floor((end - start) / step) + 1; + + if (count >= 2 && count <= 4) { + return Array.from({ length: count }, (_, index) => { + const value = start + index * step; + return { + value, + label: formatTierCompactLabel( + compactEntryFromLadderValue(value, points), + ), + }; + }); + } + } + + const center = Math.round(((min + max) / 2) / 50) * 50; + return [center - 50, center + 50].map((value) => ({ + value, + label: formatTierCompactLabel(compactEntryFromLadderValue(value, points)), + })); +} + function TierTooltip({ active, payload, @@ -267,6 +352,10 @@ export default function TierHistoryChart({ })).filter((line) => line.value >= min - TIER_SPAN && line.value <= max); }, [points]); + const adaptiveYGuides = useMemo(() => { + return summaryVariant === "inline" ? buildAdaptiveYGuides(points) : []; + }, [points, summaryVariant]); + const summary = useMemo(() => { if (points.length === 0) return null; const first = points[0]; @@ -359,22 +448,39 @@ export default function TierHistoryChart({ className="text-base-content/5" vertical={false} /> - {tierLines.map((line) => ( - - ))} + {summaryVariant === "inline" + ? adaptiveYGuides.map((guide) => ( + + )) + : tierLines.map((line) => ( + + ))}