Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 21x 21x 21x 21x 4x 21x 37x 37x 40x 6x 37x 40x 39x 1x 1x 1x 48x 40x 40x 40x 40x 40x 40x 40x 7x 40x 31x 20x 5x 5x 5x 31x 7x 8x 8x 8x 8x 7x 31x 3x 6x 3x 20x 3x 17x 20x 21x 20x 34x 32x 32x 31x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 33x 34x 34x 37x 40x 40x 34x 34x 8x 31x 31x 31x 31x 31x 31x 31x | // SPDX-FileCopyrightText: 2024-2026 Hack23 AB
// SPDX-License-Identifier: Apache-2.0
/**
* Generates color-coded mindmap HTML sections using pure CSS —
* no JavaScript or third-party libraries required.
*
* Two rendering modes are provided:
* 1. **Standard mindmap** (`buildMindmapSection`) — a flat central topic with
* colored branch nodes and optional leaf items. Suitable for simple
* topic-branch visualisations.
* 2. **Intelligence mindmap** (`buildIntelligenceMindmapSection`) — a
* multi-layer policy domain intelligence map with actor-network nodes,
* influence-weighted nodes (via CSS `--node-influence` custom property),
* policy connection indicators, and stakeholder perspective overlays using
* `<details>/<summary>` elements (CSS-only toggle, no JavaScript).
*
* Both renderers produce WCAG 2.1 AA compliant HTML with appropriate ARIA
* roles, labels, and heading levels.
*
* @module Generators/MindmapContent
*/
import { escapeHTML } from '../utils/file-utils.js';
import type { IntelligenceMindmap, MindmapBranchColor, MindmapNode } from '../types/index.js';
// ---------------------------------------------------------------------------
// Types
// ---------------------------------------------------------------------------
// Re-export the canonical MindmapBranchColor from the types barrel so that
// existing consumers importing it from this module continue to work.
export type { MindmapBranchColor } from '../types/index.js';
/** A single branch of the mindmap, attached to the central node. */
export interface MindmapBranch {
/** Branch label (rendered in the colored branch node). */
readonly label: string;
/** Semantic color for the branch node. */
readonly color: MindmapBranchColor;
/** Child leaf items displayed below the branch node. */
readonly items?: readonly string[] | undefined;
/** Optional icon/emoji prefix for the branch label. */
readonly icon?: string | undefined;
}
/** Full mindmap configuration. */
export interface MindmapConfig {
/** Central topic text (the root of the mindmap). */
readonly topic: string;
/** Array of branches radiating from the central node. */
readonly branches: readonly MindmapBranch[];
/** Optional introductory paragraph rendered above the mindmap. */
readonly summary?: string | undefined;
}
// ---------------------------------------------------------------------------
// Color palette (mapped to CSS custom properties on each branch element)
// ---------------------------------------------------------------------------
const BRANCH_PALETTE: Readonly<
Record<MindmapBranchColor, { bg: string; border: string; text: string }>
> = {
cyan: { bg: '#e3f2fd', border: '#1565c0', text: '#1565c0' },
magenta: { bg: '#fce4ec', border: '#c62828', text: '#c62828' },
yellow: { bg: '#fff8e1', border: '#f57f17', text: '#f57f17' },
green: { bg: '#e8f5e9', border: '#2e7d32', text: '#2e7d32' },
purple: { bg: '#f3e5f5', border: '#7b1fa2', text: '#7b1fa2' },
orange: { bg: '#fff3e0', border: '#e65100', text: '#e65100' },
blue: { bg: '#e8eaf6', border: '#283593', text: '#283593' },
red: { bg: '#ffebee', border: '#b71c1c', text: '#b71c1c' },
};
/** Color mapping for intelligence mindmap node categories. */
const CATEGORY_PALETTE: Readonly<Record<string, { bg: string; border: string; text: string }>> = {
policy_domain: { bg: '#e3f2fd', border: '#1565c0', text: '#1565c0' },
sub_topic: { bg: '#f3e5f5', border: '#7b1fa2', text: '#7b1fa2' },
actor: { bg: '#e8f5e9', border: '#2e7d32', text: '#2e7d32' },
action: { bg: '#fff3e0', border: '#e65100', text: '#e65100' },
outcome: { bg: '#e8eaf6', border: '#283593', text: '#283593' },
};
/** Icon/emoji mapping for actor types within intelligence mindmaps. */
const ACTOR_TYPE_LABELS: Readonly<Record<string, string>> = {
mep: '👤',
group: '🏛️',
committee: '📋',
external: '🌐',
};
// ---------------------------------------------------------------------------
// Section heading labels (14 languages)
// ---------------------------------------------------------------------------
const MINDMAP_HEADINGS: Readonly<Record<string, string>> = {
en: 'Policy Mindmap',
sv: 'Policykarta',
da: 'Politikkort',
no: 'Politikkart',
fi: 'Politiikkakartta',
de: 'Politikkarte',
fr: 'Carte conceptuelle',
es: 'Mapa conceptual',
nl: 'Beleidskaart',
ar: 'خريطة السياسات',
he: 'מפת מדיניות',
ja: '政策マインドマップ',
ko: '정책 마인드맵',
zh: '政策思维导图',
};
const INTELLIGENCE_MINDMAP_HEADINGS: Readonly<Record<string, string>> = {
en: 'Intelligence Policy Map',
sv: 'Underrättelsebaserad policykarta',
da: 'Intelligensbaseret politikkort',
no: 'Etterretningsbasert politikkart',
fi: 'Tiedustelupohjainen politiikkakartta',
de: 'Intelligenz-Politikkarte',
fr: 'Carte de renseignement politique',
es: 'Mapa de inteligencia política',
nl: 'Intelligentie beleidskaart',
ar: 'خريطة الاستخبارات السياسية',
he: 'מפת מודיעין מדיני',
ja: '政策インテリジェンスマップ',
ko: '정책 인텔리전스 맵',
zh: '政策情报图谱',
};
const STAKEHOLDER_PERSPECTIVES_LABELS: Readonly<Record<string, string>> = {
en: 'Stakeholder Perspectives',
sv: 'Intressentperspektiv',
da: 'Interessentperspektiver',
no: 'Interessentperspektiver',
fi: 'Sidosryhmänäkökulmat',
de: 'Interessengruppen-Perspektiven',
fr: 'Perspectives des parties prenantes',
es: 'Perspectivas de las partes interesadas',
nl: 'Perspectieven van belanghebbenden',
ar: 'وجهات نظر أصحاب المصلحة',
he: 'נקודות מבט של בעלי עניין',
ja: 'ステークホルダーの視点',
ko: '이해관계자 관점',
zh: '利益相关者视角',
};
const POLICY_CONNECTIONS_LABELS: Readonly<Record<string, string>> = {
en: 'Policy Connections',
sv: 'Policyförbindelser',
da: 'Politikforbindelser',
no: 'Politikkforbindelser',
fi: 'Politiikkayhteydet',
de: 'Politikverbindungen',
fr: 'Connexions politiques',
es: 'Conexiones políticas',
nl: 'Beleidsverbindingen',
ar: 'الروابط السياسية',
he: 'קשרים מדיניים',
ja: '政策的つながり',
ko: '정책 연결',
zh: '政策关联',
};
const ACTOR_NETWORK_LABELS: Readonly<Record<string, string>> = {
en: 'Actor Network',
sv: 'Aktörsnätverk',
da: 'Aktørnetværk',
no: 'Aktørnettverk',
fi: 'Toimijaverkosto',
de: 'Akteursnetzwerk',
fr: "Réseau d'acteurs",
es: 'Red de actores',
nl: 'Actornetwerk',
ar: 'شبكة الجهات الفاعلة',
he: 'רשת גורמים',
ja: 'アクターネットワーク',
ko: '행위자 네트워크',
zh: '行动者网络',
};
const POLICY_DOMAINS_LABELS: Readonly<Record<string, string>> = {
en: 'Policy Domains',
sv: 'Policyområden',
da: 'Politikområder',
no: 'Politikkområder',
fi: 'Politiikan alat',
de: 'Politikbereiche',
fr: 'Domaines politiques',
es: 'Ámbitos políticos',
nl: 'Beleidsdomeinen',
ar: 'مجالات السياسة',
he: 'תחומי מדיניות',
ja: '政策分野',
ko: '정책 분야',
zh: '政策领域',
};
const INFLUENCE_LABELS: Readonly<Record<string, string>> = {
en: 'Influence',
sv: 'Inflytande',
da: 'Indflydelse',
no: 'Innflytelse',
fi: 'Vaikutusvalta',
de: 'Einfluss',
fr: 'Influence',
es: 'Influencia',
nl: 'Invloed',
ar: 'التأثير',
he: 'השפעה',
ja: '影響力',
ko: '영향력',
zh: '影响力',
};
const PERSPECTIVE_LABELS: Readonly<Record<string, string>> = {
en: 'perspective',
sv: 'perspektiv',
da: 'perspektiv',
no: 'perspektiv',
fi: 'näkökulma',
de: 'Perspektive',
fr: 'perspective',
es: 'perspectiva',
nl: 'perspectief',
ar: 'منظور',
he: 'נקודת מבט',
ja: '視点',
ko: '관점',
zh: '视角',
};
const DETAILS_LABELS: Readonly<Record<string, string>> = {
en: 'Details',
sv: 'Detaljer',
da: 'Detaljer',
no: 'Detaljer',
fi: 'Yksityiskohdat',
de: 'Details',
fr: 'Détails',
es: 'Detalles',
nl: 'Details',
ar: 'التفاصيل',
he: 'פרטים',
ja: '詳細',
ko: '세부 정보',
zh: '详情',
};
// ---------------------------------------------------------------------------
// Rendering helpers — standard mindmap
// ---------------------------------------------------------------------------
function renderBranch(branch: MindmapBranch): string {
const palette = BRANCH_PALETTE[branch.color] ?? BRANCH_PALETTE.cyan;
const iconPrefix = branch.icon ? `${branch.icon} ` : '';
const labelHtml = `${escapeHTML(iconPrefix)}${escapeHTML(branch.label)}`;
const leafItems =
branch.items && branch.items.length > 0
? `\n <ul class="mindmap-leaf-list" role="list">\n${branch.items
.map((item) => ` <li>${escapeHTML(item)}</li>`)
.join('\n')}\n </ul>`
: '';
return ` <div class="mindmap-branch" role="listitem"
style="--branch-bg:${palette.bg};--branch-border:${palette.border};--branch-text:${palette.text}">
<div class="mindmap-branch-label">${labelHtml}</div>${leafItems}
</div>`;
}
// ---------------------------------------------------------------------------
// Rendering helpers — intelligence mindmap
// ---------------------------------------------------------------------------
/**
* Recursively count all nodes in the tree, including nested children.
*
* @param nodes - Root-level nodes to count
* @returns Total node count including all descendants
*/
function countNodesRecursive(nodes: readonly MindmapNode[]): number {
let count = nodes.length;
for (const node of nodes) {
if (node.children.length > 0) {
count += countNodesRecursive(node.children);
}
}
return count;
}
/**
* Get color palette entry for a mindmap node.
* Checks the node's `color` field against `BRANCH_PALETTE` first (allowing
* builders to override category-based colors), then falls back to the
* category palette, and finally to the default `policy_domain` palette.
*
* @param category - Node category string key
* @param color - Optional semantic color key from the branch palette
* @returns Color palette object with bg, border, and text properties
*/
function getNodePalette(
category: string,
color?: string
): { bg: string; border: string; text: string } {
if (color && Object.hasOwn(BRANCH_PALETTE, color)) {
return BRANCH_PALETTE[color as MindmapBranchColor];
}
Eif (Object.hasOwn(CATEGORY_PALETTE, category)) {
const entry = CATEGORY_PALETTE[category];
Eif (entry) return entry;
}
return { bg: '#e3f2fd', border: '#1565c0', text: '#1565c0' };
}
/**
* Clamp influence value to valid 0–1 range.
*
* @param value - Influence value to clamp
* @returns Clamped value between 0 and 1 inclusive
*/
function clampInfluence(value: number): number {
return Math.max(0, Math.min(1, value));
}
/**
* Render a single intelligence mindmap node as HTML.
* Recursively renders children as nested sub-nodes.
*
* @param node - The mindmap node to render
* @param depth - Current depth in the hierarchy (1 = domain layer)
* @param detailsLabel - Localized label for the child details toggle
* @param influenceLabel - Localized label for influence meter
* @returns HTML string for this node and its children
*/
function renderIntelligenceNode(
node: MindmapNode,
depth: number,
detailsLabel: string,
influenceLabel: string
): string {
const palette = getNodePalette(node.category, node.color);
const influence = clampInfluence(node.influence);
const influencePct = (influence * 100).toFixed(0);
const metaCommittee = node.metadata?.committee
? ` data-committee="${escapeHTML(node.metadata.committee)}"`
: '';
const metaGroup = node.metadata?.politicalGroup
? ` data-group="${escapeHTML(node.metadata.politicalGroup)}"`
: '';
const metaDoc = node.metadata?.documentRef
? ` data-doc="${escapeHTML(node.metadata.documentRef)}"`
: '';
const childrenHtml =
node.children.length > 0
? `\n <details class="mindmap-actor-overlay" aria-label="${escapeHTML(detailsLabel)}: ${escapeHTML(node.label)}">\n <summary class="mindmap-actor-toggle">${escapeHTML(detailsLabel)}</summary>\n <ul class="mindmap-subnodes mindmap-layer-${depth + 1}" role="list">\n${node.children
.map(
(child) =>
` <li>${renderIntelligenceNode(child, depth + 1, detailsLabel, influenceLabel)}</li>`
)
.join('\n')}\n </ul>\n </details>`
: '';
return `<div class="mindmap-intel-node mindmap-node-${escapeHTML(node.category)}"
data-node-id="${escapeHTML(node.id)}" data-influence="${influencePct}"
style="--branch-bg:${palette.bg};--branch-border:${palette.border};--branch-text:${palette.text};--node-influence:${influence.toFixed(2)}"${metaCommittee}${metaGroup}${metaDoc}
aria-label="${escapeHTML(node.label)} (${escapeHTML(influenceLabel)}: ${influencePct}%)">
<div class="mindmap-intel-label">${escapeHTML(node.label)}</div>
<div class="mindmap-influence-bar" role="meter" aria-valuenow="${influencePct}" aria-valuemin="0" aria-valuemax="100" aria-label="${escapeHTML(influenceLabel)}: ${influencePct}%">
<div class="mindmap-influence-fill" style="width:${influencePct}%"></div>
</div>${childrenHtml}
</div>`;
}
/**
* Render the connections section as a `<details>` overlay panel.
* Each connection is rendered with strength and type indicators.
* Connection endpoints may reference either layer node IDs or actorNetwork
* IDs; when a `nodeLabels` map is provided, IDs are resolved to
* human-readable labels for display.
*
* @param connections - Policy connections to render
* @param label - Localized heading label for the toggle
* @param nodeLabels - Optional ID → label map for resolving endpoint names
* @returns HTML string for the connections overlay, or empty string
*/
function renderConnectionsOverlay(
connections: IntelligenceMindmap['connections'],
label: string,
nodeLabels?: ReadonlyMap<string, string>
): string {
if (connections.length === 0) return '';
const resolveName = (id: string): string => nodeLabels?.get(id) ?? id;
const items = connections
.map(
(c) =>
` <li class="mindmap-connection mindmap-connection-${escapeHTML(c.strength)} mindmap-connection-type-${escapeHTML(c.type)}"
aria-label="${escapeHTML(resolveName(c.from))} → ${escapeHTML(resolveName(c.to))}: ${escapeHTML(c.type)} (${escapeHTML(c.strength)}) — ${escapeHTML(c.evidence)}">
<span class="connection-from">${escapeHTML(resolveName(c.from))}</span>
<span class="connection-arrow" aria-hidden="true"> → </span>
<span class="connection-to">${escapeHTML(resolveName(c.to))}</span>
<span class="connection-meta">[${escapeHTML(c.type)}, ${escapeHTML(c.strength)}]</span>
<span class="connection-evidence">${escapeHTML(c.evidence)}</span>
</li>`
)
.join('\n');
return ` <details class="mindmap-connections-overlay">
<summary class="mindmap-connections-toggle">${escapeHTML(label)}</summary>
<ul class="mindmap-connections-list" role="list">
${items}
</ul>
</details>`;
}
/**
* Render the actor network section as a `<details>` overlay panel.
*
* @param actorNetwork - Actor nodes to render in the network panel
* @param label - Localized heading label for the toggle
* @param influenceLabel - Localized label for influence meter
* @returns HTML string for the actor network overlay, or empty string
*/
function renderActorNetworkOverlay(
actorNetwork: IntelligenceMindmap['actorNetwork'],
label: string,
influenceLabel: string
): string {
if (actorNetwork.length === 0) return '';
const items = actorNetwork
.map((actor) => {
const typeIcon = ACTOR_TYPE_LABELS[actor.type] ?? '•';
const influence = clampInfluence(actor.influence);
const influencePct = (influence * 100).toFixed(0);
return ` <li class="mindmap-actor mindmap-actor-${escapeHTML(actor.type)}"
data-actor-id="${escapeHTML(actor.id)}"
style="--node-influence:${influence.toFixed(2)}"
aria-label="${escapeHTML(actor.name)} (${escapeHTML(actor.type)}, ${escapeHTML(influenceLabel)}: ${influencePct}%)">
<span class="actor-icon" aria-hidden="true">${escapeHTML(typeIcon)}</span>
<span class="actor-name">${escapeHTML(actor.name)}</span>
<span class="actor-type-badge">${escapeHTML(actor.type)}</span>
<div class="mindmap-influence-bar" role="meter" aria-valuenow="${influencePct}" aria-valuemin="0" aria-valuemax="100" aria-label="${escapeHTML(influenceLabel)}: ${influencePct}%">
<div class="mindmap-influence-fill" style="width:${influencePct}%"></div>
</div>
</li>`;
})
.join('\n');
return ` <details class="mindmap-actor-network-overlay">
<summary class="mindmap-actor-network-toggle">${escapeHTML(label)}</summary>
<ul class="mindmap-actor-network-list" role="list">
${items}
</ul>
</details>`;
}
/**
* Render stakeholder perspective overlays as `<details>` panels.
*
* @param groups - Stakeholder group labels to render as panels
* @param label - Localized heading label for the outer toggle
* @param perspectiveLabel - Localized suffix for stakeholder perspective aria-label
* @returns HTML string for the stakeholder overlay, or empty string
*/
function renderStakeholderOverlays(
groups: readonly string[] | undefined,
label: string,
perspectiveLabel: string
): string {
if (!groups || groups.length === 0) return '';
const panels = groups
.map(
(g) =>
` <details class="mindmap-stakeholder-panel" aria-label="${escapeHTML(g)} ${escapeHTML(perspectiveLabel)}">
<summary>${escapeHTML(g)}</summary>
<p class="mindmap-stakeholder-desc">${escapeHTML(g)}</p>
</details>`
)
.join('\n');
return ` <details class="mindmap-stakeholder-overlay">
<summary class="mindmap-stakeholder-toggle">${escapeHTML(label)}</summary>
<div class="mindmap-stakeholder-panels">
${panels}
</div>
</details>`;
}
// ---------------------------------------------------------------------------
// Public API
// ---------------------------------------------------------------------------
/**
* Generate a color-coded mindmap section as an HTML string.
*
* Returns an empty string when `config` is null/undefined or has no branches,
* following the same convention as `buildSwotSection` and
* `buildDashboardSection`.
*
* @param config - Mindmap data (topic, branches, optional summary).
* @param lang - BCP 47 language code for the section heading.
* @param heading - Optional heading override.
* @returns HTML string for the mindmap section, or empty string.
*/
export function buildMindmapSection(
config: MindmapConfig | null | undefined,
lang: string = 'en',
heading?: string
): string {
if (!config || !config.branches || config.branches.length === 0) {
return '';
}
const titleText: string = heading?.trim() || MINDMAP_HEADINGS[lang] || 'Policy Mindmap';
const summaryBlock = config.summary?.trim()
? ` <p class="mindmap-summary">${escapeHTML(config.summary.trim())}</p>\n`
: '';
const branchItems = config.branches.map((b) => renderBranch(b)).join('\n');
return `<section class="mindmap-section" role="region" aria-label="${escapeHTML(titleText)}">
<h2>${escapeHTML(titleText)}</h2>
${summaryBlock} <div class="mindmap-container" data-branch-count="${config.branches.length}">
<div class="mindmap-center" role="heading" aria-level="3">${escapeHTML(config.topic)}</div>
<div class="mindmap-branches" role="list">
${branchItems}
</div>
</div>
</section>`;
}
/**
* Generate a multi-layer intelligence mindmap section as an HTML string.
*
* Renders a hierarchical policy domain intelligence map with:
* - Influence-weighted nodes (CSS `--node-influence` custom property)
* - Actor-network visualization via `<details>` child overlays
* - Policy connection indicators in a collapsible `<details>` panel
* - Stakeholder perspective overlays via `<details>/<summary>` (no JS)
* - WCAG 2.1 AA accessible roles, labels, and meter elements
*
* Returns an empty string when `imap` is null/undefined or has no layers
* with nodes.
*
* @param imap - Intelligence mindmap data.
* @param lang - BCP 47 language code for section headings.
* @param heading - Optional heading override.
* @returns HTML string for the intelligence mindmap section, or empty string.
*/
export function buildIntelligenceMindmapSection(
imap: IntelligenceMindmap | null | undefined,
lang: string = 'en',
heading?: string
): string {
if (!imap) return '';
const allNodes = imap.layers.flatMap((l) => l.nodes);
if (allNodes.length === 0) return '';
const titleText: string =
heading?.trim() || INTELLIGENCE_MINDMAP_HEADINGS[lang] || 'Intelligence Policy Map';
const detailsLabel = DETAILS_LABELS[lang] ?? 'Details';
const stakeholderLabel = STAKEHOLDER_PERSPECTIVES_LABELS[lang] ?? 'Stakeholder Perspectives';
const connectionsLabel = POLICY_CONNECTIONS_LABELS[lang] ?? 'Policy Connections';
const actorNetworkLabel = ACTOR_NETWORK_LABELS[lang] ?? 'Actor Network';
const policyDomainsLabel = POLICY_DOMAINS_LABELS[lang] ?? 'Policy Domains';
const influenceLabel = INFLUENCE_LABELS[lang] ?? 'Influence';
const perspectiveLabel = PERSPECTIVE_LABELS[lang] ?? 'perspective';
const summaryBlock = imap.summary?.trim()
? ` <p class="mindmap-summary">${escapeHTML(imap.summary.trim())}</p>\n`
: '';
// Render domain layer (depth 1 nodes as primary branches); fall back to
// allNodes when the depth-1 layer is missing *or* empty.
// Deeper hierarchy (depth 2–4) is expressed via MindmapNode.children and
// rendered recursively by renderIntelligenceNode — separate layer entries
// at depth > 1 are used only for label resolution, not for direct rendering.
const depth1Nodes = imap.layers.find((l) => l.depth === 1)?.nodes ?? [];
const domainNodes = depth1Nodes.length > 0 ? depth1Nodes : allNodes;
const domainItems = domainNodes
.map(
(node) => ` <li>${renderIntelligenceNode(node, 1, detailsLabel, influenceLabel)}</li>`
)
.join('\n');
// Build label lookup for connection endpoint resolution.
// This allows connections referencing actorNetwork IDs to display
// human-readable names instead of raw IDs. We index *all* layer nodes
// (including depth > 1) so that connections referencing deeper nodes still
// resolve to human-readable names even though those nodes are rendered via
// children rather than as standalone layer entries.
const nodeLabels = new Map<string, string>();
const addLabels = (nodes: readonly MindmapNode[]): void => {
for (const n of nodes) {
nodeLabels.set(n.id, n.label);
if (n.children.length > 0) addLabels(n.children);
}
};
addLabels(allNodes);
for (const actor of imap.actorNetwork) {
nodeLabels.set(actor.id, actor.name);
}
const connectionsHtml = renderConnectionsOverlay(imap.connections, connectionsLabel, nodeLabels);
const actorNetworkHtml = renderActorNetworkOverlay(
imap.actorNetwork,
actorNetworkLabel,
influenceLabel
);
const stakeholderHtml = renderStakeholderOverlays(
imap.stakeholderGroups,
stakeholderLabel,
perspectiveLabel
);
// Count from the rendered tree (domainNodes + their children recursively)
// rather than allNodes, so data-total-nodes reflects only what the renderer
// actually outputs.
const totalNodes = countNodesRecursive(domainNodes);
const totalConnections = imap.connections.length;
const totalActors = imap.actorNetwork.length;
return `<section class="mindmap-section intelligence-mindmap" role="region" aria-label="${escapeHTML(titleText)}">
<h2>${escapeHTML(titleText)}</h2>
${summaryBlock} <div class="mindmap-container intelligence-map" data-branch-count="${domainNodes.length}" data-total-nodes="${totalNodes}" data-connections="${totalConnections}" data-actors="${totalActors}">
<div class="mindmap-center" role="heading" aria-level="3">${escapeHTML(imap.centralTopic)}</div>
<ul class="mindmap-branches mindmap-layer-1" role="list" aria-label="${escapeHTML(policyDomainsLabel)}">
${domainItems}
</ul>
${connectionsHtml}
${actorNetworkHtml}
${stakeholderHtml} </div>
</section>`;
}
|