Tree Macro built in core

344 views
Skip to first unread message

Damon Pritchett

unread,
Jun 12, 2019, 3:05:49 PM6/12/19
to TiddlyWiki
I'm curious as to whether or now anyone has used the built in tree macro very much. The documentation says that it creates an expandable tree based on tiddler titles, but I never seem to get an expandable tree. All I get is an indented list of tiddlers with the titles shown minus the prefix I used. I think this could be very useful, but presently doesn't really seem to be. How do I use the macro differently to get a true expandable tree of tiddler titles? There must be something fundamental that I'm missing. I've tried looking at the macro, but my lack of macro experience makes it very hard to follow. I'm wanting to use this to generate an expandable tag tree.

Thanks,

Damon

Mat

unread,
Jun 12, 2019, 3:17:13 PM6/12/19
to TiddlyWiki
Examples . You need to scroll down a little so you can click on the folders.

<:-)

Damon Pritchett

unread,
Jun 12, 2019, 3:24:54 PM6/12/19
to TiddlyWiki
Sorry Mat, but I don't see any folders no matter how long the list is. All I get is a single list of tiddler titles that start with the prefix I give the macro. Plus, the prefix is removed from the list which I'd like to not have happen.

Damon

Mat

unread,
Jun 12, 2019, 3:53:20 PM6/12/19
to TiddlyWiki
Well this is what it looks like in the link I provided above. The alphabetically sorted tiddlers "run out" and the expandable folder list starts.


Capture.PNG



<:-)

Mark S.

unread,
Jun 12, 2019, 3:53:54 PM6/12/19
to TiddlyWiki
In the example given at TiddlyWiki.com, based on prefix $:/, scroll down until you get to "boot". It has a folder icon in front of it.  Clicking on it expands it to show the sub-tiddlers.

So ... the expandable part needs to be deeper one level. If your test data only has one level of "depth", then you won't get an expandable folder.

Mat

unread,
Jun 12, 2019, 4:00:32 PM6/12/19
to TiddlyWiki
Ah, sorry, you're saying that you can't get it to work in your wiki.

The tiddlers must, as far as I can tell, use a file path name with /

So if you have e.g <<tree prefix:"hey">> then other tiddlers should be named e.g hey/one , hey/one/one  etc

<:-)


Damon Pritchett

unread,
Jun 12, 2019, 5:49:45 PM6/12/19
to TiddlyWiki
Ok - I see. My tiddlers don't have a "/" in any of their names so that explains it. A couple more questions now. What does the "chunk" parameter do? Also, would it be terribly difficult to modify the macro to list the folders first and also not to exclude the prefix from the listed tiddler names?

Thanks,

Damon

Mat

unread,
Jun 12, 2019, 6:34:42 PM6/12/19
to TiddlyWiki
Damon, make a backup copy of your TW, then do a search for $:/core/macros/tree and investigate and experiment to see how far you get.

<:-)

Damon Pritchett

unread,
Jun 12, 2019, 7:24:16 PM6/12/19
to TiddlyWiki
I'll give it a shot.

Damon

@TiddlyTweeter

unread,
Jun 13, 2019, 12:54:01 AM6/13/19
to TiddlyWiki
Hi Damon

There was a discussion on GitHub you might find informative https://github.com/Jermolene/TiddlyWiki5/issues/3792

Best wishes
Josiah

PMario

unread,
Jun 13, 2019, 3:12:30 AM6/13/19
to TiddlyWiki
Hi,


On Wednesday, June 12, 2019 at 11:49:45 PM UTC+2, Damon Pritchett wrote:
Ok - I see. My tiddlers don't have a "/" in any of their names so that explains it. A couple more questions now. What does the "chunk" parameter do?

We call it a "namespace" eg: $:/ is a shortcut namespace for all system tiddlers.

$:/core/ ... core stuff and so on.
 
Also, would it be terribly difficult to modify the macro to list the folders first and also not to exclude the prefix from the listed tiddler names?

It wasn't designed, to be used that way. So it would probably be a rewrite.

-mario

Jeremy Ruston

unread,
Jun 13, 2019, 3:52:38 AM6/13/19
to tiddl...@googlegroups.com
Hi Damon, Mario,

Prompted by this discussion, I’ve just updated the tree macro so that the separator can be customised:


When the build has completed in a few minutes, you’ll be able to see a second example here:


As it turns out, I suspect it’s not wildly useful beyond the system tiddlers. Given the following data tiddlers:


The output is:


Best wishes

Jeremy.


--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/a4176b59-2239-4c8b-a5cf-fbdeeb722e53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

@TiddlyTweeter

unread,
Jun 13, 2019, 10:40:23 AM6/13/19
to TiddlyWiki

Jeremy Ruston wrote:
As it turns out, I suspect it’s not wildly useful beyond the system tiddlers. Given the following data tiddlers:

 
For some use cases, perhaps? For instance a navigator for a novel you want separate from "system" ($:).

Say...

 Great Expectations-Vol 1-Chapter 1-Para 1

through to 

 Great Expectations-Vol 2-Chapter 52-Para 135

In someways I think its about having a navigator that is more than for $:? But its not exactly desperately needed :-)

But the Tree Explorer certainly helps, I think, understand structure in TW. And its a good metaphorical likeness to file browsers.

Best wishes
Josiah


... The output is ...



Damon Pritchett

unread,
Jun 13, 2019, 10:09:00 PM6/13/19
to TiddlyWiki
Great discussion and I like the new option for separator in the tree macro. Looking forward to the next release although I may start using the updated tree macro sooner.

Damon

Damon Pritchett

unread,
Jun 13, 2019, 11:03:49 PM6/13/19
to TiddlyWiki
The more I look at this, the more I like it and it may be just what I've been needing for a long time. I do have a question. Would it be possible to have the macro, as on option, look at the caption or another field instead of the tiddler title? I ask this because I can see, at least in my case, the tiddler titles getting extremely long which is not aesthetically pleasing not to mention hard to read.

Thanks again,

Damon

Damon Pritchett

unread,
Jun 14, 2019, 11:44:43 AM6/14/19
to TiddlyWiki
In looking at the tree macro this morning, I'm wondering if I changed the filter lines that contain [

all[shadows+tiddlers]


to something that searched for a certain field instead of the title. It's probably not that simple and I thought I'd ask for opinions before I started hacking things.

Thanks,

Damon

Damon Pritchett

unread,
Jun 14, 2019, 3:08:11 PM6/14/19
to TiddlyWiki
All right, it's definitely not that simple. Can what I want to do be done with just modifications or is a whole new macro needed for that?

Damon

Mark S.

unread,
Jun 14, 2019, 4:31:45 PM6/14/19
to TiddlyWiki
Be sure to have a backukp, or use on a disposable TW file.

Clone the existing $:/core/macros/tree tiddler, rename it to $:/core/macros/tree2, and replace the contents with the code below.

Invoke as "tree2" -- this way there will be no confusion when reporting results to the community.

This uses the "description" field to form the relationships. I guess the next step would be for someone to write a version where you can specify any field to form the relationships.



\define leaf-link2(full-title,chunk,separator: "/")
<$link to=<<__full-title__>>><$text text=<<__chunk__>>/></$link>
\end

\define leaf-node2(prefix,chunk)
<li>
<$list filter="[<__prefix__>addsuffix<__chunk__>]" variable="full-title">
<$list filter="[description<full-title>is[shadow]] [description<full-title>is[tiddler]]" variable="dummy">
<$list filter="[<full-title>removeprefix<__prefix__>]" variable="chunk">
<span>{{$:/core/images/file}}</span> <$macrocall $name="leaf-link2" full-title=<<full-title>> chunk=<<chunk>>/>
</
$list>
</$list>
</
$list>
</li>
\end

\define branch-node2(prefix,chunk,separator: "/")
<li>
<$set name="
reveal-state" value={{{ [[$:/state/tree/]addsuffix<__prefix__>addsuffix<__chunk__>] }}}>
<$reveal type="
nomatch" stateTitle=<<reveal-state>> text="show">
<$button setTitle=<<reveal-state>> setTo="
show" class="tc-btn-invisible">
{{$:/core/images/folder}} <$text text=<<__chunk__>>/>
</$button>
</$reveal>
<$reveal type="
match" stateTitle=<<reveal-state>> text="show">
<$button setTitle=<<reveal-state>> setTo="
hide" class="tc-btn-invisible">
{{$:/core/images/folder}} <$text text=<<__chunk__>>/>
</$button>
</$reveal>
<span>(<$count filter="
[all[shadows+tiddlers]each[description]get[description]removeprefix<__prefix__>removeprefix<__chunk__>] -[<__prefix__>addsuffix<__chunk__>]"/>)</span>
<$reveal type="
match" stateTitle=<<reveal-state>> text="show">
<$macrocall $name="
tree-node2" prefix={{{ [<__prefix__>addsuffix<__chunk__>] }}} separator=<<__separator__>>/>
</$reveal>
</$set>
</li>
\end

\define tree-node2(prefix,separator: "
/")
<ol>
<$list filter="
[all[shadows+tiddlers]each[description]get[description]removeprefix<__prefix__>splitbefore<__separator__>sort[]!suffix<__separator__>]" variable="chunk">
<$macrocall $name="
leaf-node2" prefix=<<__prefix__>> chunk=<<chunk>> separator=<<__separator__>>/>
</$list>
<$list filter="
[all[shadows+tiddlers]each[description]get[description]removeprefix<__prefix__>splitbefore<__separator__>sort[]suffix<__separator__>]" variable="chunk">
<$macrocall $name="
branch-node2" prefix=<<__prefix__>> chunk=<<chunk>> separator=<<__separator__>>/>
</$list>
</ol>
\end

\define tree2(prefix: "
$:/",separator: "/")
<div class="
tc-tree">
<span><$text text=<<__prefix__>>/></span>
<div>
<$macrocall $name="
tree-node2" prefix=<<__prefix__>> separator=<<__separator__>>/>
</div>
</div>
\end


Damon Pritchett

unread,
Jun 14, 2019, 6:28:58 PM6/14/19
to TiddlyWiki
Thanks Mark! That worked great. In looking at your code, I can see where I went wrong when I tried to do the same thing. Lack of experience on my part certainly is evident.

Damon

Damon Pritchett

unread,
Jun 14, 2019, 7:56:44 PM6/14/19
to TiddlyWiki
After playing around with this new macro further, I've found that it only works as long as the description matches the tiddler title exactly. If not, then there is an entry in the tree list to a tiddler that doesn't exist.  What tweak could I make that would fix this? 

Thanks,

Damon

Mark S.

unread,
Jun 14, 2019, 11:54:37 PM6/14/19
to TiddlyWiki


On Friday, June 14, 2019 at 4:56:44 PM UTC-7, Damon Pritchett wrote:
After playing around with this new macro further, I've found that it only works as long as the description matches the tiddler title exactly. If not, then there is an entry in the tree list to a tiddler that doesn't exist.  What tweak could I make that would fix this? 



I don't know what you mean. Nothing should depend on the title. Perhaps you could attach some sample tiddlers so we could see what is happening.

Thanks!

Pit.W.

unread,
Jun 16, 2019, 5:01:33 AM6/16/19
to tiddl...@googlegroups.com


Am 13.06.2019 um 09:52 schrieb Jeremy Ruston:
I suspect it’s not wildly useful beyond the system tiddlers


Some useful use-cases, maybe not wildly so...

If I call <<tree prefix:"2019" separator:"-">> I get a tree of my journal tiddlers; nice.

It might be wildly useful in Biology: I  want to inventorise my aquarium using latin nomenclature, where I have a fish named "Pisces Botiidae Cypriniformes Osteichthyes Botiidae Botiini Leptobotia curta"

I call the macro with : <<tree prefix:"Pisces" separator:" ">>

One might argue that a relational Access databse can achieve the same, but it could not, in the same file, deal with entries like "unknown red fish" "decorative white stone" Task: clean the glass"

On top: If I enter one fish, all higher levels of the systemic nomenclature are displayed in the tree

In History, one could display dynasties, or the "Order of Battle" of a historic army, using the comma as a separator


_________________________________________________________________
________________________________________________________
Ihre E-Mail-Postfächer sicher & zentral an einem Ort. Jetzt wechseln und alte E-Mail-Adresse mitnehmen! https://www.eclipso.de


Damon Pritchett

unread,
Jun 16, 2019, 10:59:33 AM6/16/19
to TiddlyWiki
Hey Mark,

Yeah, I didn't explain very well. Hopefully, the following will help.

So I have a tiddler titled "Atchison Daily Champion, Sunday, March 8, 1868." I put the following in the description field "Newspapers-Kansas-Atchison-Daily Champion-1868-03-08." The output of the macro looked just as expected (see screenshot), except that the link on the 08 node doesn't link to my tiddler. It wants to link to a tiddler named the same as the description field. This is not what I was hoping for. I want to use the description field to generate the tree, but retain the shorter, more readable tiddler title.  

tree.png

Mark S.

unread,
Jun 16, 2019, 1:13:58 PM6/16/19
to TiddlyWiki
Ok a coupe tweaks to leaf-node2 may do it (until you find another bug) :

\define leaf-node2(prefix,chunk)
<li>
<$list filter="[<__prefix__>addsuffix<__chunk__>]" variable="full-title">
<$list filter="[description<full-title>is[shadow]] [description<full-title>is[tiddler]]" variable="tiddler">

<$list filter="[<full-title>removeprefix<__prefix__>]" variable="chunk">
<span>{{$:/core/images/file}}</span> <$macrocall $name="leaf-link2" full-title=<<tiddler>> chunk=<<chunk>>/>

</$list>
</$list>
</$list>
</li>
\end

Damon Pritchett

unread,
Jun 16, 2019, 10:43:23 PM6/16/19
to TiddlyWiki
Thanks Mark! That did the trick. I really appreciate the help. I think I understand what you did and why as well. I just wish I could think of those kinds of things on my own. Time and experience will change that I'm sure.

Damon

Damon Pritchett

unread,
Jun 27, 2019, 3:16:35 PM6/27/19
to TiddlyWiki
Hey Mark, et. al.,

I've been using the modified tree macro for quite a while now and am very happy with it. I would like to make another modification to it, but I haven't been able to figure out how to do it yet so am reaching out for hlep. What I would like to do is to have the folders sorted alphabetically with the non-folders (that is, not have the folders all grouped together at the end).  Is this even possible without a total rewrite?

Thanks,

Damon

Mark S.

unread,
Jun 27, 2019, 5:22:14 PM6/27/19
to TiddlyWiki
You can try this change to tree-node2, which may work as long AS you don't have any entries ending in "XXX" or "YYY". (these are end-of-title markers, which could be made more obscure if necessary).

\define tree-node2(prefix,separator: "/")
<ol>
<$list filter="[all[shadows+tiddlers]each[description]get[description]removeprefix<__prefix__>splitbefore<__separator__>!suffix<__separator__>addsuffix[XXX]]
 [all[shadows+tiddlers]each[description]get[description]removeprefix<__prefix__>splitbefore<__separator__>suffix<__separator__>addsuffix[YYY]] +[sort[]]"
 variable="chunk">
<$list filter="[<chunk>removesuffix[XXX]]" variable="chunk2">
<$macrocall $name="leaf-node2" prefix=<<__prefix__>> chunk=<<chunk2>> separator=<<__separator__>>/>
</$list>
<$list filter="[<chunk>removesuffix[YYY]]" variable="chunk2">
<$macrocall $name="branch-node2" prefix=<<__prefix__>> chunk=<<chunk2>> separator=<<__separator__>>/>
</$list>
</$list>
</ol>
\end

Damon Pritchett

unread,
Jun 28, 2019, 10:06:36 AM6/28/19
to TiddlyWiki
Thanks again, Mark. That seems to do the trick with a small amount of testing that I've done. I'll give it a more thorough going through over the next several days.

Damon

Damon Pritchett

unread,
Jun 30, 2019, 4:41:28 PM6/30/19
to TiddlyWiki
After playing some more, it seems like you're tweak is going to work just fine. The only thing additional that I did was change the sort to sortan since I'm using a lot of numbers.

Damon
Reply all
Reply to author
Forward
0 new messages