Skip to content

Commit cd3ca34

Browse files
authored
Merge pull request #193 from tkf/setter
Document property accessors
2 parents 5b5d789 + a2e4175 commit cd3ca34

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

docs/src/userguide/vlspec.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,30 @@ The resulting `VLSpec` object is indistinguishable from one that is created via
104104

105105
The main benefit of this approach is that one can directly leverage JSON vega-lite examples and code.
106106

107+
## Manipulating `VLSpec` object directly
108+
109+
Vega-Lite properties can be directly accessed as properties of the `VLSpec` object.
110+
111+
```julia
112+
julia> spec = [(a=x, b=exp(x), c=sin(x)) for x in 0:10] |>
113+
@vlplot(:point, x=:a, y=:b);
114+
115+
julia> spec.mark
116+
:point
117+
118+
julia> spec.encoding.x.field
119+
"a"
120+
```
121+
122+
To modify properties, use [Setfield.jl](https://github.com/jw3126/Setfield.jl):
123+
124+
```julia
125+
julia> using Setfield # imports `@set` etc.
126+
127+
julia> spec2 = @set spec.mark = :line
128+
spec3 = @set spec2.encoding.y.field = "c"
129+
```
130+
107131
## Loading and saving vega-lite specifications
108132

109133
The `load` and `save` functions can be used to load and save vega-lite specifications to and from disc. The following example loads a vega-lite specification from a file named `myfigure.vegalite`:

0 commit comments

Comments
 (0)