generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Stats View): ✨ Initial Stats View set up, no content yet
- Loading branch information
1 parent
7f4078d
commit bfe0227
Showing
6 changed files
with
141 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import type { Graph } from "graphlib"; | ||
import { ItemView, WorkspaceLeaf } from "obsidian"; | ||
import { | ||
DATAVIEW_INDEX_DELAY, | ||
VIEW_TYPE_BREADCRUMBS_STATS, | ||
} from "src/constants"; | ||
import type BreadcrumbsPlugin from "src/main"; | ||
import Stats from "./Components/Stats.svelte"; | ||
|
||
export default class StatsView extends ItemView { | ||
private plugin: BreadcrumbsPlugin; | ||
private view: Stats; | ||
|
||
constructor(leaf: WorkspaceLeaf, plugin: BreadcrumbsPlugin) { | ||
super(leaf); | ||
this.plugin = plugin; | ||
} | ||
|
||
async onload(): Promise<void> { | ||
super.onload(); | ||
await this.plugin.saveSettings(); | ||
this.app.workspace.onLayoutReady(async () => { | ||
setTimeout(async () => await this.draw(), DATAVIEW_INDEX_DELAY); | ||
}); | ||
} | ||
|
||
getViewType() { | ||
return VIEW_TYPE_BREADCRUMBS_STATS; | ||
} | ||
getDisplayText() { | ||
return "Breadcrumbs Stats"; | ||
} | ||
|
||
icon = "bullet-list-glyph"; | ||
|
||
async onOpen(): Promise<void> { | ||
await this.plugin.saveSettings(); | ||
} | ||
|
||
onClose(): Promise<void> { | ||
if (this.view) { | ||
this.view.$destroy(); | ||
} | ||
return Promise.resolve(); | ||
} | ||
|
||
// ANCHOR Remove duplicate implied links | ||
|
||
dfsAllPaths(g: Graph, startNode: string): string[][] { | ||
const queue: { node: string; path: string[] }[] = [ | ||
{ node: startNode, path: [] }, | ||
]; | ||
const pathsArr: string[][] = []; | ||
|
||
let i = 0; | ||
while (queue.length > 0 && i < 1000) { | ||
i++; | ||
const currPath = queue.shift(); | ||
|
||
const newNodes = (g.successors(currPath.node) ?? []) as string[]; | ||
const extPath = [currPath.node, ...currPath.path]; | ||
queue.unshift( | ||
...newNodes.map((n: string) => { | ||
return { node: n, path: extPath }; | ||
}) | ||
); | ||
|
||
if (newNodes.length === 0) { | ||
pathsArr.push(extPath); | ||
} | ||
} | ||
return pathsArr; | ||
} | ||
|
||
async draw(): Promise<void> { | ||
this.contentEl.empty(); | ||
// const { gParents, gSiblings, gChildren } = this.plugin.currGraphs; | ||
// const currFile = this.app.workspace.getActiveFile(); | ||
// const settings = this.plugin.settings; | ||
|
||
this.view = new Stats({ | ||
target: this.contentEl, | ||
props: {}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters