Skip to content

Commit 358e3b0

Browse files
committed
update color generation for Tag Cloud snippet 2
1 parent ee8f05f commit 358e3b0

File tree

1 file changed

+28
-71
lines changed

1 file changed

+28
-71
lines changed

Snippets/Tag Cloud 2/README.md

Lines changed: 28 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,13 @@ The following are preview images of what the snippet will do and appear like:
4242
````shell
4343
```dataviewjs
4444
/*
45-
Snippet: Tag Cloud Version 2
45+
Snippet: Tag Cloud - Version 2
4646
4747
This snippet requires the Dataview Plugin
48-
https://github.com/blacksmithgu/obsidian-dataview
49-
50-
Creates a cloud with all of your tags which are clickable to
51-
search for associated pages related to the selected cloud.
48+
https://github.com/blacksmithgu/obsidian-dataview
5249
53-
sortOption
54-
1 = Sort Alphabetically (Descending)
55-
2 = Sort Alphabetically (Ascending)
56-
3 = Sort Random / Shuffle
57-
58-
bRandomColor
59-
true = Uses random colors for each tag
60-
false = Tags with more uses gets more colorful
50+
View settings at:
51+
https://github.com/Aetherinox/obsidian-dataview-snippets/tree/main/Snippets/Tag%20Cloud%202
6152
*/
6253
6354
/*
@@ -74,6 +65,24 @@ const weightWordCount = 0.5;
7465
const minFontSize = 12;
7566
const maxFontSize = 32;
7667
const tagsFilter = [ "#tag1", "#tag2" ];
68+
const arrColors = [];
69+
70+
/*
71+
Generate 40 colors
72+
*/
73+
74+
for ( let i = 0; i < 40; i++ )
75+
{
76+
77+
let R = Math.floor( ( Math.random( ) * 100 ) + 100 );
78+
let G = Math.floor( ( Math.random( ) * 100 ) + 100 );
79+
let B = Math.floor( ( Math.random( ) * 100 ) + 100 );
80+
81+
let rgb = ( R << 16 ) + ( G << 8 ) + B;
82+
let itemColor = `#${rgb.toString( 16 )}`;
83+
84+
arrColors.push( itemColor );
85+
}
7786
7887
/*
7988
Get all backlinks
@@ -128,68 +137,16 @@ function Generate_FontSize( backlinks, wordCount )
128137
function Generate_Color( tagName, tagInfo )
129138
{
130139
if ( tagName == null ) { return "#FFFFFF"; }
131-
const colors =
132-
{
133-
"grey-01": "#636363",
134-
"grey-02": "#777777",
135-
"grey-03": "#8e8e8e",
136-
"grey-1": "#c8c9cb",
137-
"teal-1": "#cfebf1",
138-
"green-1": "#b3dfce",
139-
"yellow-1": "#f4e3bd",
140-
"orange-1": "#f4d4b3",
141-
"red-1": "#ddb6b9",
142-
"fuchsia-1": "#fbb7ce",
143-
"purple-1": "#d0c2df",
144-
"blue-1": "#c5cadf",
145-
"dblue-1": "#c5c6cc",
146-
"grey-2": "#a3a5a8",
147-
"teal-2": "#b0dde8",
148-
"green-2": "#80c9ae",
149-
"yellow-2": "#edd091",
150-
"orange-2": "#edb780",
151-
"red-2": "#c7868a",
152-
"fuchsia-2": "#f987ae",
153-
"purple-2": "#b09ac9",
154-
"blue-2": "#9ea6c9",
155-
"dblue-2": "#9ea1ab",
156-
"grey-3": "#7e8085",
157-
"teal-3": "#90cfde",
158-
"green-3": "#4db38e",
159-
"yellow-3": "#e6bd64",
160-
"orange-3": "#e59a4d",
161-
"red-3": "#b1565b",
162-
"fuchsia-3": "#f6578d",
163-
"purple-3": "#9071b3",
164-
"blue-3": "#7782b3",
165-
"dblue-3": "#777b89",
166-
"teal-4": "#60bbd0",
167-
"green-4": "#00935d",
168-
"yellow-4": "#dba022",
169-
"orange-4": "#da6f01",
170-
"red-4": "#a93c43",
171-
"fuchsia-4": "#f20f5c",
172-
"purple-4": "#613493",
173-
"blue-4": "#3c4d93",
174-
"grey-5": "#535f77",
175-
"green-5": "#008454",
176-
"yellow-5": "#c5901f",
177-
"orange-5": "#c57a2d",
178-
"red-5": "#b93f45",
179-
"red-6": "#9b3a40",
180-
"fuchsia-5": "#da0e53",
181-
"fuchsia-6": "#bf2458",
182-
};
183140
184-
let cntColors = Object.keys( colors ).length;
141+
let cntColors = Object.keys( arrColors ).length;
185142
const tagWords = tagName.split(/\W+/g);
186143
const colorIndex = Math.floor( Math.random( ) * cntColors );
187144
const colorID = dv.pages( tagName ).length;
188145
189146
if ( bRandomColor === true )
190-
return colors[ Object.keys( colors )[ colorIndex ] ];
147+
return arrColors[ Object.keys( arrColors )[ colorIndex ] ];
191148
192-
return colors[ Object.keys( colors )[ colorID ] ];
149+
return arrColors[ Object.keys( arrColors )[ colorID ] ];
193150
}
194151
195152
/*
@@ -228,10 +185,10 @@ function Sort_Shuffle( arr )
228185
}
229186
230187
/*
231-
Create cloud tags
188+
Create Cloud
232189
*/
233190
234-
const CreateTags = async ( ) =>
191+
const CreateTagCloud = async ( ) =>
235192
{
236193
const tags = new Map( );
237194
const files = new Map( );
@@ -325,7 +282,7 @@ const CreateTags = async ( ) =>
325282
} );
326283
}
327284
328-
CreateTags( )
285+
CreateTagCloud( )
329286
```
330287
````
331288

0 commit comments

Comments
 (0)