Skip to content

Commit

Permalink
fix: Better handling of indexing on initial load of Obsidian
Browse files Browse the repository at this point in the history
  • Loading branch information
HEmile committed Oct 11, 2021
1 parent 9b222f9 commit 651b7ea
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Components/CoCitations.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
.sort((a, b) => (a.measure > b.measure ? -1 : 1))
)
.then((res) => {
console.log({ res })
debug(settings, {res});
return res
})
Expand Down
7 changes: 3 additions & 4 deletions src/MyGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class MyGraph extends Graph {

nodeMapping: { [name: string]: number } = {}

initGraph(): MyGraph {
async initGraph(): Promise<MyGraph> {
let i = 0;
for (const source in this.resolvedLinks) {
if (source.split('.').last() === 'md') {
Expand Down Expand Up @@ -48,11 +48,10 @@ export default class MyGraph extends Graph {
// 'Closeness': []
};

initData(): void {
async initData(): Promise<void> {
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);
})
}

Expand Down
1 change: 1 addition & 0 deletions src/Utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export const createOrUpdateYaml = async (
file: TFile,
app: App
) => {
// @ts-ignore
const api = app.plugins.plugins.metaedit?.api

if (!api) {
Expand Down
18 changes: 8 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/*"]
Expand Down

0 comments on commit 651b7ea

Please sign in to comment.