Skip to content

Commit a0b3911

Browse files
authored
Merge pull request #19 from geo2france/dev
V1
2 parents 572484f + 167b550 commit a0b3911

File tree

43 files changed

+1350
-1557
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1350
-1557
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
/build
1313
/dist
1414

15+
# doc
16+
/docs
17+
*.excalidraw
18+
19+
# data
20+
/public/data
21+
1522
# misc
1623
.DS_Store
1724
.env.local

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "src/refine-datafair"]
22
path = src/refine-datafair
33
url = [email protected]:geo2france/refine-datafair.git
4+
[submodule "src/refine-wfs"]
5+
path = src/refine-wfs
6+
url = [email protected]:geo2france/refine-wfs.git

README.MD

+66
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,72 @@ Le contenu généré dans le dossier `dist` peut être coller sur un serveur htt
2626

2727
- **Ademe** : les données sont récupérés sur le [portail opendata](https://data.ademe.fr/) via l'API Datafair. Un [connecteur](https://github.com/geo2france/refine-datafair) a été développé pour cet usage.
2828

29+
## Développement
30+
31+
### DashboardElement
32+
33+
Le composant [DashboardElement](src/components/dashboard_element/index.tsx) peut-être utilisé pour ajouter des fonctionnalités à un _element_ (graphique ou cartographique) de tableau de bord.
34+
Il ajoute :
35+
- Une _card_ servant de conteneur, avec titre et crédit.
36+
- Un menu contextuel permettant à l'utilisateur de :
37+
- Afficher le contenu en plein écran
38+
- Exporter le contenu en format image (png)
39+
40+
Pour fonctionner correctement, le composant enfant doit exporter la référence de l'élément graphique (_echart_ ou _maplibre_) à l'aide de du hook `useDashboardElement`.
41+
42+
Exemples :
43+
```typescript
44+
export const MapIsdnd: React.FC<IMapProps> = ({ data, style }) => {
45+
const mapRef = useRef<any>(null);
46+
useDashboardElement({chartRef:mapRef})
47+
[...]
48+
return (
49+
<Map
50+
reuseMaps
51+
preserveDrawingBuffer={true}
52+
ref={mapRef}
53+
style={style} [...]/>
54+
)
55+
}
56+
```
57+
Pour les cartes, la propriété `preserveDrawingBuffer={true}` est nécessaire pour permettre l'export PNG (sinon, le fichier exporté sera blanc).
58+
59+
```typescript
60+
export const ChartIsdndGlobal: React.FC<IChartIsdndGlobalProps> = ({ data, style}) => {
61+
const chartRef = useRef<any>();
62+
useDashboardElement({chartRef})
63+
[...]
64+
return (
65+
<ReactECharts
66+
option={option} ref={chartRef} style={style} />
67+
)
68+
}
69+
```
70+
71+
### useChartEvents
72+
73+
Le hook `useChartEvents` permet de définir des fonctions callback à executer au click (_onClick_) ou au survol (_onFocus_) des graphiques.
74+
Le callback reçoit comme paramètres un objet qui contient des informations sur l'élément qui l'a déclanché (nom de la série, données, etc.). La structure de l'objet varie selon le type de graphique.
75+
76+
Généralement, le callback sera une fonction qui va modifier un état (_state_) du parent (_setState_).
77+
78+
TODO : Exemple concret montrant comment l'année cliquée sur le graphique est remontée à la page.
79+
80+
Exemple :
81+
```typescript
82+
useChartEvents({chartRef, onFocus})
83+
```
84+
85+
### useChartActionHightlight
86+
87+
Le hook `useChartActionHightlight` permet de manuellement mettre en évidence (_highlight_) une portion du graphique.
88+
L'élement à éclairer peut-être défini par son nom ou le nom de sa série (ou plus rarement son index).
89+
90+
TODO : Exemple concret avec _bar_ et _pie_ et cas d'usage.
91+
92+
Notes : le _hilight_ est un effet subtil. Souvent on privilégiera un changement de couleur pour mettre en évidence une information importante (par exemple l'année sélectionnée).
93+
Le _hilight_ sera plus souvent utilisé pour mettre un évidence un élément similaire à plusieurs graphique lors du survol d'un des deux graphique.
94+
2995
## Learn More
3096

3197
To learn more about **Refine**, please check out the [Documentation](https://refine.dev/docs)

package-lock.json

+255-1,295
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
"private": true,
1111
"dependencies": {
1212
"@ant-design/icons": "^5.0.1",
13-
"@refinedev/antd": "^5.37.5",
14-
"@refinedev/cli": "^2.16.27",
15-
"@refinedev/core": "^4.48.0",
16-
"@refinedev/devtools": "^1.1.34",
17-
"@refinedev/inferencer": "^4.5.20",
18-
"@refinedev/kbar": "^1.3.6",
19-
"@refinedev/react-router-v6": "^4.5.6",
20-
"@refinedev/simple-rest": "^5.0.1",
13+
"@refinedev/antd": "^5.37.6",
14+
"@refinedev/cli": "^2.16.29",
15+
"@refinedev/core": "^4.49.0",
16+
"@refinedev/devtools": "^1.1.37",
17+
"@refinedev/inferencer": "^4.6.0",
18+
"@refinedev/kbar": "^1.3.8",
19+
"@refinedev/react-router-v6": "^4.5.7",
20+
"@refinedev/simple-rest": "^5.0.4",
2121
"@types/geojson": "^7946.0.14",
2222
"alasql": "^4.2.5",
2323
"antd": "^5.0.5",

public/img/by.svg

+20
Loading

public/img/cc.svg

+27
Loading

src/App.tsx

+25-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import { Refine } from "@refinedev/core";
22
import { ThemedLayoutV2, notificationProvider, RefineThemes } from "@refinedev/antd";
33
import routerBindings, { DocumentTitleHandler, UnsavedChangesNotifier } from "@refinedev/react-router-v6";
44
import {dataProvider as dfDataProvider} from "./refine-datafair";
5+
import {dataProvider as wfsDataProvider} from "./refine-wfs";
56
import { HashRouter, Routes, Route, Outlet } from "react-router-dom";
67

7-
import { ConfigProvider } from "antd";
8+
import { ConfigProvider, ThemeConfig } from "antd";
89
import "@refinedev/antd/dist/reset.css";
10+
import './index.css';
911

1012
import { DmaComponent } from "./components/pages/dma";
1113
import { ressources } from "./ressources"
@@ -20,14 +22,29 @@ import { RepPchimPage } from "./components/pages/rep_pchim";
2022
import { RepTlcPage } from "./components/pages/rep_tlc";
2123
import { RepMnuPage } from "./components/pages/rep_mnu";
2224
import { RepDispmedPage } from "./components/pages/rep_dispmed";
25+
import { ObjectifsPage } from "./components/pages/objectifs";
2326

24-
const myTheme = {...RefineThemes.Orange,
27+
const myTheme:ThemeConfig = {...RefineThemes.Orange,
2528
token: {
2629
colorPrimary: "#DEAD8F",
2730
linkHoverDecoration:'underline',
2831
colorLink:'#FF6A48',
29-
colorLinkHover:'#9D7156'
32+
colorLinkHover:'#9D7156',
33+
borderRadius:4,
3034
},
35+
components:{
36+
Timeline:{
37+
itemPaddingBottom:40
38+
},
39+
Card:{
40+
headerHeight:35,
41+
headerFontSize:14,
42+
paddingLG:0,
43+
},
44+
Form:{
45+
labelColor:'rgba(0,0,0,0.7)'
46+
}
47+
}
3148
}
3249

3350
const App: React.FC = () => {
@@ -38,7 +55,8 @@ const App: React.FC = () => {
3855
routerProvider={routerBindings}
3956
dataProvider={{
4057
default:dfDataProvider("https://data.ademe.fr/data-fair/api/v1/datasets"),
41-
ademe_opendata:dfDataProvider("https://data.ademe.fr/data-fair/api/v1/datasets")
58+
ademe_opendata:dfDataProvider("https://data.ademe.fr/data-fair/api/v1/datasets"),
59+
geo2france:wfsDataProvider("https://www.geo2france.fr/geoserver/ows")
4260
}}
4361
notificationProvider={notificationProvider}
4462
resources={ressources}
@@ -77,6 +95,9 @@ const App: React.FC = () => {
7795
<Route path="cve">
7896
<Route index element={<IncinerationtPage />} />
7997
</Route>
98+
<Route path="objectifs">
99+
<Route index element={<ObjectifsPage />} />
100+
</Route>
80101
<Route path="*" element={<ErrorComponent />} />
81102
</Route>
82103
</Routes>

src/components/attributions/index.tsx

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import { Typography } from 'antd';
1+
import { Tooltip, Typography } from 'antd';
22
import React from 'react';
3+
import CC from "/img/cc.svg";
4+
import BY from "/img/by.svg";
5+
36

47
const { Text, Link } = Typography;
58

@@ -13,18 +16,25 @@ export interface AttributionProps {
1316
}
1417

1518
export const Attribution: React.FC<AttributionProps> = ({ data }) => {
19+
const licence_logo_style:React.CSSProperties = {height:'12px'}
20+
1621
const plural = data.length > 1 ? 's' : ''
1722
return (
18-
<>
19-
<Text type="secondary">{`Source${plural} : `}
23+
<div style={{paddingLeft:4, paddingBottom:4}}>
24+
<Text type="secondary">{`Source${plural} des données: `}
2025
{data.map((e: SourceProps, i:number) => (
2126
<React.Fragment key={i}>
2227
<Link href={e.url}>{e.name}</Link>
2328
{i < data.length - 1 ? ", " : ""}
2429
</React.Fragment>
2530
))}
31+
<span> | Réalisation : <a href='https://www.hautsdefrance.fr/communique-de-presse-lancement-de-lobservatoire-dechets-matieres-odema-des-hauts-de-france/' >Odema</a> </span>
32+
<Tooltip title="CC BY" placement="bottom">
33+
<img src={CC} style={licence_logo_style} />
34+
<img src={BY} style={licence_logo_style}></img>
35+
</Tooltip>
2636
</Text>
2737

28-
</>
38+
</div>
2939
)
3040
}

src/components/chart_collecte_performance/index.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
import React from "react";
1+
import React, { CSSProperties, useRef } from "react";
22
import ReactECharts from 'echarts-for-react'; // or var ReactECharts = require('echarts-for-react');
33
import { BaseRecord } from "@refinedev/core";
44
import type {EChartsOption, PieSeriesOption} from "echarts"
55
import alasql from "alasql";
66
import { chartBusinessProps } from "../../utils";
7+
import { useDashboardElement } from "../dashboard_element/hooks";
78

89
export interface ChartCollectePerformanceProps {
910
data: any[] | BaseRecord[]; // Spécifier les champs au niveau de la ressource
1011
data_territoire: any[] | BaseRecord[]; // Le endpoint précédent ne fournie pas la POPANNEE
1112
c_region?:string
13+
style? : CSSProperties
1214
}
1315

14-
export const ChartCollectePerformance: React.FC<ChartCollectePerformanceProps> = ( {data, data_territoire, c_region='32'} ) => {
16+
export const ChartCollectePerformance: React.FC<ChartCollectePerformanceProps> = ( {data, data_territoire, c_region='32', style} ) => {
17+
const chartRef = useRef<any>()
18+
useDashboardElement({chartRef})
1519

1620
const data_pie = alasql(`SELECT TYP_COLLECTE, (sum(TONNAGE_T_HG) / sum(data_territoire.VA_POPANNEE))*1000 AS RATIO_KG_HAB
1721
FROM ? data
@@ -66,6 +70,6 @@ export const ChartCollectePerformance: React.FC<ChartCollectePerformanceProps> =
6670

6771
return(
6872
<ReactECharts
69-
option={option} style={{ height: "450px"}}/>
73+
option={option} ref={chartRef} style={style}/>
7074
)
7175
}

src/components/chart_evolution_rep_collecte/index.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { chartBusinessProps } from "../../utils"
33
import { BarSeriesOption, EChartsOption } from "echarts";
44
import ReactECharts from 'echarts-for-react';
55
import alasql from "alasql";
6-
import { useRef } from "react";
6+
import { CSSProperties, useRef } from "react";
77
import { useChartActionHightlight, useChartEvents } from "../../utils/usecharthighlight";
88

99
export interface ChartEvolutionRepCollecteProps{
@@ -12,11 +12,12 @@ export interface ChartEvolutionRepCollecteProps{
1212
year?:number
1313
onFocus?:any;
1414
focus_item?:string;
15+
style? : CSSProperties
1516
}
1617

1718

1819
//TODO ajouter un "Segmented Controls" pour switcher vers des bares normalized ?
19-
export const ChartEvolutionRepCollecte: React.FC<ChartEvolutionRepCollecteProps> = ({ data, filiere, onFocus, focus_item, year }) => {
20+
export const ChartEvolutionRepCollecte: React.FC<ChartEvolutionRepCollecteProps> = ({ data, filiere, onFocus, focus_item, year, style }) => {
2021
const chartRef = useRef<any>()
2122

2223
useChartEvents({chartRef:chartRef, onFocus:onFocus})
@@ -71,5 +72,5 @@ export const ChartEvolutionRepCollecte: React.FC<ChartEvolutionRepCollecteProps>
7172
],
7273
}
7374
return (<ReactECharts
74-
option={option} ref={chartRef} style={{ height: "450px" }} />)
75+
option={option} ref={chartRef} style={ style } />)
7576
}

0 commit comments

Comments
 (0)