mirror of
https://github.com/zadam/trilium.git
synced 2025-01-30 10:57:51 +08:00
link map is kept centered on the active note box
This commit is contained in:
parent
ec06b940f4
commit
9d958e1860
3 changed files with 45 additions and 11 deletions
|
@ -115,12 +115,16 @@ function createPanZoom(domElement, options) {
|
||||||
zoomTo: publicZoomTo,
|
zoomTo: publicZoomTo,
|
||||||
zoomAbs: zoomAbs,
|
zoomAbs: zoomAbs,
|
||||||
smoothZoom: smoothZoom,
|
smoothZoom: smoothZoom,
|
||||||
getTransform: getTransformModel,
|
|
||||||
showRectangle: showRectangle,
|
showRectangle: showRectangle,
|
||||||
|
|
||||||
pause: pause,
|
pause: pause,
|
||||||
resume: resume,
|
resume: resume,
|
||||||
isPaused: isPaused,
|
isPaused: isPaused,
|
||||||
|
|
||||||
|
getTransform: getTransformModel,
|
||||||
|
getMinZoom: getMinZoom,
|
||||||
|
getMaxZoom: getMaxZoom,
|
||||||
|
getOwner: () => owner
|
||||||
}
|
}
|
||||||
|
|
||||||
eventify(api);
|
eventify(api);
|
||||||
|
@ -216,6 +220,14 @@ function createPanZoom(domElement, options) {
|
||||||
return transform
|
return transform
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getMinZoom() {
|
||||||
|
return minZoom;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMaxZoom() {
|
||||||
|
return maxZoom;
|
||||||
|
}
|
||||||
|
|
||||||
function getPoint() {
|
function getPoint() {
|
||||||
return {
|
return {
|
||||||
x: transform.x,
|
x: transform.x,
|
||||||
|
@ -345,8 +357,14 @@ function createPanZoom(domElement, options) {
|
||||||
transform.x = size.x - ratio * (size.x - transform.x)
|
transform.x = size.x - ratio * (size.x - transform.x)
|
||||||
transform.y = size.y - ratio * (size.y - transform.y)
|
transform.y = size.y - ratio * (size.y - transform.y)
|
||||||
|
|
||||||
var transformAdjusted = keepTransformInsideBounds()
|
// TODO: https://github.com/anvaka/panzoom/issues/112
|
||||||
if (!transformAdjusted) transform.scale *= ratio
|
if (bounds && boundsPadding === 1 && minZoom === 1) {
|
||||||
|
transform.scale *= ratio
|
||||||
|
keepTransformInsideBounds()
|
||||||
|
} else {
|
||||||
|
var transformAdjusted = keepTransformInsideBounds()
|
||||||
|
if (!transformAdjusted) transform.scale *= ratio
|
||||||
|
}
|
||||||
|
|
||||||
triggerEvent('zoom')
|
triggerEvent('zoom')
|
||||||
|
|
||||||
|
@ -1571,7 +1589,7 @@ function removeWheelListener( elem, callback, useCapture ) {
|
||||||
// unsubscription in some browsers. But in practice, I don't think we should
|
// unsubscription in some browsers. But in practice, I don't think we should
|
||||||
// worry too much about it (those browsers are on the way out)
|
// worry too much about it (those browsers are on the way out)
|
||||||
function _addWheelListener( elem, eventName, callback, useCapture ) {
|
function _addWheelListener( elem, eventName, callback, useCapture ) {
|
||||||
elem[ _addEventListener ]( prefix + eventName, support == "wheel" ? callback : function(originalEvent ) {
|
elem[ _addEventListener ]( prefix + eventName, support == "wheel" ? callback : function( originalEvent ) {
|
||||||
!originalEvent && ( originalEvent = window.event );
|
!originalEvent && ( originalEvent = window.event );
|
||||||
|
|
||||||
// create a normalized event object
|
// create a normalized event object
|
||||||
|
@ -1613,10 +1631,7 @@ function _addWheelListener( elem, eventName, callback, useCapture ) {
|
||||||
// it's time to fire the callback
|
// it's time to fire the callback
|
||||||
return callback( event );
|
return callback( event );
|
||||||
|
|
||||||
}, {
|
}, useCapture || false );
|
||||||
capture: useCapture || false ,
|
|
||||||
passive: false
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _removeWheelListener( elem, eventName, callback, useCapture ) {
|
function _removeWheelListener( elem, eventName, callback, useCapture ) {
|
||||||
|
|
|
@ -146,6 +146,10 @@ export default class LinkMap {
|
||||||
$noteBox
|
$noteBox
|
||||||
.css("left", (middleW + p.x * 100) + "px")
|
.css("left", (middleW + p.x * 100) + "px")
|
||||||
.css("top", (middleH + p.y * 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);
|
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() {
|
initPanZoom() {
|
||||||
if (this.pzInstance) {
|
if (this.pzInstance) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
.link-map-container .note-box {
|
.link-map-container .note-box {
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
position: absolute !important;
|
position: absolute !important;
|
||||||
background-color: var(--accented-background-color);
|
background-color: var(--main-background-color);
|
||||||
color: var(--main-text-color);
|
color: var(--main-text-color);
|
||||||
z-index: 4;
|
z-index: 4;
|
||||||
border: 1px solid #666;
|
border: 1px solid #666;
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.link-map-active-note {
|
.link-map-active-note {
|
||||||
background-color: var(--more-accented-background-color) !important;
|
background-color: var(--accented-background-color) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.link-map-container .jsplumb-connection-hover path {
|
.link-map-container .jsplumb-connection-hover path {
|
||||||
|
|
Loading…
Reference in a new issue