From a10ddf6b77155f048d050ebd7811b7ec123ccd2e Mon Sep 17 00:00:00 2001 From: massivebird Date: Fri, 20 Oct 2023 23:17:42 -0400 Subject: [PATCH 1/5] adds: `isAttachment` property for `Node` objects --- src/graph/Node.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/graph/Node.ts b/src/graph/Node.ts index d83e447..0a07862 100644 --- a/src/graph/Node.ts +++ b/src/graph/Node.ts @@ -5,6 +5,7 @@ export default class Node { public readonly id: string; public readonly name: string; public readonly path: string; + public readonly isAttachment: boolean; public readonly val: number; // = weight, currently = 1 because scaling doesn't work well public readonly neighbors: Node[]; @@ -14,6 +15,7 @@ export default class Node { constructor( name: string, path: string, + isAttachment: boolean, val = 10, neighbors: Node[] = [], links: Link[] = [], @@ -22,6 +24,7 @@ export default class Node { this.id = path; this.name = name; this.path = path; + this.isAttachment = isAttachment; this.val = val; this.neighbors = neighbors; this.links = links; @@ -34,7 +37,7 @@ export default class Node { return [ files .map((file, index) => { - const node = new Node(file.name, file.path); + const node = new Node(file.name, file.path, file.extension == "md" ? false : true); const cache = app.metadataCache.getFileCache(file), tags = cache ? getAllTags(cache) : null; if (tags != null) { From 2d2583d2c50ee7db4bc7608c70800d05ee53c0ee Mon Sep 17 00:00:00 2001 From: massivebird Date: Fri, 20 Oct 2023 23:24:55 -0400 Subject: [PATCH 2/5] adds: "Show Attachments" toggle w persistent state --- src/settings/categories/FilterSettings.ts | 7 +++++-- src/views/settings/categories/FilterSettingsView.ts | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/settings/categories/FilterSettings.ts b/src/settings/categories/FilterSettings.ts index a73f0c2..9f19968 100644 --- a/src/settings/categories/FilterSettings.ts +++ b/src/settings/categories/FilterSettings.ts @@ -1,17 +1,20 @@ export class FilterSettings { doShowOrphans? = true; + doShowAttachments? = false; - constructor(doShowOrphans?: boolean) { + constructor(doShowOrphans?: boolean, doShowAttachments?: boolean) { this.doShowOrphans = doShowOrphans ?? this.doShowOrphans; + this.doShowAttachments = doShowAttachments ?? this.doShowAttachments; } public static fromStore(store: any) { - return new FilterSettings(store?.doShowOrphans); + return new FilterSettings(store?.doShowOrphans, store?.doShowAttachments); } public toObject() { return { doShowOrphans: this.doShowOrphans, + doShowAttachments: this.doShowAttachments, }; } } diff --git a/src/views/settings/categories/FilterSettingsView.ts b/src/views/settings/categories/FilterSettingsView.ts index ce13af9..a351da5 100644 --- a/src/views/settings/categories/FilterSettingsView.ts +++ b/src/views/settings/categories/FilterSettingsView.ts @@ -13,6 +13,13 @@ const FilterSettingsView = ( filterSettings.value.doShowOrphans = value; }); }); + new Setting(containerEl).setName("Show Attachments").addToggle((toggle) => { + toggle + .setValue(filterSettings.value.doShowAttachments || false) + .onChange(async (value) => { + filterSettings.value.doShowAttachments = value; + }); + }); }; export default FilterSettingsView; From 308d7d6c448c28b20caad18579f6b46ce37f3761 Mon Sep 17 00:00:00 2001 From: massivebird Date: Fri, 20 Oct 2023 23:58:06 -0400 Subject: [PATCH 3/5] adds: `linksAnAttachment` property for links I'll need this later when enabling/disabling the "Show Attachment" option. It should hide attachment nodes as well as their links. --- src/graph/Link.ts | 4 +++- src/graph/Node.ts | 2 +- src/views/graph/ForceGraph.ts | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/graph/Link.ts b/src/graph/Link.ts index d83ef1c..c142943 100644 --- a/src/graph/Link.ts +++ b/src/graph/Link.ts @@ -5,10 +5,12 @@ export type ResolvedLinkCache = Record>; export default class Link { public readonly source: string; public readonly target: string; + public readonly linksAnAttachment: boolean; - constructor(sourceId: string, targetId: string) { + constructor(sourceId: string, targetId: string, linksAnAttachment: boolean) { this.source = sourceId; this.target = targetId; + this.linksAnAttachment = linksAnAttachment; } // Creates a link index for an array of links diff --git a/src/graph/Node.ts b/src/graph/Node.ts index 0a07862..5d2e832 100644 --- a/src/graph/Node.ts +++ b/src/graph/Node.ts @@ -58,7 +58,7 @@ export default class Node { // Links together two nodes as neighbors (node -> neighbor) addNeighbor(neighbor: Node): Link | null { if (!this.isNeighborOf(neighbor)) { - const link = new Link(this.id, neighbor.id); + const link = new Link(this.id, neighbor.id, this.isAttachment || neighbor.isAttachment); this.neighbors.push(neighbor); this.addLink(link); diff --git a/src/views/graph/ForceGraph.ts b/src/views/graph/ForceGraph.ts index 5f670d4..ad0c982 100644 --- a/src/views/graph/ForceGraph.ts +++ b/src/views/graph/ForceGraph.ts @@ -137,7 +137,9 @@ export class ForceGraph { private doShowNode = (node: Node) => { return ( this.plugin.getSettings().filters.doShowOrphans || - node.links.length > 0 + node.links.length > 0 && + this.plugin.getSettings().filters.doShowAttachments || + !node.isAttachment ); }; From a5489a004e238e6ef3f459c18166dc106dbb5999 Mon Sep 17 00:00:00 2001 From: massivebird Date: Sat, 21 Oct 2023 15:23:55 -0400 Subject: [PATCH 4/5] fixes: `doShowNode` order of operations --- src/views/graph/ForceGraph.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/views/graph/ForceGraph.ts b/src/views/graph/ForceGraph.ts index ad0c982..ae6e999 100644 --- a/src/views/graph/ForceGraph.ts +++ b/src/views/graph/ForceGraph.ts @@ -136,10 +136,10 @@ export class ForceGraph { private doShowNode = (node: Node) => { return ( - this.plugin.getSettings().filters.doShowOrphans || - node.links.length > 0 && - this.plugin.getSettings().filters.doShowAttachments || - !node.isAttachment + (this.plugin.getSettings().filters.doShowOrphans || + node.links.length > 0) && + (this.plugin.getSettings().filters.doShowAttachments || + !node.isAttachment) ); }; From 7e69ebb1672547bae8c183fabd6b999e99fe302d Mon Sep 17 00:00:00 2001 From: massivebird Date: Sat, 21 Oct 2023 15:40:58 -0400 Subject: [PATCH 5/5] feat: hides relevant links when hiding attachments When disabling the "Show Attachment" setting, attachments are hidden as well as all their outgoing/incoming links. --- src/views/graph/ForceGraph.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/views/graph/ForceGraph.ts b/src/views/graph/ForceGraph.ts index ae6e999..7d9f23c 100644 --- a/src/views/graph/ForceGraph.ts +++ b/src/views/graph/ForceGraph.ts @@ -143,6 +143,10 @@ export class ForceGraph { ); }; + private doShowLink = (link: Link) => { + return this.plugin.getSettings().filters.doShowAttachments || !link.linksAnAttachment + } + private onNodeHover = (node: Node | null) => { if ( (!node && !this.highlightedNodes.size) || @@ -189,6 +193,7 @@ export class ForceGraph { .linkDirectionalParticleWidth( this.plugin.getSettings().display.particleSize ) + .linkVisibility(this.doShowLink) .onLinkHover(this.onLinkHover) .linkColor((link: Link) => this.isHighlightedLink(link)