Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Skip pages with exclude-from-graph-view: true #77

Merged
merged 5 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading