From 9d99da14e1a70e022097447e88a80b251fbdd38d Mon Sep 17 00:00:00 2001 From: Kieran Date: Fri, 27 Jun 2025 20:15:59 +0100 Subject: [PATCH 1/3] feat(map): add `mapIncludeRelation` and `mapExcludeRelation` to include only or exclude specific relation types --- apps/client/src/widgets/note_map.ts | 14 +++++++++++--- apps/server/src/routes/api/note_map.ts | 9 +++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/apps/client/src/widgets/note_map.ts b/apps/client/src/widgets/note_map.ts index d7fb10af4..d0274fc86 100644 --- a/apps/client/src/widgets/note_map.ts +++ b/apps/client/src/widgets/note_map.ts @@ -324,7 +324,13 @@ export default class NoteMapWidget extends NoteContextAwareWidget { } const mapRootNoteId = this.getMapRootNoteId(); - const data = await this.loadNotesAndRelations(mapRootNoteId); + + const labelValues = (name: string) => this.note?.getLabels(name).map(l => l.value) ?? []; + + const excludeRelations = labelValues("mapExcludeRelation"); + const includeRelations = labelValues("mapIncludeRelation"); + + const data = await this.loadNotesAndRelations(mapRootNoteId, excludeRelations, includeRelations); const nodeLinkRatio = data.nodes.length / data.links.length; const magnifiedRatio = Math.pow(nodeLinkRatio, 1.5); @@ -473,8 +479,10 @@ export default class NoteMapWidget extends NoteContextAwareWidget { ctx.restore(); } - async loadNotesAndRelations(mapRootNoteId: string): Promise { - const resp = await server.post(`note-map/${mapRootNoteId}/${this.mapType}`); + async loadNotesAndRelations(mapRootNoteId: string, excludeRelations: string[], includeRelations: string[]): Promise { + const resp = await server.post(`note-map/${mapRootNoteId}/${this.mapType}`, { + excludeRelations, includeRelations + }); this.calculateNodeSizes(resp); diff --git a/apps/server/src/routes/api/note_map.ts b/apps/server/src/routes/api/note_map.ts index 470152bd6..b77c634c2 100644 --- a/apps/server/src/routes/api/note_map.ts +++ b/apps/server/src/routes/api/note_map.ts @@ -110,6 +110,11 @@ function getLinkMap(req: Request) { const ignoreExcludeFromNoteMap = mapRootNote.isLabelTruthy("excludeFromNoteMap"); let unfilteredNotes; + const toSet = (data: unknown) => new Set(data instanceof Array ? data : []); + + const excludeRelations = toSet(req.body.excludeRelations); + const includeRelations = toSet(req.body.includeRelations); + if (mapRootNote.type === "search") { // for search notes, we want to consider the direct search results only without the descendants unfilteredNotes = mapRootNote.getSearchResultNotes(); @@ -152,6 +157,10 @@ function getLinkMap(req: Request) { } return !parentNote.getChildNotes().find((childNote) => childNote.noteId === rel.value); + } else if (includeRelations.size != 0 && !includeRelations.has(rel.name)) { + return false; + } else if (excludeRelations.has(rel.name)) { + return false; } else { return true; } From 31df2341c313b20674b5b5efcdecf234f5614770 Mon Sep 17 00:00:00 2001 From: Kieran Date: Fri, 27 Jun 2025 20:18:28 +0100 Subject: [PATCH 2/3] feat(map): add `mapIncludeRelation` and `mapExcludeRelation` to `builtin_attributes` --- apps/server/src/services/builtin_attributes.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/server/src/services/builtin_attributes.ts b/apps/server/src/services/builtin_attributes.ts index 86fa35a9d..2d35992aa 100644 --- a/apps/server/src/services/builtin_attributes.ts +++ b/apps/server/src/services/builtin_attributes.ts @@ -45,6 +45,8 @@ export default [ { type: "label", name: "pageSize" }, { type: "label", name: "viewType" }, { type: "label", name: "mapRootNoteId" }, + { type: "label", name: "mapExcludeRelation" }, + { type: "label", name: "mapIncludeRelation" }, { type: "label", name: "bookmarkFolder" }, { type: "label", name: "sorted" }, { type: "label", name: "sortDirection" }, From e70ba009294ff6ed2f33f18936a48326510219d3 Mon Sep 17 00:00:00 2001 From: Kieran Date: Fri, 27 Jun 2025 20:25:09 +0100 Subject: [PATCH 3/3] docs(map): document relation filtering --- docs/User Guide/User Guide/Note Types/Note Map.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/User Guide/User Guide/Note Types/Note Map.md b/docs/User Guide/User Guide/Note Types/Note Map.md index 2433e7161..a07569a38 100644 --- a/docs/User Guide/User Guide/Note Types/Note Map.md +++ b/docs/User Guide/User Guide/Note Types/Note Map.md @@ -3,4 +3,6 @@ A Note map is a note type which displays a standalone version of the feature of the same name: [Note Map (Link map, Tree map)](../Advanced%20Usage/Note%20Map%20\(Link%20map%2C%20Tree%20map\).md). -Once created, the note map will display the relations between notes. Only the notes that are part of the parent of the note map will be displayed (including their children). \ No newline at end of file +Once created, the note map will display the relations between notes. Only the notes that are part of the parent of the note map will be displayed (including their children). + +The labels `mapIncludeRelation` and `mapExcludeRelation`, if set, filter the note map to include only the specified relations or to exclude the specified relations, respectively.