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}%
+
+ {entry.name}: {formatNumber(value)} +
+ ) + })} +