Skip to content

Commit

Permalink
factoring the legend
Browse files Browse the repository at this point in the history
  • Loading branch information
jerem1508 committed Aug 27, 2024
1 parent 41b7ee3 commit 8adcdfd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 98 deletions.
21 changes: 21 additions & 0 deletions client/src/pages/european-projects/components/legend.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export function GetLegend(legendArray: [string, string][]) {
return (
<ul className="legend">
{legendArray.map((item) => (
<li
style={{ display: "flex", alignItems: "center", marginBottom: "5px" }}
>
<div
style={{
width: "20px",
height: "20px",
background: item[1],
marginRight: "10px",
}}
></div>
<span>{item[0]}</span>
</li>
))}
</ul>
);
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { useQuery } from "@tanstack/react-query";
import { Col, Container, Row } from "@dataesr/dsfr-plus";

import Template from "./template";
import { GetData } from "./query";
import { GetLegend } from "../../../../../legend";
import optionsSub from "./options";
import optionSubSuccessRate from "./options-succes-rate";
import optionsCoordinationNumber from "./options-coordination_number";
import optionCoordinationNumberSuccessRate from "./options-coordination_number-succes-rate";
import optionsNumberInvolved from "./options-number_involved";
import optionNumberInvolvedSuccessRate from "./options-number_involved-succes-rate";
import ChartWrapper from "../../../../../chart-wrapper";
import { Col, Container, Row } from "@dataesr/dsfr-plus";
import Template from "./template";

export default function FundingRanking({ indicateurId }) {
const { data, isLoading } = useQuery({
Expand Down Expand Up @@ -56,88 +57,20 @@ export default function FundingRanking({ indicateurId }) {
<ChartWrapper
id={indicateurId}
options={optionsChart(prepareData(data, sortIndicateur))}
legend={
<ul className="legend">
<li
style={{
display: "flex",
alignItems: "center",
marginBottom: "5px",
}}
>
<div
style={{
width: "20px",
height: "20px",
background: "#009099",
marginRight: "10px",
}}
/>
<span>Projets évalués</span>
</li>
<li
style={{
display: "flex",
alignItems: "center",
marginBottom: "5px",
}}
>
<div
style={{
width: "20px",
height: "20px",
background: "#233E41",
marginRight: "10px",
}}
/>
<span>Projets lauréats</span>
</li>
</ul>
}
legend={GetLegend([
["Projets évalués", "#009099"],
["Projets lauréats", "#233E41"],
])}
/>
</Col>
<Col>
<ChartWrapper
id={successGraphId}
options={optionChartSuccess(prepareData(data, sortIndicateur))}
legend={
<ul className="legend">
<li
style={{
display: "flex",
alignItems: "center",
marginBottom: "5px",
}}
>
<div
style={{
width: "20px",
height: "20px",
background: "#27A658",
marginRight: "10px",
}}
/>
<span>Taux de réussite du pays</span>
</li>
<li
style={{
display: "flex",
alignItems: "center",
marginBottom: "5px",
}}
>
<div
style={{
width: "20px",
height: "20px",
background: "#D75521",
marginRight: "10px",
}}
/>
<span>Taux de réussite moyen</span>
</li>
</ul>
}
legend={GetLegend([
["Taux de réussite du pays", "#27A658"],
["Taux de réussite moyen", "#D75521"],
])}
/>
</Col>
</Row>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,31 @@
import { useQuery } from "@tanstack/react-query";
import { useSearchParams } from "react-router-dom";

import Template from "./template";
import { GetData } from "./query";
import { getDefaultParams } from "./utils";
import { GetLegend } from "../../../../../legend";
import options from "./options";

import ChartWrapper from "../../../../../chart-wrapper";
import { getDefaultParams } from "./utils";
import Template from "./template";

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

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

if (isLoading || !data) return <Template />
if (isLoading || !data) return <Template />;
return (
<ChartWrapper
id="top10beneficiaries"
options={options(data, searchParams.get('country_code') ?? null)}
legend={(
<ul className="legend">
<li style={{ display: "flex", alignItems: "center", marginBottom: "5px" }}>
<div style={{ width: "20px", height: "20px", background: "#233E41", marginRight: "10px" }}></div>
<span>Total des subventions en euros €</span>
</li>
<li style={{ display: "flex", alignItems: "center", marginBottom: "5px" }}>
<div style={{ width: "20px", height: "20px", background: "#D75521", marginRight: "10px" }}></div>
<span>Poids du cumul des subventions (%)</span>
</li>
</ul>
)}
options={options(data, searchParams.get("country_code") ?? null)}
legend={GetLegend([
["Total des subventions en euros €", "#233E41"],
["Poids du cumul des subventions (%)", "#D75521"],
])}
/>
);
}
}

0 comments on commit 8adcdfd

Please sign in to comment.