This commit is contained in:
HyeongBaeYang committed 2026-03-09 15:45:27 +09:00
commit fa4864e9ef
6 files changed
+328 -389

No files matched your search

+8 -221
View File
@@ -1,7 +1,8 @@
import React, { useState, useEffect, useRef } from 'react';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { CrawlingResponse, TargetPersona, SellingPoint } from '../../types/api';
import { CrawlingResponse, TargetPersona } from '../../types/api';
import { GeometricChart } from './GeometricChart';
interface AnalysisResultSectionProps {
onBack: () => void;
@@ -9,200 +10,9 @@ interface AnalysisResultSectionProps {
data: CrawlingResponse;
}
// 레이더 차트 컴포넌트
interface RadarChartProps {
data: SellingPoint[];
size?: number;
}
const RadarChart: React.FC<RadarChartProps> = ({ data, size = 360 }) => {
const [animatedScores, setAnimatedScores] = useState<number[]>(data.map(() => 0));
const [isAnimating, setIsAnimating] = useState(true);
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);
const newScores = targetScores.map(target => target * easeProgress);
setAnimatedScores(newScores);
if (progress < 1) {
requestAnimationFrame(animate);
} else {
setIsAnimating(false);
}
};
requestAnimationFrame(animate);
}, [data]);
const padding = 80;
const center = size / 2 + padding;
const maxRadius = size / 2 - 20;
const levels = 5;
const angleStep = (2 * Math.PI) / data.length;
const getPoint = (index: number, score: number) => {
const angle = angleStep * index - Math.PI / 2;
const radius = (score / 100) * maxRadius;
return {
x: center + radius * Math.cos(angle),
y: center + radius * Math.sin(angle),
};
};
const dataPoints = animatedScores.map((score, i) => getPoint(i, score));
const dataPath = dataPoints.map((p, i) => (i === 0 ? `M ${p.x} ${p.y}` : `L ${p.x} ${p.y}`)).join(' ') + ' Z';
const levelPaths = Array.from({ length: levels }, (_, levelIndex) => {
const levelRadius = ((levelIndex + 1) / levels) * maxRadius;
const points = data.map((_, i) => {
const angle = angleStep * i - Math.PI / 2;
return {
x: center + levelRadius * Math.cos(angle),
y: center + levelRadius * Math.sin(angle),
};
});
return points.map((p, i) => (i === 0 ? `M ${p.x} ${p.y}` : `L ${p.x} ${p.y}`)).join(' ') + ' Z';
});
const axisLines = data.map((_, i) => {
const angle = angleStep * i - Math.PI / 2;
const endX = center + maxRadius * Math.cos(angle);
const endY = center + maxRadius * Math.sin(angle);
return `M ${center} ${center} L ${endX} ${endY}`;
});
const svgSize = size + padding * 2;
// 순위별로 정렬하여 라벨 위치에 순위 번호 배치
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));
return (
<div className="bi2-radar-container">
<svg
width={svgSize}
height={svgSize}
viewBox={`0 0 ${svgSize} ${svgSize}`}
style={{ overflow: 'visible' }}
>
{levelPaths.map((path, i) => (
<path
key={`level-${i}`}
d={path}
fill="none"
stroke="rgba(255,255,255,0.2)"
strokeWidth="1"
/>
))}
{axisLines.map((path, i) => (
<path
key={`axis-${i}`}
d={path}
fill="none"
stroke="rgba(255,255,255,0.2)"
strokeWidth="1"
/>
))}
<path
d={dataPath}
fill="rgba(45, 212, 191, 0.2)"
stroke="#2DD4BF"
strokeWidth="2"
style={{
transition: isAnimating ? 'none' : 'd 0.3s ease-out',
}}
/>
{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 angle = angleStep * i - Math.PI / 2;
const labelRadius = maxRadius + 40;
const pos = {
x: center + labelRadius * Math.cos(angle),
y: center + labelRadius * Math.sin(angle),
};
const rank = rankMap.get(i) || i + 1;
const isTopThree = rank <= 3;
return (
<g key={`label-${i}`}>
<g transform={`translate(${pos.x}, ${pos.y})`}>
<rect
x="-10"
y="-10"
width="20"
height="20"
rx="4"
fill={isTopThree ? '#94FBE0' : '#206764'}
/>
<text
x="0"
y="0"
textAnchor="middle"
dominantBaseline="central"
style={{
fontSize: '12px',
fontWeight: 600,
fill: isTopThree ? '#002224' : '#94FBE0',
fontFamily: 'Pretendard',
}}
>
{rank}
</text>
<text
x="16"
y="0"
textAnchor="start"
dominantBaseline="central"
style={{
fontSize: '14px',
fontWeight: 400,
fill: '#E5F1F2',
fontFamily: 'Pretendard',
}}
>
{item.korean_category}
</text>
</g>
</g>
);
})}
</svg>
</div>
);
};
const AnalysisResultSection: React.FC<AnalysisResultSectionProps> = ({ onBack, onGenerate, data }) => {
const { t } = useTranslation();
const { processed_info, marketing_analysis } = data;
const containerRef = useRef<HTMLDivElement>(null);
const [buttonPosition, setButtonPosition] = useState({ left: 0, width: 0 });
const brandIdentity = marketing_analysis?.brand_identity;
const marketPositioning = marketing_analysis?.market_positioning;
@@ -213,26 +23,6 @@ const AnalysisResultSection: React.FC<AnalysisResultSectionProps> = ({ onBack, o
// 셀링 포인트를 score 내림차순으로 정렬
const sortedSellingPoints = [...sellingPoints].sort((a, b) => b.score - a.score);
useEffect(() => {
const updateButtonPosition = () => {
if (containerRef.current) {
const rect = containerRef.current.getBoundingClientRect();
setButtonPosition({ left: rect.left, width: rect.width });
}
};
updateButtonPosition();
window.addEventListener('resize', updateButtonPosition);
const observer = new MutationObserver(updateButtonPosition);
observer.observe(document.body, { attributes: true, subtree: true, attributeFilter: ['class'] });
return () => {
window.removeEventListener('resize', updateButtonPosition);
observer.disconnect();
};
}, []);
return (
<div className="bi2-page">
{/* Header */}
@@ -253,13 +43,13 @@ const AnalysisResultSection: React.FC<AnalysisResultSectionProps> = ({ onBack, o
<div className="bi2-title-text">
<h1 className="bi2-main-title">{t('analysis.pageTitle')}</h1>
<p className="bi2-subtitle">
{t('analysis.pageDescHighlight')}{t('analysis.pageDescBefore')}{processed_info?.customer_name || t('analysis.defaultBrandName')}{t('analysis.pageDescAfter')}
<span style={{ color: 'var(--Color-mint-500, #94FBE0)' }}>{t('analysis.pageDescHighlight')}</span>{t('analysis.pageDescBefore')}{processed_info?.customer_name || t('analysis.defaultBrandName')}{t('analysis.pageDescAfter')}
</p>
</div>
</div>
{/* Main Content Container */}
<div ref={containerRef} className="bi2-main-container">
<div className="bi2-main-container">
{/* 매장명 & 주소 */}
<div className="bi2-store-header">
<h2 className="bi2-store-name">{processed_info?.customer_name || t('analysis.brandNameFallback')}</h2>
@@ -298,7 +88,7 @@ const AnalysisResultSection: React.FC<AnalysisResultSectionProps> = ({ onBack, o
{/* 레이더 차트 */}
<div className="bi2-selling-chart">
{sellingPoints.length > 0 && (
<RadarChart data={sellingPoints} size={360} />
<GeometricChart data={sellingPoints} />
)}
</div>
{/* 셀링 포인트 리스트 */}
@@ -369,13 +159,10 @@ const AnalysisResultSection: React.FC<AnalysisResultSectionProps> = ({ onBack, o
</div>
{/* 콘텐츠 생성 버튼 */}
<div
className="fixed bottom-8 flex justify-center z-50 pointer-events-none"
style={{ left: buttonPosition.left, width: buttonPosition.width }}
>
<div className="bi2-bottom-button-container">
<button
onClick={onGenerate}
className="pointer-events-auto bg-brand-purple hover:bg-brand-purpleHover text-white font-bold py-3 px-12 rounded-full shadow-2xl shadow-brand-purple/40 transform hover:scale-105 transition-all duration-300 flex items-center gap-2"
className="bi2-generate-btn"
>
<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden className="w-5 h-5">
<path d="M12 2l2.4 6.8L22 12l-7.6 3.2L12 22l-2.4-6.8L2 12l7.6-3.2L12 2z" />
+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>
);
})}
+16 -26
View File
@@ -518,32 +518,8 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
</div>
</div>
{/* Generate Button */}
<button
onClick={handleGenerateMusic}
disabled={isGenerating}
className={`btn-generate-sound ${isGenerating ? 'disabled' : ''}`}
>
{isGenerating ? (
<>
<svg className="animate-spin h-4 w-4" viewBox="0 0 24 24">
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" fill="none"/>
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"/>
</svg>
{t('soundStudio.generating')}
</>
) : (
t('soundStudio.generateButton')
)}
</button>
{errorMessage && (
<div className="error-message-new">
{errorMessage}
</div>
)}
{isGenerating && statusMessage && (
{/* Generate Button / Status Message (교체) */}
{isGenerating && statusMessage ? (
<div className="status-message-new">
<svg className="animate-spin h-4 w-4" viewBox="0 0 24 24">
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" fill="none"/>
@@ -551,6 +527,20 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
</svg>
{statusMessage}
</div>
) : (
<button
onClick={handleGenerateMusic}
disabled={isGenerating}
className={`btn-generate-sound ${isGenerating ? 'disabled' : ''}`}
>
{t('soundStudio.generateButton')}
</button>
)}
{errorMessage && (
<div className="error-message-new">
{errorMessage}
</div>
)}
</div>