Skip to content

Commit a8635c9

Browse files
committed
Replace deprecated functions by the new functions
1 parent c3ca7ce commit a8635c9

4 files changed

Lines changed: 16 additions & 25 deletions

File tree

docs/src/the_mtg/our_implementation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Here is a simple description of each field:
3636
- `attributes`: node values (for example length, diameter, color, 3D position).
3737
- `traversal_cache`: saved traversal results used to speed up repeated operations.
3838

39-
The values of these fields are accessed with helper functions such as [`node_id`](@ref), [`parent`](@ref), [`children`](@ref), [`node_mtg`](@ref), and [`node_attributes`](@ref).
39+
The values of these fields are accessed with helper functions such as [`node_id`](@ref), [`parent`](@ref), [`children`](@ref), [`node_mtg`](@ref), [`attribute`](@ref), and [`attributes`](@ref).
4040

4141
The MTG field of a node describes how the node is positioned in the graph: link with parent (`/`, `<`, `+`), symbol, index, and scale (see [Node MTG and attributes](@ref) and [The MTG section](@ref) for more details). It is stored as [`NodeMTG`](@ref) or [`MutableNodeMTG`](@ref). These types have four fields:
4242

@@ -112,7 +112,7 @@ node_mtg(mtg)
112112
```
113113

114114
```@example usepkg
115-
node_attributes(mtg)
115+
attributes(mtg, format=:dict)
116116
```
117117

118118
The package also provide helper functions to access the MTG encoding of the node directly:

docs/src/tutorials/2.descendants_ancestors_filters.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ descendants(mtg, :Length, symbol=:Leaf, ignore_nothing=true)
5858
!!! tip
5959
If you call the same traversal many times in a simulation loop, look at [Performance Considerations](@ref), especially in-place methods (`descendants!`, `ancestors!`).
6060

61-
You can get all the attributes of a node using the [`node_attributes`](@ref) function:
61+
You can get all the attributes of a node as a dictionary snapshot using [`attributes`](@ref):
6262

6363
```@example usepkg
64-
node_attributes(mtg)
64+
attributes(mtg, format=:dict)
6565
```
6666

6767
!!! note
@@ -89,13 +89,13 @@ node_5.Length
8989

9090
This one even has autocompletion! It means that you can type `node_5.` and then press `TAB` to see all the available attributes, and when you start typing the name of an attribute, it will suggest the completion of the name.
9191

92-
The previous notations are both equivalent to:
92+
The previous notations are equivalent to:
9393

9494
```@example usepkg
95-
node_attributes(node_5)[:Length]
95+
attribute(node_5, :Length)
9696
```
9797

98-
`node_attributes(node_5)` gives access to all attributes of this node.
98+
Use [`attributes`](@ref) when you want all values from one node at once.
9999

100100
For day-to-day use, the simpler APIs are usually clearer:
101101

@@ -151,10 +151,10 @@ The function can also help get the nodes directly if we don't pass any attribute
151151
descendants(mtg)
152152
```
153153

154-
This is useful to get more information about the nodes, like their scale, symbol, index, or link to their parent. Of course you can still get their attributes using the `node_attributes` function, *e.g.*:
154+
This is useful to get more information about the nodes, like their scale, symbol, index, or link to their parent. You can still get attributes for each returned node, for example:
155155

156156
```@example usepkg
157-
node_attributes.(descendants(mtg))
157+
[attributes(node, format=:dict) for node in descendants(mtg)]
158158
```
159159

160160
## Ancestors

docs/src/tutorials/3.transform_mtg.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ end
274274

275275
## Mutate an MTG
276276

277-
For users coming from R, we also provide the `@mutate_mtg!` macro that is similar to [`transform!`](@ref) but uses a more `tidyverse`-alike syntax. All values coming from the MTG node must be preceded by a `node.`, as with the `.data$` in the `tidyverse`. The names of the attributes are shortened to just `node.attr_name` instead of `node_attributes(node).attr_name` though. Here's an example usage:
277+
For users coming from R, we also provide the `@mutate_mtg!` macro that is similar to [`transform!`](@ref) but uses a more `tidyverse`-alike syntax. All values coming from the MTG node must be preceded by `node.`, as with `.data$` in the `tidyverse`. Attribute names are therefore written as `node.attr_name`. Here's an example usage:
278278

279279
```@example usepkg
280280
@mutate_mtg!(mtg, volume = π * 2 * node.Length, symbol = :I)

docs/src/tutorials/6.add_remove_nodes.md

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,7 @@ The MTG encoding field of the newly-created root node (`node_mtg(mtg_2)`) used s
132132
#### Node attributes
133133

134134
We can also provide attributes for the new node using the `attr_fun` argument. `attr_fun` expects a function that computes new attributes based on the input node. This function must return
135-
attribute values of the same type as the one used for other nodes attributes in the MTG (*e.g.* `Dict` or `NamedTuple`).
136-
137-
To know what is the type used for the attributes of your MTG, you can use `typeof` as follows:
138-
139-
```@example usepkg
140-
typeof(node_attributes(mtg))
141-
```
135+
attribute values (*e.g.* a `Dict{Symbol,Any}` or a `NamedTuple`).
142136

143137
If you just need to pass attributes values to a node, you can do as follows:
144138

@@ -148,10 +142,10 @@ mtg_2 = deepcopy(mtg)
148142
insert_child!(
149143
mtg_2,
150144
NodeMTG(:/, :Axis, 0, 2),
151-
node -> Dict{Symbol, Any}(:length => 2, :area => 0.1)
145+
node -> Dict{Symbol, Any}(:length => 2, :area => 0.1)
152146
)
153147
154-
node_attributes(mtg_2[1])
148+
attributes(mtg_2[1], format=:dict)
155149
```
156150

157151
But we can also compute our attributes based on other nodes data:
@@ -162,10 +156,10 @@ mtg_2 = deepcopy(mtg)
162156
insert_child!(
163157
mtg_2,
164158
NodeMTG(:/, :Axis, 0, 2),
165-
node -> Dict{Symbol, Any}(:total_length => sum(descendants(node, :length, ignore_nothing = true)))
159+
node -> Dict{Symbol, Any}(:total_length => sum(descendants(node, :length, ignore_nothing = true)))
166160
)
167161
168-
node_attributes(mtg_2[1])
162+
attributes(mtg_2[1], format=:dict)
169163
```
170164

171165
We use `mtg_2[1]` here to get the first child of the root node.
@@ -324,10 +318,7 @@ insert_siblings!(
324318
```
325319

326320
!!! danger
327-
The function used to compute the attributes must return data using the same structure as the one used for the other nodes attributes. In our example it returns a `Dict{Symbol, Any}`, but it can be different depending on your MTG. To know which structure you should use, use this command:
328-
```julia
329-
typeof(node_attributes(mtg))
330-
```
321+
The function used to compute attributes should return either a `Dict{Symbol,Any}` or a `NamedTuple`.
331322

332323
Let's see the results for the area of our leaves:
333324

0 commit comments

Comments
 (0)