[TW5] poor man's tag cloud

284 views
Skip to first unread message

UBi

unread,
Apr 1, 2014, 9:19:15 AM4/1/14
to tiddl...@googlegroups.com
Hi,

currently I'm using a start tiddler comme ça, resembling a kind of poor man's tag cloud:
<$list filter="[tags[]!is[system]sort[title]]">    
<$set name="cnt" value="<$count filter=[is[current]tagging[]]/>">    
<$transclude tiddler="$:/core/ui/TagTemplate"/><
<cnt>>    
</$set>    
</$list>    

I would like to use <<cnt>> to style the tag pills, e.g.
<$list filter="[tags[]!is[system]sort[title]]">
<$set name="cnt" value="<$count filter=[is[current]tagging[]]/>">
<span style="font-size:1.<
<cnt>>em">
<$transclude tiddler="
$:/core/ui/TagTemplate"/>
</span>
</$set>
</$list>

but that doesn't work. Why? What would be the Right Way to do it?

Uwe

Stephan Hradek

unread,
Apr 1, 2014, 9:45:24 AM4/1/14
to tiddl...@googlegroups.com
I don't think it's possible yet.

Stephan Hradek

unread,
Apr 1, 2014, 10:20:45 AM4/1/14
to tiddl...@googlegroups.com
I just created a "count" filter which WOULD help with this, but your idea is not well thought through. Imagine I have a 3 counts: 1, 10 and 100. The resulting sizes would be: "1.1em", "1.10em" and "1.100em". Would you be able to tell the difference? ;)

For completeness sake, this is the source of my count filter:

/*\
title: $:/core/modules/filters/count.js
type: application/javascript
module-type: filteroperator

Filter operator that gives the counts the current list's members

\*/

(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

/*
Export our filter function
*/

exports
.count = function(source,operator,options) {
       
// count the source if it's not an array
       
var count = 0;
       
if(!$tw.utils.isArray(source)) {
                $tw
.utils.each(source,function(element,title) {
                       
++count;
               
});
               
return [ "" + count ];
       
}
       
// return array's length        
       
return [ "" + source.length ];
};

})();


used like this (using your request)

\define mySize()
"font-size:$(cnt)$em"
\end


<$list filter="[tags[]!is[system]sort[title]]">

 
<$set name="title" value={{!!title}}>
   
<$list filter="[is[current]tagging[]count[]]">
     
<$set name="cnt" value={{!!title}}>
       
<span style=<<mySize>>>
         
<$tiddler tiddler=<<title>>>

           
<$transclude tiddler="$:/core/ui/TagTemplate"/>

         
</$tiddler>
        </
span>
     
</$set>
    </
$list>
 
</$set>
</
$list>



I'm not sure yet, whether to make it a plugin. Comments welcome.


UBi

unread,
Apr 3, 2014, 2:33:49 PM4/3/14
to tiddl...@googlegroups.com
Hallo Stephan,

I'm a bit late, but: thanks! It works! At least with counts up to 9 :-)

The missing parts for a real tag cloud implementation are AFAICS:
1) get min and max count over all tags (minCnt, maxCnt)
2) fit each count (cnt) into a corresponding font size range (minFontsize, maxFontsize):
fontSize = minFontsize + (cnt – minCount) * (maxFontsize – minFontsize) / (maxCount - minCount)

So much for the theory. Implementation is left as an exercise for the reader :-)

Uwe

Sylvain Naudin

unread,
Apr 22, 2016, 4:48:32 AM4/22/16
to TiddlyWiki
Hello Uwe,

Sorry to publish on this old post, did you have found a solution to have a cloud tag with bigger pills ? Just try Stephan code but don't work for me.


Cheers
Sylvain
Reply all
Reply to author
Forward
0 new messages