mirror of
https://github.com/calfmoon/node-factor.git
synced 2026-07-22 12:20:32 +00:00
feat(display): add settings menu
This commit is contained in:
parent
b99c464470
commit
8f06207d8a
4 changed files with 112 additions and 1 deletions
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "obsidian-sample-plugin",
|
||||
"name": "obsidian-node-factor",
|
||||
"version": "1.0.0",
|
||||
"description": "Customize factors effecting node size in graph.",
|
||||
"main": "main.js",
|
||||
|
|
|
|||
19
src/main.ts
19
src/main.ts
|
|
@ -1,7 +1,26 @@
|
|||
import { Plugin } from "obsidian";
|
||||
|
||||
import { NodeFactorSettings, DEFAULT_SETTINGS } from "./types";
|
||||
import SampleSettingTab from "./settings";
|
||||
|
||||
export default class NodeFactor extends Plugin {
|
||||
settings: NodeFactorSettings;
|
||||
|
||||
async onload() {
|
||||
await this.loadSettings();
|
||||
this.addSettingTab(new SampleSettingTab(this.app, this));
|
||||
this.registerEvent(this.app.workspace.on("layout-change", () => {}));
|
||||
}
|
||||
|
||||
async loadSettings() {
|
||||
this.settings = Object.assign(
|
||||
{},
|
||||
DEFAULT_SETTINGS,
|
||||
await this.loadData(),
|
||||
);
|
||||
}
|
||||
|
||||
async saveSettings() {
|
||||
await this.saveData(this.settings);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
75
src/settings.ts
Normal file
75
src/settings.ts
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
import { App, PluginSettingTab, Setting } from "obsidian";
|
||||
|
||||
import NodeFactor from "./main";
|
||||
|
||||
export default class SampleSettingTab extends PluginSettingTab {
|
||||
plugin: NodeFactor;
|
||||
|
||||
constructor(app: App, plugin: NodeFactor) {
|
||||
super(app, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
display(): void {
|
||||
const { containerEl } = this;
|
||||
containerEl.empty();
|
||||
|
||||
containerEl.createEl("h1", { text: "Node Factor Settings" });
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Forward link weight multiplier")
|
||||
.setDesc("Multiplier for forward links weight (0 to diable).")
|
||||
.addSlider((slider) =>
|
||||
slider
|
||||
.setLimits(0, 20, 1)
|
||||
.setDynamicTooltip()
|
||||
.setValue(this.plugin.settings.fwdMultiplier)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.fwdMultiplier = value;
|
||||
await this.plugin.saveSettings();
|
||||
}),
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Travel forward tree")
|
||||
.setDesc("Travel forward tree to calcuate node size.")
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.plugin.settings.fwdTree)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.fwdTree = value;
|
||||
await this.plugin.saveSettings();
|
||||
}),
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Backward link weight multiplier")
|
||||
.setDesc("Multiplier for backward links weight (0 to diable).")
|
||||
.addSlider((slider) =>
|
||||
slider
|
||||
.setLimits(0, 20, 1)
|
||||
.setDynamicTooltip()
|
||||
.setValue(this.plugin.settings.bwdMultiplier)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.bwdMultiplier = value;
|
||||
await this.plugin.saveSettings();
|
||||
}),
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Character per weight")
|
||||
.setDesc(
|
||||
"Add 1 weight to node size per no of given Character (0 to disable).",
|
||||
)
|
||||
.addSlider((slider) =>
|
||||
slider
|
||||
.setLimits(0, 5000, 100)
|
||||
.setDynamicTooltip()
|
||||
.setValue(this.plugin.settings.lettersPerWt)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.lettersPerWt = value;
|
||||
await this.plugin.saveSettings();
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
17
src/types.ts
Normal file
17
src/types.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
export interface NodeFactorSettings {
|
||||
fwdMultiplier: number;
|
||||
fwdTree: boolean;
|
||||
|
||||
bwdMultiplier: number;
|
||||
|
||||
lettersPerWt: number;
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: NodeFactorSettings = {
|
||||
fwdMultiplier: 1,
|
||||
fwdTree: false,
|
||||
|
||||
bwdMultiplier: 1,
|
||||
|
||||
lettersPerWt: 0,
|
||||
};
|
||||
Loading…
Reference in a new issue