Skip to content

Commit

Permalink
0.1.15
Browse files Browse the repository at this point in the history
  • Loading branch information
zsviczian committed Jun 11, 2023
1 parent 4179227 commit 210b195
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 34 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "excalibrain",
"name": "ExcaliBrain",
"version": "0.1.14",
"version": "0.1.15",
"minAppVersion": "0.15.6",
"description": "A clean, intuitive and editable graph view for Obsidian",
"author": "Zsolt Viczian",
Expand Down
40 changes: 23 additions & 17 deletions src/graph/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { LinkDirection, Neighbour, Relation, RelationType } from "src/Types";
import { getDVFieldLinksForPage, getPrimaryTag } from "src/utils/dataview";
import { getFilenameFromPath } from "src/utils/fileUtils";
import { errorlog, log } from "src/utils/utils";
import { Pages } from "./Pages";
import { Pages, addUnresolvedPage } from "./Pages";

const DEFAULT_RELATION:Relation = {
target: null,
Expand Down Expand Up @@ -120,65 +120,71 @@ export class Page {

const parentFields = this.plugin.hierarchyLowerCase.parents;
getDVFieldLinksForPage(this.plugin,dvPage,parentFields).forEach(item=>{
const referencedPage = this.pages.get(item.link);
let referencedPage = this.pages.get(item.link);
if(!referencedPage) {
referencedPage = addUnresolvedPage(item.link, this, this.plugin, this.plugin.pages)
//log(`Unexpected: ${this.file.path} references ${item.link} in DV, but it was not found in app.metadataCache. The page was skipped.`);
return;
//return;
}
this.addParent(referencedPage,RelationType.DEFINED,LinkDirection.TO, item.field);
referencedPage.addChild(this,RelationType.DEFINED,LinkDirection.FROM, item.field);
});

const childFields = this.plugin.hierarchyLowerCase.children;
getDVFieldLinksForPage(this.plugin,dvPage,childFields).forEach(item=>{
const referencedPage = this.pages.get(item.link);
let referencedPage = this.pages.get(item.link);
if(!referencedPage) {
referencedPage = addUnresolvedPage(item.link, this, this.plugin, this.plugin.pages)
//log(`Unexpected: ${this.file.path} references ${item.link} in DV, but it was not found in app.metadataCache. The page was skipped.`);
return;
//return;
}
this.addChild(referencedPage,RelationType.DEFINED,LinkDirection.TO, item.field);
referencedPage.addParent(this,RelationType.DEFINED,LinkDirection.FROM, item.field);
});

const leftFriendFields = this.plugin.hierarchyLowerCase.leftFriends;
getDVFieldLinksForPage(this.plugin,dvPage,leftFriendFields).forEach(item=>{
const referencedPage = this.pages.get(item.link);
let referencedPage = this.pages.get(item.link);
if(!referencedPage) {
//log(`Unexpected: ${this.file.path} references ${item.link} in DV, but it was not found in app.metadataCache. The page was skipped.`);
return;
referencedPage = addUnresolvedPage(item.link, this, this.plugin, this.plugin.pages)
//log(`Unexpected: ${this.file.path} references ${item.link} in DV, but it was not found in app.metadataCache. The page was skipped.`);
//return;
}
this.addLeftFriend(referencedPage,RelationType.DEFINED,LinkDirection.TO,item.field);
referencedPage.addLeftFriend(this,RelationType.DEFINED,LinkDirection.FROM, item.field);
});

const rightFriendFields = this.plugin.hierarchyLowerCase.rightFriends;
getDVFieldLinksForPage(this.plugin,dvPage,rightFriendFields).forEach(item=>{
const referencedPage = this.pages.get(item.link);
let referencedPage = this.pages.get(item.link);
if(!referencedPage) {
//log(`Unexpected: ${this.file.path} references ${item.link} in DV, but it was not found in app.metadataCache. The page was skipped.`);
return;
referencedPage = addUnresolvedPage(item.link, this, this.plugin, this.plugin.pages)
//log(`Unexpected: ${this.file.path} references ${item.link} in DV, but it was not found in app.metadataCache. The page was skipped.`);
//return;
}
this.addRightFriend(referencedPage,RelationType.DEFINED,LinkDirection.TO,item.field);
referencedPage.addRightFriend(this,RelationType.DEFINED,LinkDirection.FROM, item.field);
});

const previousFields = this.plugin.hierarchyLowerCase.previous;
getDVFieldLinksForPage(this.plugin,dvPage,previousFields).forEach(item=>{
const referencedPage = this.pages.get(item.link);
let referencedPage = this.pages.get(item.link);
if(!referencedPage) {
//log(`Unexpected: ${this.file.path} references ${item.link} in DV, but it was not found in app.metadataCache. The page was skipped.`);
return;
referencedPage = addUnresolvedPage(item.link, this, this.plugin, this.plugin.pages)
//log(`Unexpected: ${this.file.path} references ${item.link} in DV, but it was not found in app.metadataCache. The page was skipped.`);
//return;
}
this.addLeftFriend(referencedPage,RelationType.DEFINED,LinkDirection.TO,item.field);
referencedPage.addRightFriend(this,RelationType.DEFINED,LinkDirection.FROM, item.field);
});

const nextFields = this.plugin.hierarchyLowerCase.next;
getDVFieldLinksForPage(this.plugin,dvPage,nextFields).forEach(item=>{
const referencedPage = this.pages.get(item.link);
let referencedPage = this.pages.get(item.link);
if(!referencedPage) {
//log(`Unexpected: ${this.file.path} references ${item.link} in DV, but it was not found in app.metadataCache. The page was skipped.`);
return;
referencedPage = addUnresolvedPage(item.link, this, this.plugin, this.plugin.pages)
//log(`Unexpected: ${this.file.path} references ${item.link} in DV, but it was not found in app.metadataCache. The page was skipped.`);
//return;
}
this.addRightFriend(referencedPage,RelationType.DEFINED,LinkDirection.TO,item.field);
referencedPage.addLeftFriend(this,RelationType.DEFINED,LinkDirection.FROM, item.field);
Expand Down
37 changes: 21 additions & 16 deletions src/graph/Pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,27 @@ export class Pages {
if(parentPath === this.plugin.settings.excalibrainFilepath) {
return;
}
Object.keys(unresolvedLinks[parentPath]).forEach(childPath=>{
const newPage = this.get(childPath) ?? new Page(this,childPath,null,this.plugin);
if(this.plugin.settings.inferAllLinksAsFriends) {
newPage.addLeftFriend(parent,RelationType.INFERRED, LinkDirection.FROM);
parent.addLeftFriend(newPage,RelationType.INFERRED, LinkDirection.TO);
} else {
if(this.plugin.settings.inverseInfer) { //https://github.com/zsviczian/excalibrain/issues/78
newPage.addChild(parent,RelationType.INFERRED, LinkDirection.FROM);
parent.addParent(newPage,RelationType.INFERRED, LinkDirection.TO);
} else {
newPage.addParent(parent,RelationType.INFERRED, LinkDirection.FROM);
parent.addChild(newPage,RelationType.INFERRED, LinkDirection.TO);
}
}
this.add(childPath,newPage);
})
Object.keys(unresolvedLinks[parentPath]).forEach(childPath=>
addUnresolvedPage(childPath, parent, this.plugin, this)
);
});
}
}

export const addUnresolvedPage = (childPath: string, parent: Page, plugin: ExcaliBrain, pages: Pages):Page => {
const newPage = pages.get(childPath) ?? new Page(pages,childPath,null,plugin);
if(plugin.settings.inferAllLinksAsFriends) {
newPage.addLeftFriend(parent,RelationType.INFERRED, LinkDirection.FROM);
parent.addLeftFriend(newPage,RelationType.INFERRED, LinkDirection.TO);
} else {
if(plugin.settings.inverseInfer) { //https://github.com/zsviczian/excalibrain/issues/78
newPage.addChild(parent,RelationType.INFERRED, LinkDirection.FROM);
parent.addParent(newPage,RelationType.INFERRED, LinkDirection.TO);
} else {
newPage.addParent(parent,RelationType.INFERRED, LinkDirection.FROM);
parent.addChild(newPage,RelationType.INFERRED, LinkDirection.TO);
}
}
pages.add(childPath,newPage);
return newPage;
}
7 changes: 7 additions & 0 deletions src/utils/dataview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ const readDVField = (app: App, field: any, file:TFile):string[] => {
}
});

values
.filter((l:any)=>Boolean(l?.values))
.forEach((l:any)=>{
const values = Array.from(l.values());
readDVField(app,values,file).forEach(p=>res.add(p))
});

//string: e.g. list of virtual links
const stringLinks:string[] = readLinksFromString(values
.filter((l:any)=>typeof l === "string")
Expand Down

0 comments on commit 210b195

Please sign in to comment.