Skip to content

Commit c3ca7ce

Browse files
committed
Simplify doc for first-time users
1 parent c396775 commit c3ca7ce

2 files changed

Lines changed: 19 additions & 17 deletions

File tree

docs/src/tutorials/1.manipulate_node.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,28 +149,28 @@ node_5 = get_node(mtg, 5)
149149
get_root(node_5)
150150
```
151151

152-
### Get the attributes
152+
### Read and set attribute values
153153

154-
This section has its own tutorial! Head over the next page to learn how to get the nodes attributes.
154+
To read one value from a node:
155155

156-
## Columnar Attribute Backend
156+
```@example usepkg
157+
leaf = get_node(mtg, 5)
158+
leaf[:Width]
159+
```
157160

158-
By default, `read_mtg` now loads attributes using a typed columnar backend (per symbol). The node API remains simple:
161+
To set one value:
159162

160163
```@example usepkg
161-
leaf = get_node(mtg, 5)
162-
attribute(leaf, :Width)
163-
attribute!(leaf, :new_var, 1.0)
164-
attribute_names(leaf)
165-
attributes(leaf, format=:namedtuple)
164+
leaf[:Width] = 1.0
165+
leaf[:Width]
166166
```
167167

168-
For schema-level operations on one symbol:
168+
You can also use the explicit API:
169169

170170
```@example usepkg
171-
add_column!(mtg, :Leaf, :temperature, Float64, default=20.0)
172-
rename_column!(mtg, :Leaf, :temperature, :temp)
173-
drop_column!(mtg, :Leaf, :temp)
171+
attribute(leaf, :Width)
172+
attribute!(leaf, :new_var, 1.0)
173+
attributes(leaf, format=:dict)
174174
```
175175

176-
`node_attributes(node)` is still available for compatibility, but new code should prefer `attribute`/`attribute!`/`attributes`.
176+
For more examples on querying values in a subtree (descendants, ancestors, filters), continue to [Traversal, descendants, ancestors and filters](@ref).

docs/src/tutorials/2.descendants_ancestors_filters.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,13 @@ The previous notations are both equivalent to:
9595
node_attributes(node_5)[:Length]
9696
```
9797

98-
`node_attributes(node_5)` returns the node attribute container view for this node (columnar backend by default), so reading and writing through it does update the MTG.
98+
`node_attributes(node_5)` gives access to all attributes of this node.
9999

100-
However, we still recommend the higher-level APIs (`node[:attr]`, `attribute(node, :attr)`, and `attribute!(node, :attr, value)`) because they are clearer and keep user code backend-agnostic.
100+
For day-to-day use, the simpler APIs are usually clearer:
101101

102-
That is why the package implements the more generic `node_5[:Length]` notation that works with any structure used for the attributes, which helps develop more generic code.
102+
- `node[:attr]`
103+
- `attribute(node, :attr)`
104+
- `attribute!(node, :attr, value)`
103105

104106
To get the names of all attributes available in the node subtree, you can use [`get_attributes`](@ref):
105107

0 commit comments

Comments
 (0)