From 931a1d07e3ab275aa34352dbaec7b166eda67e1a Mon Sep 17 00:00:00 2001 From: "Thomas A. Christensen II" <25492070+MillironX@users.noreply.github.com> Date: Thu, 9 May 2024 03:17:04 -0500 Subject: [PATCH] feature: Skip pages with `exclude-from-graph-view: true` (#77) * chore: Add exclude-from-graph-view property to list of properties to fetch * feat: Add exclusion for pages with exclude-from-graph-view set * test: Add test to ensure exclude-from-graph-view pages are skipped * test: Add snapshot for exclude-from-graph-view tests * docs: Add exclude-to-graph-view support to README --- README.md | 4 +++- src/__snapshots__/graph.ts.snap | 24 ++++++++++++++++++++++++ src/graph.ts | 32 +++++++++++++++++++++++++++++++- src/logseq.ts | 1 + 4 files changed, 59 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 569329d..7dead75 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,9 @@ Learn more about the relationships between between your notes using network anal - Adamic Adar - Find secret connections between your notes. Click a note to learn which notes the algorithm thinks are linked - CoCitation - Checks how alike documents are by looking at how close their shared references are - Shift-click node to add it to sidebar -- If there are nodes you wish to hide from your graph add the page property `graph-hide:: true` +- If there are nodes you wish to hide from your graph add the page property `graph-hide:: true` or `exclude-from-graph-view:: true` + - `graph-hide:: true` hides nodes from this plugin's `graph analysis` mode + - `exclude-from-graph-view:: true` hides nodes from both this plugin and Logseq's native global graph view, see [the Logseq documentation](https://docs.logseq.com/#/page/built-in%20properties) - If you are interested in seeing suprising paths in your notes its a good idea to add this to notes that have lots of connections. ## Search and filters diff --git a/src/__snapshots__/graph.ts.snap b/src/__snapshots__/graph.ts.snap index 5a10f7b..6b29b45 100644 --- a/src/__snapshots__/graph.ts.snap +++ b/src/__snapshots__/graph.ts.snap @@ -396,6 +396,30 @@ exports[`buildGraph > shows journal pages when requested 1`] = ` } `; +exports[`buildGraph > skips pages with exclude-from-graph-view: true 1`] = ` +{ + "attributes": { + "isInited": true, + }, + "edges": [], + "nodes": [ + { + "attributes": { + "aliases": [], + "label": "A", + "rawAliases": [], + "type": "circle", + }, + }, + ], + "options": { + "allowSelfLoops": true, + "multi": false, + "type": "mixed", + }, +} +`; + exports[`buildGraph > skips pages with graph-hide: true 1`] = ` { "attributes": { diff --git a/src/graph.ts b/src/graph.ts index 79f7619..c123629 100644 --- a/src/graph.ts +++ b/src/graph.ts @@ -34,7 +34,7 @@ export async function buildGraph( const journals = pages.filter((p) => p["journal?"]); for (const page of pages) { - if (page.properties && page.properties.graphHide) { + if (page.properties && (page.properties.graphHide || page.properties.excludeFromGraphView)) { continue; } if (g.hasNode(page.id)) { @@ -445,6 +445,36 @@ if (import.meta.vitest) { expect(graphToJson(graph)).toMatchSnapshot(); }); + it("skips pages with exclude-from-graph-view: true", async () => { + const getAllPages = async () => [ + { id: 1, "journal?": false, name: "A" }, + { + id: 2, + "journal?": false, + name: "B", + properties: { excludeFromGraphView: true }, + }, + ]; + const getBlockReferences = async () => [ + [ + { + refs: [{ id: 2 }], + "path-refs": [{ id: 1 }, { id: 2 }], + page: { id: 1 }, + }, + ], + ]; + const getSettings = () => ({ journal: false }); + const getBlock = async (ref: BlockIdentity | EntityID) => null; + const graph = await buildGraph( + getAllPages, + getBlockReferences, + getSettings, + getBlock + ); + expect(graphToJson(graph)).toMatchSnapshot(); + }); + it("merges alias nodes", async () => { const getAllPages = async () => [ { id: 1, "journal?": false, name: "A", properties: { alias: ["B"] } }, diff --git a/src/logseq.ts b/src/logseq.ts index ce0b3cd..442e8b1 100644 --- a/src/logseq.ts +++ b/src/logseq.ts @@ -10,6 +10,7 @@ export interface Page { name: string; properties?: { graphHide?: boolean; + excludeFromGraphView?: boolean; alias?: string[] | string; icon?: string; pageIcon?: string;