Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Improve mind map fitting and bottom menu spacing https://github.com/siyuan-note/siyuan/issues/18831

Vanessa42c027468509
diff --git a/app/src/assets/scss/protyle/_list-mindmap.scss b/app/src/assets/scss/protyle/_list-mindmap.scss
index 00c899459a..0aa017b6af 100644
--- a/app/src/assets/scss/protyle/_list-mindmap.scss
+++ b/app/src/assets/scss/protyle/_list-mindmap.scss
@@ -12,7 +12,7 @@
display: flex;
flex-direction: column;
width: 100%;
- height: 420px;
+ height: 460px;
min-height: 260px;
box-sizing: border-box;
overflow: hidden;
@@ -525,7 +525,7 @@
left: 50%;
right: auto;
transform: translateX(-50%);
- bottom: 8px;
+ bottom: 0;
z-index: 6;
width: max-content;
min-width: 0;
diff --git a/app/src/protyle/render/listMindmap/model.test.ts b/app/src/protyle/render/listMindmap/model.test.ts
index 8087703e66..0b96ceb27c 100644
--- a/app/src/protyle/render/listMindmap/model.test.ts
+++ b/app/src/protyle/render/listMindmap/model.test.ts
@@ -671,7 +671,7 @@ const browserCases = async (sourceCode: string, css: string) => {
select(beta);
check.equal(inspector.hidden, false);
check.equal(inspector.classList.contains("list-mindmap__inspector--node"), true);
- check.equal(getComputedStyle(inspector).bottom, "8px");
+ check.equal(getComputedStyle(inspector).bottom, "0px");
check.equal(host.querySelector(".list-mindmap__status"), null);
const nodeMenuBounds = inspector.getBoundingClientRect();
const panelBounds = host.getBoundingClientRect();
@@ -754,7 +754,7 @@ const browserCases = async (sourceCode: string, css: string) => {
check.equal(relationElement.classList.contains("list-mindmap__relation--hover"), false);
check.equal(inspector.hidden, false);
check.equal(inspector.classList.contains("list-mindmap__inspector--line"), true);
- check.equal(getComputedStyle(inspector).bottom, "8px");
+ check.equal(getComputedStyle(inspector).bottom, "0px");
const lineMenuBounds = inspector.getBoundingClientRect();
check.ok(Math.abs(lineMenuBounds.left + lineMenuBounds.width / 2 - panelBounds.left - panelBounds.width / 2) < 2);
check.ok(lineMenuBounds.width < panelBounds.width / 2);
@@ -981,6 +981,21 @@ const browserCases = async (sourceCode: string, css: string) => {
const singleList = reset("* Single\n");
const single = new api.ListMindmapView({...options, model: api.readListMindmap(singleList)});
+ await settle();
+ single.fit();
+ check.ok(single.scale > 1 && single.scale <= 2.5, "fit enlarges small maps within the zoom limit");
+ const fitViewport = host.querySelector<HTMLElement>(".list-mindmap__viewport").getBoundingClientRect();
+ const fitNode = host.querySelector<HTMLElement>(".list-mindmap__node").getBoundingClientRect();
+ check.ok(Math.abs((fitNode.left + fitNode.right) / 2 - (fitViewport.left + fitViewport.right) / 2) < 1,
+ "fit centers visible content instead of layout padding");
+ const fitInspector = host.querySelector<HTMLElement>(".list-mindmap__inspector");
+ fitInspector.hidden = false;
+ single.fit();
+ check.deepEqual(host.querySelector<HTMLElement>(".list-mindmap__node").getBoundingClientRect().toJSON(),
+ fitNode.toJSON(), "opening the inspector preserves fit position and scale");
+ check.ok(host.querySelector<HTMLElement>(".list-mindmap__node").getBoundingClientRect().bottom <=
+ fitInspector.getBoundingClientRect().top, "fit keeps content above the visible inspector");
+ fitInspector.hidden = true;
const emptyModel = api.readListMindmap(singleList);
const emptyBlock = document.createElement("div");
emptyBlock.innerHTML = "<div><br></div>";
diff --git a/app/src/protyle/render/listMindmap/view.ts b/app/src/protyle/render/listMindmap/view.ts
index 948bd8b5fd..cdb5b8ba04 100644
--- a/app/src/protyle/render/listMindmap/view.ts
+++ b/app/src/protyle/render/listMindmap/view.ts
@@ -1362,11 +1362,8 @@ export class ListMindmapView {
this.draw();
}
- private fitPrint() {
- if (!this.positions.size || !this.viewport.clientWidth) {
- return;
- }
- // 打印按实际可见内容裁定高度,不计入编辑画布为操作按钮预留的空间。
+ private contentBounds() {
+ // 按实际可见节点、关系线和文字计算边界,不包含布局预留的空白。
let left = Infinity;
let top = Infinity;
let right = -Infinity;
@@ -1389,6 +1386,14 @@ export class ListMindmapView {
}
}
});
+ return {left, top, right, bottom};
+ }
+
+ private fitPrint() {
+ if (!this.positions.size || !this.viewport.clientWidth) {
+ return;
+ }
+ const {left, top, right, bottom} = this.contentBounds();
const width = this.viewport.clientWidth;
this.scale = Math.min(1, Math.max(1, width - 24) / Math.max(1, right - left));
this.options.host.style.setProperty("--list-mindmap-print-height", `${Math.ceil((bottom - top) * this.scale + 26)}px`);
@@ -1400,9 +1405,21 @@ export class ListMindmapView {
public fit() {
const width = this.viewport.clientWidth;
const height = this.viewport.clientHeight;
- this.scale = Math.min(1, Math.max(.15, Math.min((width - 64) / this.bounds.width, (height - 64) / this.bounds.height)));
- this.offsetX = (width - this.bounds.width * this.scale) / 2;
- this.offsetY = (height - this.bounds.height * this.scale) / 2;
+ if (!this.positions.size || !width || !height) {
+ return;
+ }
+ // 先更新关系文字的位置,再按画布上下留白缩放并居中。
+ this.draw();
+ const {left, top, right, bottom} = this.contentBounds();
+ const insetTop = 16;
+ // 菜单打开前后保持相同的底部留白,避免选中节点时画布跳动。
+ const insetBottom = 42;
+ const availableWidth = Math.max(1, width - 48);
+ const availableHeight = Math.max(1, height - insetTop - insetBottom);
+ this.scale = Math.min(2.5, Math.max(.15, Math.min(availableWidth / Math.max(1, right - left),
+ availableHeight / Math.max(1, bottom - top))));
+ this.offsetX = width / 2 - (left + right) * this.scale / 2;
+ this.offsetY = insetTop + availableHeight / 2 - (top + bottom) * this.scale / 2;
this.draw();
}