merge: PC3 mindmap Carte O D3 + scrape AEP (round 1)

This commit is contained in:
Jules Neny
2026-05-09 01:01:07 +02:00
8 changed files with 3423 additions and 7 deletions

View File

@@ -1,11 +1,88 @@
---
// Placeholder Centre : HAUT mindmap AEP (PC3) ; BAS iframe carte AEP (PC4)
// Centre - HAUT : tabs (Carte O mindmap | Chatbot RAG placeholder PC7).
// BAS : iframe carte AEP (PC4).
import CarteOWrapper from '../vue/CarteOWrapper.vue';
import ChatbotPlaceholder from '../vue/ChatbotPlaceholder.vue';
---
<div class="h-full grid grid-rows-2 gap-2 p-2">
<section class="border border-dashed border-neutral-300 rounded flex items-center justify-center">
<p class="text-sm text-neutral-400">Mindmap AEP — PC3</p>
<!-- HAUT 50% : tabs Carte O / Chatbot -->
<section class="border border-neutral-200 rounded flex flex-col overflow-hidden bg-white">
<nav role="tablist" aria-label="Vues centrales" class="flex border-b border-neutral-200 px-1 pt-1">
<button
type="button"
role="tab"
id="tab-mindmap"
aria-controls="panel-mindmap"
aria-selected="true"
data-tab="mindmap"
class="tab-btn px-3 py-2 text-sm border-b-2 border-neutral-900 font-medium text-neutral-900"
>
Carte O
</button>
<button
type="button"
role="tab"
id="tab-chatbot"
aria-controls="panel-chatbot"
aria-selected="false"
data-tab="chatbot"
class="tab-btn px-3 py-2 text-sm border-b-2 border-transparent text-neutral-500 hover:text-neutral-900"
>
Chatbot
</button>
</nav>
<div class="flex-1 overflow-hidden relative">
<div
id="panel-mindmap"
role="tabpanel"
aria-labelledby="tab-mindmap"
data-tab-panel="mindmap"
class="absolute inset-0"
>
<CarteOWrapper client:visible />
</div>
<div
id="panel-chatbot"
role="tabpanel"
aria-labelledby="tab-chatbot"
data-tab-panel="chatbot"
class="absolute inset-0 hidden"
>
<ChatbotPlaceholder client:visible />
</div>
</div>
</section>
<!-- BAS 50% : iframe carte AEP (PC4) -->
<section class="border border-dashed border-neutral-300 rounded flex items-center justify-center">
<p class="text-sm text-neutral-400">Iframe carte AEP — PC4</p>
</section>
</div>
<script>
// Tabs toggle.
const tabs = document.querySelectorAll<HTMLButtonElement>('[data-tab]');
const panels = document.querySelectorAll<HTMLElement>('[data-tab-panel]');
tabs.forEach((tab) => {
tab.addEventListener('click', () => {
const target = tab.dataset.tab;
if (!target) return;
tabs.forEach((t) => {
const active = t.dataset.tab === target;
t.setAttribute('aria-selected', active ? 'true' : 'false');
t.classList.toggle('border-neutral-900', active);
t.classList.toggle('border-transparent', !active);
t.classList.toggle('font-medium', active);
t.classList.toggle('text-neutral-900', active);
t.classList.toggle('text-neutral-500', !active);
});
panels.forEach((p) => {
p.classList.toggle('hidden', p.dataset.tabPanel !== target);
});
});
});
</script>

View File

@@ -1,9 +1,341 @@
<script setup lang="ts">
// Placeholder Carte O — PC3 implémente avec D3 + GraphView porté de nav-carte
// Carte O - mindmap force-directed D3 (V1 zoom + pan + drag + click).
// Pattern adapté de nav-carte/components/codev/CodevGraph.vue (sans coupling Nuxt).
// Drill-down V1 = zoom + pan seul. V2 récursif backlog (cf MP-PAGE-CERVEAU.md).
import { ref, onMounted, onUnmounted, watch, computed } from 'vue'
import * as d3 from 'd3'
interface CarteNode {
id: string
label: string
family: string
intention?: string
slug?: string
theme?: string
path?: string
}
interface CarteEdge {
source: string | CarteNode
target: string | CarteNode
}
const props = withDefaults(defineProps<{
nodes: CarteNode[]
edges: CarteEdge[]
familyColors?: Record<string, string>
}>(), {
familyColors: () => ({
penseur: '#3b82f6',
concept: '#10b981',
methode: '#f59e0b',
collectif: '#ef4444',
ressource: '#8b5cf6',
}),
})
const emit = defineEmits<{
'node-click': [node: CarteNode]
}>()
// Refs
const container = ref<HTMLDivElement | null>(null)
const svgEl = ref<SVGSVGElement | null>(null)
const width = ref(800)
const height = ref(600)
// State interne
type SimNode = d3.SimulationNodeDatum & CarteNode
type SimLink = d3.SimulationLinkDatum<SimNode>
let simulation: d3.Simulation<SimNode, SimLink> | null = null
let svgRoot: d3.Selection<SVGSVGElement, unknown, null, undefined> | null = null
let gZoom: d3.Selection<SVGGElement, unknown, null, undefined> | null = null
let gLinks: d3.Selection<SVGGElement, unknown, null, undefined> | null = null
let gNodes: d3.Selection<SVGGElement, unknown, null, undefined> | null = null
let zoomBehavior: d3.ZoomBehavior<SVGSVGElement, unknown> | null = null
const isMobile = computed(() => width.value < 600)
const nodeRadius = computed(() => isMobile.value ? 10 : 14)
function colorFor(family: string): string {
return props.familyColors[family] || '#9ca3af'
}
function truncate(str: string, max: number): string {
if (!str) return ''
return str.length > max ? str.slice(0, max - 1) + '…' : str
}
function buildSimNodes(): SimNode[] {
return props.nodes.map(n => ({ ...n }))
}
function buildSimLinks(simNodes: SimNode[]): SimLink[] {
const byId = new Map(simNodes.map(n => [n.id, n]))
return props.edges
.map(e => {
const s = typeof e.source === 'string' ? byId.get(e.source) : byId.get(e.source.id)
const t = typeof e.target === 'string' ? byId.get(e.target) : byId.get(e.target.id)
if (!s || !t) return null
return { source: s, target: t } as SimLink
})
.filter((x): x is SimLink => x !== null)
}
function makeDrag(sim: d3.Simulation<SimNode, SimLink>) {
return d3.drag<SVGGElement, SimNode>()
.on('start', (event, d) => {
if (!event.active) sim.alphaTarget(0.3).restart()
d.fx = d.x
d.fy = d.y
})
.on('drag', (event, d) => {
d.fx = event.x
d.fy = event.y
})
.on('end', (event, d) => {
if (!event.active) sim.alphaTarget(0)
d.fx = null
d.fy = null
})
}
function initSvg() {
if (!svgEl.value) return
svgRoot = d3.select(svgEl.value)
.attr('width', width.value)
.attr('height', height.value)
.attr('role', 'img')
.attr('aria-label', 'Carte O — mindmap de la pensée AEP')
svgRoot.selectAll('*').remove()
// Wrapper group for zoom/pan transform.
gZoom = svgRoot.append('g').attr('class', 'zoom-layer')
gLinks = gZoom.append('g').attr('class', 'links')
gNodes = gZoom.append('g').attr('class', 'nodes')
// Zoom + pan behavior.
zoomBehavior = d3.zoom<SVGSVGElement, unknown>()
.scaleExtent([0.3, 4])
.on('zoom', (event) => {
gZoom!.attr('transform', event.transform.toString())
})
svgRoot.call(zoomBehavior as any)
}
function render() {
if (!svgEl.value || props.nodes.length === 0) return
initSvg()
const simNodes = buildSimNodes()
const simLinks = buildSimLinks(simNodes)
const r = nodeRadius.value
const fontSize = isMobile.value ? 9 : 11
// Liens
gLinks!
.selectAll<SVGLineElement, SimLink>('line')
.data(simLinks)
.join('line')
.attr('stroke', '#94a3b8')
.attr('stroke-opacity', 0.45)
.attr('stroke-width', 1.2)
// Noeuds = groupe <g> par node
const nodeGroups = gNodes!
.selectAll<SVGGElement, SimNode>('g.node')
.data(simNodes, d => d.id)
.join('g')
.attr('class', 'node')
.style('cursor', 'pointer')
.on('click', (_event, d) => emit('node-click', d))
.on('mouseover', function () {
d3.select(this).select('circle')
.transition().duration(120)
.attr('stroke-width', 2.5)
})
.on('mouseout', function () {
d3.select(this).select('circle')
.transition().duration(120)
.attr('stroke-width', 1.5)
})
// Cercle (couleur famille)
nodeGroups.append('circle')
.attr('r', r)
.attr('fill', d => colorFor(d.family))
.attr('stroke', '#ffffff')
.attr('stroke-width', 1.5)
// Label
nodeGroups.append('text')
.attr('text-anchor', 'start')
.attr('dominant-baseline', 'central')
.attr('dx', r + 4)
.attr('font-size', fontSize)
.attr('font-family', 'system-ui, sans-serif')
.attr('fill', '#1f2937')
.attr('pointer-events', 'none')
.text(d => truncate(d.label, isMobile.value ? 18 : 30))
// Tooltip <title>
nodeGroups.append('title')
.text(d => `${d.label}\n[${d.family}]\n${truncate(d.intention || '', 200)}`)
// Simulation force
simulation = d3.forceSimulation<SimNode, SimLink>(simNodes)
.force('link', d3.forceLink<SimNode, SimLink>(simLinks)
.id(d => d.id)
.distance(80)
.strength(0.35))
.force('charge', d3.forceManyBody<SimNode>().strength(-220))
.force('center', d3.forceCenter(width.value / 2, height.value / 2))
.force('collide', d3.forceCollide<SimNode>().radius(r + 6))
.alphaDecay(0.03)
.on('tick', tick)
// Bind drag once simulation exists.
nodeGroups.call(makeDrag(simulation) as any)
}
function tick() {
if (!gLinks || !gNodes) return
gLinks.selectAll<SVGLineElement, SimLink>('line')
.attr('x1', d => (d.source as SimNode).x ?? 0)
.attr('y1', d => (d.source as SimNode).y ?? 0)
.attr('x2', d => (d.target as SimNode).x ?? 0)
.attr('y2', d => (d.target as SimNode).y ?? 0)
gNodes.selectAll<SVGGElement, SimNode>('g.node')
.attr('transform', d => `translate(${d.x ?? 0},${d.y ?? 0})`)
}
// Public methods exposed (zoom controls).
function zoomIn() {
if (!svgRoot || !zoomBehavior) return
svgRoot.transition().duration(250).call(zoomBehavior.scaleBy as any, 1.3)
}
function zoomOut() {
if (!svgRoot || !zoomBehavior) return
svgRoot.transition().duration(250).call(zoomBehavior.scaleBy as any, 0.77)
}
function zoomReset() {
if (!svgRoot || !zoomBehavior) return
svgRoot.transition().duration(350).call(zoomBehavior.transform as any, d3.zoomIdentity)
}
defineExpose({ zoomIn, zoomOut, zoomReset })
// Re-render on data changes.
watch(() => [props.nodes, props.edges], () => {
if (simulation) {
simulation.stop()
simulation = null
}
render()
}, { deep: true })
// ResizeObserver
let ro: ResizeObserver | null = null
onMounted(() => {
if (!container.value) return
width.value = container.value.clientWidth || 800
height.value = container.value.clientHeight || 600
render()
ro = new ResizeObserver(() => {
if (!container.value) return
width.value = container.value.clientWidth || 800
height.value = container.value.clientHeight || 600
if (svgRoot) {
svgRoot.attr('width', width.value).attr('height', height.value)
}
if (simulation) {
simulation.force('center', d3.forceCenter(width.value / 2, height.value / 2))
simulation.alpha(0.3).restart()
}
})
ro.observe(container.value)
})
onUnmounted(() => {
if (simulation) simulation.stop()
if (ro) ro.disconnect()
})
</script>
<template>
<div class="h-full w-full flex items-center justify-center text-sm text-neutral-400">
Carte O placeholder (PC3)
<div ref="container" class="carte-o-wrap">
<svg ref="svgEl" class="carte-o-svg" />
<!-- Zoom controls overlay -->
<div class="zoom-controls">
<button type="button" @click="zoomIn" aria-label="Zoom avant">+</button>
<button type="button" @click="zoomReset" aria-label="Réinitialiser le zoom"></button>
<button type="button" @click="zoomOut" aria-label="Zoom arrière"></button>
</div>
</div>
</template>
<style scoped>
.carte-o-wrap {
width: 100%;
height: 100%;
position: relative;
background: #fafafa;
overflow: hidden;
}
.carte-o-svg {
width: 100%;
height: 100%;
display: block;
cursor: grab;
}
.carte-o-svg:active {
cursor: grabbing;
}
.zoom-controls {
position: absolute;
top: 0.5rem;
right: 0.5rem;
display: flex;
flex-direction: column;
gap: 4px;
background: rgba(255, 255, 255, 0.85);
border: 1px solid rgba(0, 0, 0, 0.06);
border-radius: 8px;
padding: 4px;
backdrop-filter: blur(4px);
}
.zoom-controls button {
width: 28px;
height: 28px;
border: none;
background: transparent;
cursor: pointer;
font-size: 16px;
font-weight: 600;
color: #374151;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
}
.zoom-controls button:hover {
background: rgba(0, 0, 0, 0.05);
}
</style>

View File

@@ -0,0 +1,215 @@
<script setup lang="ts">
// Modal récap intention pour Carte O.
// Click node -> emit('node-click', n) -> selectedNode.value = n -> ce modal s'affiche.
// Esc + click backdrop ferment.
import { onMounted, onUnmounted, watch } from 'vue'
interface CarteNode {
id: string
label: string
family: string
intention?: string
slug?: string
theme?: string
}
const props = defineProps<{
node: CarteNode | null
familyColors?: Record<string, string>
}>()
const emit = defineEmits<{
close: []
}>()
function onKeydown(e: KeyboardEvent) {
if (e.key === 'Escape' && props.node) emit('close')
}
onMounted(() => window.addEventListener('keydown', onKeydown))
onUnmounted(() => window.removeEventListener('keydown', onKeydown))
watch(() => props.node, (n) => {
if (n) {
document.body.style.overflow = 'hidden'
} else {
document.body.style.overflow = ''
}
})
function colorFor(family: string): string {
return props.familyColors?.[family] || '#9ca3af'
}
</script>
<template>
<Teleport to="body">
<Transition name="modal">
<div
v-if="node"
class="modal-backdrop"
role="dialog"
aria-modal="true"
:aria-labelledby="`carte-o-modal-title`"
@click.self="emit('close')"
>
<div class="modal-card">
<button
type="button"
class="close-btn"
aria-label="Fermer"
@click="emit('close')"
>×</button>
<div class="family-badge" :style="{ backgroundColor: colorFor(node.family) }">
{{ node.family }}
</div>
<h2 id="carte-o-modal-title" class="title">
{{ node.label }}
</h2>
<p v-if="node.intention" class="intention">
{{ node.intention }}
</p>
<p v-else class="intention placeholder">
Pas d'intention extraite. Ouvrez la fiche pour le contenu complet.
</p>
<div v-if="node.theme" class="theme">
Thème : <strong>{{ node.theme }}</strong>
</div>
<a
v-if="node.slug"
:href="`/thematiques/${node.slug}`"
class="cta-link"
>
Lire la fiche
</a>
</div>
</div>
</Transition>
</Teleport>
</template>
<style scoped>
.modal-backdrop {
position: fixed;
inset: 0;
z-index: 9999;
background: rgba(0, 0, 0, 0.45);
display: flex;
align-items: center;
justify-content: center;
padding: 1rem;
backdrop-filter: blur(2px);
}
.modal-card {
position: relative;
background: #ffffff;
border-radius: 14px;
max-width: 32rem;
width: 100%;
padding: 1.75rem;
box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.35);
}
.close-btn {
position: absolute;
top: 0.5rem;
right: 0.5rem;
width: 32px;
height: 32px;
border: none;
background: transparent;
font-size: 24px;
line-height: 1;
color: #9ca3af;
cursor: pointer;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
}
.close-btn:hover {
background: #f3f4f6;
color: #374151;
}
.family-badge {
display: inline-block;
padding: 0.2rem 0.6rem;
border-radius: 999px;
font-size: 0.7rem;
font-weight: 600;
letter-spacing: 0.05em;
text-transform: uppercase;
color: #fff;
margin-bottom: 0.65rem;
}
.title {
font-size: 1.4rem;
font-weight: 600;
color: #1f2937;
margin: 0 0 0.85rem 0;
line-height: 1.3;
}
.intention {
color: #4b5563;
line-height: 1.55;
margin: 0 0 1rem 0;
font-size: 0.95rem;
}
.intention.placeholder {
font-style: italic;
color: #9ca3af;
}
.theme {
font-size: 0.85rem;
color: #6b7280;
margin-bottom: 1.25rem;
}
.cta-link {
display: inline-block;
padding: 0.55rem 1.1rem;
background: #1f2937;
color: #fff;
border-radius: 8px;
text-decoration: none;
font-size: 0.9rem;
font-weight: 500;
transition: background 0.15s;
}
.cta-link:hover {
background: #111827;
}
.modal-enter-active,
.modal-leave-active {
transition: opacity 0.2s ease;
}
.modal-enter-active .modal-card,
.modal-leave-active .modal-card {
transition: transform 0.2s ease;
}
.modal-enter-from,
.modal-leave-to {
opacity: 0;
}
.modal-enter-from .modal-card,
.modal-leave-to .modal-card {
transform: scale(0.96);
}
</style>

View File

@@ -0,0 +1,170 @@
<script setup lang="ts">
// Wrapper Carte O : fetch /data/carte-o.json + state modal.
// Vue island Astro hydratée client:visible.
import { ref, onMounted, computed } from 'vue'
import CarteO from './CarteO.vue'
import CarteOModal from './CarteOModal.vue'
interface CarteNode {
id: string
label: string
family: string
intention?: string
slug?: string
theme?: string
}
interface CarteEdge {
source: string
target: string
}
interface CarteData {
meta?: {
nodeCount?: number
edgeCount?: number
familyDistribution?: Record<string, number>
familyColors?: Record<string, string>
}
nodes: CarteNode[]
edges: CarteEdge[]
}
const props = withDefaults(defineProps<{
src?: string
}>(), {
src: '/data/carte-o.json',
})
const data = ref<CarteData | null>(null)
const error = ref<string | null>(null)
const selectedNode = ref<CarteNode | null>(null)
const isMobileScreen = ref(false)
const familyColors = computed(() =>
data.value?.meta?.familyColors || {
penseur: '#3b82f6',
concept: '#10b981',
methode: '#f59e0b',
collectif: '#ef4444',
ressource: '#8b5cf6',
}
)
onMounted(async () => {
isMobileScreen.value = window.innerWidth < 768
try {
const res = await fetch(props.src)
if (!res.ok) throw new Error(`HTTP ${res.status}`)
data.value = await res.json()
} catch (e: any) {
console.error('[CarteO] failed to load', e)
error.value = e?.message || 'Erreur de chargement'
}
// Update mobile flag on resize.
window.addEventListener('resize', () => {
isMobileScreen.value = window.innerWidth < 768
})
})
</script>
<template>
<div class="wrapper">
<!-- Mobile fallback (V1) -->
<div v-if="isMobileScreen" class="mobile-fallback">
<div class="mini-map">
<svg viewBox="0 0 200 120" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<circle cx="100" cy="60" r="8" fill="#3b82f6" />
<circle cx="50" cy="35" r="5" fill="#10b981" />
<circle cx="150" cy="35" r="5" fill="#f59e0b" />
<circle cx="55" cy="90" r="5" fill="#ef4444" />
<circle cx="145" cy="90" r="5" fill="#8b5cf6" />
<line x1="100" y1="60" x2="50" y2="35" stroke="#94a3b8" stroke-width="0.8" opacity="0.5" />
<line x1="100" y1="60" x2="150" y2="35" stroke="#94a3b8" stroke-width="0.8" opacity="0.5" />
<line x1="100" y1="60" x2="55" y2="90" stroke="#94a3b8" stroke-width="0.8" opacity="0.5" />
<line x1="100" y1="60" x2="145" y2="90" stroke="#94a3b8" stroke-width="0.8" opacity="0.5" />
</svg>
</div>
<p class="msg">
Carte O optimisée desktop. Retournez sur grand écran pour explorer la mindmap interactive.
</p>
</div>
<!-- Loading state -->
<div v-else-if="!data && !error" class="state">
<span>Chargement de la Carte O</span>
</div>
<!-- Error state -->
<div v-else-if="error" class="state error">
<span>Impossible de charger la Carte O ({{ error }})</span>
</div>
<!-- Carte O -->
<template v-else-if="data">
<CarteO
:nodes="data.nodes"
:edges="data.edges"
:family-colors="familyColors"
@node-click="selectedNode = $event"
/>
<CarteOModal
:node="selectedNode"
:family-colors="familyColors"
@close="selectedNode = null"
/>
</template>
</div>
</template>
<style scoped>
.wrapper {
height: 100%;
width: 100%;
position: relative;
}
.state {
height: 100%;
display: flex;
align-items: center;
justify-content: center;
color: #9ca3af;
font-size: 0.9rem;
}
.state.error {
color: #dc2626;
}
.mobile-fallback {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 1.5rem;
text-align: center;
gap: 1rem;
}
.mini-map {
width: 70%;
max-width: 240px;
}
.mini-map svg {
width: 100%;
height: auto;
}
.msg {
color: #6b7280;
font-size: 0.85rem;
line-height: 1.45;
font-style: italic;
max-width: 24rem;
margin: 0;
}
</style>