display properly relations in note map even if they are not in the subtree, closes #2251

This commit is contained in:
zadam
2021-10-21 22:52:52 +02:00
parent ee1b377bc2
commit 50b7063811
3 changed files with 75 additions and 11 deletions

View File

@@ -332,9 +332,9 @@ export default class NoteMapWidget extends NoteContextAwareWidget {
if (this.widgetMode === 'ribbon') {
setTimeout(() => {
const node = this.nodes.find(node => node.id === this.noteId);
const subGraphNoteIds = this.getSubGraphConnectedToCurrentNote(data);
this.graph.centerAt(node.x, node.y, 500);
this.graph.zoomToFit(400, 50, node => subGraphNoteIds.has(node.id));
}, 1000);
}
else if (this.widgetMode === 'type') {
@@ -344,6 +344,39 @@ export default class NoteMapWidget extends NoteContextAwareWidget {
}
}
getSubGraphConnectedToCurrentNote(data) {
function getGroupedLinksBySource(links) {
const map = {};
for (const link of links) {
const key = link.source.id;
map[key] = map[key] || [];
map[key].push(link);
}
return map;
}
const linksBySource = getGroupedLinksBySource(data.links);
const subGraphNoteIds = new Set();
function traverseGraph(noteId) {
if (subGraphNoteIds.has(noteId)) {
return;
}
subGraphNoteIds.add(noteId);
for (const link of linksBySource[noteId] || []) {
traverseGraph(link.target.id);
}
}
traverseGraph(this.noteId);
return subGraphNoteIds;
}
cleanup() {
this.$container.html('');
}