Skip to content

Commit 374d593

Browse files
committed
fix(visualize): mind-map fills & centres the viewport (was cramped in a corner)
- centre the tree in the viewport (vertical centring when it fits; margin auto for horizontal) instead of pinning it to the top-left corner - expand all documents by default so the tree is full and reads as a rich mind-map rather than a few lonely collapsed nodes - click +/- still folds/unfolds any branch
1 parent 03369bb commit 374d593

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

openkb/templates/graph.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,8 @@
380380
+ (hasKids ? `<span class="mm-caret" data-tog="${esc(it.id)}">${mmCollapsed.has(it.id) ? "+" + (kidsOf[it.id] || []).length : "−"}</span>` : ``)
381381
+ `</div>`;
382382
});
383-
mmEl.innerHTML = `<div class="mm-canvas" style="width:${Wpx}px;height:${Hpx}px">${svg}${html}</div>`;
383+
const offY = Math.max(0, (mmEl.clientHeight - Hpx) / 2); // centre vertically when it fits; else scroll
384+
mmEl.innerHTML = `<div class="mm-canvas" style="width:${Wpx}px;height:${Hpx}px;margin:${offY}px auto 0">${svg}${html}</div>`;
384385
mmEl.querySelectorAll("[data-tog]").forEach(el => el.onclick = e => {
385386
e.stopPropagation(); const id = el.dataset.tog;
386387
if(mmCollapsed.has(id)) mmCollapsed.delete(id); else mmCollapsed.add(id);
@@ -882,7 +883,7 @@
882883
document.getElementById("reset").addEventListener("click", () => {
883884
hover = null; closePanel();
884885
if(mode === "mindmap"){
885-
mmQuery = ""; search.value = ""; mmCollapsed.clear(); collapseDocs(); buildMindmap(); mmEl.scrollTop = 0; mmEl.scrollLeft = 0;
886+
mmQuery = ""; search.value = ""; mmCollapsed.clear(); buildMindmap(); mmEl.scrollTop = 0; mmEl.scrollLeft = 0;
886887
} else if(mode === "radial"){
887888
spread = DEFAULT_SPREAD; spreadEl.value = String(DEFAULT_SPREAD); panX = 0; panY = 0;
888889
scale = DEF_SCALE; yaw = 0; pitch = 0; layoutRadial();
@@ -896,9 +897,8 @@
896897
});
897898

898899
/* ===================== boot ===================== */
899-
function collapseDocs(){ nodes.forEach(n => { if(n.id.startsWith("summaries/")) mmCollapsed.add(n.id); }); } // start compact: docs folded
900900
window.addEventListener("resize", () => { size(); autoFit = true; if(mode === "mindmap") buildMindmap(); });
901-
size(); seed(); collapseDocs();
901+
size(); seed();
902902
setMode("graph"); // open on the 3D nebula
903903
requestAnimationFrame(frame);
904904
</script>

0 commit comments

Comments
 (0)