Would like a hierarchical tag tree

307 views
Skip to first unread message

Damon Pritchett

unread,
Jun 5, 2019, 11:17:14 AM6/5/19
to TiddlyWiki
Hi all,

I would like to create a hierarchical tag tree similar to a table of contents that also includes the root in the list. I would also like to style it in the manner of list-tree (http://listtree.tiddlyspot.com/).. I'm using tags to show relationships of company changes of name and mergers (company succession). The ToC macros work great, but they don't include the root tiddler and I really like the list-tree format. I don't fell that my knowledge is good enough yet to figure out how to modify them on my one. In addition, I want to have the root as the current tiddler.

Thanks very much in advance.

Damon

Damon Pritchett

unread,
Jun 5, 2019, 11:19:38 AM6/5/19
to TiddlyWiki
By the way, I am using tidgraph which I like very much. I'm looking for another way of showing the tag relationships in a more compact manner.

Thanks,

Damon

Mark S.

unread,
Jun 5, 2019, 11:40:04 AM6/5/19
to TiddlyWiki
About including the root in the tree. Can't you just make a tiddler one level above what you want to start at?

So, for instance, in the TOC examples, you could make a "Master" tiddler. You could tag the "Contents" macro with "Master", and then start the tree with the tag "Master". Now "Contents" is included in the tree. Or ... maybe you meant something else ?

Damon Pritchett

unread,
Jun 5, 2019, 11:50:37 AM6/5/19
to TiddlyWiki
Hi Mark S.,

Thanks for the reply. That's not exactly what I'm looking for because then I would have to create many, many extraneous "Master" tiddlers and that would clutter things up considerably in my view although that would do what I'd like as you say. I'd like this to be generic in that I'm considering putting this in a tiddler tagged ViewTemplate.

Damon

TonyM

unread,
Jun 5, 2019, 7:13:18 PM6/5/19
to TiddlyWiki
Damon,

Surely this will do it?

[[Top Tiddler]]
<div class="tc-table-of-contents">
<<toc "Top Tiddler">>
</div>

But then I do not yet use tidgraph

Regards
Tony

Damon Pritchett

unread,
Jun 5, 2019, 7:42:28 PM6/5/19
to TiddlyWiki
Hey Tony,

Yes, that works in a sense, but I would like the output to look like what the ListTree plugin output looks like. Also, I'm not sure how to call the ToC macro with the title of the current tiddler.

This image is kind of what I'm looking for with the possibility of it being expandable.

Capture.PNG

Mark S.

unread,
Jun 5, 2019, 8:16:13 PM6/5/19
to TiddlyWiki
To call the TOC with the title of the current tiddler, use:

<$macrocall $name="toc2" tag=<<currentTiddler>>/>

Note that I'm using "toc2". This is the macro you will need to create to get your lines. Install the line-tree plugin if you haven't already.
Then create a new tiddler and tag it $:/tags/Macro. Put in the following contents:

\define toc-body2(tag,sort:"",itemClassFilter,exclude,path)
<ul class="list-tree">
 
<$list filter="""[all[shadows+tiddlers]tag<__tag__>!has[draft.of]$sort$] -[<__tag__>] -[enlist<__exclude__>]""">
   
<$vars item=<<currentTiddler>> path={{{ [<__path__>addsuffix[/]addsuffix<__tag__>] }}} excluded="""[enlist<__exclude__>] -[<__tag__>]""">
      <$set name="toc-item-class" filter=<<__itemClassFilter__>> emptyValue="toc-item" value="toc-item-selected">
        <li class="xlist-tree">
          <$list filter="[all[current]toc-link[no]]" emptyMessage="<$link><$view field='caption'><$view field='title'/
></$view></$link>">
            <<toc-caption>>
          </$list>
          <$macrocall $name="
toc-body" tag=<<item>> sort=<<__sort__>> itemClassFilter=<<__itemClassFilter__>> exclude=<<excluded>> path=<<path>>/>
        </li>
      </$set>
    </$vars>
  </$list>
</ul>
\end

\define toc2(tag,sort:"",itemClassFilter:"
")
<$macrocall $name="
toc-body2"  tag=<<__tag__>> sort=<<__sort__>> itemClassFilter=<<__itemClassFilter__>> />
\end


This worked in my quick tests.

Be sure to have backups before you do any of this, of course.

Good luck

TonyM

unread,
Jun 5, 2019, 8:25:05 PM6/5/19
to tiddl...@googlegroups.com
Damon,

Have you researched the alternative Toc's in Tiddlywiki.com ? 

[[TableOfContents]]
<div class="tc-table-of-contents">
<<toc-expandable "TableOfContents" "sort[title]">>
</div>


Or make a macro
\define contents(roottiddler:"TableOfContents")
[[$roottiddler$]]
<div class="tc-table-of-contents">
<<toc-expandable "roottiddler" "sort[title]">>
</div>

<<contents>>
or
<<contents tiddlername">>

Or for Current Tiddler as default
\define contentsc()
[[$
(currentTiddler)$]] <!-- or linkWidget -->
<div class="tc-table-of-contents">
<<toc-expandable "$(currentTiddler)$" "sort[title]">>
</div>

<<contentsc>>

I also like Marks suggestion to build your own TOC macro if you want to customise it.
The key coding feature is how it needs two macros one which calls the other, and the other calls itself.

Regards
Tony


Mohammad

unread,
Jun 6, 2019, 3:06:16 AM6/6/19
to TiddlyWiki
Added to TWScripts.

Damon Pritchett

unread,
Jun 6, 2019, 9:41:37 AM6/6/19
to TiddlyWiki
Thanks Mark and Tony,

I will play around with your suggestions and see where it takes me. 

Thanks,

Damon

Damon Pritchett

unread,
Jun 6, 2019, 11:04:44 AM6/6/19
to TiddlyWiki
Have had some fun this morning working with Mark's idea. I modified the code somewhat to add the current Tiddler to the diagram. Here's the code:

\define toc-body2(tag,sort:"",itemClassFilter,exclude,path)
<ul class="list-tree">

 
<li> <<currentTiddler>> </li>

  <ul class="list-tree">
    <$list filter="""[all[shadows+tiddlers]tag<__tag__>!has[draft.of]$sort$] -[<__tag__>] -[enlist<__exclude__>]""">
      <$vars item=<<currentTiddler>> path={{{ [<__path__>addsuffix[/]addsuffix<__tag__>] }}} excluded="""[enlist<__exclude__>] -[<__tag__>]""">
         <$set name="toc-item-class" filter=<<__itemClassFilter__>> emptyValue="toc-item" value="toc-item-selected">
          <li class="list-tree">

            <$list filter="[all[current]toc-link[no]]" emptyMessage="<$link><$view field='caption'><$view field='title'/
></$view></$link>">
              <<toc-caption>>
            </$list>
            <$macrocall $name="
toc-body" tag=<<item>> sort=<<__sort__>> itemClassFilter=<<__itemClassFilter__>> exclude=<<excluded>> path=<<path>>/>

          </li>
        </$set>
      </$vars>
    </$list>
  </ul>
</ul>
\end


\define toc2(tag,sort:"",itemClassFilter:"list-tree")
<$macrocall $name="
toc-body2"  tag=<<__tag__>> sort=<<__sort__>> itemClassFilter=<<__itemClassFilter__>> />
\end

This is quite close. However, as you can see in the picture below, it's not quite right. The top diagram is from the macro and the bottom is just a list with list-tree. There's something about the table of contents macro that is changing things slightly. I've messed around with stylesheets, but haven't quite found the key area to tweak without changing the look of the 2nd diagram. I tried tweaking the macro in the class areas, but to no avail. Any thoughts?

Picture.png

Damon Pritchett

unread,
Jun 7, 2019, 6:21:46 PM6/7/19
to TiddlyWiki
Howdy again,

I have tried for a couple of hours today to solve this problem (in my last post), but I just can't figure it out even with the Inspect feature of Chrome. It's probably very simple, but I'm not seeing it. 

Thanks,

Damon

Damon Pritchett

unread,
Jun 7, 2019, 10:08:27 PM6/7/19
to TiddlyWiki
Another question. Is it possible to do what I would like with simple nested lists? 

Damon

TonyM

unread,
Jun 9, 2019, 12:32:02 AM6/9/19
to TiddlyWiki
Damon,

Have you looked at the tree macro https://tiddlywiki.com/#tree%20Macro

Perhaps clone $:/core/macros/tree and hack it to make your own?

Other wise I can give you a generic recursive macro pair for you do build on

Regards
Tony

TonyM

unread,
Jun 9, 2019, 12:33:14 AM6/9/19
to TiddlyWiki
Short answer Yes
 
Another question. Is it possible to do what I would like with simple nested lists? 


Tony 

Damon Pritchett

unread,
Jun 9, 2019, 11:16:25 AM6/9/19
to TiddlyWiki
Hey Tony,

Thanks for pointing me to the tree macro. I gave it a quick try and it shows some promise. However, I'm not getting the results I expected. I tried it for my Item 1 example in the images above, but I didn't get an expandable/collapsible tree. It was just an indented list with Item 1 at the top. Also, "Item 1" was missing from the title of each member of the list.  I looked at the code for the macro, but I quickly became lost as my macro skills are rudimentary at best. Is there some detailed documentation on the syntax for macros somewhere? What's the best way to learn this stuff?

Maybe, the generic recursive macro that you offered would be a great way for me to learn this stuff. 

As always, thanks so much for your assistance. It's greatly appreciated.

Damon
Reply all
Reply to author
Forward
0 new messages