Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add visual regression tests #24

Merged
merged 6 commits into from
Nov 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ This package is not released yet so a bit awkward to set up. Here are the steps:

```julia
Pkg.clone("https://github.com/SimonDanisch/Makie.jl.git")
Pkg.clone("https://github.com/SimonDanisch/AbstractNumbers.jl.git")
Pkg.checkout("GLAbstraction")
Pkg.checkout("GLVisualize")
Pkg.checkout("GeometryTypes")

# For UV examples, e.g. earth texture on sphere, or textured cat
Pkg.checkout("MeshIO")

# For image loading
Pkg.add("ImageMagick")

# For precompilation
Pkg.clone("https://github.com/SimonDanisch/PackageCompiler.jl.git")
Pkg.build("PackageCompiler")
Expand Down
4 changes: 4 additions & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ Media
Juno
ModernGL
GLFW 1.4.1

@windows ImageMagick
@linux ImageMagick
@osx QuartzImageIO
7 changes: 4 additions & 3 deletions src/Makie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ using Base: RefValue
struct Backend{B} end


include("plotsbase/utils.jl")
include("plotutils/utils.jl")

include("plotsbase/scene.jl")
include("plotsbase/converts.jl")
include("plotsbase/conversions.jl")
include("plotutils/units.jl")

const makie = Scene{:makie}

include("plotutils/layout.jl")

include("plotsbase/atomics.jl")
# The actual implementation

include("atomics/shared.jl")
include("atomics/scatter.jl")
include("atomics/lines.jl")
Expand Down
30 changes: 28 additions & 2 deletions src/atomics/scatter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,39 @@ function expand_for_glvisualize(kw_args)
end


# function scatter()
# marker
# strokecolor
# strokewidth
# glowcolor
# glowwidth
# markersize
# rotations
# if haskey(scene, :positions)
# positions = to_positions(positions)
# elseif haskey(scene, :z)
# xyz = getindex.(scene, (:x, :y, :z))
# positions = to_positions(xyz)
# elseif haskey(scene, :y)
# xy = getindex.(scene, (:x, :y, :z))
# positions = to_positions(xy)
# end
# begin
# color = to_color(color)
# end
# begin
# colormap = to_colormap(colormap)
# intensity = to_intensity(intensity)
# colornorm = to_colornorm(colornorm, intensity)
# end
# end
#
function _scatter(scene, kw_args)
attributes = scatter_defaults(scene, kw_args)
gl_data = expand_for_glvisualize(attributes)
shape = to_signal(attributes[:marker])
main = (shape, to_signal(attributes[:positions]))
viz = GLVisualize.sprites(main, Style(:default), gl_data)
viz = GLVisualize.assemble_shader(viz).children[]
viz = visualize(main, Style(:default), gl_data)
insert_scene!(scene, :scatter, viz, attributes)
end

Expand Down
21 changes: 21 additions & 0 deletions src/plotsbase/atomics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,21 @@ end
colornorm = ((b, colornorm) -> to_colornorm(b, colornorm, heatmap))(colornorm)
end

@default function axis(scene, kw_args)
axisnames = to_text(axisnames)

showticks = to_bool(showticks)
tickfont2d = to_font(tickfont2d)
tickfont3d = to_font(tickfont3d)
showaxis = to_bool(showaxis)
showgrid = to_bool(showgrid)

scalefuncs = to_scalefunc(scalefuncs)
gridcolors = to_color(gridcolors)
gridthickness = to_3floats(gridthickness)
axiscolors = to_color(axiscolors)
end


function expand_kwargs(scene, kw_args)
# TODO get in all the shorthands from Plots.jl
Expand Down Expand Up @@ -280,6 +295,12 @@ const atomic_funcs = (
:legend => """
legend(series, labels)
creates a legend from an array of plots and labels
""",

:axis => """
axis(xrange, yrange, [zrange])

Creates a axis from a x,y,z ranges
"""
)

Expand Down
32 changes: 7 additions & 25 deletions src/plotsbase/axis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,6 @@ function labelposition(ranges, dim)
pos .* axis_vec .- (normal * 0.2f0)
end

@default function axis(scene, kw_args)
axisnames = to_text(axisnames)
visible = to_bool(visible)

showticks = to_bool(showticks)
tickfont2d = to_font(tickfont2d)
tickfont3d = to_font(tickfont3d)
showaxis = to_bool(showaxis)
showgrid = to_bool(showgrid)

scalefuncs = to_scalefunc(scalefuncs)
gridcolors = to_color(gridcolors)
gridthickness = to_3floats(gridthickness)
axiscolors = to_color(axiscolors)

end

function GeometryTypes.widths(x::Range)
mini, maxi = Float32.(extrema(x))
Expand Down Expand Up @@ -90,22 +74,20 @@ function draw_axis(
return
end

function axis(ranges...; kw_args...)
axis(to_node(ranges); kw_args...)
function axis(scene::Scene, x, y, attributes::Dict)
axis(scene, to_node((x, y)), attributes)
end

"""
Creates an axis visualization for a certain bounding box.
function axis(scene::Scene, x, y, z, attributes::Dict)
axis(scene, to_node((x, y, z)), attributes)
end

## Attributes:

$(sprint(x-> Markdown.plain(x, Docs.doc(axis_defaults))))
"""
function axis(ranges::Node{<: NTuple{N}}; kw_args...) where N
function axis(scene::Scene, ranges::Node{<: NTuple{N}}, attributes::Dict) where N
textbuffer = TextBuffer(Point{N, Float32}(0))
linebuffer = LinesegmentBuffer(Point{N, Float32}(0))
scene = get_global_scene()
attributes = axis_defaults(scene, expand_kwargs(scene, kw_args))
attributes = axis_defaults(scene, attributes)
tickfont = N == 2 ? :tickfont2d : :tickfont3d
names = (
:axisnames, :visible, :showaxis, :showticks,
Expand Down
16 changes: 11 additions & 5 deletions src/plotsbase/converts.jl → src/plotsbase/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ to_index_buffer(b, x) = error(
`NTuple{2, AbstractArray{Float}}` for 2D points
"""
function to_positions(b, x::Tuple{<: AbstractArray, <: AbstractArray})
Point{2, Float32}.(x...)
to_position.(b, x...)
end

"""
Expand Down Expand Up @@ -193,6 +193,10 @@ function to_position(b, x::VecLike{N}) where N
Point{N, Float32}(x)
end

function to_position(b, x, y)
Point{2, Float32}(to_absolute(b, x), to_absolute(b, y))
end


"""
to_array(b, arraylike)
Expand Down Expand Up @@ -330,18 +334,20 @@ function to_spritemarker(b, marker::Symbol)
end


to_spritemarker(b, marker::Vector{Char}) = String(marker)
to_spritemarker(b, marker::String) = marker
to_spritemarker(b, marker::AbstractVector{Char}) = String(marker)

"""
Vector of anything that is accepted as a single marker will give each point it's own marker.
Note that it needs to be a uniform vector with the same element type!
"""
function to_spritemarker(b, marker::Vector)
function to_spritemarker(b, marker::AbstractVector)
println(typeof(marker))
marker = map(marker) do sym
to_spritemarker(b, sym)
end
if isa(marker, Vector{Char})
to_spritemarker(b, marker)
if isa(marker, AbstractVector{Char})
String(marker)
else
marker
end
Expand Down
3 changes: 2 additions & 1 deletion src/plotsbase/output.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ function scene2image(screen::Screen)
yield()
render_frame(screen) # let it render
ModernGL.glFinish()
return GLWindow.screenbuffer(screen)
return Images.clamp01nan.(GLWindow.screenbuffer(screen))
end

function scene2image(scene::Scene)
screen = getscreen(scene)
if screen != nothing
Expand Down
26 changes: 19 additions & 7 deletions src/plotsbase/scene.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ end

attributes(scene::Scene) = copy(scene.data)

scene_node(x) = to_node(x)
# there is not much use in having scene being a node, besides that it's awkward to work with
scene_node(x::Scene) = x
const current_backend = Ref(:makie)

function Scene(args...)
Expand All @@ -53,11 +56,11 @@ end
function Scene(parent::Scene{Backend}, scene::Dict, name = :scene) where Backend
data = Dict{Symbol, Any}()
for (k, v) in scene
data[Symbol(k)] = to_node(v)
data[Symbol(k)] = scene_node(v)
end
Scene{Backend}(name, Nullable(parent), data, nothing)
end
function Scene(parent::Scene{Backend}, name = :scene; attributes...) where Backend
function Scene(parent::Scene{Backend}, name::Symbol = :scene; attributes...) where Backend
Scene(parent, Dict{Symbol, Any}(attributes), name)
end

Expand All @@ -68,7 +71,7 @@ end

function (::Type{Scene{Backend}})(pair1::Pair, tail::Pair...) where Backend
args = [pair1, tail...]
Scene(Dict(map(x-> x[1] => to_node(x[2]), args)))
Scene(Dict(map(x-> x[1] => scene_node(x[2]), args)))
end


Expand All @@ -85,7 +88,6 @@ and manually added via `show` by doing e.g.
"""
function show!(scene::Scene{Backend}, childscene::Scene{Backend}) where Backend
camera = to_value(childscene, :camera) # should always be available!
println(camera)
screen = getscreen(scene)
cams = collect(keys(screen.cameras))
viz = native_visual(childscene)
Expand Down Expand Up @@ -281,8 +283,14 @@ function Scene(;
resize!(w, Int.(resolution)...)

GLVisualize.add_screen(w)

dict = map(filter((k, v)-> k != :cursor_position, w.inputs)) do k_v
filtered = filter(w.inputs) do k, v
!(k in (
:cursor_position,
:window_size,
:framebuffer_size
))
end
dict = map(filtered) do k_v
k_v[1] => to_node(k_v[2])
end
dict[:screen] = w
Expand Down Expand Up @@ -316,7 +324,7 @@ function setindex!(s::Scene, obj, key::Symbol)
if haskey(s, key) # if in dictionary, just push a new value to the signal
push!(s[key], obj)
else
s.data[key] = to_node(obj)
s.data[key] = scene_node(obj)
end
end

Expand Down Expand Up @@ -408,3 +416,7 @@ function find_default(scene, kw_args, func, attribute)
Please provide attribute $attribute for $func")
end
end

function GeometryTypes.widths(scene::Scene)
widths(getscreen(scene))
end
2 changes: 0 additions & 2 deletions src/plotsbase/signals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,12 @@ function _unsafe_getindex!(dest::ArrayNode, src::AbstractArray, Is::Union{Real,
return dest
end


to_node(obj::AbstractNode) = obj
function to_node(obj::AbstractNode, f)
to_node(map(f, to_signal(obj)), f)
end
to_node(obj, f = identity) = to_node(Signal(f(obj)), f)
to_node(obj::Signal, f = identity) = Node(map(f, obj), f)
to_node(obj::Scene, f = identity) = obj
function to_node(obj::Signal{AT}, f::F = identity) where {AT <: AbstractArray, F}
A = value(obj)
ArrayNode{eltype(A), ndims(A), F, AT}(obj, f)
Expand Down
2 changes: 1 addition & 1 deletion src/plotsbase/themes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function default_theme(scene)
legend = begin
backgroundcolor = to_color(:white)
strokecolor = to_color(RGBA(0.3, 0.3, 0.3, 0.9))
strokewidth = to_float(2)
strokewidth = to_float(1)
position = to_position((0, 1))
gap = to_float(20)
textgap = to_float(15)
Expand Down
Loading