@@ -42,22 +42,13 @@ The following are preview images of what the snippet will do and appear like:
42
42
```` shell
43
43
` ` ` dataviewjs
44
44
/*
45
- Snippet: Tag Cloud Version 2
45
+ Snippet: Tag Cloud - Version 2
46
46
47
47
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
52
49
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
61
52
* /
62
53
63
54
/*
@@ -74,6 +65,24 @@ const weightWordCount = 0.5;
74
65
const minFontSize = 12;
75
66
const maxFontSize = 32;
76
67
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
+ }
77
86
78
87
/*
79
88
Get all backlinks
@@ -128,68 +137,16 @@ function Generate_FontSize( backlinks, wordCount )
128
137
function Generate_Color( tagName, tagInfo )
129
138
{
130
139
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
- };
183
140
184
- let cntColors = Object.keys( colors ).length;
141
+ let cntColors = Object.keys( arrColors ).length;
185
142
const tagWords = tagName.split(/\W+/g);
186
143
const colorIndex = Math.floor( Math.random( ) * cntColors );
187
144
const colorID = dv.pages( tagName ).length;
188
145
189
146
if ( bRandomColor === true )
190
- return colors [ Object.keys( colors )[ colorIndex ] ];
147
+ return arrColors [ Object.keys( arrColors )[ colorIndex ] ];
191
148
192
- return colors [ Object.keys( colors )[ colorID ] ];
149
+ return arrColors [ Object.keys( arrColors )[ colorID ] ];
193
150
}
194
151
195
152
/*
@@ -228,10 +185,10 @@ function Sort_Shuffle( arr )
228
185
}
229
186
230
187
/*
231
- Create cloud tags
188
+ Create Cloud
232
189
*/
233
190
234
- const CreateTags = async ( ) =>
191
+ const CreateTagCloud = async ( ) =>
235
192
{
236
193
const tags = new Map( );
237
194
const files = new Map( );
@@ -325,7 +282,7 @@ const CreateTags = async ( ) =>
325
282
} );
326
283
}
327
284
328
- CreateTags ( )
285
+ CreateTagCloud ( )
329
286
` ` `
330
287
` ` ` `
331
288
0 commit comments