tiddlywikitiddlywiki5

Tiddlywiki. TiddlyTools. TagCloud for specific tags only


I just found a great tool for TagCloud generating - https://tiddlytools.com/filtergenerators.html#TiddlyTools%2FFilterGenerators%2FTagCloud

Could you please help me out to change the code for showing only specific tags (For Example: just "TiddlyTools" and "$:/tags/ControlPanel" without others tags)?

\define config() $:/config/TiddlyTools/TagCloud

\define tag-pill-styles() ---------- copied from $:/core/macros/tag - use $(count)$ to set font-size
\define tag-pill-styles()
   background-color:$(backgroundColor)$;
   fill:$(foregroundColor)$;
   color:$(foregroundColor)$;
   font-size:calc(0.5em + (0.2em * ($(count)$ / 5) ) );
\end

\define tag-pill-inner() ---------- copied from $:/core/macros/tag - added $(count)$ display in pill
\define tag-pill-inner(tag,icon,colour,fallbackTarget,colourA,colourB,element-tag,element-attributes,actions)
<$vars foregroundColor=<<contrastcolour target:"""$colour$""" fallbackTarget:"""$fallbackTarget$""" colourA:"""$colourA$""" colourB:"""$colourB$""">> backgroundColor="""$colour$""">
<$element-tag$ $element-attributes$ class="tc-tag-label tc-btn-invisible" style=<<tag-pill-styles>>>
$actions$<$transclude tiddler="""$icon$"""/> <$view tiddler=<<__tag__>> field="title" format="text" /> ($(count)$)
</$element-tag$>
</$vars>
\end

\define tagcloud_get()
<$list filter="[all[tiddlers+shadows]tags[]]">
   <$text text="[["/>{{{ [<currentTiddler>tagging[]count[]divide[10000]] }}};<<currentTiddler>><$text text="]]"/>
</$list>
\end

\define tagcloud_sort()
<$list filter="[enlist<items>!nsort[]]">
   <$list filter="[<currentTiddler>split[;]last[]]"><$text text="[["/><<currentTiddler>><$text text="]]"/></$list>
</$list>
\end

\define tagcloud_showbycount()
<$wikify    name="items"  text=<<tagcloud_get>>  >
   <$wikify name="sorted" text=<<tagcloud_sort>> >
      <$list filter=<<sorted>>>
         <$vars count={{{ [<currentTiddler>tagging[]count[]] }}}>
            <<tag>>
         </$vars>
      </$list>
   </$wikify>
</$wikify>
\end

\define tagcloud_showbyname()
<$list filter="[all[tiddlers+shadows]tags[]sort[]]">
   <$vars count={{{ [<currentTiddler>tagging[]count[]] }}}>
      <<tag>>
   </$vars>
</$list>
\end

<style> .tt-tagcloud input { width:auto !important; } </style>

<div class="tt-tagcloud">
There are      ''<$text text={{{ [all[tiddlers+shadows]tags[]count[]]" }}}/> tags''
and a total of ''<$text text={{{ [all[tiddlers+shadows]tags[]tagging[]count[]]" }}}/>
tagged tiddlers''<br>
sort by:
<$radio tiddler=<<config>> field="sortorder" value="count"> tagging count </$radio>
<$radio tiddler=<<config>> field="sortorder" value="name">  tag name      </$radio>
<p>
<$reveal default={{{ [<config>get[sortorder]] ~[[count]] }}} type="match" text="count"> <<tagcloud_showbycount>> </$reveal>
<$reveal default={{{ [<config>get[sortorder]]            }}} type="match" text="name">  <<tagcloud_showbyname>>  </$reveal>
</p>


Solution

  • Eric Shulman, the author of TiddlyTools, has updated the code. Thanks again, Eric!

    \define config() $:/config/TiddlyTools/TagCloud
    
    \define tag-pill-styles() ---------- copied from $:/core/macros/tag - use $(count)$ to set font-size
    \define tag-pill-styles()
       background-color:$(backgroundColor)$;
       fill:$(foregroundColor)$;
       color:$(foregroundColor)$;
       font-size:calc(0.5em + (0.2em * ($(count)$ / 5) ) );
    \end
    
    \define tag-pill-inner() ---------- copied from $:/core/macros/tag - added $(count)$ display in pill
    \define tag-pill-inner(tag,icon,colour,fallbackTarget,colourA,colourB,element-tag,element-attributes,actions)
    <$vars foregroundColor=<<contrastcolour target:"""$colour$""" fallbackTarget:"""$fallbackTarget$""" colourA:"""$colourA$""" colourB:"""$colourB$""">> backgroundColor="""$colour$""">
    <$element-tag$ $element-attributes$ class="tc-tag-label tc-btn-invisible" style=<<tag-pill-styles>>>
    $actions$<$transclude tiddler="""$icon$"""/> <$view tiddler=<<__tag__>> field="title" format="text" /> ($(count)$)
    </$element-tag$>
    </$vars>
    \end
    
    \define tagcloud_get()
    <$list filter="[<config>get[taglist]enlist-input[]]">
       <$text text="[["/>{{{ [<currentTiddler>tagging[]count[]divide[10000]] }}};<<currentTiddler>><$text text="]]"/>
    </$list>
    \end
    
    \define tagcloud_sort()
    <$list filter="[enlist<items>!nsort[]]">
       <$list filter="[<currentTiddler>split[;]last[]]"><$text text="[["/><<currentTiddler>><$text text="]]"/></$list>
    </$list>
    \end
    
    \define tagcloud_showbycount()
    <$wikify    name="items"  text=<<tagcloud_get>>  >
       <$wikify name="sorted" text=<<tagcloud_sort>> >
          <$list filter=<<sorted>>>
             <$vars count={{{ [<currentTiddler>tagging[]count[]] }}}>
                <<tag>>
             </$vars>
          </$list>
       </$wikify>
    </$wikify>
    \end
    
    \define tagcloud_showbyname()
    <$list filter="[<config>get[taglist]enlist-input[]sort[]]">
       <$vars count={{{ [<currentTiddler>tagging[]count[]] }}}>
          <<tag>>
       </$vars>
    </$list>
    \end
    
    <style> .tt-tagcloud input { width:auto !important; } </style>
    
    <div class="tt-tagcloud">
    Select tags:
    <$button>none
       <$action-setfield $tiddler=<<config>> taglist="" />
    </$button>
    <$button>all
       <$set name="taglist" filter="[all[tiddlers+shadows]tags[]sort[]]">
       <$action-setfield $tiddler=<<config>> taglist=<<taglist>> />
       </$set>
    </$button><br>
    <div style="display:inline-block;float:left;margin-right:1em;margin-bottom:1em;">
       <$select tiddler=<<config>> field="taglist" multiple>
          <$list filter="[all[tiddlers+shadows]tags[]sort[]]"><option><<currentTiddler>></option></$list>
       </$select>
    </div>
    <br>
    There are          ''<$text text={{{ [<config>get[taglist]enlist-input[]count[]]" }}}/> selected tags''
    tagging a total of ''<$text text={{{ [<config>get[taglist]enlist-input[]tagging[]count[]]" }}}/> tiddlers''<br>
    Sort results by:
    <$radio tiddler=<<config>> field="sortorder" value="count"> count </$radio>
    <$radio tiddler=<<config>> field="sortorder" value="name">  name  </$radio>
    <p style="clear:both;">
    <$reveal default={{{ [<config>get[sortorder]] ~[[count]] }}} type="match" text="count"> <<tagcloud_showbycount>> </$reveal>
    <$reveal default={{{ [<config>get[sortorder]]            }}} type="match" text="name">  <<tagcloud_showbyname>>  </$reveal>
    </p>