22 lines
23 KiB
JavaScript
22 lines
23 KiB
JavaScript
/*
|
|
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
|
if you want to view the source, please visit the github repository of this plugin
|
|
*/
|
|
|
|
var v=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var F=(c,t)=>{for(var i in t)v(c,i,{get:t[i],enumerable:!0})},O=(c,t,i,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of k(t))!C.call(c,s)&&s!==i&&v(c,s,{get:()=>t[s],enumerable:!(e=E(t,s))||e.enumerable});return c};var A=c=>O(v({},"__esModule",{value:!0}),c);var L={};F(L,{default:()=>b});module.exports=A(L);var M={exportFormat:"mmd",includeOrphans:!1,includeAttachments:!1,lastExported:"",includeWeights:!1,relationshipStrategy:"tags",weightThreshold:1,subgraphs:!1,direction:"TD",maxEPerV:10,enableAutoBridge:!0,manualBackoff:!1,maxNodes:40,maxRelationships:60,maxTags:10};var h=require("obsidian"),N=class extends h.PluginSettingTab{constructor(t,i){super(t,i),this.plugin=i}display(){let{containerEl:t}=this;t.empty(),this.plugin.settings.viewMode?this.plugin.settings.viewMode==="singleGraph"?this.singleGraph(t):this.plugin.settings.viewMode==="fullGraph"&&this.fullGraph(t):this.singleOrFull(t)}singleOrFull(t){let i=t.createDiv({cls:"egv-choice-container"});i.createEl("h2",{text:"Change default settings",cls:"egv-choice-header"}),i.createEl("p",{text:"Select the focus you want to tweak settings on",cls:"egv-choice-description"});let e=i.createDiv({cls:"egv-cards-container"}),s=e.createDiv({cls:"egv-choice-card"});s.createDiv({cls:"egv-card-icon single-parent-icon"}),s.createEl("h3",{text:"Single-parent focus"}),s.createEl("p",{text:"Snapshot relationships from a single tag or note"});let n=new h.ButtonComponent(s.createDiv({cls:"egv-card-button-container"})).setButtonText("Change settings").setCta().onClick(async()=>{this.plugin.settings.viewMode="singleGraph",await this.plugin.saveSettings(),this.display()}),a=e.createDiv({cls:"egv-choice-card"});a.createDiv({cls:"egv-card-icon full-graph-icon"}),a.createEl("h3",{text:"Full vault focus"}),a.createEl("p",{text:"Snapshot your vault from a wider angle"});let o=new h.ButtonComponent(a.createDiv({cls:"egv-card-button-container"})).setButtonText("Change settings").setCta().onClick(async()=>{this.plugin.settings.viewMode="fullGraph",await this.plugin.saveSettings(),this.display()})}singleGraph(t){let i=t.createDiv({cls:"single-div"});new h.ButtonComponent(i).setIcon("arrow-left").setTooltip("Back to main choices").onClick(async()=>{this.plugin.settings.viewMode=void 0,await this.plugin.saveSettings(),this.display()}),i.createEl("h2",{text:"Single parent graph settings"});let e=t.createDiv({cls:"sg-div"});new h.Setting(e).setName("Parent node type").setDesc("Set your graph to draw from either your chosen tag or chosen note").addDropdown(s=>s.addOption("singleTag","Tag").addOption("singleNote","Note").setValue(this.plugin.settings.relationshipStrategy||"singleTag").onChange(async n=>{this.plugin.settings.relationshipStrategy=n,await this.plugin.saveSettings(),this.display()})),this.plugin.settings.relationshipStrategy==="singleTag"?new h.Setting(e).setName("Parent tag").setDesc("Enter the tag to use as your graph parent (without #)").addText(s=>s.setPlaceholder("Enter tag").setValue(this.plugin.settings.rootTag||"").onChange(async n=>{this.plugin.settings.rootTag=n,await this.plugin.saveSettings()})):this.plugin.settings.relationshipStrategy==="singleNote"&&new h.Setting(e).setName("Parent note").setDesc("Enter the title of the note to use as your graph parent").addText(s=>s.setPlaceholder("Enter note title").setValue(this.plugin.settings.rootNote||"").onChange(async n=>{this.plugin.settings.rootNote=n,await this.plugin.saveSettings()})),this.displayFormatSettings(t)}fullGraph(t){let i=t.createDiv({cls:"fgh"});new h.ButtonComponent(i).setIcon("arrow-left").setTooltip("Back to main choices").onClick(async()=>{this.plugin.settings.viewMode=void 0,await this.plugin.saveSettings(),this.display()}),i.createEl("h2",{text:"Full graph settings"});let e=t.createDiv({cls:"full-div"});new h.Setting(e).setName("Relationship between notes").setDesc("Choose how your notes are organised").addDropdown(s=>s.addOption("tags","by tags").addOption("internalLinks","by internal links").addOption("folders","by folders").setValue(this.plugin.settings.relationshipStrategy||"tags").onChange(async n=>{this.plugin.settings.relationshipStrategy=n,await this.plugin.saveSettings(),this.display()})),new h.Setting(e).setName("Include orphan notes").setDesc("Whether to include notes with no relationship to other notes by default").addToggle(s=>s.setValue(this.plugin.settings.includeOrphans).onChange(async n=>{this.plugin.settings.includeOrphans=n,await this.plugin.saveSettings()})),this.displayFormatSettings(t)}displayFormatSettings(t){let i=t.createDiv({cls:"formset-div"});i.createEl("h3",{text:"Export format settings"}),new h.Setting(i).setName("Export format").setDesc("Choose either a .mmd (Mermaid) or .dot (Graphviz) file").addDropdown(e=>e.addOption("mmd",".mmd").addOption("dot",".dot").setValue(this.plugin.settings.exportFormat).onChange(async s=>{this.plugin.settings.exportFormat=s,await this.plugin.saveSettings(),this.display()})),new h.Setting(i).setName("Include attachments").setDesc("Whether to include any non-markdown files by default").addToggle(e=>e.setValue(this.plugin.settings.includeAttachments).onChange(async s=>{this.plugin.settings.includeAttachments=s,await this.plugin.saveSettings()})),new h.Setting(i).setName("Include relationship weights").setDesc("Store relationship importance metadata in the exported file").addToggle(e=>e.setValue(this.plugin.settings.includeWeights).onChange(async s=>{this.plugin.settings.includeWeights=s,await this.plugin.saveSettings()})),this.plugin.settings.exportFormat==="dot"?this.displayDotSettings(i):this.plugin.settings.exportFormat==="mmd"&&this.displayMermaidSettings(i)}displayDotSettings(t){let i=t.createDiv({cls:"dotsetdiv"});i.createEl("h4",{text:"DOT format settings"}),new h.Setting(i).setName("Weight threshold").setDesc("Only include important relationships above a minimum score").addSlider(e=>e.setLimits(0,10,1).setValue(this.plugin.settings.weightThreshold||0).setDynamicTooltip().onChange(async s=>{this.plugin.settings.weightThreshold=s,await this.plugin.saveSettings()})),new h.Setting(i).setName("Subgraph clustering").setDesc("Whether to cluster notes by their common tag or folder").addToggle(e=>e.setValue(this.plugin.settings.subgraphs||!1).onChange(async s=>{this.plugin.settings.subgraphs=s,await this.plugin.saveSettings()}))}displayMermaidSettings(t){let i=t.createDiv({cls:"mmdsetdiv"});i.createEl("h4",{text:"Mermaid settings"}),new h.Setting(i).setName("Direction").setDesc("Mermaid layout").addDropdown(e=>e.addOption("TD","Top down").addOption("LR","Left right").addOption("RL","Right left").addOption("BT","Bottom top").setValue(this.plugin.settings.direction||"TD").onChange(async s=>{this.plugin.settings.direction=s,await this.plugin.saveSettings()})),new h.Setting(i).setName("Max relationships per node").setDesc("Optionally limit the number of relationships to render on elements").addSlider(e=>e.setLimits(0,20,1).setValue(this.plugin.settings.maxEPerV||0).setDynamicTooltip().onChange(async s=>{this.plugin.settings.maxEPerV=s,await this.plugin.saveSettings()})),this.plugin.settings.viewMode!=="singleGraph"&&this.backoffStrategy(i)}backoffStrategy(t){let i=t.createDiv({cls:"backoff-div"});new h.Setting(i).setName("Enable auto graph reduction").setDesc("NOTE: Turning this off may produce unreadable Mermaid graphs").addToggle(e=>e.setValue(this.plugin.settings.enableAutoBridge).onChange(async s=>{this.plugin.settings.enableAutoBridge=s,await this.plugin.saveSettings(),this.display()})),this.plugin.settings.enableAutoBridge===!0&&(new h.Setting(i).setName("Manual limit configuration").setDesc("Enable manual configuration of graph limits (advanced)").addToggle(e=>e.setValue(this.plugin.settings.manualBackoff||!1).onChange(async s=>{this.plugin.settings.manualBackoff=s,await this.plugin.saveSettings(),this.display()})),this.plugin.settings.manualBackoff===!0&&(new h.Setting(i).setName("Max elements").setDesc("Limit the number of elements included").addSlider(e=>e.setLimits(10,100,5).setValue(Math.min(this.plugin.settings.maxNodes||40,100)).setDynamicTooltip().onChange(async s=>{this.plugin.settings.maxNodes=s,await this.plugin.saveSettings()})),new h.Setting(i).setName("Max relationships").setDesc("Limit the relationships included").addSlider(e=>e.setLimits(10,75,5).setValue(Math.min(this.plugin.settings.maxRelationships||60,75)).setDynamicTooltip().onChange(async s=>{this.plugin.settings.maxRelationships=s,await this.plugin.saveSettings()})),new h.Setting(i).setName("Max tags").setDesc("Limit the number of tags included").addSlider(e=>e.setLimits(5,50,1).setValue(Math.min(this.plugin.settings.maxTags||10,50)).setDynamicTooltip().onChange(async s=>{this.plugin.settings.maxTags=s,await this.plugin.saveSettings()}))))}};var p=require("obsidian"),T=class extends p.Modal{constructor(t,i){super(t),this.plugin=i}onOpen(){let{contentEl:t}=this;t.empty(),t.addClass("egv-export-modal");let i=t.createDiv({cls:"egv-file-row"}),e=new p.Setting(i).setName("File name").setClass("egv-filename-setting"),s=new p.TextComponent(e.controlEl).setValue(this.filename).onChange(d=>this.filename=d),n=new p.ButtonComponent(i).setButtonText("Export").setCta().onClick(()=>this.export()),a=t.createDiv({cls:"egv-section"});a.createEl("h3",{text:"Graph type"});let o=new p.Setting(a).setName("Graph scope").addDropdown(d=>d.addOption("fullGraph","Full graph").addOption("singleGraph","Single parent graph").setValue(this.plugin.settings.viewMode||"notSet").onChange(async y=>{this.plugin.settings.viewMode=y,await this.plugin.saveSettings(),this.strategy(a)}));this.strategy(a);let g=t.createDiv({cls:"egv-section"});g.createEl("h3",{text:"Format settings"}),new p.Setting(g).setName("Export format").addDropdown(d=>d.addOption("mmd",".mmd").addOption("dot",".dot").setValue(this.plugin.settings.exportFormat).onChange(async y=>{this.plugin.settings.exportFormat=y,await this.plugin.saveSettings(),this.mmdOrDot(g)})),this.mmdOrDot(g)}strategy(t){let i=t.querySelector(".options-div");i&&i.remove();let e=t.createDiv({cls:"options-div"});this.plugin.settings.viewMode==="singleGraph"?(new p.Setting(e).setName("Parent type").addDropdown(s=>s.addOption("singleTag","Tag").addOption("singleNote","Note").setValue(this.plugin.settings.relationshipStrategy).onChange(async n=>{this.plugin.settings.relationshipStrategy=n,await this.plugin.saveSettings(),this.singleOrFull(e)})),this.singleOrFull(e)):(new p.Setting(e).setName("Relationship type").addDropdown(s=>s.addOption("tags","By tags").addOption("internalLinks","By links").addOption("folders","By folders").setValue(this.plugin.settings.relationshipStrategy).onChange(async n=>{this.plugin.settings.relationshipStrategy=n,await this.plugin.saveSettings()})),new p.Setting(e).setName("Include orphans").setDesc("Include notes with no relationships to other notes").addToggle(s=>s.setValue(this.plugin.settings.includeOrphans).onChange(async n=>{this.plugin.settings.includeOrphans=n,await this.plugin.saveSettings()})))}singleOrFull(t){let i=t.querySelector(".single-diplay-div");i&&i.remove();let e=t.createDiv({cls:"single-display-div"});this.plugin.settings.relationshipStrategy==="singleTag"?new p.Setting(e).setName("Parent tag").setDesc("Enter tag without #").addText(s=>s.setValue(this.plugin.settings.rootTag||"").onChange(async n=>{this.plugin.settings.rootTag=n,await this.plugin.saveSettings()})):new p.Setting(e).setName("Parent note").setDesc("Enter note title").addText(s=>s.setValue(this.plugin.settings.rootNote||"").onChange(async n=>{this.plugin.settings.rootNote=n,await this.plugin.saveSettings()}))}mmdOrDot(t){let i=t.querySelector(".format-div");i&&i.remove();let e=t.createDiv({cls:"format-div"});this.plugin.settings.exportFormat==="mmd"?new p.Setting(e).setName("Mermaid layout").addDropdown(s=>s.addOption("TD","Top down").addOption("BT","Bottom to top").addOption("LR","Left to right").addOption("RL","Right to left").setValue(this.plugin.settings.direction||"TD").onChange(async n=>{this.plugin.settings.direction=n,await this.plugin.saveSettings()})):this.plugin.settings.exportFormat==="dot"&&(new p.Setting(e).setName("Weight threshold").setDesc("Only include important relationships with a minimum score").addSlider(s=>s.setLimits(1,10,1).setValue(this.plugin.settings.weightThreshold||10).setDynamicTooltip().onChange(async n=>{this.plugin.settings.weightThreshold=n,await this.plugin.saveSettings()})),new p.Setting(e).setName("Use subgraphs").addToggle(s=>s.setValue(this.plugin.settings.subgraphs||!1).onChange(async n=>{this.plugin.settings.subgraphs=n,await this.plugin.saveSettings()})))}export(){if(!this.filename){new p.Notice("Please enter a filename");return}this.plugin.exportGraph(this.filename),this.close()}onClose(){let{contentEl:t}=this;t.empty()}};var m=require("obsidian");function w(c){return c.replace(/[^a-zA-Z0-9]/g,"_")}function D(c){return c.replace(/"/g,'\\"')}var x=class{constructor(t,i){this.app=t,this.settings=i}buildGraph(){let t={nodes:[],relationships:[]};return this.harvestVault(t),this.settings.exportFormat==="dot"?this.runDotSettings(t):this.runMMDSettings(t),t}harvestVault(t){let i={cache:this.app.metadataCache,vault:this.app.vault,nodes:new Map,relationships:[],settings:this.settings,getN(){return Array.from(this.nodes.keys()).filter(e=>e.endsWith(".md")).length},getT(){return Array.from(this.nodes.values()).filter(e=>e.type==="tag").length},getK(){let e=new Map;return this.relationships.forEach(n=>{let a=this.nodes.get(n.target),o=this.nodes.get(n.source);(a==null?void 0:a.type)==="tag"&&(o==null?void 0:o.type)==="note"&&(e.has(n.source)||e.set(n.source,0),e.set(n.source,e.get(n.source)+1))}),Array.from(e.values()).reduce((n,a)=>n+a,0)/Math.max(1,e.size)},getOptimalN(e=150){let s=this.getT(),n=this.getK();return Math.floor(Math.sqrt(2*e*s/Math.max(1,n)))},isTearing(e=150){if(this.settings.viewMode==="singleGraph"||this.settings.enableAutoBridge===!1)return!1;let s=this.getN(),n=this.getT(),a=this.getK(),o=0,g=new Map;this.relationships.forEach(r=>{let l=this.nodes.get(r.target),f=this.nodes.get(r.source);(l==null?void 0:l.type)==="tag"&&(f==null?void 0:f.type)==="note"&&(g.has(r.target)||g.set(r.target,[]),g.get(r.target).push(r.source))}),g.forEach(r=>{r.length>1&&(o+=r.length*(r.length-1)/2)});let d=100,y=Math.min(e,75);return s>d||o>y||s+o>150||n>50}};switch(this.reapNotes(i),this.reapTags(i),this.reapLinks(i),this.reapFolders(i),this.settings.includeAttachments&&this.clusterAttachments(i),this.settings.relationshipStrategy){case"tags":this.tagNetwork(i);break;case"internalLinks":this.linkNetwork(i);break;case"folders":this.plantFolders(i);break;case"singleTag":this.singleTagNetwork(i);break;case"singleNote":this.singleNoteNetwork(i);break}t.nodes=Array.from(i.nodes.values()),t.relationships=i.relationships}reapNotes(t){let i=t.vault.getMarkdownFiles();for(let e of i)t.nodes.set(e.path,{id:(0,m.normalizePath)(e.path),name:e.basename,type:"note"})}reapTags(t){var s;let i=t.vault.getMarkdownFiles(),e=new Set;for(let n of i){let a=t.cache.getFileCache(n),o=[];if((s=a==null?void 0:a.frontmatter)!=null&&s.tags){let g=a.frontmatter.tags;Array.isArray(g)?o.push(...g):typeof g=="string"&&o.push(g)}o.forEach(g=>{e.add(g),t.nodes.has(g)||t.nodes.set(g,{id:g,name:g,type:"tag"}),t.relationships.push({source:n.path,target:g,weight:1})})}}reapLinks(t){let i=t.vault.getMarkdownFiles();for(let e of i){let s=t.cache.getFileCache(e);s!=null&&s.links&&s.links.forEach(n=>{let a=t.vault.getAbstractFileByPath(n.link+".md");a&&a instanceof m.TFile&&t.relationships.push({source:e.path,target:a.path,weight:1})})}}reapFolders(t){let i=t.vault.getAllLoadedFiles().filter(e=>e instanceof m.TFolder);for(let e of i)t.nodes.set(e.name,{id:e.name,name:e.name,type:"folder"}),e.children.forEach(s=>{s instanceof m.TFile&&s.extension==="md"&&t.relationships.push({source:s.path,target:e.name,weight:1})})}clusterAttachments(t){let i=t.vault.getFiles();for(let e of i)if(e.extension!==".md"){t.nodes.set(e.path,{id:(0,m.normalizePath)(e.path),name:e.basename,type:"attachment"});let s=t.vault.getMarkdownFiles();for(let n of s){let a=t.cache.getFileCache(n);a!=null&&a.embeds&&a.embeds.forEach(o=>{(o.link===e.path||o.link===e.basename)&&t.relationships.push({source:n.path,target:e.path,weight:1})})}}}tagNetwork(t){console.log("Before tagNetwork:",t.nodes.size,"nodes,",t.relationships.length,"relationships");let i=new Map,e=[];t.nodes.forEach((n,a)=>{(n.type==="note"||n.type==="tag")&&i.set(a,n)}),t.relationships.forEach(n=>{let a=t.nodes.get(n.target),o=t.nodes.get(n.source);(a==null?void 0:a.type)==="tag"&&(o==null?void 0:o.type)==="note"&&e.push(n)}),t.settings.exportFormat==="mmd"&&({...t,nodes:new Map(i),relationships:[...e]}.isTearing()?(console.log("Singularity detected - applying backoff strategy"),this.backoffSingularity(i,e,t)):console.log("Graph size within acceptable limits")),t.settings.includeOrphans||this.prune(i,e);let s=i.size+e.length;console.log("After tagNetwork:",i.size,"nodes,",e.length,"relationships",`(${s} total elements)`),s>200&&console.warn("Graph may still be too large for optimal Mermaid rendering"),t.nodes=i,t.relationships=e}linkNetwork(t){let i=new Map,e=[];t.nodes.forEach((s,n)=>{s.type==="note"&&i.set(n,s)}),t.relationships.forEach(s=>{let n=t.nodes.get(s.target),a=t.nodes.get(s.source);(n==null?void 0:n.type)==="note"&&(a==null?void 0:a.type)==="note"&&e.push(s)}),t.settings.includeOrphans||this.prune(i,e),t.nodes=i,t.relationships=e}plantFolders(t){let i=new Map,e=[];t.nodes.forEach((s,n)=>{(s.type==="note"||s.type==="folder")&&i.set(n,s)}),t.relationships.forEach(s=>{let n=t.nodes.get(s.target),a=t.nodes.get(s.source);(n==null?void 0:n.type)==="folder"&&(a==null?void 0:a.type)==="note"&&e.push(s)}),t.settings.includeOrphans||this.prune(i,e),t.nodes=i,t.relationships=e}singleTagNetwork(t){let i=this.settings.rootTag||"",e=new Map,s=[];if(i&&t.nodes.has(i))e.set(i,t.nodes.get(i));else{new m.Notice(`Tag "${i}" not found in your vault`);return}t.relationships.forEach(n=>{let a=t.nodes.get(n.target),o=t.nodes.get(n.source);(n.target===i&&(o==null?void 0:o.type)==="note"||n.source===i&&(a==null?void 0:a.type)==="note")&&(n.target===i&&o?e.set(n.source,o):n.source===i&&a&&e.set(n.target,a),s.push(n))}),t.nodes=e,t.relationships=s}singleNoteNetwork(t){var a;let i=this.settings.rootNote||"",e=new Map,s=[],n=(a=Array.from(t.nodes.entries()).find(([o,g])=>g.type==="note"&&g.name===i))==null?void 0:a[0];if(!n){new m.Notice(`Note "${i}" not found in your vault`);return}e.set(n,t.nodes.get(n)),t.relationships.forEach(o=>{if(o.source===n){let g=t.nodes.get(o.target);g&&(e.set(o.target,g),s.push(o))}else if(o.target===n){let g=t.nodes.get(o.source);g&&(e.set(o.source,g),s.push(o))}}),t.nodes=e,t.relationships=s}backoffSingularity(t,i,e){let s=e.settings.maxNodes||40,n=e.settings.maxRelationships||60,a=e.settings.maxTags||10;console.log("Starting backoff task");let o=new Map;i.forEach(r=>{let l=e.nodes.get(r.target);(l==null?void 0:l.type)==="tag"&&(o.has(r.target)||o.set(r.target,[]),o.get(r.target).push(r.source))});let g=Array.from(o.entries()).sort((r,l)=>l[1].length-r[1].length).slice(0,a).map(([r])=>r),d=new Map;g.forEach(r=>{var l;(l=o.get(r))==null||l.forEach(f=>{d.set(f,(d.get(f)||0)+1)})});let y=new Set(Array.from(d.entries()).sort((r,l)=>l[1]-r[1]).slice(0,s-g.length).map(([r])=>r));t.clear(),i.length=0,g.forEach(r=>{let l=e.nodes.get(r);l&&t.set(r,l)}),y.forEach(r=>{let l=e.nodes.get(r);l&&t.set(r,l)});let S=new Set;e.relationships.forEach(r=>{var l,f;if(t.has(r.source)&&t.has(r.target)&&S.size<n){let V=((l=e.nodes.get(r.source))==null?void 0:l.type)!=="tag",G=((f=e.nodes.get(r.target))==null?void 0:f.type)==="tag";V&&G&&(i.push(r),S.add(`${r.source}-${r.target}`))}}),e.relationships.forEach(r=>{let l=`${r.source}-${r.target}`;t.has(r.source)&&t.has(r.target)&&!S.has(l)&&S.size<n&&(i.push(r),S.add(l))}),console.log(`Final reduced graph: ${t.size} nodes, ${i.length} relationships (${t.size+i.length} total elements)`)}prune(t,i){let e=new Set;i.forEach(n=>{e.add(n.source),e.add(n.target)});let s=new Map;t.forEach((n,a)=>{e.has(a)&&s.set(a,n)}),t.clear(),s.forEach((n,a)=>t.set(a,n))}runDotSettings(t){this.settings.includeWeights&&this.settings.weightThreshold&&(t.relationships=t.relationships.filter(i=>i.weight>=this.settings.weightThreshold)),this.settings.subgraphs&&this.clusterSubgraphs(t)}clusterSubgraphs(t){t.nodes.forEach(i=>{i.subgraph=i.type})}runMMDSettings(t){if(this.settings.maxEPerV){let i=[],e=new Map,s=[...t.relationships].sort((n,a)=>a.weight-n.weight);for(let n of s){let a=e.get(n.source)||0;a<this.settings.maxEPerV&&(i.push(n),e.set(n.source,a+1))}t.relationships=i}}runMMDPrinter(t){console.log(`Nodes count: ${t.nodes.length}, Relationships count: ${t.relationships.length}`);let i=`graph ${this.settings.direction||"TD"}
|
|
`;return t.nodes.forEach(e=>{let s=w(e.id);i+=` ${s}["${D(e.name)}"]
|
|
`}),t.relationships.forEach(e=>{let s=w(e.source),n=w(e.target);i+=` ${s} --> ${n}
|
|
`}),i}runDotPrinter(t){let e=`digraph ${this.app.vault.getName()} {
|
|
`;if(e+=` rankdir=LR;
|
|
`,e+=` node [shape=box, style=rounded];
|
|
`,this.settings.subgraphs){let s=new Map;t.nodes.forEach(n=>{let a=n.subgraph||n.type;s.has(a)||s.set(a,[]),s.get(a).push(n)}),s.forEach((n,a)=>{e+=` subgraph cluster_${w(a)} {
|
|
`,e+=` label="${a}";
|
|
`,e+=` style=rounded;
|
|
`,e+=` color="#cccccc";
|
|
`,n.forEach(o=>{let g=w(o.id),d=o.type==="attachment"?'fillcolor="#ffcc80", style="filled,rounded"':'fillcolor="#e3f2fd", style="filled,rounded"';e+=` "${g}" [label="${D(o.name)}", ${d}];
|
|
`}),e+=` }
|
|
`})}else t.nodes.forEach(s=>{let n=w(s.id),a=s.type==="attachment"?'fillcolor="#ffcc80", style="filled,rounded"':'fillcolor="#e3f2fd", style="filled,rounded"';e+=` "${n}" [label="${D(s.name)}", ${a}];
|
|
`});return t.relationships.forEach(s=>{let n=w(s.source),a=w(s.target),o=this.settings.includeWeights&&s.weight>1?` [weight=${s.weight}]`:"";e+=` "${n}" -> "${a}"${o};
|
|
`}),e+="}",e}};var u=require("obsidian"),b=class extends u.Plugin{async onload(){await this.loadSettings(),this.whisperer=new x(this.app,this.settings),this.addRibbonIcon("inspection-panel","Export graph view",()=>{new T(this.app,this).open()}),this.addCommand({id:"export-graph",name:"Export graph to file",callback:()=>{new T(this.app,this).open()}}),this.addSettingTab(new N(this.app,this))}async loadSettings(){this.settings=Object.assign({},M,await this.loadData())}async saveSettings(){await this.saveData(this.settings)}async exportGraph(t=""){try{let i=this.whisperer.buildGraph(),e;if(t)e=(0,u.normalizePath)(t);else{let n=this.app.vault.getName();e=(0,u.normalizePath)(`${n}-graph-data`)}this.settings.lastExported=e,await this.saveSettings();let s;return this.settings.exportFormat==="mmd"?s=await this.exportMermaid(i,e):s=await this.exportDot(i,e),new u.Notice(`Success! Exported to ${(0,u.normalizePath)(this.showWhereExported(s))}`,5e3),s}catch(i){return new u.Notice(`There's a problem: ${i.message}`),null}}async exportMermaid(t,i){let e=this.whisperer.runMMDPrinter(t),s=(0,u.normalizePath)(`${i}.mmd`);return await this.app.vault.create(s,e),s}async exportDot(t,i){let e=this.whisperer.runDotPrinter(t),s=(0,u.normalizePath)(`${i}.dot`);return await this.app.vault.create(s,e),s}showWhereExported(t=""){let i;if(t)i=(0,u.normalizePath)(t);else{let s=this.app.vault.getName();i=(0,u.normalizePath)(`${s}-graph-data`)}return`${this.app.vault.getName()}/${i}`}};
|
|
|
|
/* nosourcemap */ |