Skip to content

Commit

Permalink
style: 도넛 차트 글자 잘리는 현상 해결 (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyoribogo authored Dec 3, 2023
1 parent aa867f5 commit bd87115
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/pages/ReviewResultPage/components/DoughnutChart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@ interface DoughnutChartProps {
answers: string[]
}

const splitStrings = (input: string[]): string[][] | string[] => {
const result: string[][] = []

for (const str of input) {
if (str.length <= 7) {
result.push([str])
continue
}

const chunks: string[] = []

for (let i = 0; i < str.length; i += 7) {
chunks.push(str.substring(i, i + 7).trim())
}
result.push(chunks)
}

return result
}

const DoughnutChart = ({ answers }: DoughnutChartProps) => {
const { darkMode } = useDarkMode()

Expand All @@ -15,9 +35,11 @@ const DoughnutChart = ({ answers }: DoughnutChartProps) => {
answerMap.set(answer, (answerMap.get(answer) || 0) + 1)
})

const labels = Array.from(answerMap.keys())
const labels = splitStrings(Array.from(answerMap.keys()))
const data = Array.from(answerMap.values())

console.log(labels)

const doughnutData: ChartData<'doughnut'> = {
labels,
datasets: [
Expand Down Expand Up @@ -47,9 +69,9 @@ const DoughnutChart = ({ answers }: DoughnutChartProps) => {
position: 'right',
display: true,
labels: {
padding: 20,
font: {
size: 12,
size: 13,
lineHeight: 1.5,
},
color: darkMode ? '#fff' : '#000',
usePointStyle: true,
Expand All @@ -59,7 +81,7 @@ const DoughnutChart = ({ answers }: DoughnutChartProps) => {
}

return (
<div className="mx-auto w-fit max-w-full">
<div className="mx-auto w-full max-w-full md:w-4/6">
<Doughnut data={doughnutData} options={DoughnutOptions} />
</div>
)
Expand Down

0 comments on commit bd87115

Please sign in to comment.