From df9f6ce33aa212472372a1c3a2c49a8f3fd4a3ed Mon Sep 17 00:00:00 2001 From: zadam Date: Mon, 7 Nov 2022 23:19:38 +0100 Subject: [PATCH] link map improvements --- src/public/app/widgets/note_map.js | 23 +++++++++++++++++++---- src/routes/api/note_map.js | 4 ++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/public/app/widgets/note_map.js b/src/public/app/widgets/note_map.js index b3126f172..2ab8f7d51 100644 --- a/src/public/app/widgets/note_map.js +++ b/src/public/app/widgets/note_map.js @@ -329,7 +329,7 @@ export default class NoteMapWidget extends NoteContextAwareWidget { renderData(data) { this.graph.graphData(data); - if (this.widgetMode === 'ribbon') { + if (this.widgetMode === 'ribbon' && this.note?.type !== 'search') { setTimeout(() => { this.setDimensions(); @@ -342,14 +342,18 @@ export default class NoteMapWidget extends NoteContextAwareWidget { } }, 1000); } - else if (this.widgetMode === 'type') { + else { if (data.nodes.length > 1) { setTimeout(() => { this.setDimensions(); - this.graph.zoomToFit(400, 10); + const noteIdsWithLinks = this.getNoteIdsWithLinks(data); - if (data.nodes.length < 30) { + if (noteIdsWithLinks.size > 0) { + this.graph.zoomToFit(400, 30, node => noteIdsWithLinks.has(node.id)); + } + + if (noteIdsWithLinks.size < 30) { this.graph.d3VelocityDecay(0.4); } }, 1000); @@ -357,6 +361,17 @@ export default class NoteMapWidget extends NoteContextAwareWidget { } } + getNoteIdsWithLinks(data) { + const noteIds = new Set(); + + for (const link of data.links) { + noteIds.add(link.source.id); + noteIds.add(link.target.id); + } + + return noteIds; + } + getSubGraphConnectedToCurrentNote(data) { function getGroupedLinks(links, type) { const map = {}; diff --git a/src/routes/api/note_map.js b/src/routes/api/note_map.js index da3d00f05..9b49c8d3c 100644 --- a/src/routes/api/note_map.js +++ b/src/routes/api/note_map.js @@ -94,6 +94,10 @@ function getLinkMap(req) { .map(note => note.noteId) ); + if (mapRootNote.type === 'search') { + noteIds.delete(mapRootNote.noteId); + } + for (const noteId of getNeighbors(mapRootNote, 3)) { noteIds.add(noteId); }