Skip to content

Commit

Permalink
feature: Skip pages with exclude-from-graph-view: true (#77)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
MillironX authored May 9, 2024
1 parent 09f0df9 commit 931a1d0
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions src/__snapshots__/graph.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
32 changes: 31 additions & 1 deletion src/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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"] } },
Expand Down
1 change: 1 addition & 0 deletions src/logseq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface Page {
name: string;
properties?: {
graphHide?: boolean;
excludeFromGraphView?: boolean;
alias?: string[] | string;
icon?: string;
pageIcon?: string;
Expand Down

0 comments on commit 931a1d0

Please sign in to comment.