Skip to content

Commit

Permalink
feat(Stats View): ✨ Initial Stats View set up, no content yet
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Aug 2, 2021
1 parent 7f4078d commit bfe0227
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 17 deletions.
10 changes: 5 additions & 5 deletions src/BreadcrumbsSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ export class BreadcrumbsSettingTab extends PluginSettingTab {
if (plugin.settings.showTrail) {
await plugin.drawTrail();
}
if (plugin.getActiveView()) {
await plugin.getActiveView().draw();
if (plugin.getActiveMatrixView()) {
await plugin.getActiveMatrixView().draw();
}
}, num * 1000);
plugin.registerInterval(plugin.refreshIntervalID);
Expand Down Expand Up @@ -131,7 +131,7 @@ export class BreadcrumbsSettingTab extends PluginSettingTab {
.onChange(async (value) => {
plugin.settings.showNameOrType = value;
await plugin.saveSettings();
await plugin.getActiveView().draw();
await plugin.getActiveMatrixView().draw();
})
);

Expand All @@ -146,7 +146,7 @@ export class BreadcrumbsSettingTab extends PluginSettingTab {
.onChange(async (value) => {
plugin.settings.showRelationType = value;
await plugin.saveSettings();
await plugin.getActiveView().draw();
await plugin.getActiveMatrixView().draw();
})
);

Expand Down Expand Up @@ -297,7 +297,7 @@ export class BreadcrumbsSettingTab extends PluginSettingTab {
plugin.settings.trailSeperator = value;
await plugin.saveSettings();
// BUG This doesn't seem to work... you still have to switch notes for it to redraw
await plugin.getActiveView().draw();
await plugin.getActiveMatrixView().draw();
})
);

Expand Down
Empty file added src/Components/Stats.svelte
Empty file.
6 changes: 2 additions & 4 deletions src/MatrixView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,10 @@ export default class MatrixView extends ItemView {
});
}

getViewType(): string {
getViewType() {
return VIEW_TYPE_BREADCRUMBS_MATRIX;
}

getDisplayText(): string {
getDisplayText() {
return "Breadcrumbs Matrix";
}

Expand Down Expand Up @@ -241,7 +240,6 @@ export default class MatrixView extends ItemView {

async draw(): Promise<void> {
this.contentEl.empty();
// this.currGraphs = this.plugin.currGraphs;
const { gParents, gSiblings, gChildren } = this.plugin.currGraphs;
const currFile = this.app.workspace.getActiveFile();
const settings = this.plugin.settings;
Expand Down
86 changes: 86 additions & 0 deletions src/StatsView.ts
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: {},
});
}
}
4 changes: 3 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export const VIEW_TYPE_BREADCRUMBS_MATRIX = "breadcrumbs-matrix";
export const VIEW_TYPE_BREADCRUMBS_STATS = "breadcrumbs-stats";

export const TRAIL_ICON = "breadcrumbs-trail-icon";
export const TRAIL_ICON_SVG = '<path fill="currentColor" stroke="currentColor" d="M48.8,4c-6,0-13.5,0.5-19.7,3.3S17.9,15.9,17.9,25c0,5,2.6,9.7,6.1,13.9s8.1,8.3,12.6,12.3s9,7.8,12.2,11.5 c3.2,3.7,5.1,7.1,5.1,10.2c0,14.4-13.4,19.3-13.4,19.3c-0.7,0.2-1.2,0.8-1.3,1.5s0.1,1.4,0.7,1.9c0.6,0.5,1.3,0.6,2,0.3 c0,0,16.1-6.1,16.1-23c0-4.6-2.6-8.8-6.1-12.8c-3.5-4-8.1-7.9-12.6-11.8c-4.5-3.9-8.9-7.9-12.2-11.8c-3.2-3.9-5.2-7.7-5.2-11.4 c0-7.8,3.6-11.6,8.8-14S43,8,48.8,8c4.6,0,9.3,0,11,0c0.7,0,1.4-0.4,1.7-1c0.3-0.6,0.3-1.4,0-2s-1-1-1.7-1C58.3,4,53.4,4,48.8,4 L48.8,4z M78.1,4c-0.6,0-1.2,0.2-1.6,0.7l-8.9,9.9c-0.5,0.6-0.7,1.4-0.3,2.2c0.3,0.7,1,1.2,1.8,1.2h0.1l-2.8,2.6 c-0.6,0.6-0.8,1.4-0.5,2.2c0.3,0.8,1,1.3,1.9,1.3h1.3l-4.5,4.6c-0.6,0.6-0.7,1.4-0.4,2.2c0.3,0.7,1,1.2,1.8,1.2h10v4 c0,0.7,0.4,1.4,1,1.8c0.6,0.4,1.4,0.4,2,0c0.6-0.4,1-1,1-1.8v-4h10c0.8,0,1.5-0.5,1.8-1.2c0.3-0.7,0.1-1.6-0.4-2.2L86.9,24h1.3 c0.8,0,1.6-0.5,1.9-1.3c0.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.5,6.8c-0.6,0.6-0.7,1.4-0.4,2.2s1,1.2,1.8,1.2H13l-8.5,8.6 C4,83.2,3.8,84,4.2,84.8C4.5,85.5,5.2,86,6,86h16v5.4c0,0.7,0.4,1.4,1,1.8c0.6,0.4,1.4,0.4,2,0c0.6-0.4,1-1,1-1.8V86h16 c0.8,0,1.5-0.5,1.8-1.2c0.3-0.7,0.1-1.6-0.4-2.2L35,74h4.4c0.8,0,1.5-0.5,1.8-1.2s0.2-1.6-0.4-2.2l-6.5-6.8h3 c0.8,0,1.5-0.5,1.8-1.2c0.3-0.7,0.2-1.6-0.4-2.2L25.4,46.6C25.1,46.2,24.5,46,24,46L24,46z M24,50.9l8.7,9h-3 c-0.8,0-1.5,0.5-1.8,1.2s-0.2,1.6,0.4,2.2l6.5,6.8h-4.5c-0.8,0-1.5,0.5-1.8,1.2c-0.3,0.7-0.1,1.6,0.4,2.2l8.5,8.6H10.8l8.5-8.6 c0.6-0.6,0.7-1.4,0.4-2.2c-0.3-0.7-1-1.2-1.8-1.2h-4.5l6.5-6.8c0.6-0.6,0.7-1.4,0.4-2.2c-0.3-0.7-1-1.2-1.8-1.2h-3L24,50.9z"/>'
export const TRAIL_ICON_SVG =
'<path fill="currentColor" stroke="currentColor" d="M48.8,4c-6,0-13.5,0.5-19.7,3.3S17.9,15.9,17.9,25c0,5,2.6,9.7,6.1,13.9s8.1,8.3,12.6,12.3s9,7.8,12.2,11.5 c3.2,3.7,5.1,7.1,5.1,10.2c0,14.4-13.4,19.3-13.4,19.3c-0.7,0.2-1.2,0.8-1.3,1.5s0.1,1.4,0.7,1.9c0.6,0.5,1.3,0.6,2,0.3 c0,0,16.1-6.1,16.1-23c0-4.6-2.6-8.8-6.1-12.8c-3.5-4-8.1-7.9-12.6-11.8c-4.5-3.9-8.9-7.9-12.2-11.8c-3.2-3.9-5.2-7.7-5.2-11.4 c0-7.8,3.6-11.6,8.8-14S43,8,48.8,8c4.6,0,9.3,0,11,0c0.7,0,1.4-0.4,1.7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LinksRegex = new RegExp(/\[\[(.+?)\]\]/g);
export const dropHeaderOrAlias = new RegExp(/\[\[([^#|]+)\]\]/);
Expand Down
52 changes: 45 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
TRAIL_ICON,
TRAIL_ICON_SVG,
VIEW_TYPE_BREADCRUMBS_MATRIX,
VIEW_TYPE_BREADCRUMBS_STATS,
} from "src/constants";
import type {
allGraphs,
Expand All @@ -14,6 +15,7 @@ import type {
neighbourObj,
} from "src/interfaces";
import MatrixView from "src/MatrixView";
import StatsView from "src/StatsView";
import {
closeImpliedLinks,
debug,
Expand Down Expand Up @@ -75,6 +77,11 @@ export default class BreadcrumbsPlugin extends Plugin {

this.visited = [];

this.registerView(
VIEW_TYPE_BREADCRUMBS_STATS,
(leaf: WorkspaceLeaf) => new StatsView(leaf, this)
);

this.registerView(
VIEW_TYPE_BREADCRUMBS_MATRIX,
(leaf: WorkspaceLeaf) => new MatrixView(leaf, this)
Expand All @@ -85,7 +92,9 @@ export default class BreadcrumbsPlugin extends Plugin {
setTimeout(async () => {
this.currGraphs = await this.initGraphs();

this.initView(VIEW_TYPE_BREADCRUMBS_MATRIX);
this.initStatsView(VIEW_TYPE_BREADCRUMBS_STATS);

this.initMatrixView(VIEW_TYPE_BREADCRUMBS_MATRIX);

if (this.settings.showTrail) {
await this.drawTrail();
Expand All @@ -95,7 +104,7 @@ export default class BreadcrumbsPlugin extends Plugin {
this.app.workspace.on("active-leaf-change", async () => {
this.currGraphs = await this.initGraphs();
debug(this.settings, this.currGraphs);
const activeView = this.getActiveView();
const activeView = this.getActiveMatrixView();
if (activeView) {
await activeView.draw();
}
Expand All @@ -112,7 +121,7 @@ export default class BreadcrumbsPlugin extends Plugin {
if (this.settings.showTrail) {
await this.drawTrail();
}
const activeView = this.getActiveView();
const activeView = this.getActiveMatrixView();
if (activeView) {
await activeView.draw();
}
Expand All @@ -134,14 +143,28 @@ export default class BreadcrumbsPlugin extends Plugin {
.length === 0
);
}
this.initView(VIEW_TYPE_BREADCRUMBS_MATRIX);
this.initMatrixView(VIEW_TYPE_BREADCRUMBS_MATRIX);
},
});

this.addCommand({
id: "show-breadcrumbs-stats-view",
name: "Open Stats View",
checkCallback: (checking: boolean) => {
if (checking) {
return (
this.app.workspace.getLeavesOfType(VIEW_TYPE_BREADCRUMBS_STATS)
.length === 0
);
}
this.initStatsView(VIEW_TYPE_BREADCRUMBS_STATS);
},
});

this.addSettingTab(new BreadcrumbsSettingTab(this.app, this));
}

getActiveView(): MatrixView | null {
getActiveMatrixView(): MatrixView | null {
const leaves = this.app.workspace.getLeavesOfType(
VIEW_TYPE_BREADCRUMBS_MATRIX
);
Expand Down Expand Up @@ -374,7 +397,7 @@ export default class BreadcrumbsPlugin extends Plugin {
}
}

initView = async (type: string): Promise<void> => {
initMatrixView = async (type: string): Promise<void> => {
let leaf: WorkspaceLeaf = null;
for (leaf of this.app.workspace.getLeavesOfType(type)) {
if (leaf.view instanceof MatrixView) {
Expand All @@ -385,7 +408,22 @@ export default class BreadcrumbsPlugin extends Plugin {
}
(leaf ?? this.app.workspace.getRightLeaf(false)).setViewState({
type,
active: true,
active: false,
});
};

initStatsView = async (type: string): Promise<void> => {
let leaf: WorkspaceLeaf = null;
for (leaf of this.app.workspace.getLeavesOfType(type)) {
if (leaf.view instanceof StatsView) {
return;
}
await leaf.setViewState({ type: "empty" });
break;
}
(leaf ?? this.app.workspace.getRightLeaf(false)).setViewState({
type,
active: false,
});
};

Expand Down

0 comments on commit bfe0227

Please sign in to comment.