"use client"; import { useMemo, useState } from "react"; import * as d3 from "d3"; type CommuneData = { commune: string; departement: string; year: number; taxType: string; taxRate: number; volume: number; }; const data: CommuneData[] = [ { commune: "Rouen", departement: "76", year: 2022, taxType: "Foncière", taxRate: 18.2, volume: 320000 }, { commune: "Le Havre", departement: "76", year: 2022, taxType: "Foncière", taxRate: 17.5, volume: 410000 }, { commune: "Dieppe", departement: "76", year: 2022, taxType: "Foncière", taxRate: 19.1, volume: 150000 }, { commune: "Fécamp", departement: "76", year: 2022, taxType: "Foncière", taxRate: 18.8, volume: 120000 }, { commune: "Elbeuf", departement: "76", year: 2022, taxType: "Foncière", taxRate: 20.3, volume: 98000 }, { commune: "Rouen", departement: "76", year: 2022, taxType: "Habitation", taxRate: 12.1, volume: 180000 }, { commune: "Le Havre", departement: "76", year: 2022, taxType: "Habitation", taxRate: 11.8, volume: 240000 }, ]; export default function ScatterDepartement() { const [year, setYear] = useState(2022); const [departement, setDepartement] = useState("76"); const [taxType, setTaxType] = useState("Foncière"); const width = 700; const height = 420; const margin = { top: 40, right: 30, bottom: 50, left: 60 }; /** * === DATA FILTER ===================================== */ const filteredData = useMemo(() => { return data.filter(d => d.year === year && d.departement === departement && d.taxType === taxType ); }, [year, departement, taxType]); /** * === SCALES ========================================== */ const xScale = useMemo(() => { return d3.scaleLinear() .domain(d3.extent(filteredData, d => d.taxRate) as [number, number]) .nice() .range([margin.left, width - margin.right]); }, [filteredData]); const yScale = useMemo(() => { return d3.scaleLinear() .domain(d3.extent(filteredData, d => d.volume) as [number, number]) .nice() .range([height - margin.bottom, margin.top]); }, [filteredData]); const xTicks = xScale.ticks(5); const yTicks = yScale.ticks(5); return (

Corrélation taux / volume collecté

Communes du département {departement} — {year}

{/* === CONTROLS ================================= */}
{/* === SVG ====================================== */} {/* Grid */} {yTicks.map(t => ( ))} {/* Axes */} {/* X ticks */} {xTicks.map(t => ( {t} % ))} {/* Y ticks */} {yTicks.map(t => ( {t / 1000}k € ))} {/* Points */} {filteredData.map((d, i) => ( ))}
); }