-
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 de l'indicateur artificialisation des sols sur le site
- Loading branch information
Showing
10 changed files
with
202 additions
and
69 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
packages/site/app/collectivites/[code]/[name]/IndicateurArtificialisationSols.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,44 @@ | ||
import {IndicateurArtificialisation} from 'app/collectivites/utils'; | ||
import IndicateurCard from './IndicateurCard'; | ||
import {IndicateurDefaultData} from './IndicateursCollectivite'; | ||
import {getFormattedNumber} from 'src/utils/getFormattedNumber'; | ||
import {fluxToLabel} from 'src/utils/labels'; | ||
|
||
type IndicateurArtificialisationSolsProps = { | ||
defaultData?: IndicateurDefaultData; | ||
data: IndicateurArtificialisation | null; | ||
}; | ||
|
||
const IndicateurArtificialisationSols = ({ | ||
defaultData, | ||
data, | ||
}: IndicateurArtificialisationSolsProps) => { | ||
if (!defaultData || !data || !data.total) return null; | ||
|
||
const localData = data as {[key: string]: number}; | ||
|
||
if (!localData) return null; | ||
|
||
const formattedData = (Object.keys(localData) as Array<string>) | ||
.filter(d => d !== 'collectivite_id' && d !== 'total' && localData[d] !== 0) | ||
.map(d => ({ | ||
id: fluxToLabel[d], | ||
value: localData[d], | ||
})); | ||
|
||
return ( | ||
<IndicateurCard | ||
defaultData={defaultData} | ||
data={formattedData} | ||
boxTitle={`+${getFormattedNumber(Math.floor(data.total))} ${ | ||
defaultData.titre_encadre | ||
}`} | ||
graphTitle="Répartition du flux de consommation d'espaces, par destination entre 2009 et 2022." | ||
source="Cerema, Consommation d'espaces naturels, agricoles et forestiers" | ||
unit="ha" | ||
unitSingular={true} | ||
/> | ||
); | ||
}; | ||
|
||
export default IndicateurArtificialisationSols; |
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
52 changes: 52 additions & 0 deletions
52
packages/site/app/collectivites/[code]/[name]/IndicateurGazEffetSerre.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,52 @@ | ||
import {Indicateurs} from 'app/collectivites/utils'; | ||
import {IndicateurDefaultData} from './IndicateursCollectivite'; | ||
import {secteurIdToLabel} from 'src/utils/labels'; | ||
import IndicateurCard from './IndicateurCard'; | ||
import {getFormattedNumber} from 'src/utils/getFormattedNumber'; | ||
|
||
type IndicateurGazEffetSerreProps = { | ||
defaultData?: IndicateurDefaultData; | ||
data: Indicateurs[] | null; | ||
}; | ||
|
||
const IndicateurGazEffetSerre = ({ | ||
defaultData, | ||
data, | ||
}: IndicateurGazEffetSerreProps) => { | ||
if (!defaultData || !data || data.length === 0) return null; | ||
|
||
const lastYear = Math.max(...data.map(d => d.annee)); | ||
|
||
const lastYearData = data.filter( | ||
d => d.annee === lastYear && secteurIdToLabel[d.indicateur_id] !== 'Total', | ||
); | ||
|
||
const lastYearTotal = data.find( | ||
d => d.annee === lastYear && secteurIdToLabel[d.indicateur_id] === 'Total', | ||
); | ||
|
||
if (lastYearData.length <= 1 && !lastYearTotal) return null; | ||
|
||
return ( | ||
<IndicateurCard | ||
defaultData={defaultData} | ||
data={lastYearData.map(d => ({ | ||
id: secteurIdToLabel[d.indicateur_id], | ||
value: d.valeur, | ||
}))} | ||
boxTitle={`${ | ||
lastYearTotal | ||
? `${getFormattedNumber(Math.round(lastYearTotal?.valeur))} ` | ||
: '' | ||
}${defaultData.titre_encadre}`} | ||
graphTitle={`Répartition des émissions de gaz à effet de serre (hors puits) par secteur en ${lastYear}`} | ||
source={ | ||
lastYearData.length ? lastYearData[0].source : lastYearTotal?.source | ||
} | ||
unit="t CO₂eq" | ||
unitSingular={true} | ||
/> | ||
); | ||
}; | ||
|
||
export default IndicateurGazEffetSerre; |
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.