refactor(web): simplify auction tier chart
This commit is contained in:
1 parent
ebca348723
commit
181beb85e5
2 files changed
+94
-25
No files matched your search
@@ -3,6 +3,7 @@ import {
|
|||||||
CartesianGrid,
|
CartesianGrid,
|
||||||
Line,
|
Line,
|
||||||
LineChart,
|
LineChart,
|
||||||
|
ReferenceDot,
|
||||||
ReferenceLine,
|
ReferenceLine,
|
||||||
ResponsiveContainer,
|
ResponsiveContainer,
|
||||||
Tooltip,
|
Tooltip,
|
||||||
@@ -52,6 +53,8 @@ const QUEUE_LABELS: Record<string, string> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
type PeriodKey = "30" | "90" | "all";
|
type PeriodKey = "30" | "90" | "all";
|
||||||
|
type SummaryVariant = "footer" | "inline";
|
||||||
|
type SummaryDirection = "up" | "down" | "flat";
|
||||||
|
|
||||||
const PERIOD_OPTIONS: { key: PeriodKey; label: string; days: number | null }[] =
|
const PERIOD_OPTIONS: { key: PeriodKey; label: string; days: number | null }[] =
|
||||||
[
|
[
|
||||||
@@ -112,6 +115,20 @@ function formatTierShort(tier: string) {
|
|||||||
return TIER_NAMES[tier] ?? tier;
|
return TIER_NAMES[tier] ?? tier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatPeriodChange(summary: {
|
||||||
|
first: ChartPoint;
|
||||||
|
last: ChartPoint;
|
||||||
|
direction: SummaryDirection;
|
||||||
|
}) {
|
||||||
|
const marker =
|
||||||
|
summary.direction === "up"
|
||||||
|
? "▲"
|
||||||
|
: summary.direction === "down"
|
||||||
|
? "▼"
|
||||||
|
: "·";
|
||||||
|
return `${formatTierShort(summary.first.tier)} ${marker} ${formatTierShort(summary.last.tier)}`;
|
||||||
|
}
|
||||||
|
|
||||||
function formatDate(ms: number) {
|
function formatDate(ms: number) {
|
||||||
return new Intl.DateTimeFormat("ko-KR", {
|
return new Intl.DateTimeFormat("ko-KR", {
|
||||||
month: "numeric",
|
month: "numeric",
|
||||||
@@ -160,9 +177,13 @@ function TierTooltip({
|
|||||||
export default function TierHistoryChart({
|
export default function TierHistoryChart({
|
||||||
entries,
|
entries,
|
||||||
className = "border border-base-content/10 bg-base-100 mb-5 overflow-hidden",
|
className = "border border-base-content/10 bg-base-100 mb-5 overflow-hidden",
|
||||||
|
summaryVariant = "footer",
|
||||||
|
height = 220,
|
||||||
}: {
|
}: {
|
||||||
entries: ApiTierHistoryEntry[];
|
entries: ApiTierHistoryEntry[];
|
||||||
className?: string;
|
className?: string;
|
||||||
|
summaryVariant?: SummaryVariant;
|
||||||
|
height?: number;
|
||||||
}) {
|
}) {
|
||||||
// 데이터에 존재하는 큐 목록 (솔로 우선)
|
// 데이터에 존재하는 큐 목록 (솔로 우선)
|
||||||
const availableQueues = useMemo(() => {
|
const availableQueues = useMemo(() => {
|
||||||
@@ -220,7 +241,7 @@ export default function TierHistoryChart({
|
|||||||
const peak = points.reduce((best, point) =>
|
const peak = points.reduce((best, point) =>
|
||||||
point.value > best.value ? point : best,
|
point.value > best.value ? point : best,
|
||||||
);
|
);
|
||||||
const direction =
|
const direction: SummaryDirection =
|
||||||
last.value > first.value
|
last.value > first.value
|
||||||
? "up"
|
? "up"
|
||||||
: last.value < first.value
|
: last.value < first.value
|
||||||
@@ -276,11 +297,29 @@ export default function TierHistoryChart({
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<div className="px-2 pt-4 pb-1">
|
<div className="relative px-2 pt-4 pb-1">
|
||||||
<ResponsiveContainer width="100%" height={220}>
|
{summaryVariant === "inline" && summary && (
|
||||||
|
<div
|
||||||
|
className={`pointer-events-none absolute right-3 top-3 z-10 border border-base-content/10 bg-base-100/90 px-2 py-1 text-[10px] font-bold shadow-sm ${
|
||||||
|
summary.direction === "up"
|
||||||
|
? "text-green-500"
|
||||||
|
: summary.direction === "down"
|
||||||
|
? "text-red-400"
|
||||||
|
: "text-base-content/50"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
기간 {formatPeriodChange(summary)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<ResponsiveContainer width="100%" height={height}>
|
||||||
<LineChart
|
<LineChart
|
||||||
data={points}
|
data={points}
|
||||||
margin={{ top: 8, right: 16, bottom: 4, left: 4 }}
|
margin={{
|
||||||
|
top: summaryVariant === "inline" ? 26 : 8,
|
||||||
|
right: summaryVariant === "inline" ? 48 : 16,
|
||||||
|
bottom: 4,
|
||||||
|
left: 4,
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<CartesianGrid
|
<CartesianGrid
|
||||||
strokeDasharray="3 3"
|
strokeDasharray="3 3"
|
||||||
@@ -328,6 +367,40 @@ export default function TierHistoryChart({
|
|||||||
className: "text-base-content/20",
|
className: "text-base-content/20",
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
{summaryVariant === "inline" && summary && (
|
||||||
|
<>
|
||||||
|
<ReferenceDot
|
||||||
|
x={summary.peak.ts}
|
||||||
|
y={summary.peak.value}
|
||||||
|
r={3}
|
||||||
|
stroke="currentColor"
|
||||||
|
fill="currentColor"
|
||||||
|
className="text-amber-400"
|
||||||
|
label={{
|
||||||
|
value: `최고 ${formatTierLabel(summary.peak)}`,
|
||||||
|
position: "top",
|
||||||
|
fill: "currentColor",
|
||||||
|
fontSize: 10,
|
||||||
|
className: "text-amber-400",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<ReferenceDot
|
||||||
|
x={summary.last.ts}
|
||||||
|
y={summary.last.value}
|
||||||
|
r={3}
|
||||||
|
stroke="currentColor"
|
||||||
|
fill="currentColor"
|
||||||
|
className="text-primary"
|
||||||
|
label={{
|
||||||
|
value: `현재 ${formatTierLabel(summary.last)}`,
|
||||||
|
position: "right",
|
||||||
|
fill: "currentColor",
|
||||||
|
fontSize: 10,
|
||||||
|
className: "text-primary",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
<Line
|
<Line
|
||||||
type="monotone"
|
type="monotone"
|
||||||
dataKey="value"
|
dataKey="value"
|
||||||
@@ -341,7 +414,7 @@ export default function TierHistoryChart({
|
|||||||
</LineChart>
|
</LineChart>
|
||||||
</ResponsiveContainer>
|
</ResponsiveContainer>
|
||||||
</div>
|
</div>
|
||||||
{summary && (
|
{summary && summaryVariant === "footer" && (
|
||||||
<div className="flex flex-wrap items-center gap-x-5 gap-y-1 border-t border-base-content/8 px-4 py-2.5 text-[11px]">
|
<div className="flex flex-wrap items-center gap-x-5 gap-y-1 border-t border-base-content/8 px-4 py-2.5 text-[11px]">
|
||||||
<span className="text-base-content/45">
|
<span className="text-base-content/45">
|
||||||
현재{" "}
|
현재{" "}
|
||||||
@@ -366,13 +439,7 @@ export default function TierHistoryChart({
|
|||||||
: "text-base-content/55"
|
: "text-base-content/55"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{formatTierShort(summary.first.tier)}
|
{formatPeriodChange(summary)}
|
||||||
{summary.direction === "up"
|
|
||||||
? " ▲ "
|
|
||||||
: summary.direction === "down"
|
|
||||||
? " ▼ "
|
|
||||||
: " · "}
|
|
||||||
{formatTierShort(summary.last.tier)}
|
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -543,6 +543,21 @@ function PlayerSpotlight({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{tierHistory.length > 0 && (
|
||||||
|
<Suspense
|
||||||
|
fallback={
|
||||||
|
<div className="h-[180px] border-b border-base-content/8 bg-base-100" />
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<TierHistoryChart
|
||||||
|
entries={tierHistory}
|
||||||
|
className="border-b border-base-content/8 bg-base-100 overflow-hidden"
|
||||||
|
summaryVariant="inline"
|
||||||
|
height={180}
|
||||||
|
/>
|
||||||
|
</Suspense>
|
||||||
|
)}
|
||||||
|
|
||||||
<div className="grid grid-cols-2 divide-x divide-base-content/5">
|
<div className="grid grid-cols-2 divide-x divide-base-content/5">
|
||||||
<div className="p-4">
|
<div className="p-4">
|
||||||
<h4 className="text-[10px] font-bold uppercase tracking-wider text-base-content/30 mb-2.5">
|
<h4 className="text-[10px] font-bold uppercase tracking-wider text-base-content/30 mb-2.5">
|
||||||
@@ -589,19 +604,6 @@ function PlayerSpotlight({
|
|||||||
<RecentSoloStats player={player} />
|
<RecentSoloStats player={player} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{tierHistory.length > 0 && (
|
|
||||||
<Suspense
|
|
||||||
fallback={
|
|
||||||
<div className="h-[180px] border-t border-base-content/8 bg-base-100" />
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<TierHistoryChart
|
|
||||||
entries={tierHistory}
|
|
||||||
className="border-t border-base-content/8 bg-base-100 overflow-hidden"
|
|
||||||
/>
|
|
||||||
</Suspense>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{(state.phase === 'bidding' || state.phase === 'sold') && (
|
{(state.phase === 'bidding' || state.phase === 'sold') && (
|
||||||
<div className="border-t border-base-content/8 px-4 py-3 bg-base-content/[0.02]">
|
<div className="border-t border-base-content/8 px-4 py-3 bg-base-content/[0.02]">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
|
|||||||
Reference in new issue
Block a user