Skip to content

Commit

Permalink
fix: 🐛 More granular graph building + fix order issues
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Nov 24, 2021
1 parent ff679cc commit 72b0243
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 80 deletions.
57 changes: 33 additions & 24 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -49369,6 +49369,10 @@ class BCPlugin extends obsidian.Plugin {
}
}
};
this.getTargetOrder = (fileFrontmatterArr, target) => {
var _a, _b;
return (_b = parseInt((_a = fileFrontmatterArr.find((arr) => arr.file.basename === target)) === null || _a === void 0 ? void 0 : _a.order)) !== null && _b !== void 0 ? _b : 9999;
};
}
async refreshIndex() {
var _a;
Expand Down Expand Up @@ -49659,28 +49663,26 @@ class BCPlugin extends obsidian.Plugin {
return fileFrontmatterArr;
}
// SECTION OneSource
populateMain(main, basename, dir, field, targets, sourceOrder, fileFrontmatterArr) {
addNodesIfNot(main, [basename], {
populateMain(mainG, source, dir, field, target, sourceOrder, targetOrder) {
addNodesIfNot(mainG, [source], {
//@ts-ignore
dir,
field,
order: sourceOrder,
});
targets.forEach((target) => {
var _a, _b;
const targetOrder = (_b = parseInt((_a = fileFrontmatterArr.find((arr) => arr.file.basename === target)) === null || _a === void 0 ? void 0 : _a.order)) !== null && _b !== void 0 ? _b : 9999;
addNodesIfNot(main, [target], {
//@ts-ignore
dir,
field,
order: targetOrder,
});
addEdgeIfNot(main, basename, target, {
//@ts-ignore
dir,
field,
});
// targets.forEach((target) => {
addNodesIfNot(mainG, [target], {
//@ts-ignore
dir,
field,
order: targetOrder,
});
addEdgeIfNot(mainG, source, target, {
//@ts-ignore
dir,
field,
});
// });
}
async getCSVRows() {
const { CSVPaths } = this.settings;
Expand Down Expand Up @@ -49877,12 +49879,14 @@ class BCPlugin extends obsidian.Plugin {
jugglLinks.forEach((jugglLink) => {
const { basename } = jugglLink.file;
jugglLink.links.forEach((link) => {
var _a, _b;
const { dir, field, linksInLine } = link;
if (dir === "")
return;
const sourceOrder = (_b = parseInt((_a = fileFrontmatterArr.find((arr) => arr.file.basename === basename)) === null || _a === void 0 ? void 0 : _a.order)) !== null && _b !== void 0 ? _b : 9999;
this.populateMain(mainG, basename, dir, field, linksInLine, sourceOrder, fileFrontmatterArr);
const sourceOrder = this.getTargetOrder(fileFrontmatterArr, basename);
linksInLine.forEach((linkInLine) => {
const targetsOrder = this.getTargetOrder(fileFrontmatterArr, linkInLine);
this.populateMain(mainG, basename, dir, field, linkInLine, sourceOrder, targetsOrder);
});
});
});
}
Expand Down Expand Up @@ -49910,8 +49914,9 @@ class BCPlugin extends obsidian.Plugin {
var _a;
// This is getting the order of the folder note, not the source pointing up to it
const sourceOrder = (_a = parseInt(fileFront.order)) !== null && _a !== void 0 ? _a : 9999;
this.populateMain(mainG, source, "up", field, [folderNoteBasename], sourceOrder, fileFrontmatterArr);
this.populateMain(mainG, folderNoteBasename, "down", oppField, [source], sourceOrder, fileFrontmatterArr);
const targetOrder = this.getTargetOrder(fileFrontmatterArr, folderNoteBasename);
this.populateMain(mainG, source, "up", field, folderNoteBasename, sourceOrder, targetOrder);
this.populateMain(mainG, folderNoteBasename, "down", oppField, source, targetOrder, sourceOrder);
});
}
});
Expand Down Expand Up @@ -49947,8 +49952,9 @@ class BCPlugin extends obsidian.Plugin {
var _a;
// This is getting the order of the folder note, not the source pointing up to it
const sourceOrder = (_a = parseInt(fileFront.order)) !== null && _a !== void 0 ? _a : 9999;
this.populateMain(mainG, source, "up", field, [tagNoteBasename], sourceOrder, fileFrontmatterArr);
this.populateMain(mainG, tagNoteBasename, "down", oppField, [source], sourceOrder, fileFrontmatterArr);
const targetOrder = this.getTargetOrder(fileFrontmatterArr, tagNoteBasename);
this.populateMain(mainG, source, "up", field, tagNoteBasename, sourceOrder, targetOrder);
this.populateMain(mainG, tagNoteBasename, "down", oppField, source, targetOrder, sourceOrder);
});
}
});
Expand Down Expand Up @@ -49976,7 +49982,10 @@ class BCPlugin extends obsidian.Plugin {
var _a;
const values = this.parseFieldValue(fileFrontmatter[field]);
const sourceOrder = (_a = parseInt(fileFrontmatter.order)) !== null && _a !== void 0 ? _a : 9999;
this.populateMain(mainG, basename, dir, field, values, sourceOrder, fileFrontmatterArr);
values.forEach((target) => {
const targetOrder = this.getTargetOrder(fileFrontmatterArr, target);
this.populateMain(mainG, basename, dir, field, target, sourceOrder, targetOrder);
});
if (useCSV)
this.addCSVCrumbs(mainG, CSVRows, dir, field);
});
Expand Down
130 changes: 74 additions & 56 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,37 +465,34 @@ export default class BCPlugin extends Plugin {
// SECTION OneSource

populateMain(
main: MultiGraph,
basename: string,
mainG: MultiGraph,
source: string,
dir: Directions,
field: string,
targets: string[],
target: string,
sourceOrder: number,
fileFrontmatterArr: dvFrontmatterCache[]
targetOrder: number
): void {
addNodesIfNot(main, [basename], {
addNodesIfNot(mainG, [source], {
//@ts-ignore
dir,
field,
order: sourceOrder,
});
targets.forEach((target) => {
const targetOrder =
parseInt(
fileFrontmatterArr.find((arr) => arr.file.basename === target)?.order
) ?? 9999;
addNodesIfNot(main, [target], {
//@ts-ignore
dir,
field,
order: targetOrder,
});
addEdgeIfNot(main, basename, target, {
//@ts-ignore
dir,
field,
});
// targets.forEach((target) => {

addNodesIfNot(mainG, [target], {
//@ts-ignore
dir,
field,
order: targetOrder,
});
addEdgeIfNot(mainG, source, target, {
//@ts-ignore
dir,
field,
});
// });
}

async getCSVRows() {
Expand Down Expand Up @@ -730,20 +727,23 @@ export default class BCPlugin extends Plugin {
jugglLink.links.forEach((link) => {
const { dir, field, linksInLine } = link;
if (dir === "") return;
const sourceOrder =
parseInt(
fileFrontmatterArr.find((arr) => arr.file.basename === basename)
?.order
) ?? 9999;
this.populateMain(
mainG,
basename,
dir,
field,
linksInLine,
sourceOrder,
fileFrontmatterArr
);
const sourceOrder = this.getTargetOrder(fileFrontmatterArr, basename);
linksInLine.forEach((linkInLine) => {
const targetsOrder = this.getTargetOrder(
fileFrontmatterArr,
linkInLine
);

this.populateMain(
mainG,
basename,
dir,
field,
linkInLine,
sourceOrder,
targetsOrder
);
});
});
});
}
Expand Down Expand Up @@ -780,24 +780,28 @@ export default class BCPlugin extends Plugin {

sources.forEach((source) => {
// This is getting the order of the folder note, not the source pointing up to it
const sourceOrder = parseInt(fileFront.order) ?? 9999;
const sourceOrder = parseInt(fileFront.order as string) ?? 9999;
const targetOrder = this.getTargetOrder(
fileFrontmatterArr,
folderNoteBasename
);
this.populateMain(
mainG,
source,
"up",
field as string,
[folderNoteBasename],
folderNoteBasename,
sourceOrder,
fileFrontmatterArr
targetOrder
);
this.populateMain(
mainG,
folderNoteBasename,
"down",
oppField,
[source],
sourceOrder,
fileFrontmatterArr
source,
targetOrder,
sourceOrder
);
});
}
Expand Down Expand Up @@ -841,30 +845,40 @@ export default class BCPlugin extends Plugin {

sources.forEach((source) => {
// This is getting the order of the folder note, not the source pointing up to it
const sourceOrder = parseInt(fileFront.order) ?? 9999;
const sourceOrder = parseInt(fileFront.order as string) ?? 9999;
const targetOrder = this.getTargetOrder(
fileFrontmatterArr,
tagNoteBasename
);
this.populateMain(
mainG,
source,
"up",
field as string,
[tagNoteBasename],
tagNoteBasename,
sourceOrder,
fileFrontmatterArr
targetOrder
);
this.populateMain(
mainG,
tagNoteBasename,
"down",
oppField,
[source],
sourceOrder,
fileFrontmatterArr
source,
targetOrder,
sourceOrder
);
});
}
});
}

getTargetOrder = (fileFrontmatterArr: dvFrontmatterCache[], target: string) =>
parseInt(
fileFrontmatterArr.find((arr) => arr.file.basename === target)
?.order as string
) ?? 9999;

async initGraphs(): Promise<MultiGraph> {
const { settings, app } = this;
debugGroupStart(settings, "debugMode", "Initialise Graphs");
Expand All @@ -891,15 +905,19 @@ export default class BCPlugin extends Plugin {
iterateHiers(userHiers, (hier, dir, field) => {
const values = this.parseFieldValue(fileFrontmatter[field]);
const sourceOrder = parseInt(fileFrontmatter.order as string) ?? 9999;
this.populateMain(
mainG,
basename,
dir,
field,
values,
sourceOrder,
fileFrontmatterArr
);

values.forEach((target) => {
const targetOrder = this.getTargetOrder(fileFrontmatterArr, target);
this.populateMain(
mainG,
basename,
dir,
field,
target,
sourceOrder,
targetOrder
);
});
if (useCSV) this.addCSVCrumbs(mainG, CSVRows, dir, field);
});
});
Expand Down

0 comments on commit 72b0243

Please sign in to comment.