Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import React, { useState, useEffect, useMemo } from "react";
import { getDepartmentCorrelation, DepartmentCorrelationParams, TaxType } from "../../../api/stats";
import { DepartmentCorrelationPoint } from "../../../models/DepartmentCorrelation";
import { groupByCommune } from "./scatterplot.utils";
const ScatterPlot: React.FC = () => {
const [raw, setRaw] = useState<DepartmentCorrelationPoint[]>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const [selectedTax, setSelectedTax] = useState<TaxType>("tfpb");
const [year, setYear] = useState<number>(2019);
const [department, setDepartment] = useState<string>("");
useEffect(() => {
let cancelled = false;
async function load() {
try {
setLoading(true);
setError(null);
const params: DepartmentCorrelationParams = { tax: selectedTax, year, department };
const res = await getDepartmentCorrelation(params);
if (!cancelled) setRaw(res.member);
} catch (e: any) {
if (!cancelled) setError(e.message ?? "Erreur API");
} finally {
if (!cancelled) setLoading(false);
}
}
load();
return () => {
cancelled = true;
};
}, [selectedTax, year, department]);
const series = useMemo(() => groupByCommune(raw), [raw]);
if (loading) return <p className="loading-message">Chargement…</p>;
if (error) return <p className="error-message">Erreur : {error}</p>;
if (raw.length === 0) return <p className="no-data-message">Aucune donnée.</p>;
return (
<div></div>
);
};
export default ScatterPlot;