From ccc7d9956559d2195e20345e7a794662b52cd403 Mon Sep 17 00:00:00 2001 From: Agando Date: Sat, 6 Jun 2026 06:00:27 +0200 Subject: auto: 2026-06-06_06:00 changes --- modules/ext/mindmap.js | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'modules/ext/mindmap.js') diff --git a/modules/ext/mindmap.js b/modules/ext/mindmap.js index d0cab54..1daa85b 100644 --- a/modules/ext/mindmap.js +++ b/modules/ext/mindmap.js @@ -247,13 +247,18 @@ class MindmapModule { cyan: '#22d3ee', magenta: '#e879f9', white: '#e0e0e0' }; - const layout = { nodes: [], edges: [], width: 0, height: 0, _y: pad }; + const layout = { nodes: [], edges: [], width: 0, height: 0, _y: pad, minX: Infinity, maxX: 0, minY: Infinity, maxY: 0 }; const layoutTree = (node, x) => { const myY = layout._y; const myX = x; const color = colorMap[node.color] || '#818cf8'; layout.nodes.push({ x: myX, y: myY, w: nw, h: nh, text: node.text, color, id: node.id }); + if (myX < layout.minX) layout.minX = myX; + const rightEdge = x + nw; + if (rightEdge > layout.maxX) layout.maxX = rightEdge; + const bottomEdge = myY + nh; + if (bottomEdge > layout.maxY) layout.maxY = bottomEdge; if (node.children && node.children.length > 0) { const totalW = node.children.length * nw + (node.children.length - 1) * hGap; @@ -267,28 +272,33 @@ class MindmapModule { } layout._y -= nh + vGap; } - const rightEdge = x + nw; - if (rightEdge > layout.width) layout.width = rightEdge; }; layout._y = pad; layoutTree(this.root, pad); - layout.height = layout._y + nh + pad; - // Build SVG - let svg = ``; + // Normalize coordinates — shift so minX becomes pad + const xShift = (layout.minX === Infinity ? 0 : -layout.minX) + pad; + layout.height = layout.maxY + pad; + const svgWidth = (layout.maxX - layout.minX) + pad * 2; + + // Build SVG — apply xShift to all coordinates + let svg = ``; // Edges first (behind nodes) for (const e of layout.edges) { - const mx = (e.x1 + e.x2) / 2; - svg += ``; + const sx = e.x1 + xShift, sy = e.y1; + const ex = e.x2 + xShift, ey = e.y2; + const mx = (sx + ex) / 2; + svg += ``; } // Nodes on top for (const n of layout.nodes) { - svg += ``; + const nx = n.x + xShift; + svg += ``; const text = n.text.length > 18 ? n.text.substring(0, 16) + '..' : n.text; - svg += `${text.replace(/&/g,'&').replace(//g,'>')}`; + svg += `${text.replace(/&/g,'&').replace(//g,'>')}`; } svg += ''; -- cgit v1.2.3