Files
Negotiation_daegu/frontend/src/components/PriceChart.tsx
T
민헌andClaude Fable 5 2e5fefada7 콘솔 구조 개편 — 시나리오 4분면 선택·상품 정보 섹션·체크 스텝퍼·긴장도 구간 게이지
- 협상 케이스를 4분면(매출 규모×경쟁 강도) 시나리오 A/B/D/C 그리드로 교체
- 상품 정보 섹션 신설: 공급가·인터넷 최저가·공급 유형·거래 기간·응답률/VOC 이동
- 가격 패널 하단(시나리오·최저가·내부기준 문구) 제거
- 협상 진행을 체크 원형 세로 스텝퍼로 교체
- 긴장도를 3구간(낮음·보통·높음) 게이지로, 페르소나를 구간 결과로 묶어 인과 표시
- 차트 첫 제안 점 값 라벨의 좌측 클립 보정

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UFZ7JWdwCaQAwNYJErL8pP
2026-08-31 14:09:17 +09:00

150 lines
5.1 KiB
TypeScript

import type { DemoCase } from '../content/cases'
/**
* 제안가 추이 차트 — 이 화면의 시그니처.
* 라운드마다 내려오는 제안가를 영역 차트로 그리고, 기존가·목표가·앵커가를
* 점선 기준선으로 깔아 "지금 제안이 어느 구간에 있는지" 하나만 전달한다.
*/
export function PriceChart({ demoCase, priceTrail }: { demoCase: DemoCase; priceTrail: number[] }) {
const { anchor, target, item_price } = demoCase
const W = 300
const H = 150
const PAD = { top: 14, right: 72, bottom: 12, left: 10 }
const plotW = W - PAD.left - PAD.right
const plotH = H - PAD.top - PAD.bottom
const hi = Math.max(item_price, ...(priceTrail.length ? priceTrail : [item_price]))
const lo = Math.min(anchor, ...(priceTrail.length ? priceTrail : [anchor]))
const span = (hi - lo) || 1
const yOf = (v: number) => PAD.top + (1 - (v - lo) / span) * plotH
// 첫 라운드부터 점이 왼쪽에 고정되도록 슬롯을 최소 3칸으로 유지
const slots = Math.max(priceTrail.length - 1, 3)
const xOf = (i: number) => PAD.left + (i / slots) * plotW
// 기준선 3종 — 라벨은 선 오른쪽에 두고, 세로로 가까우면 밀어내서 겹침을 막는다
const refs = [
{ v: item_price, label: '기존가', color: 'var(--color-base-content)', op: 0.4 },
{ v: target, label: '목표가', color: 'var(--color-base-content)', op: 0.75 },
{ v: anchor, label: '앵커가', color: 'var(--color-primary)', op: 1 },
]
.map((r) => ({ ...r, y: yOf(r.v), ly: yOf(r.v) }))
.sort((a, b) => a.y - b.y)
const MIN_GAP = 13
for (let i = 1; i < refs.length; i++) {
if (refs[i].ly - refs[i - 1].ly < MIN_GAP) refs[i].ly = refs[i - 1].ly + MIN_GAP
}
const overflow = refs[refs.length - 1].ly - (H - 4)
if (overflow > 0) for (const r of refs) r.ly -= overflow
const pts = priceTrail.map((v, i) => ({ x: xOf(i), y: yOf(v), v }))
const line = pts.map((p, i) => `${i === 0 ? 'M' : 'L'}${p.x},${p.y}`).join(' ')
const area = pts.length >= 2
? `${line} L${pts[pts.length - 1].x},${H - PAD.bottom} L${pts[0].x},${H - PAD.bottom} Z`
: null
const last = pts.length ? pts[pts.length - 1] : null
return (
<svg
viewBox={`0 0 ${W} ${H}`}
className="w-full"
role="img"
aria-label={
last
? `제안가 추이 — 현재 ${last.v.toLocaleString()}원, 목표가 ${target.toLocaleString()}원, 앵커가 ${anchor.toLocaleString()}원`
: `가격 기준선 — 기존가 ${item_price.toLocaleString()}원, 목표가 ${target.toLocaleString()}원, 앵커가 ${anchor.toLocaleString()}원`
}
>
<defs>
<linearGradient id="trend-fill" x1="0" y1="0" x2="0" y2="1">
<stop offset="0%" stopColor="var(--color-primary)" stopOpacity="0.16" />
<stop offset="100%" stopColor="var(--color-primary)" stopOpacity="0" />
</linearGradient>
</defs>
{refs.map((r) => (
<g key={r.label}>
<line
x1={PAD.left}
y1={r.y}
x2={W - PAD.right + 6}
y2={r.y}
stroke={r.color}
strokeOpacity={r.op * 0.45}
strokeWidth="1"
strokeDasharray="3 4"
/>
<text
x={W - 2}
y={r.ly + 3}
textAnchor="end"
fontSize="9.5"
fill={r.color}
fillOpacity={Math.min(r.op + 0.2, 1)}
className="num"
>
{r.label} {r.v.toLocaleString()}
</text>
</g>
))}
{area && <path d={area} fill="url(#trend-fill)" />}
{pts.length >= 2 && (
<path
d={line}
fill="none"
stroke="var(--color-primary)"
strokeWidth="2"
strokeLinejoin="round"
strokeLinecap="round"
/>
)}
{pts.slice(0, -1).map((p, i) => (
<circle key={i} cx={p.x} cy={p.y} r="2.5" fill="var(--color-primary)" fillOpacity="0.4" />
))}
{last && (
<g>
<circle className="chart-pulse" cx={last.x} cy={last.y} r="6" fill="var(--color-primary)" />
<circle
cx={last.x}
cy={last.y}
r="4"
fill="var(--color-base-100)"
stroke="var(--color-primary)"
strokeWidth="2.5"
/>
<text
x={last.x}
y={last.y < 26 ? last.y + 18 : last.y - 10}
textAnchor={last.x > W - PAD.right - 30 ? 'end' : last.x < 36 ? 'start' : 'middle'}
fontSize="10.5"
fontWeight="700"
fill="var(--color-base-content)"
stroke="var(--color-base-100)"
strokeWidth="3"
paintOrder="stroke"
className="num"
>
{last.v.toLocaleString()}
</text>
</g>
)}
{!last && (
<text
x={PAD.left + plotW / 2}
y={PAD.top + plotH / 2 + 3}
textAnchor="middle"
fontSize="10.5"
fill="var(--color-base-content)"
fillOpacity="0.45"
>
첫 제안가를 입력하면 추이가 그려져요
</text>
)}
</svg>
)
}