Skip to content

Commit

Permalink
feat: 육각형 스탯 취합 후 평균 값 계산 로직 구현 (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyoribogo authored Nov 29, 2023
1 parent a6b852d commit feb6fb3
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/pages/ReviewResultPage/components/RadarChart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,19 @@ interface RadarChartProps {
const RadarChart = ({ answers }: RadarChartProps) => {
const { darkMode } = useDarkMode()

const labels = answers.map((answer) => answer.statName)
const data = answers.map((answer) => answer.statScore)
const statGroups = new Map<string, number[]>()

answers.forEach((answer) => {
const statGroup = statGroups.get(answer.statName)
statGroups.set(answer.statName, [...(statGroup || []), answer.statScore])
})

const labels = Array.from(statGroups.keys())
const data = Array.from(statGroups.values()).map((scores) => {
const average = scores.reduce((acc, cur) => acc + cur, 0) / scores.length

return Number(average.toFixed(2))
})

const radarData: ChartData<'radar'> = {
labels,
Expand All @@ -31,6 +42,7 @@ const RadarChart = ({ answers }: RadarChartProps) => {
const radarOptions: ChartOptions<'radar'> = {
scales: {
r: {
suggestedMax: 10,
ticks: {
stepSize: 10,
count: 4,
Expand Down

0 comments on commit feb6fb3

Please sign in to comment.