| 697 | /* K5: Hierarchie links eingehend, rechts ausgehend */ |
| 698 | |
| 699 | async function hierarchyLayout(page) { |
| 700 | return page.evaluate(() => { |
| 701 | const galaxy = globalThis.__atlasGalaxy, fit = globalThis.__atlasGalaxyFit; |
| 702 | const canvas = document.querySelector('.atlas-galaxy canvas')?.getBoundingClientRect(); |
| 703 | const boxes = galaxy?.labelBoxes ?? []; |
| 704 | // Namen: Weltkaesten der Szene, mit derselben Kamera in Pixel gerechnet. |
| 705 | const names = boxes.map((box) => { |
| 706 | // Stand vor K5: ohne `project` gibt es keine Namen-Messung. |
| 707 | const [a, b] = typeof fit?.project === 'function' |
| 708 | ? fit.project([{ x: box.x - box.width / 2, y: box.y + box.height / 2, z: 0 }, { x: box.x + box.width / 2, y: box.y - box.height / 2, z: 0 }]) : []; |
| 709 | return a && b && canvas ? { text: box.name, left: canvas.left + Math.min(a.x, b.x), right: canvas.left + Math.max(a.x, b.x), top: canvas.top + Math.min(a.y, b.y), bottom: canvas.top + Math.max(a.y, b.y), worldWidth: box.width } : null; |
| 710 | }).filter(Boolean); |
| 711 | const labels = [...document.querySelectorAll('[data-testid="atlas-hierarchy-edge-label"], .atlas-galaxy-path-label')].map((el) => { |
| 712 | const r = el.getBoundingClientRect(); return { text: el.textContent?.trim() ?? '', left: r.left, right: r.right, top: r.top, bottom: r.bottom }; |
| 713 | }).filter((r) => r.right > r.left); |
| 714 | const hit = (a, b) => !(a.right <= b.left + 1 || b.right <= a.left + 1 || a.bottom <= b.top + 1 || b.bottom <= a.top + 1); |
| 715 | const overlaps = []; |
| 716 | for (const label of labels) for (const name of names) if (hit(label, name)) overlaps.push(`${label.text} x ${name.text}`); |
| 717 | for (let i = 0; i < names.length; i += 1) for (let j = i + 1; j < names.length; j += 1) if (hit(names[i], names[j])) overlaps.push(`${names[i].text} x ${names[j].text}`); |
| 718 | // Abgeschnitten heisst: der Kasten hat die Breitengrenze der Textur erreicht (1600 px bei Schrift 12, rund 312 Einheiten). |
| 719 | const truncated = names.filter((name) => name.worldWidth >= 305).map((name) => name.text); |
| 720 | const placements = galaxy?.hierarchy?.placements ?? []; |
| 721 | const chip = document.querySelector('[data-testid="atlas-graph-mode-chip"][data-mode="hierarchy"]'); |
| 722 | const hint = chip?.closest('[data-hint]')?.getAttribute('data-hint') ?? chip?.getAttribute('data-hint') ?? ''; |
| 723 | // Vollstaendigkeitspruefung: die Ueberschrift des Bandes und die Notiz bei fehlenden Namen, beide im DOM gemessen. |
| 724 | const bandElement = document.querySelector('[data-testid="atlas-hierarchy-band-label"]'); |
| 725 | const bandRect = bandElement?.getBoundingClientRect(); |
| 726 | const band = bandElement && bandRect ? { text: bandElement.textContent?.replace(/\s+/g, ' ').trim() ?? '', left: bandRect.left, right: bandRect.right, |
| 727 | top: bandRect.top, bottom: bandRect.bottom, inCanvas: Boolean(canvas && bandRect.bottom > canvas.top && bandRect.top < canvas.bottom && bandRect.right > canvas.left && bandRect.left < canvas.right) } : null; |
| 728 | const bandOverlaps = band ? [...names, ...labels].filter((other) => hit(band, other)).map((other) => other.text) : []; |
| 729 | const key = document.querySelector('[data-testid="atlas-hierarchy-key"]')?.textContent?.trim() ?? null; |
| 730 | return { mode: galaxy?.mode, placements: placements.map((p) => ({ name: p.name, key: p.key, x: Math.round(p.x), y: Math.round(p.y), hop: p.hop, side: p.side ?? null, mixed: p.mixed === true })), |
| 731 | edges: galaxy?.hierarchy?.edges ?? [], bandInfo: galaxy?.hierarchy?.band ?? null, namesMode: galaxy?.hierarchy?.names ?? null, |
| 732 | edgeLabels: labels.map((label) => label.text), names: names.length, nameTexts: names.map((name) => name.text), overlaps, truncated, hint, band, bandOverlaps, key }; |
| 733 | }); |
| 734 | } |
| 735 | |
| 736 | /** Ein Ausschnitt um die Leinwand, damit die Namen auch im Bild zu lesen sind. */ |
| 737 | async function canvasShot(page, id, label, caption) { |