Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UFZ7JWdwCaQAwNYJErL8pP
108 lines
4.6 KiB
TypeScript
108 lines
4.6 KiB
TypeScript
import type { DemoCase } from '../content/cases'
|
|
|
|
/**
|
|
* 가격 트랙 — 이 페이지의 시그니처.
|
|
* 앵커가·목표가·기존 공급가를 한 수평 트랙에 놓고, 제안가가 내려오는 과정을 마커로 보여준다.
|
|
* 파랑 구간(앵커 이하) = 구매측 최적 · 앰버 구간(목표가 초과) = 협상 여지.
|
|
*/
|
|
export function PriceTrack({ demoCase, priceTrail }: { demoCase: DemoCase; priceTrail: number[] }) {
|
|
const { anchor, target, item_price } = demoCase
|
|
const current = priceTrail.length ? priceTrail[priceTrail.length - 1] : null
|
|
|
|
// 트랙 범위: min(앵커, 최저 제안가) 아래 여유 3% ~ max(기존가, 최고 제안가) 위 여유 3%
|
|
// (제안가가 앵커보다 낮아도 마커가 트랙 밖으로 클리핑되지 않도록 동적 확장)
|
|
const hi = Math.max(item_price, ...(priceTrail.length ? priceTrail : [item_price])) * 1.03
|
|
const lo = Math.min(anchor, ...(priceTrail.length ? priceTrail : [anchor])) * 0.97
|
|
const pos = (v: number) => Math.min(Math.max(((v - lo) / (hi - lo)) * 100, 0), 100)
|
|
|
|
// 기준선 3종 — 제안가가 범위를 크게 넓히면 서로 몰려 라벨이 겹치므로,
|
|
// 가까운 라벨(간격 < MIN_GAP%)은 아랫줄로 내려 층을 나눈다.
|
|
const MIN_GAP = 18
|
|
const ticks = [
|
|
{ value: anchor, label: '앵커가', cls: 'bg-blue' },
|
|
{ value: target, label: '목표가', cls: 'bg-ink/50' },
|
|
{ value: item_price, label: '기존가', cls: 'bg-muted/60' },
|
|
].sort((a, b) => a.value - b.value)
|
|
const rows = ticks.map(() => 0)
|
|
for (let i = 1; i < ticks.length; i++) {
|
|
let row = 0
|
|
for (let j = 0; j < i; j++) {
|
|
if (pos(ticks[i].value) - pos(ticks[j].value) < MIN_GAP && rows[j] === row) {
|
|
row += 1
|
|
j = -1 // 줄을 내렸으니 앞 라벨들과 다시 비교
|
|
}
|
|
}
|
|
rows[i] = row
|
|
}
|
|
const maxRow = Math.max(...rows)
|
|
|
|
// 가장자리에선 중앙정렬 대신 안쪽으로 붙여 패널 밖 클리핑을 막는다
|
|
const align = (p: number) =>
|
|
p <= 6
|
|
? 'translate-x-0 text-left'
|
|
: p >= 94
|
|
? '-translate-x-full text-right'
|
|
: '-translate-x-1/2 text-center'
|
|
|
|
const Tick = ({ value, label, cls, row }: { value: number; label: string; cls: string; row: number }) => (
|
|
<div className="absolute top-0 h-full" style={{ left: `${pos(value)}%` }}>
|
|
<div className={`h-full w-px ${cls}`} />
|
|
<div
|
|
className={`absolute whitespace-nowrap ${align(pos(value))}`}
|
|
style={{ top: `calc(100% + ${4 + row * 28}px)` }}
|
|
>
|
|
<div className="text-[10px] leading-tight text-muted">{label}</div>
|
|
<div className="font-mono text-[11px] font-medium leading-tight">{value.toLocaleString()}</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
|
|
return (
|
|
<div>
|
|
<div
|
|
className="relative mt-6 h-3 rounded-full bg-paper"
|
|
style={{ marginBottom: `${2.25 + maxRow * 1.75}rem` }}
|
|
>
|
|
{/* 구간 채색: [lo~anchor]=파랑(최적) · [anchor~target]=연파랑(합의권) · [target~hi]=앰버(초과) */}
|
|
<div className="absolute inset-y-0 left-0 rounded-l-full bg-blue/70" style={{ width: `${pos(anchor)}%` }} />
|
|
<div
|
|
className="absolute inset-y-0 bg-blue-soft"
|
|
style={{ left: `${pos(anchor)}%`, width: `${pos(target) - pos(anchor)}%` }}
|
|
/>
|
|
<div
|
|
className="absolute inset-y-0 rounded-r-full bg-amber-soft"
|
|
style={{ left: `${pos(target)}%`, width: `${100 - pos(target)}%` }}
|
|
/>
|
|
{ticks.map((t, i) => (
|
|
<Tick key={t.label} value={t.value} label={t.label} cls={t.cls} row={rows[i]} />
|
|
))}
|
|
|
|
{/* 과거 제안 흔적 */}
|
|
{priceTrail.slice(0, -1).map((p, i) => (
|
|
<div
|
|
key={i}
|
|
className="absolute top-1/2 size-1.5 -translate-x-1/2 -translate-y-1/2 rounded-full bg-ink/25"
|
|
style={{ left: `${pos(p)}%` }}
|
|
/>
|
|
))}
|
|
|
|
{/* 현재 제안가 마커 */}
|
|
{current != null && (
|
|
<div
|
|
className="track-marker absolute top-1/2 -translate-x-1/2 -translate-y-1/2"
|
|
style={{ left: `${pos(current)}%` }}
|
|
>
|
|
<div className="size-4 rounded-full border-[3px] border-ink bg-white shadow-sm" />
|
|
<div className="absolute bottom-full left-1/2 mb-1.5 -translate-x-1/2 whitespace-nowrap rounded bg-ink px-1.5 py-0.5 font-mono text-[11px] font-semibold text-white">
|
|
{current.toLocaleString()}
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
{current == null && (
|
|
<p className="text-xs text-muted">첫 제안가를 입력하면 트랙 위에 표시됩니다.</p>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|