diff --git a/packages/site/app/stats/CollectiviteActivesEtTotalParType.tsx b/packages/site/app/stats/CollectiviteActivesEtTotalParType.tsx index fe026e2c757..2ffddf2b373 100644 --- a/packages/site/app/stats/CollectiviteActivesEtTotalParType.tsx +++ b/packages/site/app/stats/CollectiviteActivesEtTotalParType.tsx @@ -34,17 +34,25 @@ function useCollectiviteActivesEtTotalParType( return { categories: [ { - id: epcis.typologie + ' activés', - label: epcis.typologie + ' activés', - value: epcis.actives, + id: 'Collectivités actives', + value: data.reduce( + (total, currValue) => total + (currValue.actives ?? 0), + 0, + ), }, { - id: epcis.typologie + ' inactifs', - label: epcis.typologie + ' inactifs', - value: (epcis.total || 0) - (epcis.actives || 0), + id: 'Collectivités inactives', + value: data.reduce( + (total, currValue) => + total + ((currValue.total ?? 0) - (currValue.actives ?? 0)), + 0, + ), }, ], - total: epcis.total, + total: data.reduce( + (total, currValue) => total + (currValue.total ?? 0), + 0, + ), }; }, ); @@ -75,15 +83,15 @@ export default function CollectiviteActivesEtTotalParType({ total={total || 0} rows={10} columns={10} - margin={{top: 0, right: 30, bottom: 10, left: 30}} - animate={false} + margin={{top: 10, right: 10, bottom: 10, left: 10}} + animate={true} /> )} labels={categories.map(c => c.id)} customColors={['#889FC2', '#D9D9D9']} containerClassname="mt-6" graphContainerClassname="h-[400px]" - legendContainerClassname="md:grid-flow-col max-md:mx-6 max-md:flex" + legendContainerClassname="flex-col" /> ); } diff --git a/packages/site/app/stats/EvolutionCollectivitesLabellisees.tsx b/packages/site/app/stats/EvolutionCollectivitesLabellisees.tsx new file mode 100644 index 00000000000..8ec54c6f52e --- /dev/null +++ b/packages/site/app/stats/EvolutionCollectivitesLabellisees.tsx @@ -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 ( + ( + + )} + 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; diff --git a/packages/site/app/stats/EvolutionFiches.tsx b/packages/site/app/stats/EvolutionFiches.tsx index ed2224a92fa..a023ce4171f 100644 --- a/packages/site/app/stats/EvolutionFiches.tsx +++ b/packages/site/app/stats/EvolutionFiches.tsx @@ -8,22 +8,26 @@ import LineChart from '@components/charts/LineChart'; type Vue = | 'stats_locales_evolution_nombre_fiches' - | 'stats_locales_evolution_collectivite_avec_minimum_fiches'; + | 'stats_locales_evolution_collectivite_avec_minimum_fiches' + | 'stats_evolution_nombre_plans'; const colonneValeur = { stats_locales_evolution_nombre_fiches: 'fiches', stats_locales_evolution_collectivite_avec_minimum_fiches: 'collectivites', + stats_evolution_nombre_plans: 'plans', }; const legende = { stats_locales_evolution_nombre_fiches: 'Nombre total de fiches', stats_locales_evolution_collectivite_avec_minimum_fiches: 'Collectivités avec cinq fiches ou plus', + stats_evolution_nombre_plans: 'Historique du nombre de plans', }; const labels = { fiches: 'Fiches', collectivites: 'Collectivités', + plans: 'Plans', }; export function useEvolutionFiches( @@ -34,7 +38,9 @@ export function useEvolutionFiches( return useSWR(`${vue}-${codeRegion}-${codeDepartement}`, async () => { let select = supabase.from(vue).select().gte('mois', fromMonth); - select = addLocalFilters(select, codeDepartement, codeRegion); + if (vue !== 'stats_evolution_nombre_plans') { + select = addLocalFilters(select, codeDepartement, codeRegion); + } const {data, error} = await select; diff --git a/packages/site/app/stats/EvolutionIndicateurs.tsx b/packages/site/app/stats/EvolutionIndicateurs.tsx index 449957238bb..ae81c9d583f 100644 --- a/packages/site/app/stats/EvolutionIndicateurs.tsx +++ b/packages/site/app/stats/EvolutionIndicateurs.tsx @@ -9,7 +9,7 @@ import {addLocalFilters} from './utils'; const useCollectivitesAvecIndicateur = ( codeRegion: string, - codeDepartement: string + codeDepartement: string, ) => { const date = new Date(); const formattedDate = `${date.getFullYear()}-${date.getMonth() + 1}-01`; @@ -32,7 +32,7 @@ const useCollectivitesAvecIndicateur = ( if (!data || !data.length) return null; return data[0].collectivites; - } + }, ); }; @@ -50,9 +50,8 @@ export function EvolutionIndicateurs({ return ( <> - Évolution de l’utilisation des indicateurs -
- {data} collectivité{data !== 1 && 's'} + Évolution de l’utilisation des indicateurs - {data} collectivité + {data !== 1 && 's'} {data === 1 ? ' a' : ' ont'} renseigné des indicateurs
diff --git a/packages/site/app/stats/EvolutionPlansAction.tsx b/packages/site/app/stats/EvolutionPlansAction.tsx index faeb10186ce..c905307c638 100644 --- a/packages/site/app/stats/EvolutionPlansAction.tsx +++ b/packages/site/app/stats/EvolutionPlansAction.tsx @@ -14,17 +14,22 @@ export function EvolutionPlansAction({ const {data: collectivites} = useEvolutionFiches( 'stats_locales_evolution_collectivite_avec_minimum_fiches', region, - department + department, ); const {data: fiches} = useEvolutionFiches( 'stats_locales_evolution_nombre_fiches', region, - department + department, + ); + const {data: plans} = useEvolutionFiches( + 'stats_evolution_nombre_plans', + region, + department, ); return ( <> - {collectivites && fiches && ( + {collectivites && fiches && plans && ( <> Évolution de l'utilisation des plans d'action @@ -32,7 +37,8 @@ export function EvolutionPlansAction({ {collectivites.last} collectivité {collectivites.last !== 1 && 's'} {collectivites.last === 1 ? ' a ' : ' ont '} - créé des plans d’actions et {fiches.last} fiche + créé {plans.last} plan{plans.last !== 1 && 's'} d’actions et{' '} + {fiches.last} fiche {fiches.last !== 1 && 's'} actions {fiches.last === 1 ? ' a été créée' : ' ont été créées'} @@ -59,6 +65,16 @@ export function EvolutionPlansAction({ />
)} + {plans && region === '' && department === '' && ( +
+ Historique du nombre de plans + +
+ )} ); diff --git a/packages/site/app/stats/EvolutionTotalActivationParType.tsx b/packages/site/app/stats/EvolutionTotalActivationParType.tsx index dc1ae4531ef..f2e62650c0f 100644 --- a/packages/site/app/stats/EvolutionTotalActivationParType.tsx +++ b/packages/site/app/stats/EvolutionTotalActivationParType.tsx @@ -44,7 +44,7 @@ export function useEvolutionTotalActivation( courant: data[data.length - 1], evolution: [ { - id: 'EPCI', + id: 'EPCI à fiscalité propre', data: data.map(d => ({x: d.mois, y: d.total_epci})), }, { @@ -55,6 +55,10 @@ export function useEvolutionTotalActivation( id: 'Syndicats', data: data.map(d => ({x: d.mois, y: d.total_syndicat})), }, + { + id: 'Autres collectivités', + data: data.map(d => ({x: d.mois, y: d.total_autre})), + }, ], }; }, @@ -84,9 +88,9 @@ export default function EvolutionTotalActivationParType({ ? 'collectivités activées' : 'collectivité activée'}{' '} dont {courant.total_epci} EPCI,  + {courant.total_commune} commune{courant.total_commune !== 1 && 's'},{' '} {courant.total_syndicat} syndicat{courant.total_syndicat !== 1 && 's'}{' '} - et  - {courant.total_commune} commune{courant.total_commune !== 1 && 's'} + et {courant.total_autre} autre{courant.total_autre !== 1 && 's'} - - Progression de l’activation des EPCI à fiscalité propre - {nationalStats && ' sur le territoire national'} -
{nationalStats && ( -
- +
+ Collectivités engagées +
+ +
)}
- Progression globale + Progression globale de l'activation
+ {!regionCode && !departmentCode && ( + + )} ); diff --git a/packages/site/components/carte/CarteCollectivites.tsx b/packages/site/components/carte/CarteCollectivites.tsx index 7d3f6061789..5bde32536ef 100644 --- a/packages/site/components/carte/CarteCollectivites.tsx +++ b/packages/site/components/carte/CarteCollectivites.tsx @@ -20,12 +20,14 @@ type CarteCollectivitesProps = { filtre: FiltresLabels; etoiles: number[]; forcedZoom?: number; + displayLabellisee?: boolean; }; const CarteCollectivites = ({ filtre, etoiles, forcedZoom, + displayLabellisee = false, }: CarteCollectivitesProps) => { const {data} = useCarteCollectivitesEngagees(); const [localData, setLocalData] = useState(data); @@ -108,7 +110,11 @@ const CarteCollectivites = ({ {localData.collectivites .filter(c => !!c.geojson) .map(c => ( - + ))} ); diff --git a/packages/site/components/carte/CollectiviteFeature.tsx b/packages/site/components/carte/CollectiviteFeature.tsx index 8c931216b61..c9c66422952 100644 --- a/packages/site/components/carte/CollectiviteFeature.tsx +++ b/packages/site/components/carte/CollectiviteFeature.tsx @@ -12,18 +12,28 @@ type labellisation_w_geojson = type CollectiviteFeatureProps = { collectivite: labellisation_w_geojson; + displayLabellisee?: boolean; }; /** * Une feature est un élément affiché dans une carte */ -const CollectiviteFeature = ({collectivite}: CollectiviteFeatureProps) => { +const CollectiviteFeature = ({ + collectivite, + displayLabellisee, +}: CollectiviteFeatureProps) => { const router = useRouter(); const geojson = collectivite.geojson as unknown as GeoJsonObject; + + const fillColor = + (displayLabellisee && collectivite.labellisee) || !displayLabellisee + ? '#4D75AC' + : '#9E9E9E'; + const style: PathOptions = { - fillColor: '#4D75AC', + fillColor: fillColor, fillOpacity: 0.7, - color: '#4D75AC', + color: fillColor, weight: 1.5, }; diff --git a/packages/site/components/charts/BarChart.tsx b/packages/site/components/charts/BarChart.tsx new file mode 100644 index 00000000000..b1b4c786c01 --- /dev/null +++ b/packages/site/components/charts/BarChart.tsx @@ -0,0 +1,70 @@ +import {BarDatum, ResponsiveBar} from '@nivo/bar'; +import {defaultColors} from './chartsTheme'; +import {dateAsMonthAndYear} from './utils'; +import BarChartTooltip from './BarChartTooltip'; + +type BarChatyProps = { + data: BarDatum[]; + keys: string[]; + indexBy: string; + customColors?: string[]; + axisLeftLabel?: string; + axisBottomAsYears?: boolean; +}; + +const BarChart = ({ + data, + keys, + indexBy, + customColors, + axisLeftLabel, +}: BarChatyProps) => { + return ( + } + animate={true} + motionConfig="slow" + /> + ); +}; + +export default BarChart; diff --git a/packages/site/components/charts/BarChartTooltip.tsx b/packages/site/components/charts/BarChartTooltip.tsx new file mode 100644 index 00000000000..fac6f5aa9a3 --- /dev/null +++ b/packages/site/components/charts/BarChartTooltip.tsx @@ -0,0 +1,22 @@ +import {BarTooltipProps} from '@nivo/bar'; +import {theme} from './chartsTheme'; +import {getFormattedNumber} from 'src/utils/getFormattedNumber'; +import {dateAsMonthAndYear} from './utils'; +import TooltipColor from './TooltipColor'; + +const BarChartTooltip = ({ + id, + value, + indexValue, + color, +}: BarTooltipProps<{}>) => ( +
+
+ + {id} - {dateAsMonthAndYear(indexValue.toString())} :{' '} + {getFormattedNumber(value)} +
+
+); + +export default BarChartTooltip; diff --git a/packages/site/components/charts/LineChart.tsx b/packages/site/components/charts/LineChart.tsx index 16333f46dfa..38d6d08e9f0 100644 --- a/packages/site/components/charts/LineChart.tsx +++ b/packages/site/components/charts/LineChart.tsx @@ -1,7 +1,7 @@ import {ResponsiveLine, SliceTooltipProps} from '@nivo/line'; import {defaultColors, theme} from './chartsTheme'; import {axisBottomAsDate, axisLeftMiddleLabel} from './utils'; -import Tooltip from './Tooltip'; +import LineChartTooltip from './LineChartTooltip'; type LineChartProps = { data: { @@ -60,7 +60,7 @@ const LineChart = ({ pointBorderColor={{from: 'serieColor'}} enableSlices="x" sliceTooltip={slice => - customTooltip ? customTooltip(slice) : + customTooltip ? customTooltip(slice) : } animate={true} motionConfig="slow" diff --git a/packages/site/components/charts/Tooltip.tsx b/packages/site/components/charts/LineChartTooltip.tsx similarity index 55% rename from packages/site/components/charts/Tooltip.tsx rename to packages/site/components/charts/LineChartTooltip.tsx index b1c05ccb45d..c967bc98ebf 100644 --- a/packages/site/components/charts/Tooltip.tsx +++ b/packages/site/components/charts/LineChartTooltip.tsx @@ -1,28 +1,17 @@ import {SliceTooltipProps} from '@nivo/line'; import {theme} from './chartsTheme'; import {getFormattedNumber} from 'src/utils/getFormattedNumber'; +import TooltipColor from './TooltipColor'; -const Tooltip = ({slice}: SliceTooltipProps) => ( +const LineChartTooltip = ({slice}: SliceTooltipProps) => (
{slice.points.map(point => (
- + {point.serieId} {getFormattedNumber(point.data.yFormatted)}
))}
); -const Color = ({fill}: {fill: string}) => ( - -); - -export default Tooltip; +export default LineChartTooltip; diff --git a/packages/site/components/charts/TooltipColor.tsx b/packages/site/components/charts/TooltipColor.tsx new file mode 100644 index 00000000000..a22cc93e04b --- /dev/null +++ b/packages/site/components/charts/TooltipColor.tsx @@ -0,0 +1,13 @@ +const TooltipColor = ({fill}: {fill: string}) => ( + +); + +export default TooltipColor;