Skip to content

Commit

Permalink
feat: ✨ Setting to change Dataview wait time
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Aug 13, 2021
1 parent 989d60b commit 9d7650f
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 18 deletions.
23 changes: 23 additions & 0 deletions src/BreadcrumbsSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,29 @@ export class BreadcrumbsSettingTab extends PluginSettingTab {
})
);

if (this.app.plugins.plugins.dataview !== undefined) {
new Setting(generalDetails)
.setName("Dataview Wait Time")
.setDesc(
'Enter an integer number of seconds to wait for the Dataview Index to load. The larger your vault, the longer it will take. If you see an error in the console saying "Cannot destructure currGraphs of undefined", try making this time longer. If you don\'t get that error, you can make this time shorter to make the Breadcrumbs load faster. The default is 5 seconds.'
)
.addText((text) =>
text
.setPlaceholder("Seconds")
.setValue((plugin.settings.dvWaitTime / 1000).toString())
.onChange(async (value) => {
const num = Number(value);

if (num > 0) {
plugin.settings.dvWaitTime = num * 1000;
await plugin.saveSettings();
} else {
new Notice("The interval must be a non-negative number");
}
})
);
}

new Setting(generalDetails)
.setName("Refresh Interval")
.setDesc(
Expand Down
25 changes: 18 additions & 7 deletions src/MatrixView.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { Edge, Graph } from "graphlib";
import { cloneDeep, sum } from "lodash";
import type { Graph } from "graphlib";
import { cloneDeep } from "lodash";
import { ItemView, TFile, WorkspaceLeaf } from "obsidian";
import {
DATAVIEW_INDEX_DELAY,
DIRECTIONS,
TRAIL_ICON,
VIEW_TYPE_BREADCRUMBS_MATRIX,
Expand Down Expand Up @@ -40,7 +39,10 @@ export default class MatrixView extends ItemView {
this.matrixQ = this.plugin.settings.defaultView;

this.app.workspace.onLayoutReady(async () => {
setTimeout(async () => await this.draw(), DATAVIEW_INDEX_DELAY);
setTimeout(
async () => await this.draw(),
this.plugin.settings.dvWaitTime
);
});

this.plugin.addCommand({
Expand Down Expand Up @@ -345,19 +347,28 @@ export default class MatrixView extends ItemView {
const upSquare: SquareProps = {
realItems: rUp,
impliedItems: iUp,
fieldName: hier.up[0] === "" ? "<Parents>" : hier.up.join(", "),
fieldName:
hier.up[0] === ""
? `${hier.down.join(",")}<Parents>`
: hier.up.join(", "),
};

const sameSquare: SquareProps = {
realItems: rSame,
impliedItems: iSameArr,
fieldName: hier.same[0] === "" ? "<Siblings>" : hier.same.join(", "),
fieldName:
hier.same[0] === ""
? `${hier.up.join(",")}<Siblings>`
: hier.same.join(", "),
};

const downSquare: SquareProps = {
realItems: rDown,
impliedItems: iDown,
fieldName: hier.down[0] === "" ? "<Children>" : hier.down.join(", "),
fieldName:
hier.down[0] === ""
? `${hier.up.join(",")}<Children>`
: hier.down.join(", "),
};

return [upSquare, sameSquare, downSquare];
Expand Down
10 changes: 5 additions & 5 deletions src/StatsView.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import type { Graph } from "graphlib";
import { ItemView, WorkspaceLeaf } from "obsidian";
import {
DATAVIEW_INDEX_DELAY,
VIEW_TYPE_BREADCRUMBS_STATS,
} from "src/constants";
import { VIEW_TYPE_BREADCRUMBS_STATS } from "src/constants";
import type BreadcrumbsPlugin from "src/main";
import Stats from "./Components/Stats.svelte";

Expand All @@ -20,7 +17,10 @@ export default class StatsView extends ItemView {
super.onload();
await this.plugin.saveSettings();
this.app.workspace.onLayoutReady(async () => {
setTimeout(async () => await this.draw(), DATAVIEW_INDEX_DELAY);
setTimeout(
async () => await this.draw(),
this.plugin.settings.dvWaitTime
);
});
}

Expand Down
2 changes: 0 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ export const TRAIL_ICON_SVG =
export const splitLinksRegex = new RegExp(/\[\[(.+?)\]\]/g);
export const dropHeaderOrAlias = new RegExp(/\[\[([^#|]+)\]\]/);

export const DATAVIEW_INDEX_DELAY = 5000;

export const VISTYPES: visTypes[] = [
"Force Directed Graph",
"Tidy Tree",
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface BreadcrumbsSettings {
userHierarchies: userHierarchy[];
indexNote: string[];
refreshIndexOnActiveLeafChange: boolean;
dvWaitTime: number;
refreshIntervalTime: number;
defaultView: boolean;
showNameOrType: boolean;
Expand Down
6 changes: 2 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Graph } from "graphlib";
import { addIcon, MarkdownView, Plugin, TFile, WorkspaceLeaf } from "obsidian";
import { BreadcrumbsSettingTab } from "src/BreadcrumbsSettingTab";
import {
DATAVIEW_INDEX_DELAY,
DIRECTIONS,
TRAIL_ICON,
TRAIL_ICON_SVG,
Expand All @@ -14,7 +13,6 @@ import type {
Directions,
dvFrontmatterCache,
HierarchyGraphs,
relObj,
} from "src/interfaces";
import MatrixView from "src/MatrixView";
import {
Expand All @@ -25,7 +23,6 @@ import {
getNeighbourObjArr,
getObsMetadataCache,
mergeGs,
splitAndTrim,
} from "src/sharedFunctions";
import StatsView from "src/StatsView";
import { VisModal } from "src/VisModal";
Expand All @@ -36,6 +33,7 @@ const DEFAULT_SETTINGS: BreadcrumbsSettings = {
userHierarchies: [],
indexNote: [""],
refreshIndexOnActiveLeafChange: false,
dvWaitTime: 5000,
refreshIntervalTime: 0,
defaultView: true,
showNameOrType: true,
Expand Down Expand Up @@ -160,7 +158,7 @@ export default class BreadcrumbsPlugin extends Plugin {
}, this.settings.refreshIntervalTime * 1000);
this.registerInterval(this.refreshIntervalID);
}
}, DATAVIEW_INDEX_DELAY);
}, this.settings.dvWaitTime);
});

addIcon(TRAIL_ICON, TRAIL_ICON_SVG);
Expand Down

0 comments on commit 9d7650f

Please sign in to comment.