Skip to content

Commit 36ee9cc

Browse files
committed
refactor(settings): Add user overrides
This updates the settings menu to be more intuitive and give fine-grained control over the mermaid backoff strategy.
1 parent d6f928d commit 36ee9cc

3 files changed

Lines changed: 165 additions & 72 deletions

File tree

src/schema.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ export interface EGVSettings {
1313
// MMD
1414
direction?: 'TD' | 'LR' | 'RL' | 'BT'
1515
maxEPerV?: number
16+
// MMD backoff
17+
disableAutoBridging: boolean
18+
maxNodes?: number
19+
maxRelationships?: number
20+
maxTags?: number
1621
}
1722

1823
export const DEFAULT_SET: EGVSettings = {
@@ -26,6 +31,10 @@ export const DEFAULT_SET: EGVSettings = {
2631
subgraphs: false,
2732
direction: 'TD',
2833
maxEPerV: 10,
34+
disableAutoBridging: false,
35+
maxNodes: 40,
36+
maxRelationships: 60,
37+
maxTags: 10,
2938
}
3039

3140
// Processing structs

src/settings.ts

Lines changed: 148 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ export class EGVSettingTab extends PluginSettingTab {
4848

4949
new Setting(containerEl)
5050
.setName('Include attachments')
51-
.setDesc(
52-
'Whether to include non-markdown files from your vault by default'
53-
)
51+
.setDesc('Whether to include any non-markdown files by default')
5452
.addToggle((toggle) =>
5553
toggle
5654
.setValue(this.plugin.settings.includeAttachments)
@@ -62,7 +60,7 @@ export class EGVSettingTab extends PluginSettingTab {
6260

6361
new Setting(containerEl)
6462
.setName('Relationship between notes')
65-
.setDesc('Choose how notes are organised')
63+
.setDesc('Choose how your notes are organised')
6664
.addDropdown((dropdown) =>
6765
dropdown
6866
.addOption('tags', 'by tags')
@@ -75,88 +73,169 @@ export class EGVSettingTab extends PluginSettingTab {
7573
| 'internalLinks'
7674
| 'folders'
7775
await this.plugin.saveSettings()
76+
this.display()
7877
})
7978
)
8079

81-
// Either dot
80+
new Setting(containerEl)
81+
.setName('Include edge weights')
82+
.setDesc(
83+
'Include relationship-strength metadata between elements in export file'
84+
)
85+
.addToggle((toggle) =>
86+
toggle
87+
.setValue(this.plugin.settings.includeWeights)
88+
.onChange(async (value) => {
89+
this.plugin.settings.includeWeights = value
90+
await this.plugin.saveSettings()
91+
})
92+
)
93+
94+
// Either Some Dot or Some MMD
8295
if (this.plugin.settings.exportFormat === 'dot') {
96+
this.displayDotSettings(containerEl)
97+
} else if (this.plugin.settings.exportFormat === 'mmd') {
98+
this.displayMermaidSettings(containerEl)
99+
}
100+
}
101+
102+
// Some DOT
103+
private displayDotSettings(containerEl: HTMLElement) {
104+
new Setting(containerEl)
105+
.setName('Weight threshold')
106+
.setDesc(
107+
'Minimum score for a relationship to be included in the graph.'
108+
)
109+
.addSlider((slider) =>
110+
slider
111+
.setLimits(1, 10, 1)
112+
.setValue(this.plugin.settings.weightThreshold || 1)
113+
.setDynamicTooltip()
114+
.onChange(async (value) => {
115+
this.plugin.settings.weightThreshold = value
116+
await this.plugin.saveSettings()
117+
})
118+
)
119+
120+
new Setting(containerEl)
121+
.setName('Enable subgraphs')
122+
.setDesc('Group nodes into subgraphs based on relationships.')
123+
.addToggle((toggle) =>
124+
toggle
125+
.setValue(this.plugin.settings.subgraphs || false)
126+
.onChange(async (value) => {
127+
this.plugin.settings.subgraphs = value
128+
await this.plugin.saveSettings()
129+
})
130+
)
131+
}
132+
133+
// Some MMD
134+
private displayMermaidSettings(containerEl: HTMLElement) {
135+
new Setting(containerEl)
136+
.setName('Graph direction')
137+
.setDesc('Choose your mermaid layout')
138+
.addDropdown((dropdown) =>
139+
dropdown
140+
.addOption('TD', 'Top to Bottom')
141+
.addOption('LR', 'Left to Right')
142+
.addOption('RL', 'Right to Left')
143+
.addOption('BT', 'Bottom to Top')
144+
.setValue(this.plugin.settings.direction || 'TD')
145+
.onChange(async (value) => {
146+
this.plugin.settings.direction = value as
147+
| 'TD'
148+
| 'LR'
149+
| 'RL'
150+
| 'BT'
151+
await this.plugin.saveSettings()
152+
})
153+
)
154+
155+
new Setting(containerEl)
156+
.setName('Max relationships per note')
157+
.setDesc('Limit relationships per note to reduce visual clutter')
158+
.addSlider((slider) =>
159+
slider
160+
.setLimits(1, 20, 1)
161+
.setValue(this.plugin.settings.maxEPerV || 8)
162+
.setDynamicTooltip()
163+
.onChange(async (value) => {
164+
this.plugin.settings.maxEPerV = value
165+
await this.plugin.saveSettings()
166+
})
167+
)
168+
169+
// Some MMD(Strategy(tag-based))
170+
if (this.plugin.settings.relationshipStrategy === 'tags') {
83171
new Setting(containerEl)
84-
.setName('Include edge weights')
172+
.setName('Turn off automatic graph reduction')
85173
.setDesc(
86-
'For rendering the strength of links between notes in editors like Gephi.'
174+
'NOTE: Turning this off may produce unreadable diagrams in Mermaid editors'
87175
)
88176
.addToggle((toggle) =>
89177
toggle
90-
.setValue(this.plugin.settings.includeWeights)
178+
.setValue(
179+
this.plugin.settings.disableAutoBridging || false
180+
)
91181
.onChange(async (value) => {
92-
this.plugin.settings.includeWeights = value
182+
this.plugin.settings.disableAutoBridging = value
93183
await this.plugin.saveSettings()
184+
this.display()
94185
})
95186
)
96187

97-
new Setting(containerEl)
98-
.setName('Weight threshold')
99-
.setDesc(
100-
'Minimum weight for a relationship to be included in the graph.'
101-
)
102-
.addSlider((slider) =>
103-
slider
104-
.setLimits(1, 10, 1)
105-
.setValue(this.plugin.settings.weightThreshold || 1)
106-
.setDynamicTooltip()
107-
.onChange(async (value) => {
108-
this.plugin.settings.weightThreshold = value
109-
await this.plugin.saveSettings()
110-
})
111-
)
188+
// Some MMD(Strategy(tag-based) && auto-bridging disabled)
189+
if (this.plugin.settings.disableAutoBridging) {
190+
containerEl.createEl('h4', {
191+
text: 'Set manual limits',
192+
cls: 'bridging-desc',
193+
})
112194

113-
new Setting(containerEl)
114-
.setName('Enable subgraphs')
115-
.setDesc('Group nodes into subgraphs based on relationships.')
116-
.addToggle((toggle) =>
117-
toggle
118-
.setValue(this.plugin.settings.subgraphs || false)
119-
.onChange(async (value) => {
120-
this.plugin.settings.subgraphs = value
121-
await this.plugin.saveSettings()
122-
})
123-
)
195+
new Setting(containerEl)
196+
.setName('Maximum nodes')
197+
.setDesc('Maximum number of nodes in diagram')
198+
.addSlider((slider) =>
199+
slider
200+
.setLimits(10, 100, 5)
201+
.setValue(this.plugin.settings.maxNodes || 40)
202+
.setDynamicTooltip()
203+
.onChange(async (value) => {
204+
this.plugin.settings.maxNodes = value
205+
await this.plugin.saveSettings()
206+
})
207+
)
124208

125-
// Either mermaid
126-
} else if (this.plugin.settings.exportFormat === 'mmd') {
127-
new Setting(containerEl)
128-
.setName('Graph direction')
129-
.setDesc('Choose your mermaid layout')
130-
.addDropdown((dropdown) =>
131-
dropdown
132-
.addOption('TD', 'Top to Bottom')
133-
.addOption('LR', 'Left to Right')
134-
.addOption('RL', 'Right to Left')
135-
.addOption('BT', 'Bottom to Top')
136-
.setValue(this.plugin.settings.direction || 'TD')
137-
.onChange(async (value) => {
138-
this.plugin.settings.direction = value as
139-
| 'TD'
140-
| 'LR'
141-
| 'RL'
142-
| 'BT'
143-
await this.plugin.saveSettings()
144-
})
145-
)
209+
new Setting(containerEl)
210+
.setName('Maximum relationships')
211+
.setDesc('Maximum number of relationships')
212+
.addSlider((slider) =>
213+
slider
214+
.setLimits(10, 150, 5)
215+
.setValue(
216+
this.plugin.settings.maxRelationships || 60
217+
)
218+
.setDynamicTooltip()
219+
.onChange(async (value) => {
220+
this.plugin.settings.maxRelationships = value
221+
await this.plugin.saveSettings()
222+
})
223+
)
146224

147-
new Setting(containerEl)
148-
.setName('Max relationships for each note')
149-
.setDesc('Use this setting to de-clutter your mermaid chart')
150-
.addSlider((slider) =>
151-
slider
152-
.setLimits(1, 20, 1)
153-
.setValue(this.plugin.settings.maxEPerV || 8)
154-
.setDynamicTooltip()
155-
.onChange(async (value) => {
156-
this.plugin.settings.maxEPerV = value
157-
await this.plugin.saveSettings()
158-
})
159-
)
225+
new Setting(containerEl)
226+
.setName('Maximum tags')
227+
.setDesc('Maximum number of tags')
228+
.addSlider((slider) =>
229+
slider
230+
.setLimits(3, 30, 1)
231+
.setValue(this.plugin.settings.maxTags || 10)
232+
.setDynamicTooltip()
233+
.onChange(async (value) => {
234+
this.plugin.settings.maxTags = value
235+
await this.plugin.saveSettings()
236+
})
237+
)
238+
}
160239
}
161240
}
162241
}

src/whisperer.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ export class VaultWhisperer {
114114
return Math.floor(Math.sqrt((2 * E_max * t) / Math.max(1, k)))
115115
},
116116
isTearing(E_max: number = 150): boolean {
117+
// Respect the user override
118+
if (this.settings.disableAutoBridging === true) {
119+
return false
120+
}
121+
117122
const N = this.getN()
118123
const T = this.getT()
119124
const K = this.getK()
@@ -458,9 +463,9 @@ export class VaultWhisperer {
458463
relationships: NodeRelationship[],
459464
vaultEnv: VaultEnv
460465
): void {
461-
const MAX_NODES = 40
462-
const MAX_RELATIONSHIPS = 60
463-
const MAX_TAGS = 10
466+
const MAX_NODES = vaultEnv.settings.maxNodes || 40
467+
const MAX_RELATIONSHIPS = vaultEnv.settings.maxRelationships || 60
468+
const MAX_TAGS = vaultEnv.settings.maxTags || 10
464469

465470
console.log('Starting backoff task')
466471

0 commit comments

Comments
 (0)