-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ajout des nouveaux graphes à la page stats
- Loading branch information
Showing
14 changed files
with
304 additions
and
57 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
97 changes: 97 additions & 0 deletions
97
packages/site/app/stats/EvolutionCollectivitesLabellisees.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,97 @@ | ||
import ChartWithLegend from '@components/charts/ChartWithLegend'; | ||
import {supabase} from 'app/initSupabase'; | ||
import useSWR from 'swr'; | ||
import {fromMonth} from './shared'; | ||
import {addLocalFilters} from './utils'; | ||
import BarChart from '@components/charts/BarChart'; | ||
|
||
const useEvolutionCollectivitesLabellisees = ( | ||
codeRegion: string, | ||
codeDepartement: string, | ||
) => { | ||
return useSWR( | ||
`stats_evolution_nombre_labellisations-${codeRegion}-${codeDepartement}`, | ||
async () => { | ||
let select = supabase | ||
.from('stats_evolution_nombre_labellisations') | ||
.select() | ||
.gte('mois', fromMonth); | ||
|
||
// select = addLocalFilters(select, codeDepartement, codeRegion); | ||
|
||
const {data, error} = await select; | ||
|
||
if (error) { | ||
throw new Error(error.message); | ||
} | ||
if (!data || !data.length) { | ||
return null; | ||
} | ||
|
||
return data | ||
.filter(d => d.mois !== null) | ||
.map(d => { | ||
if (d.mois) console.log(new Date(d.mois).getFullYear()); | ||
|
||
return { | ||
mois: d.mois, | ||
'1 étoile': d.etoile_1 ?? 0, | ||
'2 étoiles': d.etoile_2 ?? 0, | ||
'3 étoiles': d.etoile_3 ?? 0, | ||
'4 étoiles': d.etoile_4 ?? 0, | ||
'5 étoiles': d.etoile_5 ?? 0, | ||
}; | ||
}); | ||
}, | ||
); | ||
}; | ||
|
||
type EvolutionCollectivitesLabelliseesProps = { | ||
region?: string; | ||
department?: string; | ||
}; | ||
|
||
const EvolutionCollectivitesLabellisees = ({ | ||
region = '', | ||
department = '', | ||
}: EvolutionCollectivitesLabelliseesProps) => { | ||
const {data} = useEvolutionCollectivitesLabellisees(region, department); | ||
|
||
if (!data) return null; | ||
|
||
return ( | ||
<ChartWithLegend | ||
graph={colors => ( | ||
<BarChart | ||
data={ | ||
data as { | ||
mois: string; | ||
'1 étoile': number; | ||
'2 étoiles': number; | ||
'3 étoiles': number; | ||
'4 étoiles': number; | ||
'5 étoiles': number; | ||
}[] | ||
} | ||
keys={[ | ||
'1 étoile', | ||
'2 étoiles', | ||
'3 étoiles', | ||
'4 étoiles', | ||
'5 étoiles', | ||
]} | ||
indexBy="mois" | ||
customColors={colors} | ||
axisLeftLabel="Étoiles" | ||
/> | ||
)} | ||
labels={['1 étoile', '2 étoiles', '3 étoiles', '4 étoiles', '5 étoiles']} | ||
customColors={['#21AB8E', '#34BAB5', '#FFCA00', '#FFB7AE', '#FF732C']} | ||
containerClassname="mt-8" | ||
graphContainerClassname="h-[400px]" | ||
legendContainerClassname="md:grid-flow-col max-md:mx-6 max-md:flex" | ||
/> | ||
); | ||
}; | ||
|
||
export default EvolutionCollectivitesLabellisees; |
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
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
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
Oops, something went wrong.