Skip to content

Commit c396775

Browse files
committed
Fixes #75
1 parent 77716a4 commit c396775

4 files changed

Lines changed: 62 additions & 9 deletions

File tree

docs/make.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ makedocs(;
2323
"Our implementation" => "the_mtg/our_implementation.md"
2424
],
2525
"Tutorials" => [
26-
"tutorials/0.read_write.md",
27-
"tutorials/1.manipulate_node.md",
28-
"tutorials/2.descendants_ancestors_filters.md",
29-
"tutorials/3.transform_mtg.md",
30-
"tutorials/4.convert_mtg.md",
31-
"tutorials/5.plotting.md",
32-
"tutorials/6.add_remove_nodes.md",
33-
"tutorials/7.performance_considerations.md",
26+
"Read and Write MTGs" => "tutorials/0.read_write.md",
27+
"Create and Manipulate Nodes" => "tutorials/1.manipulate_node.md",
28+
"Traversal, Descendants, Ancestors and Filters" => "tutorials/2.descendants_ancestors_filters.md",
29+
"Transform and Select Attributes" => "tutorials/3.transform_mtg.md",
30+
"Convert MTGs to Tables and Graphs" => "tutorials/4.convert_mtg.md",
31+
"Plot MTGs" => "tutorials/5.plotting.md",
32+
"Add and Remove Nodes" => "tutorials/6.add_remove_nodes.md",
33+
"Performance Considerations" => "tutorials/7.performance_considerations.md",
3434
],
3535
"API" => "api.md",
3636
]

docs/src/get_started.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
This page let's you take a peek at what the package is capable of. If you want a better, more in-depth introduction to the package, take a look at the tutorials, starting from [Read and Write MTGs](@ref). If you don't know what an MTG is, you can read more about starting from [The MTG concept](@ref).
66

7+
If your main goal is to query trees (children, descendants, ancestors, filters), go directly to [Traversal, descendants, ancestors and filters](@ref).
8+
79
## Installation
810

911
You must have a working Julia installation on your computer. The version of Julia should be greater than 1.3.
@@ -80,3 +82,11 @@ You can also convert your MTG to a [MetaGraph](https://juliagraphs.org/MetaGraph
8082
```@example usepkg
8183
MetaGraph(mtg)
8284
```
85+
86+
## Next step: traversal tutorial
87+
88+
If you are new to MTGs or graph vocabulary, this is usually the best next page:
89+
90+
- [Traversal, descendants, ancestors and filters](@ref)
91+
92+
It explains these words in plain language and gives practical query recipes.

docs/src/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ The MTG format helps describe the plant at different scales at the same time. Fo
2525

2626
You can find out how to use the package on the [Getting started](@ref) section, or more about the MTG format in the [The MTG concept](@ref).
2727

28+
If your immediate goal is querying MTGs (descendants, ancestors, filters), go to [Traversal, descendants, ancestors and filters](@ref).
29+
2830
## References
2931

3032
Godin, C., et Y. Caraglio. 1998. « A Multiscale Model of Plant Topological Structures ». Journal of Theoretical Biology 191 (1): 1‑46. https://doi.org/10.1006/jtbi.1997.0561.

docs/src/tutorials/2.descendants_ancestors_filters.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Node attributes
1+
# Traversal, descendants, ancestors and filters
22

33
```@setup usepkg
44
using MultiScaleTreeGraph
@@ -17,6 +17,47 @@ file = joinpath(dirname(dirname(pathof(MultiScaleTreeGraph))),"test","files","si
1717
mtg = read_mtg(file)
1818
```
1919

20+
## If you are new to these words
21+
22+
If you are not from computer science, the vocabulary can be confusing. In this package:
23+
24+
- **Traversal** means "walking through nodes one by one".
25+
- A **parent** is the node directly above another node.
26+
- A **child** is a node directly below another node.
27+
- **Descendants** are children, children of children, etc.
28+
- **Ancestors** are parent, parent of parent, etc.
29+
30+
You can think of this like a family tree.
31+
32+
For the common cases:
33+
34+
- Use [`descendants`](@ref) to move downward in the MTG.
35+
- Use [`ancestors`](@ref) to move upward in the MTG.
36+
- Add filters (`symbol`, `scale`, `filter_fun`) when you only need part of the MTG.
37+
38+
## Traversal quick recipes
39+
40+
These examples cover the most common requests:
41+
42+
```@example usepkg
43+
node_5 = get_node(mtg, 5)
44+
45+
# 1) Get one attribute for the whole subtree
46+
descendants(mtg, :Length)
47+
48+
# 2) Get nodes instead of values
49+
descendants(mtg)
50+
51+
# 3) Get one attribute from parents and grandparents
52+
ancestors(node_5, :Length)
53+
54+
# 4) Filter by symbol and ignore nodes without the attribute
55+
descendants(mtg, :Length, symbol=:Leaf, ignore_nothing=true)
56+
```
57+
58+
!!! tip
59+
If you call the same traversal many times in a simulation loop, look at [Performance Considerations](@ref), especially in-place methods (`descendants!`, `ancestors!`).
60+
2061
You can get all the attributes of a node using the [`node_attributes`](@ref) function:
2162

2263
```@example usepkg

0 commit comments

Comments
 (0)