From 4018af06d5b7867cda9c71e1def9f2981be76439 Mon Sep 17 00:00:00 2001 From: withsang Date: Thu, 30 Nov 2023 02:43:40 +0900 Subject: [PATCH] fix(text): fix gender diversity threshold --- .../LocalCouncilReportText/AgeText.tsx | 3 -- .../LocalCouncilReportText/GenderText.tsx | 32 +++++++++++++------ .../MetroCouncilReportText/AgeText.tsx | 3 -- .../MetroCouncilReportText/GenderText.tsx | 32 +++++++++++++------ .../organisms/LocalCouncilReport.tsx | 7 ++-- .../organisms/MetroCouncilReport.tsx | 6 ++-- 6 files changed, 50 insertions(+), 33 deletions(-) diff --git a/src/components/molecules/LocalCouncilReportText/AgeText.tsx b/src/components/molecules/LocalCouncilReportText/AgeText.tsx index e177f7d..ffe4f65 100644 --- a/src/components/molecules/LocalCouncilReportText/AgeText.tsx +++ b/src/components/molecules/LocalCouncilReportText/AgeText.tsx @@ -92,9 +92,6 @@ export const AgeText = ({ {getNameFromId(ageHistogramParagraph.uniArea.localId)?.join(" ")} 예요. -
-
- 이전 정보를 확인하려면 아래의 슬라이더를 밀어 보세요. ); return 존재하지 않는 템플릿입니다.; diff --git a/src/components/molecules/LocalCouncilReportText/GenderText.tsx b/src/components/molecules/LocalCouncilReportText/GenderText.tsx index f93f817..2a639a8 100644 --- a/src/components/molecules/LocalCouncilReportText/GenderText.tsx +++ b/src/components/molecules/LocalCouncilReportText/GenderText.tsx @@ -51,10 +51,14 @@ function calculatePercentage(a: number, b: number) { return Math.round((a / (a + b)) * 100); } -function calculateGenderRatio(a: number, b: number) { +function calculateGenderDiversity(a: number, b: number) { return Math.max(a / b, b / a); } +function calculateFemaleRatio(femalePop: number, malePop: number) { + return femalePop / (femalePop + malePop); +} + export const GenderText = ({ variation = 1, data = defaultData, @@ -66,31 +70,39 @@ export const GenderText = ({ const localName = getNameFromId(localId)?.join(" "); const nowPercentage = calculatePercentage(current.femalePop, current.malePop); const meanPercentage = calculatePercentage(meanFemalePop, meanMalePop); - const nowGenderRatio = calculateGenderRatio( + const nowGenderDiversity = calculateGenderDiversity( + current.femalePop, + current.malePop, + ); + const prevGenderDiversity = calculateGenderDiversity( + prev.femalePop, + prev.malePop, + ); + const nowGenderRatio = calculateFemaleRatio( current.femalePop, current.malePop, ); - const prevGenderRatio = calculateGenderRatio(prev.femalePop, prev.malePop); + const meanGenderRatio = calculateFemaleRatio(meanFemalePop, meanMalePop); if (variation === 1) return ( {current.year}년 지방선거 당선자의 성비는{" "} - {nowGenderRatio > prevGenderRatio + {nowGenderDiversity > prevGenderDiversity ? "퇴보했습니다." - : nowGenderRatio === prevGenderRatio - ? "변화하지 않았습니다" + : nowGenderDiversity === prevGenderDiversity + ? "변화하지 않았습니다." : "나아졌습니다."} {" "}

{current.year}년 지방선거에서 {localName}의 당선자의 성별은 남성{" "} - {current.malePop}명({100 - nowPercentage}%){" "} + {current.malePop}명({100 - nowPercentage}%) , 여성{" "} - {current.femalePop}명({nowPercentage}%){" "} + {current.femalePop}명({nowPercentage}%) 입니다.

전국 지역 의회는 평균적으로 남성이{" "} {100 - meanPercentage}%, 여성이{" "} @@ -100,9 +112,9 @@ export const GenderText = ({ {Math.round(nowPercentage / 10)}명인 정도이기 때문에,{" "} - {nowGenderRatio > prevGenderRatio + {nowGenderRatio < meanGenderRatio ? "전국 대비 성별 다양성이 충분하다고 보기는 어렵습니다." - : nowGenderRatio === prevGenderRatio + : nowGenderRatio === meanGenderRatio ? "전국 평균 수준입니다." : "전국 평균 대비 높은 수준입니다."} diff --git a/src/components/molecules/MetroCouncilReportText/AgeText.tsx b/src/components/molecules/MetroCouncilReportText/AgeText.tsx index fd114d4..28fa741 100644 --- a/src/components/molecules/MetroCouncilReportText/AgeText.tsx +++ b/src/components/molecules/MetroCouncilReportText/AgeText.tsx @@ -89,9 +89,6 @@ export const AgeText = ({ {getNameFromId(ageHistogramParagraph.uniArea.localId)?.join(" ")} 예요. -
-
- 이전 정보를 확인하려면 아래의 슬라이더를 밀어 보세요.
); return 존재하지 않는 템플릿입니다.; diff --git a/src/components/molecules/MetroCouncilReportText/GenderText.tsx b/src/components/molecules/MetroCouncilReportText/GenderText.tsx index eb5fd42..96f9d2d 100644 --- a/src/components/molecules/MetroCouncilReportText/GenderText.tsx +++ b/src/components/molecules/MetroCouncilReportText/GenderText.tsx @@ -47,41 +47,53 @@ function calculatePercentage(a: number, b: number) { return Math.round((a / (a + b)) * 100); } -function calculateGenderRatio(a: number, b: number) { +function calculateGenderDiversity(a: number, b: number) { return Math.max(a / b, b / a); } +function calculateFemaleRatio(femalePop: number, malePop: number) { + return femalePop / (femalePop + malePop); +} + export const GenderText = ({ variation = 1, data = defaultData }: Props) => { if (!data) return 데이터를 불러오는 중입니다..; const { current, prev, meanMalePop, meanFemalePop } = data; const nowPercentage = calculatePercentage(current.femalePop, current.malePop); const meanPercentage = calculatePercentage(meanFemalePop, meanMalePop); - const nowGenderRatio = calculateGenderRatio( + const nowGenderDiversity = calculateGenderDiversity( + current.femalePop, + current.malePop, + ); + const prevGenderDiversity = calculateGenderDiversity( + prev.femalePop, + prev.malePop, + ); + const nowGenderRatio = calculateFemaleRatio( current.femalePop, current.malePop, ); - const prevGenderRatio = calculateGenderRatio(prev.femalePop, prev.malePop); + const meanGenderRatio = calculateFemaleRatio(meanFemalePop, meanMalePop); if (variation === 1) return ( {current.year}년 지방선거 당선자의 성비는{" "} - {nowGenderRatio > prevGenderRatio + {nowGenderDiversity > prevGenderDiversity ? "퇴보했습니다." - : nowGenderRatio === prevGenderRatio - ? "변화하지 않았습니다" + : nowGenderDiversity === prevGenderDiversity + ? "변화하지 않았습니다." : "나아졌습니다."} {" "}

{current.year}년 지방선거에서 당선자의 성별은 남성{" "} - {current.malePop}명({100 - nowPercentage}%){" "} + {current.malePop}명({100 - nowPercentage}%) , 여성{" "} - {current.femalePop}명({nowPercentage}%){" "} + {current.femalePop}명({nowPercentage}%) 입니다.

전국 지역 의회는 평균적으로 남성이{" "} {100 - meanPercentage}%, 여성이{" "} @@ -91,9 +103,9 @@ export const GenderText = ({ variation = 1, data = defaultData }: Props) => { {Math.round(nowPercentage / 10)}명인 정도이기 때문에,{" "} - {nowGenderRatio > prevGenderRatio + {nowGenderRatio < meanGenderRatio ? "전국 대비 성별 다양성이 충분하다고 보기는 어렵습니다." - : nowGenderRatio === prevGenderRatio + : nowGenderRatio === meanGenderRatio ? "전국 평균 수준입니다." : "전국 평균 대비 높은 수준입니다."} diff --git a/src/components/organisms/LocalCouncilReport.tsx b/src/components/organisms/LocalCouncilReport.tsx index 8fcb3e5..bd58737 100644 --- a/src/components/organisms/LocalCouncilReport.tsx +++ b/src/components/organisms/LocalCouncilReport.tsx @@ -124,11 +124,11 @@ const LocalCouncilReport = ({ const newGenderPieChartColorMap = new Map(); const genderColors = [ { - type: "남", + type: "남성", color: "#289FD4", }, { - type: "여", + type: "여성", color: "#AE2D6C", }, ]; @@ -177,7 +177,6 @@ const LocalCouncilReport = ({ binMax: maxAge, count, colorGroup: colorGroupMap.get(ageGroup as ColorGroup) || 0, - // colorGroup: ageGroup as ColorGroup, }); }); setAgeHistogramData(newAgeHistogramData); @@ -193,7 +192,7 @@ const LocalCouncilReport = ({ const newGenderPieChartData: PieChartData[] = []; data.forEach(({ gender, count }) => { newGenderPieChartData.push({ - type: gender, + type: `${gender}성`, value: count, }); }); diff --git a/src/components/organisms/MetroCouncilReport.tsx b/src/components/organisms/MetroCouncilReport.tsx index 6fb17c4..5243a58 100644 --- a/src/components/organisms/MetroCouncilReport.tsx +++ b/src/components/organisms/MetroCouncilReport.tsx @@ -121,11 +121,11 @@ const MetroCouncilReport = ({ const newGenderPieChartColorMap = new Map(); const genderColors = [ { - type: "남", + type: "남성", color: "#289FD4", }, { - type: "여", + type: "여성", color: "#AE2D6C", }, ]; @@ -189,7 +189,7 @@ const MetroCouncilReport = ({ const newGenderPieChartData: PieChartData[] = []; data.forEach(({ gender, count }) => { newGenderPieChartData.push({ - type: gender, + type: `${gender}성`, value: count, }); });