Skip to content

Commit

Permalink
Ajout du composant MainPartners et intégration dans la vue Overview, …
Browse files Browse the repository at this point in the history
…avec des options de graphique et des fonctions utilitaires pour la récupération des données.
  • Loading branch information
jerem1508 committed Dec 10, 2024
1 parent 29ea01f commit fd2b2e3
Show file tree
Hide file tree
Showing 13 changed files with 302 additions and 122 deletions.
8 changes: 7 additions & 1 deletion client/src/pages/european-projects/charts-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,20 @@
"description": null,
"integrationURL": "/european-projects/components/pages/analysis/overview/charts/projects-types-1"
},

{
"id": "mainBeneficiaries",
"title": "",
"subtitle": "Principaux bénéficiaires qui concentrent 50 % des subventions allouées aux équipes",
"description": "Ad duis occaecat voluptate deserunt tempor enim nulla officia.",
"integrationURL": "/european-projects/components/pages/analysis/overview/charts/main-beneficiaries"
},
{
"id": "mainPartners",
"title": "",
"subtitle": "Principaux partenaires des équipes du pays sélectionné",
"description": "",
"integrationURL": "/european-projects/components/pages/analysis/overview/charts/main-beneficiaries"
},
{
"id": "top10beneficiaries",
"title": "",
Expand Down
75 changes: 71 additions & 4 deletions client/src/pages/european-projects/components/chart-ep.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,85 @@
import HighchartsInstance from "highcharts";

export function ChartEP(
type: NonNullable<HighchartsInstance.Options["chart"]>["type"]
function deepMerge(obj1, obj2) {
for (const key in obj2) {
if (Object.prototype.hasOwnProperty.call(obj2, key)) {
if (obj2[key] instanceof Object && obj1[key] instanceof Object) {
obj1[key] = deepMerge(obj1[key], obj2[key]);
} else {
obj1[key] = obj2[key];
}
}
}
return obj1;
}

export function CreateChartOptions(
type: NonNullable<HighchartsInstance.Options["chart"]>["type"],
options: NonNullable<HighchartsInstance.Options>
) {
const chartOptions: HighchartsInstance.Options = {
const rootStyles = getComputedStyle(document.documentElement);

const defaultOptions: HighchartsInstance.Options = {
chart: {
type: type,
height: 500,
backgroundColor: "transparent",
},
title: { text: "" },
legend: { enabled: false },
credits: { enabled: false },
xAxis: {
labels: {
autoRotation: [-45, -90],
style: {
fontSize: "13px",
fontFamily: "Marianne, sans-serif",
color: rootStyles.getPropertyValue("--label-color"),
},
},
},
yAxis: [
{
labels: {
style: {
fontSize: "13px",
fontFamily: "Marianne, sans-serif",
color: rootStyles.getPropertyValue("--label-color"),
},
},
title: {
style: {
fontSize: "16px",
fontFamily: "Marianne, sans-serif",
color: rootStyles.getPropertyValue("--label-color"),
},
},
},
{
labels: {
style: {
fontSize: "13px",
fontFamily: "Marianne, sans-serif",
color: rootStyles.getPropertyValue("--label-color"),
},
},
title: {
style: {
fontSize: "16px",
fontFamily: "Marianne, sans-serif",
color: rootStyles.getPropertyValue("--label-color"),
},
},
},
],
};

if (type !== "empty") {
if (defaultOptions.chart) {
defaultOptions.chart.type = type;
}
}

const chartOptions = deepMerge(defaultOptions, options);

return chartOptions;
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import HighchartsInstance from "highcharts";

import { CreateChartOptions } from "../../../../../chart-ep";
import { getColorByPillierName } from "./utils";

export default function Options(data) {
return {
chart: {
type: "bar",
height: 500,
backgroundColor: "transparent",
},
title: { text: "" },
if (!data) return null;

const newOptions: HighchartsInstance.Options = {
xAxis: {
categories: data.map((item) => item.programme_name_fr),
title: { text: "" },
Expand All @@ -16,17 +15,9 @@ export default function Options(data) {
title: { text: "" },
endOnTick: false,
},

legend: { enabled: false },
credits: { enabled: false },
plotOptions: {
series: {
groupPadding: 0.1,
pointPadding: 0.1,
},
},
series: [
{
type: "bar",
name: "Part captée en %",
data: data.map((item) => ({
y: item.total_funding,
Expand All @@ -40,4 +31,6 @@ export default function Options(data) {
},
],
};

return CreateChartOptions("bar", newOptions);
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
import HighchartsInstance from "highcharts";

import { CreateChartOptions } from "../../../../../chart-ep";

export default function Options(data) {
if (!data) return null;

return {
chart: {
type: "bar",
height: 500,
backgroundColor: "transparent",
},
title: { text: "" },
legend: { enabled: false },
credits: { enabled: false },

const newOptions: HighchartsInstance.Options = {
xAxis: {
type: "category",
labels: {
autoRotation: [-45, -90],
style: {
fontSize: "13px",
fontFamily: "Verdana, sans-serif",
},
},
},
yAxis: {
min: 0,
Expand All @@ -32,6 +20,7 @@ export default function Options(data) {
},
series: [
{
type: "bar",
name: "Total subventions en euros",
colors: ["#1E3859"],
colorByPoint: true,
Expand All @@ -40,4 +29,6 @@ export default function Options(data) {
},
],
};

return CreateChartOptions("bar", newOptions);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useQuery } from "@tanstack/react-query";
import { useSearchParams } from "react-router-dom";

import { GetData } from "./query";
import options from "./options";

import ChartWrapper from "../../../../../chart-wrapper";
import { getDefaultParams } from "./utils";
import { RenderData } from "./render-data";
import DefaultSkeleton from "../../../../../charts-skeletons/default";

export default function MainPartners() {
const [searchParams] = useSearchParams();
const params = getDefaultParams(searchParams);

const { data, isLoading } = useQuery({
queryKey: ["MainBeneficiaries", params],
queryFn: () => GetData(params),
});

if (isLoading || !data) return <DefaultSkeleton />;

return <>MainPartners chart</>; //TODO: Implement MainPartners chart
return (
<ChartWrapper
id="mainPartners"
options={options(data)}
legend={null}
renderData={RenderData}
/>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import HighchartsInstance from "highcharts";

import { CreateChartOptions } from "../../../../../chart-ep";

export default function Options(data) {
if (!data) return null;

const newOptions: HighchartsInstance.Options = {
xAxis: {
type: "category",
},
yAxis: {
min: 0,
title: {
text: "Euros € (millions)",
},
},
tooltip: {
pointFormat: "Total des subventions : <b>{point.y:.1f} €</b>",
},
series: [
{
type: "bar",
name: "Total subventions en euros",
colors: ["#1E3859"],
colorByPoint: true,
groupPadding: 0,
data: data.list.map((item) => [item.acronym, item.total_fund_eur]),
},
],
};

return CreateChartOptions("bar", newOptions);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { VITE_APP_SERVER_URL } = import.meta.env;

export async function GetData(params: string) {
let url = `${VITE_APP_SERVER_URL}/european-projects/main-beneficiaries`;
if (params !== "") {
url = `${VITE_APP_SERVER_URL}/european-projects/main-beneficiaries?${params}`;
}

return fetch(url).then((response) => response.json());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
function TableWrapper({ children }) {
return (
<div className="fr-table--sm fr-table fr-table--bordered">
<div className="fr-table__wrapper">
<div className="fr-table__container">
<div className="fr-table__content">
<table id="table-bordered">{children}</table>
</div>
</div>
</div>
</div>
);
}

export function RenderData(options) {
return (
<TableWrapper>
<thead>
<tr>
<th>Id des partenaires</th>
<th>Liste des partenaires</th>
<th>Nombre de projets communs</th>
<th>Pays</th>
</tr>
</thead>
<tbody>
{options.series[0].data.map((item) => (
<tr key={item.id}>
<td>{item.id}</td>
<td>{item.name}</td>
<td>{item.country}</td>
</tr>
))}
</tbody>
</TableWrapper>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function getDefaultParams(searchParams) {
const params = [...searchParams].map(([key, value]) => `${key}=${value}`).join('&');

return params + '&stage=successful';
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useEffect } from "react";
import FundedObjectives from "./charts/funded-objectives";
import SynthesisFocus from "./charts/synthesis-focus";
import MainBeneficiaries from "./charts/main-beneficiaries";
import MainPartners from "./charts/main-partners";

export default function Overview() {
const [searchParams, setSearchParams] = useSearchParams();
Expand All @@ -21,6 +22,8 @@ export default function Overview() {
<FundedObjectives />
<div className="fr-my-5w" />
<MainBeneficiaries />
<div className="fr-my-5w" />
<MainPartners />
</Container>
);
}
Loading

0 comments on commit fd2b2e3

Please sign in to comment.