Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexW00 committed Oct 24, 2023
2 parents 153dbb4 + f196ac2 commit 869a912
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/graph/Link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ export type ResolvedLinkCache = Record<string, Record<string, number>>;
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
Expand Down
7 changes: 5 additions & 2 deletions src/graph/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -14,6 +15,7 @@ export default class Node {
constructor(
name: string,
path: string,
isAttachment: boolean,
val = 10,
neighbors: Node[] = [],
links: Link[] = [],
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -55,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);

Expand Down
7 changes: 5 additions & 2 deletions src/settings/categories/FilterSettings.ts
Original file line number Diff line number Diff line change
@@ -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,
};
}
}
11 changes: 9 additions & 2 deletions src/views/graph/ForceGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,17 @@ export class ForceGraph {

private doShowNode = (node: Node) => {
return (
this.plugin.getSettings().filters.doShowOrphans ||
node.links.length > 0
(this.plugin.getSettings().filters.doShowOrphans ||
node.links.length > 0) &&
(this.plugin.getSettings().filters.doShowAttachments ||
!node.isAttachment)
);
};

private doShowLink = (link: Link) => {
return this.plugin.getSettings().filters.doShowAttachments || !link.linksAnAttachment
}

private onNodeHover = (node: Node | null) => {
if (
(!node && !this.highlightedNodes.size) ||
Expand Down Expand Up @@ -187,6 +193,7 @@ export class ForceGraph {
.linkDirectionalParticleWidth(
this.plugin.getSettings().display.particleSize
)
.linkVisibility(this.doShowLink)
.onLinkHover(this.onLinkHover)
.linkColor((link: Link) =>
this.isHighlightedLink(link)
Expand Down
7 changes: 7 additions & 0 deletions src/views/settings/categories/FilterSettingsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 869a912

Please sign in to comment.