Skip to content

Commit c93b7ca

Browse files
committed
add an example to manual
1 parent 4a5e6ec commit c93b7ca

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

docs/make.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ makedocs(
3636
"Interactive" => [
3737
"Pyramid" => "man/pyramid.md",
3838
"Nations" => "man/nations.md",
39-
"Movies" => "man/movies.md"
39+
"Movies" => "man/movies.md",
40+
"Polygon" => "man/polygon.md"
4041
],
4142
"API" => Any[
4243
"Functions" => "lib/functions.md",

docs/src/man/polygon.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Example
2+
3+
```@example
4+
using InMemoryDatasets, StatisticalGraphics
5+
6+
function npolygon(n, sangle, radius)
7+
stepsize = 360 / n
8+
res = Vector{Tuple{Float64,Float64}}(undef, n)
9+
for i in 1:n
10+
degree = (i - 1) * stepsize + sangle
11+
res[i] = (cosd(degree) * radius, sind(degree) * radius)
12+
end
13+
res
14+
end
15+
16+
17+
ds = Dataset(sangle=range(0, 500, step=10))
18+
insertcols!(ds, :radius => [0.95^i for i in 0:nrow(ds)-1])
19+
insertcols!(ds, :n => (3:8...,))
20+
flatten!(ds, :n)
21+
modify!(ds, (3, 1, 2) => byrow(npolygon) => :polygon)
22+
modify!(ds, :polygon => byrow(x -> 1:length(x)) => :vert)
23+
flatten!(ds, [:polygon, :vert])
24+
modify!(ds, :polygon => splitter => [:x, :y])
25+
modify!(ds, :radius => byrow(x -> 1.1 - x) => :opacity)
26+
27+
sgmanipulate(groupby(ds, :n),
28+
Polygon(x=:x, y=:y, id=:sangle,
29+
opacityresponse=:opacity,
30+
colorresponse=:opacity,
31+
outlinecolor=:white,
32+
outlinethickness=0.5
33+
),
34+
nominal=:opacity,
35+
width=400,
36+
xaxis=Axis(show=false),
37+
yaxis=Axis(show=false),
38+
legend=false,
39+
wallcolor=:lightgray
40+
)
41+
```

0 commit comments

Comments
 (0)