Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : Vrai-Prix8 * File : src/components/RadarMap.tsx9 * Module : components10 * Repository : https://git.spboucher.ai/vrai-prix11 * Created : 2026-08-0912 * Last Modified : 2026-08-0913 *14 * Author : Simon-Pierre Boucher15 * Position : Professor of Finance16 * Institution : Université du Québec en Outaouais (UQO)17 * Organization : SP Boucher18 * Website : https://spboucher.ai19 * Git : https://git.spboucher.ai20 *21 * Preferred Contact: contact@spboucher.ai22 * Development : dev@spboucher.ai23 * Support : support@spboucher.ai24 * Security/Admin : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142/**43 * RadarMap — carte maison « plan d'arpenteur », construite from scratch (SVG pur).44 * Aucune tuile, aucune bibliothèque : le sujet est au centre, chaque comparable45 * est positionné par azimut et distance réels (projection locale équirectangulaire),46 * sur des anneaux de distance concentriques. Signature Vrai-Prix : encre, lime,47 * étiquettes mono, grille d'arpentage, flèche nord, échelle.48 */49"use client";50import { useMemo, useState } from "react";5152export interface RadarComp {53 id: string;54 lat: number;55 lng: number;56 label: string;57 price: string;58 adjusted: string;59 date: string;60 distanceM: number;61 weight: number;62}6364interface Props {65 subject: { lat: number; lng: number; label: string };66 comps: RadarComp[];67 highlight?: string | null;68 onHover?: (id: string | null) => void;69}7071const SIZE = 640; // viewBox72const C = SIZE / 2;73const PLOT_R = C - 46; // rayon utile7475/** Anneaux « ronds » couvrant la distance max. */76function pickRings(maxM: number): number[] {77 const scales = [78 [100, 250, 500],79 [250, 500, 1000],80 [500, 1000, 2000],81 [1000, 2500, 5000],82 [2500, 5000, 10000],83 [5000, 10000, 20000],84 [10000, 25000, 50000],85 ];86 for (const s of scales) if (maxM <= s[2]) return s;87 return scales[scales.length - 1];88}8990const fmtDist = (m: number) =>91 m < 1000 ? `${m} m` : `${m / 1000} km`.replace(".", ",");9293export default function RadarMap({ subject, comps, highlight, onHover }: Props) {94 const [hover, setHover] = useState<string | null>(null);95 const active = highlight ?? hover;9697 const { pts, rings, scale } = useMemo(() => {98 const cos = Math.cos((subject.lat * Math.PI) / 180);99 const raw = comps.map((c) => ({100 ...c,101 x: (c.lng - subject.lng) * 111320 * cos,102 y: (c.lat - subject.lat) * 110574,103 }));104 const maxM = Math.max(120, ...raw.map((p) => Math.hypot(p.x, p.y)));105 const ringsM = pickRings(maxM);106 const outer = ringsM[ringsM.length - 1];107 const k = PLOT_R / outer;108 return {109 pts: raw.map((p) => ({ ...p, px: C + p.x * k, py: C - p.y * k })),110 rings: ringsM,111 scale: k,112 };113 }, [subject, comps]);114115 const hovered = pts.find((p) => p.id === active) ?? null;116117 return (118 <div className="relative">119 <svg120 viewBox={`0 0 ${SIZE} ${SIZE}`}121 role="img"122 aria-label={`Plan des comparables autour de ${subject.label}`}123 className="block w-full bg-[var(--surface)]"124 >125 <defs>126 <filter id="grain">127 <feTurbulence type="fractalNoise" baseFrequency="0.9" numOctaves="2" result="n" />128 <feColorMatrix in="n" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.03 0" />129 <feComposite operator="over" in2="SourceGraphic" />130 </filter>131 </defs>132133 {/* fond papier + grain */}134 <rect width={SIZE} height={SIZE} fill="var(--surface)" />135 <rect width={SIZE} height={SIZE} fill="#f5f3ee" opacity="0.6" filter="url(#grain)" />136137 {/* grille d'arpentage */}138 {Array.from({ length: 15 }, (_, i) => (i + 1) * (SIZE / 16)).map((g) => (139 <g key={g} stroke="rgba(20,24,20,0.05)" strokeWidth="1">140 <line x1={g} y1="0" x2={g} y2={SIZE} />141 <line x1="0" y1={g} x2={SIZE} y2={g} />142 </g>143 ))}144145 {/* anneaux de distance */}146 {rings.map((m, i) => (147 <g key={m}>148 <circle149 cx={C}150 cy={C}151 r={m * scale}152 fill="none"153 stroke={i === rings.length - 1 ? "rgba(20,24,20,0.85)" : "rgba(20,24,20,0.22)"}154 strokeWidth={i === rings.length - 1 ? 1.5 : 1}155 strokeDasharray={i === rings.length - 1 ? "none" : "5 6"}156 />157 <text158 x={C + m * scale * 0.7071 + 4}159 y={C - m * scale * 0.7071 - 4}160 fontSize="10.5"161 fontFamily="var(--font-jetbrains), monospace"162 fill="rgba(20,24,20,0.45)"163 style={{ textTransform: "uppercase", letterSpacing: "0.08em" }}164 >165 {fmtDist(m)}166 </text>167 </g>168 ))}169170 {/* croix cardinale */}171 <line x1={C} y1={C - PLOT_R} x2={C} y2={C + PLOT_R} stroke="rgba(20,24,20,0.14)" strokeWidth="1" />172 <line x1={C - PLOT_R} y1={C} x2={C + PLOT_R} y2={C} stroke="rgba(20,24,20,0.14)" strokeWidth="1" />173174 {/* flèche nord */}175 <g transform={`translate(${SIZE - 34}, 38)`}>176 <path d="M0,-16 L7,8 L0,3 L-7,8 Z" fill="var(--ink)" />177 <text y="24" textAnchor="middle" fontSize="11" fontWeight="700" fontFamily="var(--font-jetbrains), monospace" fill="var(--ink)">178 N179 </text>180 </g>181182 {/* échelle */}183 <g transform={`translate(28, ${SIZE - 30})`}>184 <line x1="0" y1="0" x2={rings[0] * scale} y2="0" stroke="var(--ink)" strokeWidth="2.5" />185 <line x1="0" y1="-4" x2="0" y2="4" stroke="var(--ink)" strokeWidth="2" />186 <line x1={rings[0] * scale} y1="-4" x2={rings[0] * scale} y2="4" stroke="var(--ink)" strokeWidth="2" />187 <text x={rings[0] * scale + 8} y="4" fontSize="10.5" fontFamily="var(--font-jetbrains), monospace" fill="var(--ink-2)">188 {fmtDist(rings[0])}189 </text>190 </g>191192 {/* rayons vers comparables (au survol) */}193 {hovered && (194 <line195 x1={C}196 y1={C}197 x2={hovered.px}198 y2={hovered.py}199 stroke="var(--green)"200 strokeWidth="1.5"201 strokeDasharray="3 4"202 />203 )}204205 {/* comparables : cercles numérotés, taille = poids */}206 {pts.map((p, i) => {207 const r = 9 + p.weight * 7;208 const on = p.id === active;209 return (210 <g211 key={p.id}212 transform={`translate(${p.px}, ${p.py})`}213 onMouseEnter={() => {214 setHover(p.id);215 onHover?.(p.id);216 }}217 onMouseLeave={() => {218 setHover(null);219 onHover?.(null);220 }}221 style={{ cursor: "pointer" }}222 >223 <circle224 r={r}225 fill={on ? "var(--lime)" : "var(--green)"}226 stroke="var(--ink)"227 strokeWidth={on ? 2.5 : 1.5}228 />229 <text230 textAnchor="middle"231 dy="0.36em"232 fontSize={r > 12 ? 12 : 10.5}233 fontWeight="700"234 fontFamily="var(--font-jetbrains), monospace"235 fill={on ? "var(--ink)" : "#f5f3ee"}236 >237 {i + 1}238 </text>239 </g>240 );241 })}242243 {/* sujet : losange lime pulsant au centre */}244 <g transform={`translate(${C}, ${C})`}>245 <rect246 x={-13}247 y={-13}248 width={26}249 height={26}250 transform="rotate(45)"251 fill="var(--lime)"252 stroke="var(--ink)"253 strokeWidth="2.5"254 >255 <animate attributeName="opacity" values="1;0.75;1" dur="2.4s" repeatCount="indefinite" />256 </rect>257 <rect x={-4} y={-4} width={8} height={8} transform="rotate(45)" fill="var(--ink)" />258 </g>259260 {/* cartouche */}261 <g fontFamily="var(--font-jetbrains), monospace">262 <text x="28" y="34" fontSize="11" fontWeight="700" fill="var(--ink)" style={{ textTransform: "uppercase", letterSpacing: "0.12em" }}>263 ◆ PLAN DES COMPARABLES264 </text>265 <text x="28" y="50" fontSize="10" fill="rgba(20,24,20,0.5)" style={{ textTransform: "uppercase", letterSpacing: "0.08em" }}>266 {comps.length} ventes · azimut + distance réels267 </text>268 </g>269 </svg>270271 {/* infobulle */}272 {hovered && (273 <div274 className="pointer-events-none absolute z-10 max-w-[230px] rounded-lg border border-lime bg-ink px-3.5 py-2.5 text-[12px] leading-relaxed text-paper shadow-[0_8px_24px_rgba(16,18,16,0.35)]"275 style={{276 left: `${(hovered.px / SIZE) * 100}%`,277 top: `${(hovered.py / SIZE) * 100}%`,278 transform: `translate(${hovered.px > SIZE * 0.62 ? "-108%" : "12px"}, ${hovered.py > SIZE * 0.7 ? "-108%" : "-8px"})`,279 }}280 >281 <p className="vp-display mb-0.5 font-bold text-lime">{hovered.label}</p>282 <p className="vp-mono text-[10.5px] uppercase tracking-[0.05em]">283 {hovered.date} · {fmtDist(Math.round(hovered.distanceM))}284 </p>285 <p>286 Vendu {hovered.price} → ajusté <b>{hovered.adjusted}</b>287 </p>288 </div>289 )}290 </div>291 );292}293