Skip to content

Commit

Permalink
nearly finished tests for context plotting :)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmaccode authored May 12, 2024
1 parent 74c1c67 commit 7778709
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 6 deletions.
33 changes: 28 additions & 5 deletions src/Contexts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Creates a new `:div` for `comp` and concatenates all provided `cons` vertically.
```
"""
function vcat(comp::AbstractContext, cons::AbstractContext ...)
newdiv = div(randstring(3))
newdiv = div(gen_ref(3))
style!(comp.window, "display" => "inline-block")
push!(newdiv, comp.window)
push!(newdiv, br())
Expand All @@ -51,14 +51,14 @@ Creates a new `:div` for `comp` and concatenates all provided `cons` horizontall
```
"""
function hcat(comp::AbstractContext, cons::AbstractContext ...)
newdiv = div(randstring(3))
newdiv = div(gen_ref(3))
style!(comp.window, "display" => "inline-block")
push!(newdiv, comp.window)
[begin
style!(co.window, "display" => "inline-block")
push!(newdiv, co.window)
end for co in cons]
newdiv
newdiv::Component{:div}
end

"""
Expand All @@ -77,7 +77,7 @@ function vcat(comp::Component{:div}, cons::AbstractContext ...)
style!(con.window, "display" => "inline-block")
push!(comp[:children], con.window)
end for con in cons]
comp
comp::Component{:div}
end

"""
Expand All @@ -98,6 +98,26 @@ function hcat(comp::Component{:div}, cons::AbstractContext ...)
comp
end

function vcat(comp::Component{:div}, cons::Component{:div} ...)
push!(comp, br())
[begin
style!(con, "display" => "inline-block")
push!(comp[:children], con)
end for con in cons]
comp::Component{:div}
end


function hcat(comp::Component{:div}, cons::Component{:div} ...)
push!(comp, br())
[begin
style!(con, "display" => "inline-block")
push!(comp[:children], con)
end for con in cons]
comp::Component{:div}
end


push!(comp::Component{:div}, cons::AbstractContext ...) = hcat(comp, cons ...)

"""
Expand Down Expand Up @@ -209,12 +229,15 @@ con = context(500, 500) do con::Context
end
```
"""
function context(f::Function = c::Context -> c::Context, width::Int64 = 500, height::Int64= 720, margin::Pair{Int64, Int64} = 0 => 0)
function context(f::Function, width::Int64 = 500, height::Int64= 720, margin::Pair{Int64, Int64} = 0 => 0)
con::Context = Context(width, height, margin)
f(con)
con::Context
end

context(width::Int64 = 500, height::Int64= 720, margin::Pair{Int64, Int64} = 0 => 0) = begin
context(c::Context -> c::Context, width, height, margin)
end
"""
```julia
context(f::Function, con::Context, width::Int64 = 1280, height::Int64= 720, margin::Pair{Int64, Int64} = 1 => 1) -> ::Context
Expand Down
2 changes: 1 addition & 1 deletion src/Gattino.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ using Gattino
colors = Gattino.make_gradient((1, 100, 120), 10, 30, 10, -10)
circs = []
for e in 1:length(colors)
circy = Gattino.circle("$e", cx = 5 + (6 * e), cy = 50, r = 5)
circy = Gattino.circle("\$e", cx = 5 + (6 * e), cy = 50, r = 5)
style!(circy, "fill" => colors[e])
push!(circs, circy)
end
Expand Down
38 changes: 38 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,44 @@ using Gattino
end
end
@testset "context plotting" verbose = true begin
newcon = context() do con::Context
group!(con, "layer1") do g::Group
Gattino.text!(g, 5, 5, "tests", "fill" => "white")
Gattino.line!(g, 5 => 5, 5 => 10)
end
group!(con, "scaledl") do g::Group
Gattino.line!(g, [5, 10, 15], [5, 10, 15])
Gattino.line!(g, ['c', 'd', 'a'], [5, 10, 15])
end
group!(con, "grid") do g::Group
Gattino.grid!(g, 4)
Gattino.gridlabels!(g, [5, 10, 15], [5, 10, 15], 4)
end
Gattino.labeled_grid!(con, [5, 10, 15], [5, 10, 15], [10], [10])
group!(con, "points2") do g::Group
Gattino.points!(g, randn(100), randn(100))
end
group!(con, "back") do g::Group
axislabels!(g, "hello", "world")
axes!(g)
end
group!(con, "bars") do g::Group
Gattino.hist_plot!(g, [5, 10, 15], [32, 26, 23])
end
group!(con, "moreplots") do g::Group
Gattino.scatter_plot!(g, [5, 10, 15], [5, 10, 11])
Gattino.line_plot!(g, ["h", "o", "a", "a"], [5, 20, 11, 8])
end
end
@testset "line and text annotations" begin
@test length(con.window[:children]["layer1"][:children]) == 2
@test con.window[:children]["layer1"][:children][1]["text"] == "tests"
end
@testset "grid" begin
@test length(con.window[:children]["grid"]) == 16
end
@testset "feature plotting (points, bars, line!)" begin

end
end
end

0 comments on commit 7778709

Please sign in to comment.