|
| 1 | +import { useQuery } from "@tanstack/react-query"; |
| 2 | +import { Title } from "@dataesr/dsfr-plus"; |
| 3 | + |
| 4 | +import { getData } from "./query"; |
| 5 | +import Options from "./options"; |
| 6 | +import { useGetParams, processEvolutionData, renderDataTable } from "./utils"; |
| 7 | +import { getI18nLabel } from "../../../../../../utils"; |
| 8 | +import { EPChartsSources } from "../../../../config.js"; |
| 9 | + |
| 10 | +import ChartWrapper from "../../../../../../components/chart-wrapper"; |
| 11 | +import DefaultSkeleton from "../../../../../../components/charts-skeletons/default"; |
| 12 | + |
| 13 | +import i18n from "../../i18n.json"; |
| 14 | + |
| 15 | +interface EvolutionChartsProps { |
| 16 | + countryAdjective?: string; |
| 17 | + currentLang?: string; |
| 18 | +} |
| 19 | + |
| 20 | +const configWeight = { |
| 21 | + id: "mscaEvolutionWeight", |
| 22 | + idQuery: "mscaEvolution", |
| 23 | + comment: { |
| 24 | + fr: ( |
| 25 | + <> |
| 26 | + Ce graphique présente l'évolution du poids des projets lauréats du pays sélectionné par rapport au total européen, ventilé par type de |
| 27 | + financement MSCA. |
| 28 | + </> |
| 29 | + ), |
| 30 | + en: ( |
| 31 | + <> |
| 32 | + This chart shows the evolution of the share of successful projects from the selected country compared to the European total, broken down by |
| 33 | + MSCA funding type. |
| 34 | + </> |
| 35 | + ), |
| 36 | + }, |
| 37 | + readingKey: { |
| 38 | + fr: <>Un poids de 10% signifie que le pays représente 10% des porteurs de projets lauréats au niveau européen pour ce type de financement.</>, |
| 39 | + en: <>A share of 10% means that the country represents 10% of successful project PIs at the European level for this funding type.</>, |
| 40 | + }, |
| 41 | + sources: EPChartsSources, |
| 42 | + integrationURL: "/european-projects/components/pages/msca/charts/evolution-weight", |
| 43 | +}; |
| 44 | + |
| 45 | +const configSuccessRate = { |
| 46 | + id: "mscaEvolutionSuccessRate", |
| 47 | + idQuery: "mscaEvolution", |
| 48 | + comment: { |
| 49 | + fr: ( |
| 50 | + <> |
| 51 | + Ce graphique présente l'évolution du taux de succès des projets du pays sélectionné, calculé comme le ratio entre projets lauréats et projets |
| 52 | + évalués, ventilé par type de financement MSCA. |
| 53 | + </> |
| 54 | + ), |
| 55 | + en: ( |
| 56 | + <> |
| 57 | + This chart shows the evolution of the success rate of projects from the selected country, calculated as the ratio of successful to evaluated |
| 58 | + projects, broken down by MSCA funding type. |
| 59 | + </> |
| 60 | + ), |
| 61 | + }, |
| 62 | + readingKey: { |
| 63 | + fr: <>Un taux de succès de 20% signifie que 20% des projets soumis et évalués ont été retenus pour ce type de financement.</>, |
| 64 | + en: <>A success rate of 20% means that 20% of submitted and evaluated projects were selected for this funding type.</>, |
| 65 | + }, |
| 66 | + sources: EPChartsSources, |
| 67 | + integrationURL: "/european-projects/components/pages/msca/charts/evolution-success-rate", |
| 68 | +}; |
| 69 | + |
| 70 | +export default function EvolutionFundingsCharts({ countryAdjective = "français", currentLang: propLang }: EvolutionChartsProps) { |
| 71 | + const { params, currentLang: urlLang } = useGetParams(); |
| 72 | + const currentLang = propLang || urlLang; |
| 73 | + |
| 74 | + const { data, isLoading } = useQuery({ |
| 75 | + queryKey: ["mscaEvolution", params], |
| 76 | + queryFn: () => getData(params), |
| 77 | + enabled: params !== "", |
| 78 | + }); |
| 79 | + |
| 80 | + if (isLoading || !data) return <DefaultSkeleton />; |
| 81 | + |
| 82 | + const processedData = processEvolutionData(data, currentLang); |
| 83 | + |
| 84 | + if (processedData.years.length === 0) { |
| 85 | + return ( |
| 86 | + <div className="fr-alert fr-alert--info"> |
| 87 | + <p>{getI18nLabel(i18n, "evolution.noDataAvailable", currentLang)}</p> |
| 88 | + </div> |
| 89 | + ); |
| 90 | + } |
| 91 | + |
| 92 | + const weightOptions = Options({ |
| 93 | + processedData, |
| 94 | + chartType: "weight", |
| 95 | + countryAdjective, |
| 96 | + currentLang, |
| 97 | + }); |
| 98 | + |
| 99 | + const successRateOptions = Options({ |
| 100 | + processedData, |
| 101 | + chartType: "successRate", |
| 102 | + countryAdjective, |
| 103 | + currentLang, |
| 104 | + }); |
| 105 | + |
| 106 | + return ( |
| 107 | + <div className="evolution-charts"> |
| 108 | + <Title as="h2" look="h5"> |
| 109 | + {getI18nLabel(i18n, "evolution.sectionTitle", currentLang)} {countryAdjective} {getI18nLabel(i18n, "evolution.byFundingType", currentLang)} |
| 110 | + </Title> |
| 111 | + |
| 112 | + {/* Graphique 1: Poids des projets */} |
| 113 | + <div className="fr-mb-4w chart-container--default"> |
| 114 | + <ChartWrapper config={configWeight} options={weightOptions} renderData={() => renderDataTable(processedData, "weight", currentLang)} /> |
| 115 | + </div> |
| 116 | + |
| 117 | + {/* Graphique 2: Taux de succès */} |
| 118 | + <div className="fr-mb-4w chart-container--default"> |
| 119 | + <ChartWrapper |
| 120 | + config={configSuccessRate} |
| 121 | + options={successRateOptions} |
| 122 | + renderData={() => renderDataTable(processedData, "successRate", currentLang)} |
| 123 | + /> |
| 124 | + </div> |
| 125 | + </div> |
| 126 | + ); |
| 127 | +} |
0 commit comments