-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from dataesr/fundingRankingCharts
add first chart - part 1
- Loading branch information
Showing
7 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
.../european-projects/components/pages/analysis/positioning/charts/funding-ranking/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
|
||
import Template from "./template"; | ||
import { GetData } from "./query"; | ||
import options from "./options"; | ||
import ChartWrapper from "../../../../../chart-wrapper"; | ||
|
||
export default function FundingRanking() { | ||
const { data, isLoading } = useQuery({ | ||
queryKey: ["fundingRanking"], | ||
queryFn: () => GetData() | ||
}) | ||
|
||
if (isLoading || !data) return <Template /> | ||
|
||
const prepareData = (data, sortKey) => { | ||
return data.sort((a, b) => b[sortKey] - a[sortKey]).slice(0, 10); | ||
} | ||
|
||
return ( | ||
<ChartWrapper | ||
id="fundingRankingSub" | ||
options={options(prepareData(data, "total_successful"))} | ||
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> | ||
)} | ||
/> | ||
) | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
...uropean-projects/components/pages/analysis/positioning/charts/funding-ranking/options.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
export default function Options(data) { | ||
if (!data) return null; | ||
|
||
return { | ||
chart: { | ||
type: "bar", | ||
height: 500, | ||
}, | ||
title: { text: "" }, | ||
legend: { enabled: false }, | ||
credits: { enabled: false }, | ||
|
||
xAxis: { | ||
type: 'category', | ||
labels: { | ||
autoRotation: [-45, -90], | ||
style: { | ||
fontSize: '13px', | ||
fontFamily: 'Verdana, sans-serif' | ||
} | ||
} | ||
}, | ||
yAxis: { | ||
min: 0, | ||
title: { | ||
text: 'Euros € (millions)' | ||
} | ||
}, | ||
tooltip: { | ||
pointFormat: 'Total des subventions : <b>{point.y:.1f} €</b>' | ||
}, | ||
plotOptions: { | ||
series: { dataLabels: { enabled: true } } | ||
}, | ||
series: [ | ||
{ | ||
name: 'Total subventions en euros', | ||
colors: ['#009099'], | ||
colorByPoint: true, | ||
groupPadding: 0, | ||
data: data.map((item) => ({ | ||
name: item.name, | ||
y: item.total_evaluated, | ||
rank_evaluated: item.rank_evaluated, | ||
})), | ||
dataLabels: [{ | ||
align: 'right', | ||
format: '{point.rank_evaluated}e' | ||
}], | ||
}, | ||
{ | ||
name: 'Total subventions en euros', | ||
colors: ['#233E41'], | ||
colorByPoint: true, | ||
groupPadding: 0, | ||
data: data.map((item) => ({ | ||
name: item.name, | ||
y: item.total_successful, | ||
rank_successful: item.rank_successful, | ||
})), | ||
dataLabels: [{ | ||
align: 'right', | ||
format: '{point.rank_successful}e' | ||
}], | ||
} | ||
] | ||
}; | ||
} |
8 changes: 8 additions & 0 deletions
8
.../european-projects/components/pages/analysis/positioning/charts/funding-ranking/query.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const { VITE_APP_SERVER_URL } = import.meta.env; | ||
|
||
export async function GetData() { | ||
const url = `${VITE_APP_SERVER_URL}/european-projects/analysis-positioning-top-10-funding-ranking`; | ||
|
||
return fetch(url).then((response) => (response.json())) | ||
} | ||
|
7 changes: 7 additions & 0 deletions
7
...ropean-projects/components/pages/analysis/positioning/charts/funding-ranking/template.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function Template() { | ||
return ( | ||
<> | ||
graph template | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters