diff --git a/src/BreadcrumbsSettingTab.ts b/src/BreadcrumbsSettingTab.ts index 273cf8a3..4ecb0e17 100644 --- a/src/BreadcrumbsSettingTab.ts +++ b/src/BreadcrumbsSettingTab.ts @@ -85,7 +85,7 @@ export class BreadcrumbsSettingTab extends PluginSettingTab { plugin.currGraphs = await plugin.initGraphs(); } if (plugin.trailDiv) { - await plugin.drawTrail(plugin.currGraphs.gParents); + await plugin.drawTrail(); } if (plugin.matrixView) { await plugin.matrixView.draw(); @@ -166,7 +166,7 @@ export class BreadcrumbsSettingTab extends PluginSettingTab { : "" }`, }); - await plugin.drawTrail(plugin.currGraphs.gParents); + await plugin.drawTrail(); } else { plugin.trailDiv.remove(); } @@ -182,7 +182,7 @@ export class BreadcrumbsSettingTab extends PluginSettingTab { let finalValue: string[]; text .setPlaceholder("Index Note") - .setValue(plugin.settings.indexNote.join(", ")) + .setValue([plugin.settings.indexNote].flat().join(", ")) .onChange(async (value) => { finalValue = splitAndTrim(value); }); diff --git a/src/MatrixView.ts b/src/MatrixView.ts index fb6fc72d..be487ec1 100644 --- a/src/MatrixView.ts +++ b/src/MatrixView.ts @@ -87,18 +87,6 @@ export default class MatrixView extends ItemView { // ANCHOR Remove duplicate implied links - // removeDuplicateImpliedBetter( - // real: internalLinkObj[], - // implied: internalLinkObj[] - // ): internalLinkObj[] { - // implied = implied.filter((impliedItem, i, self) => { - // real.forEach((realItem) => { - // return !(i === self.findIndex((t) => t.to)); - // }); - // }); - // return implied; - // } - removeDuplicateImplied( real: internalLinkObj[], implied: internalLinkObj[] @@ -116,21 +104,67 @@ export default class MatrixView extends ItemView { }); } + nextLevel(obj: { [x: string]: any }, gChildren: Graph): void { + for (const child in obj) { + if (Object.prototype.hasOwnProperty.call(obj, child)) { + const childrenOfChild = (gChildren.successors(obj[child]) ?? + []) as string[]; + childrenOfChild.forEach((innerChild) => (obj[child] = { innerChild })); + obj[child] = { ...childrenOfChild }; + } + } + } + + // createIndexObj(gChildren: Graph, currFile: string, depth: number) { + // const initialChildren: [string, number][][] = [[]]; + + // const immediateChildren = (gChildren.successors(currFile) ?? + // []) as string[]; + // immediateChildren.forEach((child) => initialChildren[0].push([child, 1])); + + // console.log(initialChildren); + + // for (let i = 0; i < depth; i++) { + // initialChildren.push([]); + // initialChildren[i].forEach((childArr) => { + // const childrenOfChild = ( + // (gChildren.successors(childArr[0]) ?? []) as string[] + // ).map((child) => [child, i + 2]); + // initialChildren[i + 1].push(childrenOfChild); + // }); + // } + // console.log(initialChildren); + // } + async draw(): Promise { this.contentEl.empty(); - this.currGraphs = this.plugin.currGraphs; - const currFile = this.app.workspace.getActiveFile(); - const settings = this.plugin.settings; - const button = this.contentEl.createEl("button", { + const viewToggleButton = this.contentEl.createEl("button", { text: this.matrixQ ? "List" : "Matrix", }); - button.addEventListener("click", async () => { + viewToggleButton.addEventListener("click", async () => { this.matrixQ = !this.matrixQ; - button.innerText = this.matrixQ ? "List" : "Matrix"; + viewToggleButton.innerText = this.matrixQ ? "List" : "Matrix"; await this.draw(); }); + // const createIndexButton = this.contentEl.createEl("button", { + // text: "Create Index", + // }); + // createIndexButton.addEventListener("click", () => + // console.log( + // this.createIndexObj( + // this.plugin.currGraphs.gChildren, + // currFile.basename, + // 2 + // ) + // ) + // ); + + this.currGraphs = this.plugin.currGraphs; + const currFile = this.app.workspace.getActiveFile(); + const settings = this.plugin.settings; + const [parentFieldName, siblingFieldName, childFieldName] = [ settings.showNameOrType ? settings.parentFieldName : "Parent", settings.showNameOrType ? settings.siblingFieldName : "Sibling", diff --git a/src/main.ts b/src/main.ts index de7ec83b..0070b019 100644 --- a/src/main.ts +++ b/src/main.ts @@ -168,7 +168,7 @@ export default class BreadcrumbsPlugin extends Plugin { getShortestBreadcrumbs(g: Graph): string[] { const from = this.app.workspace.getActiveFile().basename; const paths = graphlib.alg.dijkstra(g, from); - const indexNotes: string[] = this.settings.indexNote; + const indexNotes: string[] = [this.settings.indexNote].flat(); const allTrails: string[][] = [];