From a2906e25996746c50e312e30c93e1dba177f657c Mon Sep 17 00:00:00 2001 From: ekachxaidze98 Date: Mon, 28 Oct 2024 17:06:35 +0400 Subject: [PATCH] CORE: add % --- templates/sdg/charts/reChartBarChart.jsx | 46 ++++++++++++++++++++++-- templates/sdg/styles.module.css | 5 +++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/templates/sdg/charts/reChartBarChart.jsx b/templates/sdg/charts/reChartBarChart.jsx index b4b9cc67..eb30d4f1 100644 --- a/templates/sdg/charts/reChartBarChart.jsx +++ b/templates/sdg/charts/reChartBarChart.jsx @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useContext } from 'react' import { BarChart, Bar, @@ -12,6 +12,7 @@ import { } from 'recharts' import styles from '../styles.module.css' +import { GlobalContext } from '../../../store' import { formatNumber } from 'utils/helpers' @@ -33,6 +34,47 @@ const ReChartBarChart = ({ return formatNumber(value) } + const renderTooltip = ({ payload, label }) => { + if (!payload || !payload.length) return null + + const { ...globalStore } = useContext(GlobalContext) + const globalCountMetadata = + globalStore.dataProvider?.statistics?.countMetadata || 1 + + return ( +
+

{label}

+ {payload.map((entry, index) => { + const { value, color } = entry + if (toggle) { + const firstPercentage = ( + (value / globalCountMetadata) * + 100 + ).toFixed(2) + const secondPercentage = ((value / totalOutputCount) * 100).toFixed( + 2 + ) + return ( + // eslint-disable-next-line react/no-array-index-key +

+ {entry.name} (proportion of all papers with SDG):{' '} + {firstPercentage}% +
+ {entry.name} (percentage of all papers): {secondPercentage}% +

+ ) + } + return ( + // eslint-disable-next-line react/no-array-index-key +

+ {entry.name}: {formatNumber(value)} +

+ ) + })} +
+ ) + } + return (
@@ -58,7 +100,7 @@ const ReChartBarChart = ({ - + {sdgTypes .filter((sdg) => visibleColumns.includes(sdg.id)) diff --git a/templates/sdg/styles.module.css b/templates/sdg/styles.module.css index c9ef7544..1ccf6c07 100644 --- a/templates/sdg/styles.module.css +++ b/templates/sdg/styles.module.css @@ -382,3 +382,8 @@ padding: 24px; background: #fff; } + +.bar-tooltip { + padding: 10px; + background: #fff; +}