Skip to content

Commit 0330239

Browse files
committed
change: cloud-tags - change font sensitivity to make quantity more meaningful
1 parent 46b95c4 commit 0330239

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Snippets/Tag Cloud 1/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ const QueryFiles = dv.pages( QueryStr );
6868
const bRandomColor = true;
6969
const sortOption = 1;
7070
const weightBacklinks = 0.1;
71-
const weightWordCount = 0.3;
71+
const weightWordCount = 0.05;
7272
const minFontSize = 12;
73-
const maxFontSize = 32;
73+
const maxFontSize = 36;
7474
const tagsFilter = [ "#tag1", "#tag2" ];
7575
const arrColors = [];
7676
@@ -323,9 +323,9 @@ const QueryFiles = dv.pages( QueryStr );
323323
const bRandomColor = true;
324324
const sortOption = 1;
325325
const weightBacklinks = 0.1;
326-
const weightWordCount = 0.3;
326+
const weightWordCount = 0.05;
327327
const minFontSize = 12;
328-
const maxFontSize = 32;
328+
const maxFontSize = 36;
329329
const tagsFilter = [ "#tag1", "#tag2" ];
330330
331331
const arrColors=[];dv.container.className+=" atx-tcv1-dataview";for(let t=0;t<40;t++){let t=Math.floor(100*Math.random()+100),o=Math.floor(100*Math.random()+100),e=Math.floor(100*Math.random()+100),a=(t<<16)+(o<<8)+e,n=`#${a.toString(16)}`;arrColors.push(n)}async function QueryBacklinks(t){const o=t.split("/").pop().split(".").slice(0,-1).join(".");return dv.query(`\n LIST\n FROM [[${o}]] AND ${QueryStr}\n SORT file.name DESC\n `)}async function QueryWordcount(t){const o=require("fs"),e=require("path"),a=o.readFileSync(e.join(app.vault.adapter.basePath,t),"utf-8").replace(/---[\s\S]*?---|```[\s\S]*?```|\$[\s\S]*?\$|\$\$[\s\S]*?\$\$/g,"").match(/\S+/g);return a?a.length:0}function Generate_FontSize(t,o){const e=2.5*Math.sqrt(t*weightBacklinks+o*weightWordCount);return Math.round(e/100*(maxFontSize-minFontSize)+minFontSize)}function Generate_Color(t,o){if(null==t)return"#FFFFFF";let e=Object.keys(arrColors).length;t.split(/\W+/g);const a=Math.floor(Math.random()*e),n=dv.pages(t).length;return!0===bRandomColor?arrColors[Object.keys(arrColors)[a]]:arrColors[Object.keys(arrColors)[n]]}function Sort_DESC(t){return t.sort(((t,o)=>t.id.localeCompare(o.id))),t}function Sort_ASC(t){return t.sort(((t,o)=>o.id.localeCompare(t.id))),t}function Sort_Shuffle(t){for(let o=t.length-1;o>0;o--){const e=Math.floor(Math.random()*(o+1));[t[o],t[e]]=[t[e],t[o]]}return t}const CreateTagCloud=async()=>{const tags=new Map,files=new Map;Promise.all(QueryFiles.map((async t=>{const o=t.file,e=QueryBacklinks(o.path),a=QueryWordcount(o.path);o.tags&&await Promise.all(o.tags.map((async t=>{tags.has(t)||tags.set(t,{backlinks:0,wordCount:0});const o=tags.get(t),n=await e;o.backlinks+=n.value.values.length;const r=await a;o.wordCount+=r})));for(let t=0;t<tagsFilter.length;t++)tags.has(tagsFilter[t])&&tags.delete(tagsFilter[t]);const n={backlinks:0,wordCount:0},r=await e;n.backlinks=r.value.values.length;const s=await a;n.wordCount=s,files.set(o,n)}))).then((()=>{const data=[];let count=0;if(tags.forEach(((t,o)=>{count++;const e=Generate_FontSize(t.backlinks,t.wordCount),a=Generate_Color(o,t),n=dv.pages(o).length;data.push({name:`\\${o}`,id:o,length:n,fontSize:e,color:a})})),0===count){const t=dv.el("div","🔖 No Tags Found",{cls:"atx-tcv1-results_none"});return t.setAttribute("style","text-align:center;"),""}const sortOptions={1:"Sort_DESC",2:"Sort_ASC",3:"Sort_Shuffle"};let funcSort=sortOptions[sortOption];return void 0===funcSort&&(funcSort=sortOptions[1]),eval(funcSort)(data).map((t=>`<div class="cloudtags-v1-item"><a class="cloudtags-v1-link" href="obsidian://search?query=tag:${encodeURIComponent(t.id)}" style="font-size:${t.fontSize}px; color: ${t.color};">${t.id}</a><div class="tagcloud-v1-length">${t.length}</div></div>`)).join("")})).then((t=>dv.paragraph(t))).catch((t=>{console.error("Error: "+t)}))};CreateTagCloud();

Snippets/Tag Cloud 2/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ const QueryFiles = dv.pages( QueryStr );
133133
const bRandomColor = true;
134134
const sortOption = 1;
135135
const weightBacklinks = 0.1;
136-
const weightWordCount = 0.5;
137-
const minFontSize = 10;
136+
const weightWordCount = 0.05;
137+
const minFontSize = 12;
138138
const maxFontSize = 36;
139139
const tagsFilter = [ "#tag1", "#tag2" ];
140140
const arrColors = [];
@@ -388,8 +388,8 @@ const QueryFiles = dv.pages( QueryStr );
388388
const bRandomColor = true;
389389
const sortOption = 1;
390390
const weightBacklinks = 0.1;
391-
const weightWordCount = 0.5;
392-
const minFontSize = 10;
391+
const weightWordCount = 0.05;
392+
const minFontSize = 12;
393393
const maxFontSize = 36;
394394
const tagsFilter = [ "#tag1", "#tag2" ];
395395

0 commit comments

Comments
 (0)