I have been trying to get my head around the array method of loading an rTree.
The new array structure is quite opaque to me, and the run rev newsletter example given just before rTree 2's release doesn't seem to work (well it would for me.)
In my case I have an array of some 949 items. They are table of contents (the chapter and section headings of a body of text) that I want to display as an rTree.
Currently I am stepping through my array and creating each node as I go but wondered if the array assignment method might be quicker.
My array "aNav" is two dimensional. The first index being just that, an index, the number of the entry (will correspond to the node index in the rTree) and also the reference I use to locate the selected section of the text. The second index being content details for the entry.
Of these, the ones I am interested in to construct my content tree are as follows:
aNav[displayorder]["nav_entry"]
-- The text to display at the rTree node.
aNav[displayorder]["node_depth"]
-- the depth of the entry.
This is 1 higher than the node depth as understood by rTree so I subtract 1 from it to get the rTree node depth
aNav[displayorder]["node_parent"]
-- if the node_depth is "1" then this is "ROOT".
If the node_depth is greater than "1" then this is the index ("playorder") for the parent node of this child.
I also create a custom property for each node equal to the value of "play order" which I use to display the selected section.
Ignoring any other node attributes (like "firstIconCollapsed" etc) how can I put this data into a new array that I can then just copy into an rTree?
if this method is faster than my current, node by node construction then I might be able to create my rTree on the fly.
James
loading an array in rTree v2
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 474
- Joined: Thu Sep 04, 2008 6:23 am
- Location: Melbourne Australia
Re: loading an array in rTree v2
after a long break from LC my head is finally getting into gear.
I finally deciphered how to construct the tree from my array.
this is a first pass and needs a bit of tweaking as I want a bit more detail on the icons given my tree is up to 4 levels deep.
But it has the bare bones of being able to step through my array
It is MUCH faster.
My node by node construction took over 5 seconds (a long time these days).
This construction took 0.111 secs.
It may be fast enough to build as my TOC window appears, thereby getting around the problem of the tree not liking the stack closed when it is constructed.
I finally deciphered how to construct the tree from my array.
Code: Select all
put item 2 of line 1 of the extents of aNav into navpoints
--step through each element
repeat with x = 1 to navpoints
put aNav[X]["nav_entry"] into tree_array[X]["label"] --text of node
put X into tree_array[X]["ref"] --custom param to ref entry in text
-- check to see if child or root
if aNav[X]["node_parent"] = "ROOT" then
--this is a root node so we need to set the [0] parameter of the rTree
put X&cr after tree_array[0]["rootNodeIDs"]
else --we have a child
put X&cr after tree_array[aNav[X]["node_parent"]]["children"]
put 1061 into tree_array[X]["firstIconCollapsed"]
put 1061 into tree_array[X]["firstIconExpanded"]
put empty into tree_array[X]["secondIconCollapsed"]
put empty into tree_array[X]["secondIconExpanded"]
end if
end repeat
dispatch "nodeData" to grp "TOCNavigation" of stack "theTOC" with tree_array
dispatch "renderTree" to group "TOCNavigation" of stack "theTOC"
But it has the bare bones of being able to step through my array
It is MUCH faster.
My node by node construction took over 5 seconds (a long time these days).
This construction took 0.111 secs.
It may be fast enough to build as my TOC window appears, thereby getting around the problem of the tree not liking the stack closed when it is constructed.
Re: loading an array in rTree v2
Hi James!
Nice solution! Glad you got it up and running and thanks a lot for sharing!
Kind regards
Mats
Nice solution! Glad you got it up and running and thanks a lot for sharing!
Kind regards
Mats
http:www.tapirsoft.on-rev.com
Open Source LiveCode Plugins - rIDE, rGrid, rTree
LiveCode projects
Open Source LiveCode Plugins - rIDE, rGrid, rTree
LiveCode projects