You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/the_mtg/our_implementation.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,7 +36,7 @@ Here is a simple description of each field:
36
36
-`attributes`: node values (for example length, diameter, color, 3D position).
37
37
-`traversal_cache`: saved traversal results used to speed up repeated operations.
38
38
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).
40
40
41
41
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:
42
42
@@ -112,7 +112,7 @@ node_mtg(mtg)
112
112
```
113
113
114
114
```@example usepkg
115
-
node_attributes(mtg)
115
+
attributes(mtg, format=:dict)
116
116
```
117
117
118
118
The package also provide helper functions to access the MTG encoding of the node directly:
If you call the same traversal many times in a simulation loop, look at [Performance Considerations](@ref), especially in-place methods (`descendants!`, `ancestors!`).
60
60
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):
62
62
63
63
```@example usepkg
64
-
node_attributes(mtg)
64
+
attributes(mtg, format=:dict)
65
65
```
66
66
67
67
!!! note
@@ -89,13 +89,13 @@ node_5.Length
89
89
90
90
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.
91
91
92
-
The previous notations are both equivalent to:
92
+
The previous notations are equivalent to:
93
93
94
94
```@example usepkg
95
-
node_attributes(node_5)[:Length]
95
+
attribute(node_5, :Length)
96
96
```
97
97
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.
99
99
100
100
For day-to-day use, the simpler APIs are usually clearer:
101
101
@@ -151,10 +151,10 @@ The function can also help get the nodes directly if we don't pass any attribute
151
151
descendants(mtg)
152
152
```
153
153
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:
155
155
156
156
```@example usepkg
157
-
node_attributes.(descendants(mtg))
157
+
[attributes(node, format=:dict) for node in descendants(mtg)]
Copy file name to clipboardExpand all lines: docs/src/tutorials/3.transform_mtg.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -274,7 +274,7 @@ end
274
274
275
275
## Mutate an MTG
276
276
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:
Copy file name to clipboardExpand all lines: docs/src/tutorials/6.add_remove_nodes.md
+6-15Lines changed: 6 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -132,13 +132,7 @@ The MTG encoding field of the newly-created root node (`node_mtg(mtg_2)`) used s
132
132
#### Node attributes
133
133
134
134
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`).
142
136
143
137
If you just need to pass attributes values to a node, you can do as follows:
We use `mtg_2[1]` here to get the first child of the root node.
@@ -324,10 +318,7 @@ insert_siblings!(
324
318
```
325
319
326
320
!!! 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`.
0 commit comments