브랜드 분석 및 기타 UI 수정

This commit is contained in:
skkim committed 2026-03-09 15:09:51 +09:00
1 parent 3cbc48181b
commit dc3d128b22
6 files changed
+328 -389

No files matched your search

+152 -109
View File
@@ -1,149 +1,192 @@
import React from 'react';
export interface USP {
label: string;
subLabel: string;
score: number;
description: string;
}
import React, { useState, useEffect } from 'react';
import { SellingPoint } from '../../types/api';
interface GeometricChartProps {
data: USP[];
data: SellingPoint[];
}
export const GeometricChart: React.FC<GeometricChartProps> = ({ data }) => {
const size = 500;
const [animatedScores, setAnimatedScores] = useState<number[]>(data.map(() => 0));
useEffect(() => {
const targetScores = data.map(item => item.score);
const duration = 1500;
const startTime = Date.now();
const animate = () => {
const elapsed = Date.now() - startTime;
const progress = Math.min(elapsed / duration, 1);
const easeProgress = 1 - Math.pow(1 - progress, 3);
setAnimatedScores(targetScores.map(t => t * easeProgress));
if (progress < 1) requestAnimationFrame(animate);
};
requestAnimationFrame(animate);
}, [data]);
const size = 560;
const center = size / 2;
const radius = 110;
const maxRadius = 160;
const sides = data.length;
const levels = 5;
const angleStep = (Math.PI * 2) / sides;
const accentColor = "#94FBE0";
const getPoints = (r: number) => {
return data.map((_, i) => {
const angle = (Math.PI * 2 * i) / sides - Math.PI / 2;
const x = center + r * Math.cos(angle);
const y = center + r * Math.sin(angle);
return `${x},${y}`;
}).join(' ');
};
const getDataPoints = () => {
return data.map((item, i) => {
const normalizedScore = item.score / 100;
const r = radius * normalizedScore;
const angle = (Math.PI * 2 * i) / sides - Math.PI / 2;
const x = center + r * Math.cos(angle);
const y = center + r * Math.sin(angle);
return `${x},${y}`;
}).join(' ');
};
const labelRadius = radius + 55;
const labels = data.map((item, i) => {
const angle = (Math.PI * 2 * i) / sides - Math.PI / 2;
const x = center + labelRadius * Math.cos(angle);
const y = center + labelRadius * Math.sin(angle);
let anchor: 'start' | 'middle' | 'end' = 'middle';
if (x < center - 20) anchor = 'end';
if (x > center + 20) anchor = 'start';
return { x, y, text: item.label, sub: item.subLabel, anchor, score: item.score };
const getAngle = (i: number) => angleStep * i - Math.PI / 2;
const getPoint = (i: number, r: number) => ({
x: center + r * Math.cos(getAngle(i)),
y: center + r * Math.sin(getAngle(i)),
});
// 순위 매핑
const sortedIndices = [...data]
.map((item, i) => ({ index: i, score: item.score }))
.sort((a, b) => b.score - a.score)
.map((item, rank) => ({ ...item, rank: rank + 1 }));
const rankMap = new Map<number, number>();
sortedIndices.forEach(item => rankMap.set(item.index, item.rank));
// 레벨 폴리곤
const levelPolygons = Array.from({ length: levels }, (_, li) => {
const r = ((li + 1) / levels) * maxRadius;
return data.map((_, i) => {
const p = getPoint(i, r);
return `${p.x},${p.y}`;
}).join(' ');
});
// 데이터 폴리곤
const dataPolygon = animatedScores.map((score, i) => {
const r = (score / 100) * maxRadius;
const p = getPoint(i, r);
return `${p.x},${p.y}`;
}).join(' ');
// 데이터 포인트
const dataPoints = animatedScores.map((score, i) => {
const r = (score / 100) * maxRadius;
return getPoint(i, r);
});
const labelRadius = maxRadius + 22;
return (
<div className="flex flex-col items-center justify-center py-2 relative w-full h-full">
<svg viewBox={`0 0 ${size} ${size}`} className="w-full h-auto max-w-[500px]" style={{ overflow: 'visible' }}>
<div className="bi2-radar-container">
<svg
viewBox={`0 0 ${size} ${size}`}
style={{ overflow: 'visible', width: '440px', height: '440px' }}
>
<defs>
<radialGradient id="polyGradient" cx="50%" cy="50%" r="50%" fx="50%" fy="50%">
<stop offset="0%" stopColor={accentColor} stopOpacity="0.3" />
<stop offset="100%" stopColor={accentColor} stopOpacity="0.05" />
</radialGradient>
<filter id="radar-glow" x="-20%" y="-20%" width="140%" height="140%">
<feGaussianBlur stdDeviation="4" result="coloredBlur" />
<feMerge>
<feMergeNode in="coloredBlur" />
<feMergeNode in="SourceGraphic" />
</feMerge>
</filter>
<filter id="badge-glow" x="-50%" y="-50%" width="200%" height="200%">
<feDropShadow dx="0" dy="0" stdDeviation="4" floodColor="#94FBE0" floodOpacity="0.4" />
</filter>
</defs>
{[1, 0.75, 0.5, 0.25].map((scale, i) => (
{/* 그리드 레벨 */}
{levelPolygons.map((points, i) => (
<polygon
key={i}
points={getPoints(radius * scale)}
key={`level-${i}`}
points={points}
fill="none"
stroke={accentColor}
strokeOpacity={0.25 - (0.02 * i)}
stroke="rgba(255,255,255,0.2)"
strokeWidth="1"
strokeDasharray={i === 0 ? "0" : "4 2"}
/>
))}
{/* 축 선 */}
{data.map((_, i) => {
const angle = (Math.PI * 2 * i) / sides - Math.PI / 2;
const x = center + radius * Math.cos(angle);
const y = center + radius * Math.sin(angle);
const p = getPoint(i, maxRadius);
return (
<line
key={i}
key={`axis-${i}`}
x1={center}
y1={center}
x2={x}
y2={y}
stroke={accentColor}
strokeOpacity="0.25"
x2={p.x}
y2={p.y}
stroke="rgba(255,255,255,0.2)"
strokeWidth="1"
/>
);
})}
{/* 데이터 폴리곤 */}
<polygon
points={getDataPoints()}
fill="url(#polyGradient)"
stroke={accentColor}
strokeWidth="2.5"
points={dataPolygon}
fill="rgba(45, 212, 191, 0.15)"
stroke="#2DD4BF"
strokeWidth="2"
strokeLinejoin="round"
filter="url(#radar-glow)"
/>
{/* 데이터 포인트 */}
{dataPoints.map((point, i) => (
<circle
key={`point-${i}`}
cx={point.x}
cy={point.y}
r="4"
fill="#2DD4BF"
stroke="#1A1A2E"
strokeWidth="2"
/>
))}
{/* 라벨 */}
{data.map((item, i) => {
const normalizedScore = item.score / 100;
const r = radius * normalizedScore;
const angle = (Math.PI * 2 * i) / sides - Math.PI / 2;
const x = center + r * Math.cos(angle);
const y = center + r * Math.sin(angle);
const isHigh = item.score >= 90;
return (
<g key={i}>
{isHigh && (
<circle cx={x} cy={y} r="10" fill={accentColor} fillOpacity="0.4" />
)}
<circle cx={x} cy={y} r={isHigh ? 5 : 4} fill="#fff" />
</g>
)
})}
const angle = getAngle(i);
const pos = getPoint(i, labelRadius);
const rank = rankMap.get(i) || i + 1;
const isTopThree = rank <= 3;
const isLeftSide = Math.cos(angle) < -0.1;
const textX = isLeftSide ? -14 : 14;
const textAnchor: 'start' | 'end' = isLeftSide ? 'end' : 'start';
{labels.map((l, i) => {
const isHigh = l.score >= 90;
return (
<g key={i}>
<text
x={l.x}
y={l.y - 7}
textAnchor={l.anchor}
fill={isHigh ? "#fff" : "#e2e8f0"}
fontSize={isHigh ? "14" : "12"}
fontWeight={isHigh ? "700" : "600"}
className="tracking-tight"
style={{ fontFamily: "sans-serif" }}
>
{l.text}
</text>
<text
x={l.x}
y={l.y + 9}
textAnchor={l.anchor}
fill={isHigh ? accentColor : "#94a3b8"}
fontSize={isHigh ? "11" : "10"}
fontWeight={isHigh ? "600" : "400"}
className="uppercase tracking-wider"
>
{l.sub}
</text>
<g key={`label-${i}`}>
<g transform={`translate(${pos.x}, ${pos.y})`}>
{isLeftSide && (
<text
x={textX}
y="0"
textAnchor={textAnchor}
dominantBaseline="central"
className="bi2-radar-label-text"
style={{ fontSize: '20px', fontWeight: 600, fill: '#E5F1F2', fontFamily: 'Pretendard' }}
>
{item.korean_category}
</text>
)}
<g filter={isTopThree ? 'url(#badge-glow)' : undefined}>
<rect x="-12.5" y="-12.5" width="25" height="25" rx="4" fill={isTopThree ? '#94FBE0' : '#206764'} />
<text
x="0" y="0"
textAnchor="middle"
dominantBaseline="central"
style={{ fontSize: '16px', fontWeight: 600, fill: isTopThree ? '#002224' : '#94FBE0', fontFamily: 'Pretendard' }}
>
{rank}
</text>
</g>
{!isLeftSide && (
<text
x={textX}
y="0"
textAnchor={textAnchor}
dominantBaseline="central"
className="bi2-radar-label-text"
style={{ fontSize: '20px', fontWeight: 600, fill: '#E5F1F2', fontFamily: 'Pretendard' }}
>
{item.korean_category}
</text>
)}
</g>
</g>
);
})}