mirror of
https://github.com/zadam/trilium.git
synced 2025-11-06 05:15:59 +01:00
link map is kept centered on the active note box
This commit is contained in:
@@ -146,6 +146,10 @@ export default class LinkMap {
|
||||
$noteBox
|
||||
.css("left", (middleW + p.x * 100) + "px")
|
||||
.css("top", (middleH + p.y * 100) + "px");
|
||||
|
||||
if ($noteBox.hasClass("link-map-active-note")) {
|
||||
this.moveToCenterOfElement($noteBox[0]);
|
||||
}
|
||||
},
|
||||
() => {},
|
||||
() => {},
|
||||
@@ -160,6 +164,21 @@ export default class LinkMap {
|
||||
setTimeout(() => this.renderer.stop(), 3000);
|
||||
}
|
||||
|
||||
moveToCenterOfElement(element) {
|
||||
const elemBounds = element.getBoundingClientRect();
|
||||
const containerBounds = this.pzInstance.getOwner().getBoundingClientRect();
|
||||
|
||||
const centerX = -elemBounds.left + containerBounds.left + (containerBounds.width / 2) - (elemBounds.width / 2);
|
||||
const centerY = -elemBounds.top + containerBounds.top + (containerBounds.height / 2) - (elemBounds.height / 2);
|
||||
|
||||
const transform = this.pzInstance.getTransform();
|
||||
|
||||
const newX = transform.x + centerX;
|
||||
const newY = transform.y + centerY;
|
||||
|
||||
this.pzInstance.moveTo(newX, newY);
|
||||
}
|
||||
|
||||
initPanZoom() {
|
||||
if (this.pzInstance) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user