mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
fixes for link map
This commit is contained in:
parent
242bea236f
commit
a4acbf3aea
@ -20,12 +20,14 @@ export async function showDialog() {
|
|||||||
$maxNotesInput.val(10);
|
$maxNotesInput.val(10);
|
||||||
LINK_TYPES.forEach(lt => $("#link-map-" + lt).prop('checked', true));
|
LINK_TYPES.forEach(lt => $("#link-map-" + lt).prop('checked', true));
|
||||||
|
|
||||||
const note = noteDetailService.getActiveNoteId();
|
const note = noteDetailService.getActiveNote();
|
||||||
|
|
||||||
if (!note) {
|
if (!note) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$linkMapContainer.css("height", $("body").height() - 150);
|
||||||
|
|
||||||
linkMapService = new LinkMapService(note, $linkMapContainer);
|
linkMapService = new LinkMapService(note, $linkMapContainer);
|
||||||
linkMapService.render();
|
linkMapService.render();
|
||||||
|
|
||||||
|
@ -14,8 +14,13 @@ const linkOverlays = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
export default class LinkMap {
|
export default class LinkMap {
|
||||||
constructor(note, $linkMapContainer) {
|
constructor(note, $linkMapContainer, options = {}) {
|
||||||
this.note = note;
|
this.note = note;
|
||||||
|
this.options = $.extend({
|
||||||
|
maxDepth: 10,
|
||||||
|
zoom: 1.0
|
||||||
|
}, options);
|
||||||
|
|
||||||
this.$linkMapContainer = $linkMapContainer;
|
this.$linkMapContainer = $linkMapContainer;
|
||||||
this.linkMapContainerId = this.$linkMapContainer.attr("id");
|
this.linkMapContainerId = this.$linkMapContainer.attr("id");
|
||||||
}
|
}
|
||||||
@ -37,17 +42,15 @@ export default class LinkMap {
|
|||||||
|
|
||||||
const maxNotes = 50;
|
const maxNotes = 50;
|
||||||
|
|
||||||
const currentNoteId = this.note.noteId;
|
const links = await server.post(`notes/${this.note.noteId}/link-map`, {
|
||||||
|
|
||||||
const links = await server.post(`notes/${currentNoteId}/link-map`, {
|
|
||||||
maxNotes,
|
maxNotes,
|
||||||
maxDepth: 1
|
maxDepth: this.options.maxDepth
|
||||||
});
|
});
|
||||||
|
|
||||||
const noteIds = new Set(links.map(l => l.noteId).concat(links.map(l => l.targetNoteId)));
|
const noteIds = new Set(links.map(l => l.noteId).concat(links.map(l => l.targetNoteId)));
|
||||||
|
|
||||||
if (noteIds.size === 0) {
|
if (noteIds.size === 0) {
|
||||||
noteIds.add(currentNoteId);
|
noteIds.add(this.note.noteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// preload all notes
|
// preload all notes
|
||||||
@ -55,6 +58,7 @@ export default class LinkMap {
|
|||||||
|
|
||||||
const graph = new Springy.Graph();
|
const graph = new Springy.Graph();
|
||||||
graph.addNodes(...noteIds);
|
graph.addNodes(...noteIds);
|
||||||
|
graph.addEdges(...links.map(l => [l.noteId, l.targetNoteId]));
|
||||||
|
|
||||||
const layout = new Springy.Layout.ForceDirected(
|
const layout = new Springy.Layout.ForceDirected(
|
||||||
graph,
|
graph,
|
||||||
@ -81,7 +85,7 @@ export default class LinkMap {
|
|||||||
$noteBox.append($("<span>").addClass("title").append($link));
|
$noteBox.append($("<span>").addClass("title").append($link));
|
||||||
});
|
});
|
||||||
|
|
||||||
if (noteId === currentNoteId) {
|
if (noteId === this.note.noteId) {
|
||||||
$noteBox.addClass("link-map-active-note");
|
$noteBox.addClass("link-map-active-note");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +93,7 @@ export default class LinkMap {
|
|||||||
|
|
||||||
this.jsPlumbInstance.draggable($noteBox[0], {
|
this.jsPlumbInstance.draggable($noteBox[0], {
|
||||||
start: params => {
|
start: params => {
|
||||||
renderer.stop();
|
this.renderer.stop();
|
||||||
},
|
},
|
||||||
drag: params => {},
|
drag: params => {},
|
||||||
stop: params => {}
|
stop: params => {}
|
||||||
@ -103,7 +107,7 @@ export default class LinkMap {
|
|||||||
layout,
|
layout,
|
||||||
() => {},
|
() => {},
|
||||||
(edge, p1, p2) => {
|
(edge, p1, p2) => {
|
||||||
const connectionId = edge.source.id + '-' + edge.target.id;
|
const connectionId = this.linkMapContainerId + '-' + edge.source.id + '-' + edge.target.id;
|
||||||
|
|
||||||
if ($("#" + connectionId).length > 0) {
|
if ($("#" + connectionId).length > 0) {
|
||||||
return;
|
return;
|
||||||
@ -169,7 +173,7 @@ export default class LinkMap {
|
|||||||
this.$linkMapContainer.empty();
|
this.$linkMapContainer.empty();
|
||||||
|
|
||||||
// reset zoom/pan
|
// reset zoom/pan
|
||||||
this.pzInstance.zoomTo(0, 0, 0.7);
|
this.pzInstance.zoomTo(0, 0, this.options.zoom);
|
||||||
this.pzInstance.moveTo(0, 0);
|
this.pzInstance.moveTo(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -552,6 +552,10 @@ class NoteDetailRelationMap {
|
|||||||
|
|
||||||
const transform = this.$relationMapContainer.css('transform');
|
const transform = this.$relationMapContainer.css('transform');
|
||||||
|
|
||||||
|
if (transform === 'none') {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
const matches = transform.match(matrixRegex);
|
const matches = transform.match(matrixRegex);
|
||||||
|
|
||||||
if (!matches) {
|
if (!matches) {
|
||||||
|
@ -26,10 +26,14 @@ class LinkMapWidget extends StandardWidget {
|
|||||||
|
|
||||||
const $linkMapContainer = this.$body.find('.link-map-container');
|
const $linkMapContainer = this.$body.find('.link-map-container');
|
||||||
$linkMapContainer.attr("id", "link-map-container-" + linkMapContainerIdCtr++);
|
$linkMapContainer.attr("id", "link-map-container-" + linkMapContainerIdCtr++);
|
||||||
|
$linkMapContainer.css("height", "300px");
|
||||||
|
|
||||||
const LinkMapServiceClass = (await import('../services/link_map.js')).default;
|
const LinkMapServiceClass = (await import('../services/link_map.js')).default;
|
||||||
|
|
||||||
const linkMapService = new LinkMapServiceClass(this.ctx.note, $linkMapContainer);
|
const linkMapService = new LinkMapServiceClass(this.ctx.note, $linkMapContainer, {
|
||||||
|
maxDepth: 1,
|
||||||
|
zoom: 0.7
|
||||||
|
});
|
||||||
|
|
||||||
await linkMapService.render();
|
await linkMapService.render();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
.link-map-container {
|
.link-map-container {
|
||||||
position: relative;
|
position: relative;
|
||||||
height: 300px;
|
|
||||||
outline: none; /* remove dotted outline on click */
|
outline: none; /* remove dotted outline on click */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body" style="outline: none; overflow: hidden;">
|
<div class="modal-body" style="outline: none; overflow: hidden;">
|
||||||
<div id="link-map-container"></div>
|
<div id="link-map-container" class="link-map-container"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user