|
| 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