From 651b7ea5cc289ccb78c28bf822c633df44fdc0b6 Mon Sep 17 00:00:00 2001 From: Emile Date: Mon, 11 Oct 2021 10:00:41 +0200 Subject: [PATCH] fix: Better handling of indexing on initial load of Obsidian --- src/Components/CoCitations.svelte | 2 +- src/MyGraph.ts | 7 +++---- src/Utility.ts | 1 + src/main.ts | 18 ++++++++---------- tsconfig.json | 2 +- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/Components/CoCitations.svelte b/src/Components/CoCitations.svelte index 2eaea3c..4f80885 100644 --- a/src/Components/CoCitations.svelte +++ b/src/Components/CoCitations.svelte @@ -42,7 +42,7 @@ .sort((a, b) => (a.measure > b.measure ? -1 : 1)) ) .then((res) => { - console.log({ res }) + debug(settings, {res}); return res }) diff --git a/src/MyGraph.ts b/src/MyGraph.ts index c80ab68..4cf7667 100644 --- a/src/MyGraph.ts +++ b/src/MyGraph.ts @@ -19,7 +19,7 @@ export default class MyGraph extends Graph { nodeMapping: { [name: string]: number } = {} - initGraph(): MyGraph { + async initGraph(): Promise { let i = 0; for (const source in this.resolvedLinks) { if (source.split('.').last() === 'md') { @@ -48,11 +48,10 @@ export default class MyGraph extends Graph { // 'Closeness': [] }; - initData(): void { + async initData(): Promise { const n = this.nodes().length; Object.keys(this.data).forEach((key: Subtypes) => { - const nxnMatrix: undefined[][] = nxnArray(n); - this.data[key] = nxnMatrix + this.data[key] = nxnArray(n); }) } diff --git a/src/Utility.ts b/src/Utility.ts index 59e4a80..bfd97fe 100644 --- a/src/Utility.ts +++ b/src/Utility.ts @@ -135,6 +135,7 @@ export const createOrUpdateYaml = async ( file: TFile, app: App ) => { + // @ts-ignore const api = app.plugins.plugins.metaedit?.api if (!api) { diff --git a/src/main.ts b/src/main.ts index b21788c..b09c928 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,6 +4,7 @@ import { DEFAULT_SETTINGS, VIEW_TYPE_GRAPH_ANALYSIS } from "src/Constants"; import type { GraphAnalysisSettings } from 'src/Interfaces'; import MyGraph from 'src/MyGraph'; import { SampleSettingTab } from 'src/Settings'; +import { debug } from './Utility' export default class GraphAnalysisPlugin extends Plugin { @@ -36,24 +37,21 @@ export default class GraphAnalysisPlugin extends Plugin { this.app.workspace.onLayoutReady(() => { - setTimeout(() => { + setTimeout(async () => { console.time('Initialise Graph') const { resolvedLinks } = this.app.metadataCache; this.g = new MyGraph(resolvedLinks, this.app); - this.g.initGraph(); - this.g.initData(); - console.log({ g: this.g }) + await this.g.initGraph(); + await this.g.initData(); + debug(this.settings, {g: this.g}); console.timeEnd('Initialise Graph') - - }, 2000) - setTimeout(() => { this.registerView( VIEW_TYPE_GRAPH_ANALYSIS, (leaf: WorkspaceLeaf) => (this.view = new AnalysisView(leaf, this)) ); - this.initView(VIEW_TYPE_GRAPH_ANALYSIS); - }, 3000) - }) + await this.initView(VIEW_TYPE_GRAPH_ANALYSIS); + }, 13000) + }); this.registerEvent(this.app.workspace.on('active-leaf-change', () => { // const currNode = this.app.workspace.getActiveFile().path.split('.md', 1)[0] diff --git a/tsconfig.json b/tsconfig.json index 5d4e33d..8958f28 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,7 +12,7 @@ "noImplicitAny": true, "moduleResolution": "node", "importHelpers": true, - "lib": ["dom", "es5", "scripthost", "es2015"], + "lib": ["dom", "es5", "scripthost", "es2019"], "types": ["node", "svelte"], "paths": { "src": ["src/*"]