fix(web): add adaptive compact tier guides

This commit is contained in:
dahyeon committed 2026-06-08 01:28:10 -07:00
1 parent 42d4854f9c
commit b6dad78d02
1 file changed
+122 -16
+122 -16
View File
@@ -46,6 +46,7 @@ const TIER_SPAN = 400;
const RANK_SPAN = 100; const RANK_SPAN = 100;
const RANK_INDEX: Record<string, number> = { IV: 0, III: 1, II: 2, I: 3 }; const RANK_INDEX: Record<string, number> = { IV: 0, III: 1, II: 2, I: 3 };
const RANK_BY_INDEX = ["IV", "III", "II", "I"];
const QUEUE_LABELS: Record<string, string> = { const QUEUE_LABELS: Record<string, string> = {
RANKED_SOLO_5x5: "솔로랭크", RANKED_SOLO_5x5: "솔로랭크",
@@ -173,10 +174,94 @@ type ChartPoint = {
losses?: number; losses?: number;
}; };
type YGuide = {
value: number;
label: string;
};
function isSamePoint(left: ChartPoint, right: ChartPoint) { function isSamePoint(left: ChartPoint, right: ChartPoint) {
return left.ts === right.ts && left.value === right.value; 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({ function TierTooltip({
active, active,
payload, payload,
@@ -267,6 +352,10 @@ export default function TierHistoryChart({
})).filter((line) => line.value >= min - TIER_SPAN && line.value <= max); })).filter((line) => line.value >= min - TIER_SPAN && line.value <= max);
}, [points]); }, [points]);
const adaptiveYGuides = useMemo(() => {
return summaryVariant === "inline" ? buildAdaptiveYGuides(points) : [];
}, [points, summaryVariant]);
const summary = useMemo(() => { const summary = useMemo(() => {
if (points.length === 0) return null; if (points.length === 0) return null;
const first = points[0]; const first = points[0];
@@ -359,22 +448,39 @@ export default function TierHistoryChart({
className="text-base-content/5" className="text-base-content/5"
vertical={false} vertical={false}
/> />
{tierLines.map((line) => ( {summaryVariant === "inline"
<ReferenceLine ? adaptiveYGuides.map((guide) => (
key={line.tier} <ReferenceLine
y={line.value} key={`${guide.value}-${guide.label}`}
stroke="currentColor" y={guide.value}
className="text-base-content/15" stroke="currentColor"
strokeDasharray="2 4" className="text-base-content/12"
label={{ strokeDasharray="2 4"
value: formatTierShort(line.tier), label={{
position: "insideLeft", value: guide.label,
fill: "currentColor", position: "insideLeft",
fontSize: 10, fill: "currentColor",
className: "text-base-content/35", fontSize: 10,
}} className: "text-base-content/35",
/> }}
))} />
))
: tierLines.map((line) => (
<ReferenceLine
key={line.tier}
y={line.value}
stroke="currentColor"
className="text-base-content/15"
strokeDasharray="2 4"
label={{
value: formatTierShort(line.tier),
position: "insideLeft",
fill: "currentColor",
fontSize: 10,
className: "text-base-content/35",
}}
/>
))}
<XAxis <XAxis
dataKey="ts" dataKey="ts"
type="number" type="number"