Merge remote-tracking branch 'gitea/main' into feat/aep-socle-perf

This commit is contained in:
Jules Neny
2026-10-29 21:07:24 +01:00
12 changed files with 831 additions and 466 deletions
+49 -174
View File
@@ -20,7 +20,8 @@
Layout : force simple à graine fixe, calculé depuis nœuds et liens (aucune position en
données), mis en cache par signature du graphe (une fois par processus serveur), puis
projeté sur la taille mesurée. Liens : trait plein = énoncé par la source, tirets = posé
par la curation.
par la curation. La géométrie (disposer, cache, voisinage, boîte) vit dans
`utils/connaissances/graphe.ts`, testée (B19b M4).
-->
<template>
<div ref="racine" class="gc" :class="{ 'gc--fige': fige }">
@@ -82,152 +83,19 @@
@click="pas = o.v"
>{{ o.libelle }}</button>
</div>
<p class="gc__legende" aria-hidden="true">
<span class="gc__legende-trait gc__legende-trait--source" />source
<span class="gc__legende-trait gc__legende-trait--curation" />curation
</p>
<!-- Légende visible (retour de Jules du 27/10, n° 6 : « pourquoi des carrés, pourquoi des ronds ») -->
<ul class="gc__legende" aria-label="Légende du graphe">
<li><span class="gc__legende-rond" aria-hidden="true" />Concept</li>
<li><span class="gc__legende-carre" aria-hidden="true" />Source (texte, organisation, outil)</li>
<li><span class="gc__legende-trait" aria-hidden="true" />Énoncé par la source</li>
<li><span class="gc__legende-trait gc__legende-trait--curation" aria-hidden="true" />Posé par AEP</li>
</ul>
</div>
</template>
<script lang="ts">
/** Un nœud : `kind` dit sa forme (principal si dans `kindsPrincipaux`, sinon secondaire). */
export interface NoeudGraphe { id: string; libelle: string; kind: string; poids?: number }
export interface LienGraphe { de: string; vers: string; type: string; provenance: string }
export type Pas = 1 | 2 | 'tout'
type Pt = { x: number; y: number }
/** PRNG à graine fixe (mulberry32) : même graphe, même dessin, au serveur comme au navigateur. */
function alea(graine: number) {
let a = graine >>> 0
return () => {
a = (a + 0x6d2b79f5) >>> 0
let t = a
t = Math.imul(t ^ (t >>> 15), t | 1)
t ^= t + Math.imul(t ^ (t >>> 7), t | 61)
return ((t ^ (t >>> 14)) >>> 0) / 4294967296
}
}
/**
* Force simple (Fruchterman-Reingold), graine fixe, nombre de pas fixe : positions dans un
* repère sans unité, centré, d'étendue 1. Fonction pure de (nœuds, liens, principaux).
*/
export function disposer(noeuds: NoeudGraphe[], liens: LienGraphe[], principaux: Set<string>): Map<string, Pt> {
const n = noeuds.length
const pos = new Map<string, Pt>()
if (!n) return pos
const rnd = alea(0x9e3779b9)
const index = new Map(noeuds.map((x, i) => [x.id, i]))
const aretes = liens
.map((l) => [index.get(l.de), index.get(l.vers)] as const)
.filter((a): a is readonly [number, number] => a[0] != null && a[1] != null && a[0] !== a[1])
const voisins: number[][] = noeuds.map(() => [])
for (const [a, b] of aretes) { voisins[a].push(b); voisins[b].push(a) }
// Départ : les principaux en cercle, chaque secondaire au barycentre de ses voisins principaux.
const prin = noeuds.map((x, i) => (principaux.has(x.kind) ? i : -1)).filter((i) => i >= 0)
const X = new Float64Array(n)
const Y = new Float64Array(n)
prin.forEach((i, k) => {
const t = (2 * Math.PI * k) / Math.max(prin.length, 1)
X[i] = 0.4 * Math.cos(t)
Y[i] = 0.4 * Math.sin(t)
})
noeuds.forEach((x, i) => {
if (principaux.has(x.kind)) return
const v = voisins[i].filter((j) => principaux.has(noeuds[j].kind))
if (v.length) {
X[i] = (v.reduce((s, j) => s + X[j], 0) / v.length) * 1.35 + (rnd() - 0.5) * 0.08
Y[i] = (v.reduce((s, j) => s + Y[j], 0) / v.length) * 1.35 + (rnd() - 0.5) * 0.08
} else {
X[i] = (rnd() - 0.5) * 0.9
Y[i] = (rnd() - 0.5) * 0.9
}
})
const k = 0.9 * Math.sqrt(1 / n)
const ITER = 350
const dx = new Float64Array(n)
const dy = new Float64Array(n)
for (let it = 0; it < ITER; it++) {
const temp = 0.08 * (1 - it / ITER) + 0.002
dx.fill(0)
dy.fill(0)
for (let i = 0; i < n; i++) {
for (let j = i + 1; j < n; j++) {
let ex = X[i] - X[j]
let ey = Y[i] - Y[j]
let d = Math.hypot(ex, ey)
if (d < 1e-4) { ex = (rnd() - 0.5) * 1e-3; ey = (rnd() - 0.5) * 1e-3; d = Math.hypot(ex, ey) }
const f = (k * k) / d
dx[i] += (ex / d) * f; dy[i] += (ey / d) * f
dx[j] -= (ex / d) * f; dy[j] -= (ey / d) * f
}
}
for (const [a, b] of aretes) {
const ex = X[a] - X[b]
const ey = Y[a] - Y[b]
const d = Math.max(Math.hypot(ex, ey), 1e-4)
const f = (d * d) / k
dx[a] -= (ex / d) * f; dy[a] -= (ey / d) * f
dx[b] += (ex / d) * f; dy[b] += (ey / d) * f
}
for (let i = 0; i < n; i++) {
dx[i] -= X[i] * 0.9 * k * 4
dy[i] -= Y[i] * 0.9 * k * 4
const d = Math.hypot(dx[i], dy[i])
if (d > 0) {
const m = Math.min(d, temp)
X[i] += (dx[i] / d) * m
Y[i] += (dy[i] / d) * m
}
}
}
// Centré, étendue 1 (le plus grand côté de la boîte englobante)
let x0 = Infinity, x1 = -Infinity, y0 = Infinity, y1 = -Infinity
for (let i = 0; i < n; i++) { x0 = Math.min(x0, X[i]); x1 = Math.max(x1, X[i]); y0 = Math.min(y0, Y[i]); y1 = Math.max(y1, Y[i]) }
const e = Math.max(x1 - x0, y1 - y0) || 1
noeuds.forEach((x, i) => pos.set(x.id, { x: (X[i] - (x0 + x1) / 2) / e, y: (Y[i] - (y0 + y1) / 2) / e }))
return pos
}
/** Cache par signature du graphe : au serveur, une fois par processus, pas une fois par requête. */
const CACHE = new Map<string, Map<string, Pt>>()
export function disposerEnCache(noeuds: NoeudGraphe[], liens: LienGraphe[], principaux: Set<string>): Map<string, Pt> {
const sig = JSON.stringify([noeuds.map((x) => [x.id, x.kind]), liens.map((l) => [l.de, l.vers]), [...principaux]])
let p = CACHE.get(sig)
if (!p) {
p = disposer(noeuds, liens, principaux)
if (CACHE.size > 24) CACHE.delete(CACHE.keys().next().value as string)
CACHE.set(sig, p)
}
return p
}
/** Identifiants à `pas` liens au plus de `id` (le nœud compris) ; `tout` = tous. */
export function voisinage(liens: LienGraphe[], id: string, pas: Pas): Set<string> | null {
if (pas === 'tout') return null
const adj = new Map<string, string[]>()
for (const l of liens) {
if (!adj.has(l.de)) adj.set(l.de, [])
if (!adj.has(l.vers)) adj.set(l.vers, [])
adj.get(l.de)!.push(l.vers)
adj.get(l.vers)!.push(l.de)
}
const vus = new Set([id])
let front = [id]
for (let p = 0; p < pas; p++) {
const suite: string[] = []
for (const x of front) for (const y of adj.get(x) ?? []) if (!vus.has(y)) { vus.add(y); suite.push(y) }
front = suite
}
return vus
}
</script>
<script setup lang="ts">
import { boite, disposerEnCache, voisinage, type LienGraphe, type NoeudGraphe, type Pas, type Pt } from '~/utils/connaissances/graphe'
const props = withDefaults(defineProps<{
noeuds: NoeudGraphe[]
liens: LienGraphe[]
@@ -262,8 +130,8 @@ const OPTIONS_PAS: { v: Pas; libelle: string }[] = [
{ v: 'tout', libelle: 'tout' },
]
const DUREE = 600 // recadrage : ≤ 700 ms, puis immobile
const MARGE = { haut: 52, bas: 44, gauche: 96, droite: 96 }
const MARGE_TEL = { haut: 52, bas: 84, gauche: 64, droite: 64 } // < 768 : le pied de la vue fiches couvre le bas ; les libellés sont tenus dans le cadre par la borne de `ecran`
const MARGE = { haut: 52, bas: 88, gauche: 96, droite: 96 } // bas : la légende (une ligne) et le libellé du dernier nœud, qui pend sous son rond
const MARGE_TEL = { haut: 52, bas: 116, gauche: 64, droite: 64 } // < 768 : la légende tient sur deux lignes en bas ; les libellés sont tenus dans le cadre par la borne de `ecran`
// ── Taille mesurée (le rendu serveur part d'une taille plausible, comme GrapheMots) ──
const racine = ref<HTMLElement | null>(null)
@@ -311,13 +179,13 @@ const zone = computed(() => {
const m = taille.w < 768 ? MARGE_TEL : MARGE
return { x: m.gauche, y: m.haut, w: Math.max(40, taille.w - m.gauche - m.droite), h: Math.max(40, taille.h - m.haut - m.bas) }
})
/** Portrait d'écran et dessin paysage (ou l'inverse) : on tourne le dessin d'un quart. Projection, rien en base. */
const tourne = computed(() => {
let x0 = Infinity, x1 = -Infinity, y0 = Infinity, y1 = -Infinity
for (const p of monde.value.values()) { x0 = Math.min(x0, p.x); x1 = Math.max(x1, p.x); y0 = Math.min(y0, p.y); y1 = Math.max(y1, p.y) }
const paysage = x1 - x0 >= y1 - y0
return paysage !== zone.value.w >= zone.value.h
/** Le dessin est-il en paysage ? Calculé une fois par layout (le monde est en cache), pas à chaque redimensionnement. */
const paysage = computed(() => {
const b = boite(monde.value.values())
return b.x1 - b.x0 >= b.y1 - b.y0
})
/** Portrait d'écran et dessin paysage (ou l'inverse) : on tourne le dessin d'un quart. Projection, rien en base. */
const tourne = computed(() => paysage.value !== zone.value.w >= zone.value.h)
const pt = (id: string): Pt | null => {
const p = monde.value.get(id)
if (!p) return null
@@ -326,13 +194,11 @@ const pt = (id: string): Pt | null => {
const cible = computed<Camera>(() => {
const vis = visibles.value
let x0 = Infinity, x1 = -Infinity, y0 = Infinity, y1 = -Infinity
for (const x of props.noeuds) {
if (vis && !vis.has(x.id)) continue
const p = pt(x.id)
if (!p) continue
x0 = Math.min(x0, p.x); x1 = Math.max(x1, p.x); y0 = Math.min(y0, p.y); y1 = Math.max(y1, p.y)
}
const points = props.noeuds
.filter((x) => !vis || vis.has(x.id))
.map((x) => pt(x.id))
.filter((p): p is Pt => !!p)
const { x0, x1, y0, y1 } = boite(points)
if (!Number.isFinite(x0)) return { cx: 0, cy: 0, s: 1 }
const z = zone.value
const plein = Math.min(z.w, z.h) // échelle du graphe entier (étendue 1)
@@ -477,14 +343,14 @@ const liensVus = computed(() => props.liens
.gc__lien {
stroke: color-mix(in srgb, var(--text) 38%, transparent);
stroke-width: 1.1;
transition: stroke 160ms ease-out, stroke-width 160ms ease-out, opacity 160ms ease-out;
transition: stroke var(--dur-fast) var(--ease-out), stroke-width var(--dur-fast) var(--ease-out), opacity var(--dur-fast) var(--ease-out);
}
.gc__lien--curation { stroke-dasharray: 4 3; }
.gc__lien--vif { stroke: var(--text); stroke-width: 1.8; }
.gc__lien--eteint { opacity: 0.25; }
/* Sources : carrés gris, hors tabulation (au clavier, on y va par la liste des fiches) */
.gc__source { cursor: pointer; transition: opacity 160ms ease-out; }
.gc__source { cursor: pointer; transition: opacity var(--dur-fast) var(--ease-out); }
.gc__carre {
fill: color-mix(in srgb, var(--text) 52%, var(--bg-alt));
stroke: var(--bg-alt);
@@ -496,8 +362,8 @@ const liensVus = computed(() => props.liens
.gc__source--loin { opacity: 0.6; }
.gc__source-texte {
fill: color-mix(in srgb, var(--text) 80%, transparent);
font-size: 11px;
font-weight: 500;
font-size: var(--fs-xs);
font-weight: var(--fw-medium);
paint-order: stroke;
stroke: var(--bg-alt);
stroke-width: 3px;
@@ -523,7 +389,7 @@ const liensVus = computed(() => props.liens
font: inherit;
cursor: pointer;
pointer-events: auto;
transition: opacity 160ms ease-out;
transition: opacity var(--dur-fast) var(--ease-out);
}
.gc__rond {
width: calc(2 * var(--gc-r));
@@ -531,16 +397,16 @@ const liensVus = computed(() => props.liens
border-radius: 50%;
background: var(--surface);
border: 2px solid var(--text);
transition: background 160ms ease-out, border-color 160ms ease-out;
transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
.gc__libelle {
font-size: 12.5px;
font-weight: 600;
font-size: var(--fs-xs);
font-weight: var(--fw-semibold);
line-height: 1.2;
text-align: center;
overflow-wrap: anywhere;
padding: 0 3px;
border-radius: 4px;
border-radius: var(--radius-sm);
background: color-mix(in srgb, var(--bg-alt) 82%, transparent);
}
.gc__noeud--survol .gc__rond { border-width: 3px; }
@@ -581,24 +447,33 @@ const liensVus = computed(() => props.liens
.gc__pas[aria-pressed='true'] { background: var(--text); color: var(--surface); }
.gc__pas:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
/* Légende : une ligne en bas du graphe (deux au téléphone), hors de la poignée et de la barre des pas */
.gc__legende {
position: absolute;
top: var(--space-xs);
right: var(--space-sm);
left: var(--space-lg);
bottom: var(--space-xs);
max-width: calc(100% - var(--space-lg) - var(--space-sm));
margin: 0;
padding: var(--space-2xs) var(--space-xs);
list-style: none;
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 6px;
font-size: 11px;
gap: var(--space-2xs) var(--space-sm);
border-radius: var(--radius-sm);
background: color-mix(in srgb, var(--bg-alt) 88%, transparent);
font-size: var(--fs-xs);
line-height: 1.3;
color: color-mix(in srgb, var(--text) 78%, transparent);
pointer-events: none;
}
.gc__legende-trait { display: inline-block; width: 18px; border-top: 1.5px solid currentColor; margin-left: 6px; }
.gc__legende li { display: inline-flex; align-items: center; gap: var(--space-2xs); }
.gc__legende-rond { width: 10px; height: 10px; border-radius: var(--radius-full); border: 2px solid var(--text); background: var(--surface); }
.gc__legende-carre { width: 9px; height: 9px; border-radius: 2px; background: color-mix(in srgb, var(--text) 52%, var(--bg-alt)); }
.gc__legende-trait { width: 18px; border-top: 1.5px solid currentColor; }
.gc__legende-trait--curation { border-top-style: dashed; }
@media (max-width: 639.98px) { .gc__legende { display: none; } }
@media (max-width: 767.98px) {
.gc__noeud { max-width: 8rem; }
.gc__libelle { font-size: 12px; }
}
/* Mouvement réduit : état final, sans transition (la caméra saute aussi, côté script) */
+10 -4
View File
@@ -228,7 +228,7 @@
</div>
<!-- Fiche à fiche : en tête sur ordinateur, en pied au téléphone (même élément, ordre CSS) -->
<nav v-if="vf.position" class="vf-detail__nav" aria-label="Fiche à fiche">
<nav v-if="vf.position && navigationLineaire" class="vf-detail__nav" aria-label="Fiche à fiche">
<button type="button" class="vf-detail__pas" :disabled="!vf.position.precedente" @click="vf.fichePrecedente()">
<span aria-hidden="true">‹ </span>Précédente
</button>
@@ -253,7 +253,7 @@
<span class="vf-detail__statut" role="status">{{ statutLien }}</span>
</div>
<slot name="detail" :fiche="vf.ficheOuverte" :filtrer="filtrerDepuisDetail" />
<p class="vf-detail__aide">← → pour passer d'une fiche à l'autre · Échap pour fermer</p>
<p class="vf-detail__aide">{{ navigationLineaire ? "← → pour passer d'une fiche à l'autre · Échap pour fermer" : 'Échap pour fermer' }}</p>
</template>
<p v-else class="vf-etat-vide">{{ pending ? 'Chargement de la fiche…' : 'Fiche introuvable : elle a peut-être été retirée.' }}</p>
</div>
@@ -302,7 +302,7 @@ import type { MiniFiche } from '~/composables/useFicheAdapter'
import type { VueFichesEtat } from '~/composables/useVueFiches'
import { LIBELLES_TRI, type EtatVue, type TriFiches } from '~/utils/vueFiches'
const props = defineProps<{
const props = withDefaults(defineProps<{
vf: VueFichesEtat
/** Une ligne, « intention d'abord » (DESIGN-SYSTEM §Intention d'abord). */
intention?: string
@@ -313,7 +313,13 @@ const props = defineProps<{
lienPage?: (f: MiniFiche) => string | null
/** Libellés des trois états quand « Carte » n'est pas le mot juste (ex. { carte: 'Graphe' }). Le paramètre d'URL reste `vue=carte`. */
libellesVue?: Partial<Record<EtatVue, string>>
}>()
/**
* Boutons Précédente / Suivante (et le rang « N / total ») dans le détail. false = masqués
* (B19b, `/connaissances` : sur un graphe, l'ordre de la liste n'est pas un ordre de lecture) ;
* les flèches ← → et le balayage restent.
*/
navigationLineaire?: boolean
}>(), { navigationLineaire: true })
const emit = defineEmits<{
select: [fiche: MiniFiche]